replaced '4096' with definition SPI_FLASH_SEC_SIZE from header file

This commit is contained in:
Alex Shepherd
2016-08-20 17:36:47 +12:00
parent d3059d2f4e
commit 3eee73f6cd
2 changed files with 47 additions and 47 deletions

View File

@@ -29,13 +29,13 @@
// //
//------------------------------------------------------------------------ //------------------------------------------------------------------------
#include "NmraDcc.h" #include "NmraDcc.h"
#if defined(ESP8266) #if defined(ESP8266)
#include <EEPROM.h> #include <EEPROM.h>
#else #else
#include <avr/eeprom.h> #include <avr/eeprom.h>
#endif #endif
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// DCC Receive Routine // DCC Receive Routine
@@ -454,32 +454,32 @@ void ackCV(void)
notifyCVAck() ; notifyCVAck() ;
} }
uint8_t readEEPROM( unsigned int CV ) { uint8_t readEEPROM( unsigned int CV ) {
#if defined(ESP8266) #if defined(ESP8266)
return EEPROM.read(CV) ; return EEPROM.read(CV) ;
#else #else
return eeprom_read_byte( (uint8_t*) CV ); return eeprom_read_byte( (uint8_t*) CV );
#endif #endif
} }
void writeEEPROM( unsigned int CV, uint8_t Value ) { void writeEEPROM( unsigned int CV, uint8_t Value ) {
#if defined(ESP8266) #if defined(ESP8266)
EEPROM.write(CV, Value) ; EEPROM.write(CV, Value) ;
EEPROM.commit(); EEPROM.commit();
#else #else
eeprom_write_byte( (uint8_t*) CV, Value ) ; eeprom_write_byte( (uint8_t*) CV, Value ) ;
#endif #endif
} }
bool readyEEPROM() { bool readyEEPROM() {
#if defined(ESP8266) #if defined(ESP8266)
return true; return true;
#else #else
return eeprom_is_ready(); return eeprom_is_ready();
#endif #endif
} }
uint8_t validCV( uint16_t CV, uint8_t Writable ) uint8_t validCV( uint16_t CV, uint8_t Writable )
{ {
if( notifyCVResetFactoryDefault && (CV == CV_MANUFACTURER_ID ) && Writable ) if( notifyCVResetFactoryDefault && (CV == CV_MANUFACTURER_ID ) && Writable )
@@ -490,7 +490,7 @@ uint8_t validCV( uint16_t CV, uint8_t Writable )
uint8_t Valid = 1 ; uint8_t Valid = 1 ;
if( CV > MAXCV ) if( CV > MAXCV )
Valid = 0 ; Valid = 0 ;
if( Writable && ( ( CV ==CV_VERSION_ID ) || (CV == CV_MANUFACTURER_ID ) ) ) if( Writable && ( ( CV ==CV_VERSION_ID ) || (CV == CV_MANUFACTURER_ID ) ) )
@@ -506,7 +506,7 @@ uint8_t readCV( unsigned int CV )
if( notifyCVRead ) if( notifyCVRead )
return notifyCVRead( CV ) ; return notifyCVRead( CV ) ;
Value = readEEPROM(CV); Value = readEEPROM(CV);
return Value ; return Value ;
} }
@@ -515,16 +515,16 @@ uint8_t writeCV( unsigned int CV, uint8_t Value)
if( notifyCVWrite ) if( notifyCVWrite )
return notifyCVWrite( CV, Value ) ; return notifyCVWrite( CV, Value ) ;
if( readEEPROM( CV ) != Value ) if( readEEPROM( CV ) != Value )
{ {
writeEEPROM( CV, Value ) ; writeEEPROM( CV, Value ) ;
if( notifyCVChange ) if( notifyCVChange )
notifyCVChange( CV, Value) ; notifyCVChange( CV, Value) ;
} }
return readEEPROM( CV ) ; return readEEPROM( CV ) ;
} }
uint16_t getMyAddr(void) uint16_t getMyAddr(void)
{ {
uint16_t Addr ; uint16_t Addr ;
@@ -1010,9 +1010,9 @@ void NmraDcc::initAccessoryDecoder( uint8_t ManufacturerId, uint8_t VersionId, u
void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV ) void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV )
{ {
#if defined(ESP8266) #if defined(ESP8266)
EEPROM.begin(4096); EEPROM.begin(MAXCV);
#endif #endif
// Clear all the static member variables // Clear all the static member variables
memset( &DccRx, 0, sizeof( DccRx) ); memset( &DccRx, 0, sizeof( DccRx) );
@@ -1058,7 +1058,7 @@ uint8_t NmraDcc::isSetCVReady(void)
{ {
if(notifyIsSetCVReady) if(notifyIsSetCVReady)
return notifyIsSetCVReady(); return notifyIsSetCVReady();
return readyEEPROM(); return readyEEPROM();
} }
#ifdef DCC_DEBUG #ifdef DCC_DEBUG

View File

@@ -89,12 +89,12 @@ typedef struct
#define CV_VERSION_ID 7 #define CV_VERSION_ID 7
#define CV_MANUFACTURER_ID 8 #define CV_MANUFACTURER_ID 8
#define CV_29_CONFIG 29 #define CV_29_CONFIG 29
#if defined(ESP8266) #if defined(ESP8266)
#define MAXCV 4096 #define MAXCV SPI_FLASH_SEC_SIZE
#else #else
#define MAXCV E2END // the upper limit of the CV value currently defined to max memory. #define MAXCV E2END // the upper limit of the CV value currently defined to max memory.
#endif #endif
typedef enum { typedef enum {
CV29_LOCO_DIR = 0b00000001, /** bit 0: Locomotive Direction: "0" = normal, "1" = reversed */ CV29_LOCO_DIR = 0b00000001, /** bit 0: Locomotive Direction: "0" = normal, "1" = reversed */