shortened

Dependents:   CDMS_CODE CDMS_CODE_FM_28JAN2017 CDMS_CODE_FM_28JAN2017 CDMS_FM_21JUL2017_EEPROM_JOEL ... more

Fork of eeprom by bernard borredon

Committer:
chaithanyarss
Date:
Wed Jan 04 13:43:08 2017 +0000
Revision:
4:0c5b1545007c
Parent:
3:925096a4c7f0
Child:
5:b65b74065b7f
removing unnecessary functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bborredon 0:80245aff63ce 1 #ifndef __EEPROM__H_
bborredon 0:80245aff63ce 2 #define __EEPROM__H_
bborredon 0:80245aff63ce 3
bborredon 0:80245aff63ce 4 // Includes
bborredon 0:80245aff63ce 5 #include <string>
bborredon 0:80245aff63ce 6
bborredon 0:80245aff63ce 7 #include "mbed.h"
bborredon 0:80245aff63ce 8
bborredon 0:80245aff63ce 9 // Defines
bborredon 0:80245aff63ce 10 #define EEPROM_Address 0xa0
bborredon 0:80245aff63ce 11
bborredon 0:80245aff63ce 12 #define EEPROM_NoError 0x00
bborredon 0:80245aff63ce 13 #define EEPROM_BadAddress 0x01
bborredon 0:80245aff63ce 14 #define EEPROM_I2cError 0x02
bborredon 0:80245aff63ce 15 #define EEPROM_ParamError 0x03
bborredon 0:80245aff63ce 16 #define EEPROM_OutOfRange 0x04
bborredon 0:80245aff63ce 17 #define EEPROM_MallocError 0x05
bborredon 0:80245aff63ce 18
bborredon 0:80245aff63ce 19 #define EEPROM_MaxError 6
bborredon 0:80245aff63ce 20
bborredon 0:80245aff63ce 21 static std::string _ErrorMessageEEPROM[EEPROM_MaxError] = {
bborredon 0:80245aff63ce 22 "",
bborredon 0:80245aff63ce 23 "Bad chip address",
bborredon 0:80245aff63ce 24 "I2C error (nack)",
bborredon 0:80245aff63ce 25 "Invalid parameter",
bborredon 0:80245aff63ce 26 "Data address out of range",
bborredon 0:80245aff63ce 27 "Memory allocation error"
bborredon 0:80245aff63ce 28 };
bborredon 0:80245aff63ce 29
bborredon 3:925096a4c7f0 30 /** EEPROM Class
bborredon 3:925096a4c7f0 31 */
bborredon 0:80245aff63ce 32 class EEPROM {
bborredon 0:80245aff63ce 33 public:
chaithanyarss 4:0c5b1545007c 34 enum TypeEeprom {T24C512=65536} Type;
bborredon 1:a262173cac81 35
bborredon 2:79ed7ff7c23d 36 /**
bborredon 0:80245aff63ce 37 * Constructor, initialize the eeprom on i2c interface.
bborredon 3:925096a4c7f0 38 * @param sda sda i2c pin (PinName)
bborredon 3:925096a4c7f0 39 * @param scl scl i2c pin (PinName)
bborredon 3:925096a4c7f0 40 * @param address eeprom address, according to eeprom type (uint8_t)
bborredon 3:925096a4c7f0 41 * @param type eeprom type (TypeEeprom)
bborredon 3:925096a4c7f0 42 * @return none
bborredon 0:80245aff63ce 43 */
bborredon 0:80245aff63ce 44 EEPROM(PinName sda, PinName scl, uint8_t address, TypeEeprom type);
bborredon 0:80245aff63ce 45
bborredon 2:79ed7ff7c23d 46 /**
bborredon 0:80245aff63ce 47 * Random read long
bborredon 3:925096a4c7f0 48 * @param address start address (uint32_t)
bborredon 3:925096a4c7f0 49 * @param data long to read (int32_t&)
bborredon 3:925096a4c7f0 50 * @return none
bborredon 0:80245aff63ce 51 */
bborredon 1:a262173cac81 52 void read(uint32_t address, int32_t& data);
bborredon 0:80245aff63ce 53
bborredon 2:79ed7ff7c23d 54 /**
bborredon 0:80245aff63ce 55 * Sequential read byte
bborredon 3:925096a4c7f0 56 * @param address start address (uint32_t)
bborredon 3:925096a4c7f0 57 * @param data bytes array to read (int8_t[]&)
bborredon 3:925096a4c7f0 58 * @param size number of bytes to read (uint32_t)
bborredon 3:925096a4c7f0 59 * @return none
bborredon 0:80245aff63ce 60 */
bborredon 1:a262173cac81 61 void read(uint32_t address, int8_t *data, uint32_t size);
bborredon 0:80245aff63ce 62
bborredon 2:79ed7ff7c23d 63 /**
bborredon 0:80245aff63ce 64 * Write long
bborredon 3:925096a4c7f0 65 * @param address start address (uint32_t)
bborredon 3:925096a4c7f0 66 * @param data long to write (int32_t)
bborredon 3:925096a4c7f0 67 * @return none
bborredon 0:80245aff63ce 68 */
bborredon 1:a262173cac81 69 void write(uint32_t address, int32_t data);
bborredon 0:80245aff63ce 70
bborredon 2:79ed7ff7c23d 71 /**
bborredon 1:a262173cac81 72 * Write array of bytes (use the page mode)
bborredon 3:925096a4c7f0 73 * @param address start address (uint32_t)
bborredon 3:925096a4c7f0 74 * @param data bytes array to write (int8_t[])
bborredon 3:925096a4c7f0 75 * @param size number of bytes to write (uint32_t)
bborredon 3:925096a4c7f0 76 * @return none
bborredon 0:80245aff63ce 77 */
bborredon 1:a262173cac81 78 void write(uint32_t address, int8_t data[], uint32_t size);
bborredon 0:80245aff63ce 79
bborredon 2:79ed7ff7c23d 80 /**
bborredon 0:80245aff63ce 81 * Wait eeprom ready
bborredon 3:925096a4c7f0 82 * @param none
bborredon 3:925096a4c7f0 83 * @return none
bborredon 0:80245aff63ce 84 */
bborredon 0:80245aff63ce 85 void ready(void);
bborredon 0:80245aff63ce 86
bborredon 2:79ed7ff7c23d 87 /**
bborredon 0:80245aff63ce 88 * Get eeprom size in bytes
bborredon 3:925096a4c7f0 89 * @param none
bborredon 3:925096a4c7f0 90 * @return size in bytes (uint32_t)
bborredon 0:80245aff63ce 91 */
bborredon 0:80245aff63ce 92 uint32_t getSize(void);
bborredon 1:a262173cac81 93
bborredon 2:79ed7ff7c23d 94 /**
bborredon 1:a262173cac81 95 * Get eeprom name
bborredon 3:925096a4c7f0 96 * @param none
bborredon 3:925096a4c7f0 97 * @return name (const char*)
bborredon 1:a262173cac81 98 */
bborredon 1:a262173cac81 99 const char* getName(void);
bborredon 1:a262173cac81 100
bborredon 2:79ed7ff7c23d 101 /**
bborredon 1:a262173cac81 102 * Clear eeprom (write with 0)
bborredon 3:925096a4c7f0 103 * @param none
bborredon 3:925096a4c7f0 104 * @return none
bborredon 1:a262173cac81 105 */
bborredon 1:a262173cac81 106 void clear(void);
bborredon 0:80245aff63ce 107
bborredon 2:79ed7ff7c23d 108 /**
bborredon 0:80245aff63ce 109 * Get the current error number (EEPROM_NoError if no error)
bborredon 3:925096a4c7f0 110 * @param none
bborredon 3:925096a4c7f0 111 * @return none
bborredon 0:80245aff63ce 112 */
bborredon 0:80245aff63ce 113 uint8_t getError(void);
bborredon 0:80245aff63ce 114
bborredon 2:79ed7ff7c23d 115 /**
bborredon 0:80245aff63ce 116 * Get current error message
bborredon 3:925096a4c7f0 117 * @param none
bborredon 3:925096a4c7f0 118 * @return current error message(std::string)
bborredon 0:80245aff63ce 119 */
bborredon 0:80245aff63ce 120 std::string getErrorMessage(void)
bborredon 0:80245aff63ce 121 {
bborredon 0:80245aff63ce 122 return(_ErrorMessageEEPROM[_errnum]);
bborredon 0:80245aff63ce 123 }
bborredon 0:80245aff63ce 124
bborredon 0:80245aff63ce 125 //---------- local variables ----------
bborredon 0:80245aff63ce 126 private:
bborredon 1:a262173cac81 127 I2C _i2c; // Local i2c communication interface instance
bborredon 1:a262173cac81 128 int _address; // Local i2c address
bborredon 1:a262173cac81 129 uint8_t _errnum; // Error number
bborredon 1:a262173cac81 130 TypeEeprom _type; // EEPROM type
bborredon 1:a262173cac81 131 uint8_t _page_write; // Page write size
bborredon 1:a262173cac81 132 uint8_t _page_number; // Number of page
bborredon 1:a262173cac81 133 uint32_t _size; // Size in bytes
bborredon 1:a262173cac81 134 bool checkAddress(uint32_t address); // Check address range
bborredon 1:a262173cac81 135 static const char * const _name[]; // eeprom name
bborredon 0:80245aff63ce 136 //-------------------------------------
bborredon 0:80245aff63ce 137 };
bborredon 1:a262173cac81 138 #endif