Исправления
This commit is contained in:
1435
eeprom.cpp
1435
eeprom.cpp
File diff suppressed because it is too large
Load Diff
62
eeprom.h
62
eeprom.h
@@ -20,21 +20,23 @@
|
||||
#define EEPROM_MaxError 6
|
||||
|
||||
static std::string _ErrorMessageEEPROM[EEPROM_MaxError] = {
|
||||
"",
|
||||
"Bad chip address",
|
||||
"I2C error (nack)",
|
||||
"Invalid parameter",
|
||||
"Data address out of range",
|
||||
"Memory allocation error"
|
||||
};
|
||||
"",
|
||||
"Bad chip address",
|
||||
"I2C error (nack)",
|
||||
"Invalid parameter",
|
||||
"Data address out of range",
|
||||
"Memory allocation error"
|
||||
};
|
||||
|
||||
/** EEPROM Class
|
||||
*/
|
||||
class EEPROM {
|
||||
public:
|
||||
enum TypeEeprom {T24C01=128,T24C02=256,T24C04=512,T24C08=1024,T24C16=2048,
|
||||
T24C32=4096,T24C64=8192,T24C128=16384,T24C256=32768,
|
||||
T24C512=65536,T24C1024=131072,T24C1025=131073} Type;
|
||||
enum TypeEeprom {
|
||||
T24C01 = 128, T24C02 = 256, T24C04 = 512, T24C08 = 1024, T24C16 = 2048,
|
||||
T24C32 = 4096, T24C64 = 8192, T24C128 = 16384, T24C256 = 32768,
|
||||
T24C512 = 65536, T24C1024 = 131072, T24C1025 = 131073
|
||||
} Type;
|
||||
|
||||
/**
|
||||
* Constructor, initialize the eeprom on i2c interface.
|
||||
@@ -52,7 +54,7 @@ public:
|
||||
* @param data byte to read (int8_t&)
|
||||
* @return none
|
||||
*/
|
||||
void read(uint32_t address, int8_t& data);
|
||||
void read(uint32_t address, int8_t &data);
|
||||
|
||||
/**
|
||||
* Random read short
|
||||
@@ -60,7 +62,7 @@ public:
|
||||
* @param data short to read (int16_t&)
|
||||
* @return none
|
||||
*/
|
||||
void read(uint32_t address, int16_t& data);
|
||||
void read(uint32_t address, int16_t &data);
|
||||
|
||||
/**
|
||||
* Random read long
|
||||
@@ -68,7 +70,7 @@ public:
|
||||
* @param data long to read (int32_t&)
|
||||
* @return none
|
||||
*/
|
||||
void read(uint32_t address, int32_t& data);
|
||||
void read(uint32_t address, int32_t &data);
|
||||
|
||||
/**
|
||||
* Random read float
|
||||
@@ -76,7 +78,7 @@ public:
|
||||
* @param data float to read (float&)
|
||||
* @return none
|
||||
*/
|
||||
void read(uint32_t address, float& data);
|
||||
void read(uint32_t address, float &data);
|
||||
|
||||
/**
|
||||
* Random read anything
|
||||
@@ -92,7 +94,7 @@ public:
|
||||
* @param data byte to read (int8_t&)
|
||||
* @return none
|
||||
*/
|
||||
void read(int8_t& data);
|
||||
void read(int8_t &data);
|
||||
|
||||
/**
|
||||
* Sequential read byte
|
||||
@@ -151,51 +153,50 @@ public:
|
||||
* @param size number of bytes to write (uint32_t)
|
||||
* @return none
|
||||
*/
|
||||
void write(uint32_t address, int8_t data[], uint32_t size);
|
||||
void write(uint32_t address, const int8_t data[], uint32_t size);
|
||||
|
||||
/**
|
||||
* Wait eeprom ready
|
||||
* @param none
|
||||
* @return none
|
||||
*/
|
||||
void ready(void);
|
||||
void ready();
|
||||
|
||||
/**
|
||||
* Get eeprom size in bytes
|
||||
* @param none
|
||||
* @return size in bytes (uint32_t)
|
||||
*/
|
||||
uint32_t getSize(void);
|
||||
uint32_t getSize();
|
||||
|
||||
/**
|
||||
* Get eeprom name
|
||||
* @param none
|
||||
* @return name (const char*)
|
||||
*/
|
||||
const char* getName(void);
|
||||
const char *getName();
|
||||
|
||||
/**
|
||||
* Clear eeprom (write with 0)
|
||||
* @param none
|
||||
* @return none
|
||||
*/
|
||||
void clear(void);
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Get the current error number (EEPROM_NoError if no error)
|
||||
* @param none
|
||||
* @return none
|
||||
*/
|
||||
uint8_t getError(void);
|
||||
/**
|
||||
* Get the current error number (EEPROM_NoError if no error)
|
||||
* @param none
|
||||
* @return none
|
||||
*/
|
||||
uint8_t getError();
|
||||
|
||||
/**
|
||||
* Get current error message
|
||||
* @param none
|
||||
* @return current error message(std::string)
|
||||
*/
|
||||
std::string getErrorMessage(void)
|
||||
{
|
||||
return(_ErrorMessageEEPROM[_errnum]);
|
||||
std::string getErrorMessage(void) const {
|
||||
return (_ErrorMessageEEPROM[_errnum]);
|
||||
}
|
||||
|
||||
//---------- local variables ----------
|
||||
@@ -208,7 +209,8 @@ private:
|
||||
uint8_t _page_number; // Number of page
|
||||
uint32_t _size; // Size in bytes
|
||||
bool checkAddress(uint32_t address); // Check address range
|
||||
static const char * const _name[]; // eeprom name
|
||||
static const char *const _name[]; // eeprom name
|
||||
//-------------------------------------
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user