Исправления
This commit is contained in:
1631
eeprom.cpp
1631
eeprom.cpp
File diff suppressed because it is too large
Load Diff
106
eeprom.h
106
eeprom.h
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// Includes
|
// Includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
|
|
||||||
@@ -20,22 +20,24 @@
|
|||||||
#define EEPROM_MaxError 6
|
#define EEPROM_MaxError 6
|
||||||
|
|
||||||
static std::string _ErrorMessageEEPROM[EEPROM_MaxError] = {
|
static std::string _ErrorMessageEEPROM[EEPROM_MaxError] = {
|
||||||
"",
|
"",
|
||||||
"Bad chip address",
|
"Bad chip address",
|
||||||
"I2C error (nack)",
|
"I2C error (nack)",
|
||||||
"Invalid parameter",
|
"Invalid parameter",
|
||||||
"Data address out of range",
|
"Data address out of range",
|
||||||
"Memory allocation error"
|
"Memory allocation error"
|
||||||
};
|
};
|
||||||
|
|
||||||
/** EEPROM Class
|
/** EEPROM Class
|
||||||
*/
|
*/
|
||||||
class EEPROM {
|
class EEPROM {
|
||||||
public:
|
public:
|
||||||
enum TypeEeprom {T24C01=128,T24C02=256,T24C04=512,T24C08=1024,T24C16=2048,
|
enum TypeEeprom {
|
||||||
T24C32=4096,T24C64=8192,T24C128=16384,T24C256=32768,
|
T24C01 = 128, T24C02 = 256, T24C04 = 512, T24C08 = 1024, T24C16 = 2048,
|
||||||
T24C512=65536,T24C1024=131072,T24C1025=131073} Type;
|
T24C32 = 4096, T24C64 = 8192, T24C128 = 16384, T24C256 = 32768,
|
||||||
|
T24C512 = 65536, T24C1024 = 131072, T24C1025 = 131073
|
||||||
|
} Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor, initialize the eeprom on i2c interface.
|
* Constructor, initialize the eeprom on i2c interface.
|
||||||
* @param sda sda i2c pin (PinName)
|
* @param sda sda i2c pin (PinName)
|
||||||
@@ -45,39 +47,39 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
EEPROM(PinName sda, PinName scl, uint8_t address, TypeEeprom type);
|
EEPROM(PinName sda, PinName scl, uint8_t address, TypeEeprom type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random read byte
|
* Random read byte
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
* @param data byte to read (int8_t&)
|
* @param data byte to read (int8_t&)
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void read(uint32_t address, int8_t& data);
|
void read(uint32_t address, int8_t &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random read short
|
* Random read short
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
* @param data short to read (int16_t&)
|
* @param data short to read (int16_t&)
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void read(uint32_t address, int16_t& data);
|
void read(uint32_t address, int16_t &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random read long
|
* Random read long
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
* @param data long to read (int32_t&)
|
* @param data long to read (int32_t&)
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void read(uint32_t address, int32_t& data);
|
void read(uint32_t address, int32_t &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random read float
|
* Random read float
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
* @param data float to read (float&)
|
* @param data float to read (float&)
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void read(uint32_t address, float& data);
|
void read(uint32_t address, float &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random read anything
|
* Random read anything
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -86,14 +88,14 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void read(uint32_t address, void *data, uint32_t size);
|
void read(uint32_t address, void *data, uint32_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current address read byte
|
* Current address read byte
|
||||||
* @param data byte to read (int8_t&)
|
* @param data byte to read (int8_t&)
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void read(int8_t& data);
|
void read(int8_t &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sequential read byte
|
* Sequential read byte
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -102,7 +104,7 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void read(uint32_t address, int8_t *data, uint32_t size);
|
void read(uint32_t address, int8_t *data, uint32_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write byte
|
* Write byte
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -110,7 +112,7 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void write(uint32_t address, int8_t data);
|
void write(uint32_t address, int8_t data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write short
|
* Write short
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -118,7 +120,7 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void write(uint32_t address, int16_t data);
|
void write(uint32_t address, int16_t data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write long
|
* Write long
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -126,7 +128,7 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void write(uint32_t address, int32_t data);
|
void write(uint32_t address, int32_t data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write float
|
* Write float
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -134,7 +136,7 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void write(uint32_t address, float data);
|
void write(uint32_t address, float data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write anything (use the page write mode)
|
* Write anything (use the page write mode)
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -143,7 +145,7 @@ public:
|
|||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void write(uint32_t address, void *data, uint32_t size);
|
void write(uint32_t address, void *data, uint32_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write array of bytes (use the page mode)
|
* Write array of bytes (use the page mode)
|
||||||
* @param address start address (uint32_t)
|
* @param address start address (uint32_t)
|
||||||
@@ -151,53 +153,52 @@ public:
|
|||||||
* @param size number of bytes to write (uint32_t)
|
* @param size number of bytes to write (uint32_t)
|
||||||
* @return none
|
* @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
|
* Wait eeprom ready
|
||||||
* @param none
|
* @param none
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void ready(void);
|
void ready();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get eeprom size in bytes
|
* Get eeprom size in bytes
|
||||||
* @param none
|
* @param none
|
||||||
* @return size in bytes (uint32_t)
|
* @return size in bytes (uint32_t)
|
||||||
*/
|
*/
|
||||||
uint32_t getSize(void);
|
uint32_t getSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get eeprom name
|
* Get eeprom name
|
||||||
* @param none
|
* @param none
|
||||||
* @return name (const char*)
|
* @return name (const char*)
|
||||||
*/
|
*/
|
||||||
const char* getName(void);
|
const char *getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear eeprom (write with 0)
|
* Clear eeprom (write with 0)
|
||||||
* @param none
|
* @param none
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
void clear(void);
|
void clear();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current error number (EEPROM_NoError if no error)
|
* Get the current error number (EEPROM_NoError if no error)
|
||||||
* @param none
|
* @param none
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
uint8_t getError(void);
|
uint8_t getError();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current error message
|
* Get current error message
|
||||||
* @param none
|
* @param none
|
||||||
* @return current error message(std::string)
|
* @return current error message(std::string)
|
||||||
*/
|
*/
|
||||||
std::string getErrorMessage(void)
|
std::string getErrorMessage(void) const {
|
||||||
{
|
return (_ErrorMessageEEPROM[_errnum]);
|
||||||
return(_ErrorMessageEEPROM[_errnum]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------- local variables ----------
|
//---------- local variables ----------
|
||||||
private:
|
private:
|
||||||
I2C _i2c; // Local i2c communication interface instance
|
I2C _i2c; // Local i2c communication interface instance
|
||||||
@@ -208,7 +209,8 @@ private:
|
|||||||
uint8_t _page_number; // Number of page
|
uint8_t _page_number; // Number of page
|
||||||
uint32_t _size; // Size in bytes
|
uint32_t _size; // Size in bytes
|
||||||
bool checkAddress(uint32_t address); // Check address range
|
bool checkAddress(uint32_t address); // Check address range
|
||||||
static const char * const _name[]; // eeprom name
|
static const char *const _name[]; // eeprom name
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user