Fork of 24LCxx_I2C. Works for Renesas EEPROMs. Fixes problems with PageWrites over page boundaries.

Fork of 24LCxx_I2C by Yann Garcia

Committer:
charly
Date:
Tue Dec 23 17:21:25 2014 +0000
Revision:
4:2add27250e69
Parent:
2:16ce7dae9019
take care of page boundaries when writing to EEPROM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yann 0:21c698aa86f6 1 /* mbed simplified access to Microchip 24LCxx Serial EEPROM devices (I2C)
Yann 0:21c698aa86f6 2 * Copyright (c) 2010-2012 ygarcia, MIT License
Yann 0:21c698aa86f6 3 *
Yann 0:21c698aa86f6 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Yann 0:21c698aa86f6 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Yann 0:21c698aa86f6 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Yann 0:21c698aa86f6 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Yann 0:21c698aa86f6 8 * furnished to do so, subject to the following conditions:
Yann 0:21c698aa86f6 9 *
Yann 0:21c698aa86f6 10 * The above copyright notice and this permission notice shall be included in all copies or
Yann 0:21c698aa86f6 11 * substantial portions of the Software.
Yann 0:21c698aa86f6 12 *
Yann 0:21c698aa86f6 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Yann 0:21c698aa86f6 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Yann 0:21c698aa86f6 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Yann 0:21c698aa86f6 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Yann 0:21c698aa86f6 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Yann 0:21c698aa86f6 18 */
Yann 0:21c698aa86f6 19 #if !defined(__24LCXX_I2C_H__)
Yann 0:21c698aa86f6 20 #define __24LCXX_I2C_H__
Yann 0:21c698aa86f6 21
Yann 0:21c698aa86f6 22 #include <string>
Yann 0:21c698aa86f6 23 #include <vector>
Yann 0:21c698aa86f6 24
Yann 0:21c698aa86f6 25 #include "Debug.h" // Include mbed header + debug primitives. See DebugLibrary
Yann 0:21c698aa86f6 26
Yann 0:21c698aa86f6 27 namespace _24LCXX_I2C {
Yann 0:21c698aa86f6 28 /** This class provides simplified I2C access to a Microchip 24LCxx Serial EEPROM device. V0.0.0.3
Yann 0:21c698aa86f6 29 *
Yann 0:21c698aa86f6 30 * Note that if the LPC1768 is powered in 3.3V and Microchip 24LCxx Serial EEPROM device could be powered at 3.3V or 5V.
Yann 0:21c698aa86f6 31 * In this case, you shall use a bi-directional level shifter for I2C-bus. Please refer to AN97055 (http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf)
Yann 0:21c698aa86f6 32 * Microchip 24LCxx Serial EEPROM device reference:
Yann 0:21c698aa86f6 33 * - 24LC256: DS21203K
Yann 0:21c698aa86f6 34 * - 24LC64 : DS21189D
Yann 0:21c698aa86f6 35 *
Yann 0:21c698aa86f6 36 * Note that for I2C details, please visit http://www.datelec.fr/fiches/I2C.htm
Yann 0:21c698aa86f6 37 *
Yann 0:21c698aa86f6 38 * Note that this header file include following headers:
Yann 0:21c698aa86f6 39 * - <string>
Yann 0:21c698aa86f6 40 * - <vector>
Yann 0:21c698aa86f6 41 * - <mbed.h>
Yann 0:21c698aa86f6 42 *
Yann 0:21c698aa86f6 43 * @remark This class was validated with Tektronix TDS2014 oscilloscope in 3.3V and in mixte power mode 3.3V for mbed and 5V for the Microchip 24LCxx Serial EEPROM device
Yann 0:21c698aa86f6 44 * @author Yann Garcia (Don't hesitate to contact me: garcia.yann@gmail.com)
Yann 0:21c698aa86f6 45 */
Yann 0:21c698aa86f6 46 class C24LCXX_I2C { // TODO: Add EE Polling for write methods
Yann 0:21c698aa86f6 47 /** Reference counter used to guarentee unicity of the instance of I2C class
Yann 0:21c698aa86f6 48 */
Yann 1:bdf87ab4cdb8 49 static unsigned char I2CModuleRefCounter;
Yann 0:21c698aa86f6 50
Yann 0:21c698aa86f6 51 /** Device address input: A0, A1, A2 (Pins <1,3>). See DS21203K/DS21189D - Figure 5-1: Control Byte Format for address format details
Yann 0:21c698aa86f6 52 */
Yann 0:21c698aa86f6 53 unsigned char _slaveAddress;
Yann 0:21c698aa86f6 54 /** WP state indicator (pin 7); true is write protected, false otherwise
Yann 0:21c698aa86f6 55 */
Yann 0:21c698aa86f6 56 DigitalOut *_wp;
Yann 0:21c698aa86f6 57 /** An unique instance of I2C class
Yann 0:21c698aa86f6 58 */
Yann 0:21c698aa86f6 59 I2C *_i2cInstance;
Yann 0:21c698aa86f6 60 public:
Yann 0:21c698aa86f6 61 /** Memory storage mode
Yann 0:21c698aa86f6 62 */
Yann 0:21c698aa86f6 63 enum Mode {
Yann 0:21c698aa86f6 64 LittleEndian, //<! Little Endian mode: 0xA0B70708 is stored as 08: MSB and A0 LSB
Yann 0:21c698aa86f6 65 BigEndian //<! Little Endian mode: 0xA0B70708 is stored as AO: MSB and 08 LSB
Yann 0:21c698aa86f6 66 };
Yann 0:21c698aa86f6 67 public:
Yann 0:21c698aa86f6 68 /** Constructor with Write Protect command pin wired. Use it to manage the first I2C module on 3.3V or 5V network
Yann 0:21c698aa86f6 69 *
Yann 0:21c698aa86f6 70 * @param p_sda: MBed pin for SDA
Yann 0:21c698aa86f6 71 * @param p_scl: MBed pin for SCL
Yann 0:21c698aa86f6 72 * @param p_address: Device address input: A0, A1, A2 (Pins <1,3>)
Yann 0:21c698aa86f6 73 * @param p_wp: MBed pin to manage Write Protect input. If NC, WP is not managed, default value is NC, not connected
Yann 0:21c698aa86f6 74 * @param p_frequency: Frequency of the I2C interface (SCL), default value is 400KHz
Yann 0:21c698aa86f6 75 * Example:
Yann 0:21c698aa86f6 76 * - If A1 and A2 pins are tired to Vdd and A0 is tired to Vss, address shall '00000110'B
Yann 0:21c698aa86f6 77 * - If A0 and A1 pins are tired to Vss and A2 is tired to Vdd, address shall '00000100'B
Yann 0:21c698aa86f6 78 */
charly 4:2add27250e69 79 //C24LCXX_I2C(const PinName p_sda, const PinName p_scl, const unsigned char p_address, const PinName p_wp = NC, const unsigned int p_frequency = 400000);
charly 4:2add27250e69 80
charly 4:2add27250e69 81 /* defaults to a 24LC256: 256 kbit, 64Bytes PageSize */
charly 4:2add27250e69 82 C24LCXX_I2C(const PinName p_sda, const PinName p_scl, const unsigned char p_address, const PinName p_wp = NC, const unsigned int p_frequency = 400000,
charly 4:2add27250e69 83 const uint32_t deviceSize = 256, const uint8_t pageSize = 64);
Yann 0:21c698aa86f6 84
Yann 0:21c698aa86f6 85 /** Destructor
Yann 0:21c698aa86f6 86 */
Yann 0:21c698aa86f6 87 virtual ~C24LCXX_I2C();
Yann 0:21c698aa86f6 88
Yann 0:21c698aa86f6 89 /** Used to return the unique instance of I2C instance
Yann 0:21c698aa86f6 90 */
Yann 0:21c698aa86f6 91 inline const I2C * operator * () { return (const I2C *)_i2cInstance; };
Yann 0:21c698aa86f6 92
Yann 0:21c698aa86f6 93 /** Erase of memory area starting at the specified address, using the specified pattern to fill the memory area
Yann 0:21c698aa86f6 94 *
Yann 2:16ce7dae9019 95 * @param p_startAddress The address of the memory area (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 96 * @param p_count The size of the memory area to erase
Yann 1:bdf87ab4cdb8 97 * @param p_pattern The pattern value to use to fill the memory area. Default vqlue: 0x00
Yann 0:21c698aa86f6 98 * @return true on success, false otherwise
Yann 0:21c698aa86f6 99 * Exemple:
Yann 0:21c698aa86f6 100 * @code
Yann 0:21c698aa86f6 101 * ...
Yann 0:21c698aa86f6 102 * myEEPROM.EraseMemoryArea(0, 1024); // Set to 0x00 the first 1Kb memory
Yann 0:21c698aa86f6 103 * ...
Yann 0:21c698aa86f6 104 * @endcode
Yann 0:21c698aa86f6 105 */
Yann 2:16ce7dae9019 106 bool EraseMemoryArea(const short p_startAddress, const int p_count, const unsigned char p_pattern = 0x00);
Yann 0:21c698aa86f6 107
Yann 0:21c698aa86f6 108 /** Write a byte at the specified memory address
Yann 0:21c698aa86f6 109 *
Yann 0:21c698aa86f6 110 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 111 * @param p_byte The byte value to save
Yann 0:21c698aa86f6 112 * @return true on success, false otherwise
Yann 0:21c698aa86f6 113 * Exemple:
Yann 0:21c698aa86f6 114 * @code
Yann 0:21c698aa86f6 115 * unsigned char value = 0xaa;
Yann 0:21c698aa86f6 116 * ...
Yann 0:21c698aa86f6 117 * myEEPROM.Write(memoryAddress, value);
Yann 0:21c698aa86f6 118 * ...
Yann 0:21c698aa86f6 119 * @endcode
Yann 0:21c698aa86f6 120 */
Yann 0:21c698aa86f6 121 bool Write(const short p_address, const unsigned char p_byte);
Yann 0:21c698aa86f6 122
Yann 0:21c698aa86f6 123 /** Write a short at the specified memory address according to the specified mode
Yann 0:21c698aa86f6 124 *
Yann 0:21c698aa86f6 125 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 126 * @param p_short The short value to save
Yann 0:21c698aa86f6 127 * @param p_mode The storage mode. Default value: BigEndian
Yann 0:21c698aa86f6 128 * @return true on success, false otherwise
Yann 0:21c698aa86f6 129 * Exemple:
Yann 0:21c698aa86f6 130 * @code
Yann 0:21c698aa86f6 131 * short value = 0xcafe;
Yann 0:21c698aa86f6 132 * ...
Yann 0:21c698aa86f6 133 * myEEPROM.Write(memoryAddress, value, LittleEndian);
Yann 0:21c698aa86f6 134 * ...
Yann 0:21c698aa86f6 135 * @endcode
Yann 0:21c698aa86f6 136 */
Yann 0:21c698aa86f6 137 bool Write(const short p_address, const short p_short, const C24LCXX_I2C::Mode p_mode = BigEndian);
Yann 0:21c698aa86f6 138
Yann 0:21c698aa86f6 139 /** Write an integer at the specified memory address according to the specified mode
Yann 0:21c698aa86f6 140 *
Yann 0:21c698aa86f6 141 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 142 * @param p_int The integer value to save
Yann 0:21c698aa86f6 143 * @param p_mode The storage mode. Default value: BigEndian
Yann 0:21c698aa86f6 144 * @return true on success, false otherwise
Yann 0:21c698aa86f6 145 * Exemple:
Yann 0:21c698aa86f6 146 * @code
Yann 0:21c698aa86f6 147 * int value = 0xcafedeca;
Yann 0:21c698aa86f6 148 * ...
Yann 0:21c698aa86f6 149 * myEEPROM.Write(memoryAddress, value, LittleEndian);
Yann 0:21c698aa86f6 150 * ...
Yann 0:21c698aa86f6 151 * @endcode
Yann 0:21c698aa86f6 152 */
Yann 0:21c698aa86f6 153 bool Write(const short p_address, const int p_int, const C24LCXX_I2C::Mode p_mode = BigEndian);
Yann 0:21c698aa86f6 154
Yann 0:21c698aa86f6 155 /** Write a buffer of bytes at the specified memory address
Yann 0:21c698aa86f6 156 *
Yann 0:21c698aa86f6 157 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 158 * @param p_datas The string to save
Yann 0:21c698aa86f6 159 * @param p_storeLength If true, store also the length of the buffer in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true.
Yann 0:21c698aa86f6 160 * @param p_length2write The number of bytes to write, -1 for all characters. Default value: -1
Yann 0:21c698aa86f6 161 * @return true on success, false otherwise
Yann 0:21c698aa86f6 162 */
Yann 0:21c698aa86f6 163 bool Write(const short p_address, const std::vector<unsigned char> & p_datas, bool p_storeLength = true, const int p_length2write = -1);
Yann 0:21c698aa86f6 164
Yann 0:21c698aa86f6 165 /** Write a buffer of bytes at the specified memory address
Yann 0:21c698aa86f6 166 *
Yann 0:21c698aa86f6 167 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 168 * @param p_datas The buffer of bytes to save
Yann 0:21c698aa86f6 169 * @param p_storeLength If true, store also the length of the buffer in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true.
Yann 0:21c698aa86f6 170 * @param p_length2write The number of bytes to write, -1 for all bytes. Default value: -1
Yann 0:21c698aa86f6 171 * @return true on success, false otherwise
Yann 0:21c698aa86f6 172 */
Yann 0:21c698aa86f6 173 bool Write(const short p_address, const unsigned char *p_datas, bool p_storeLength = true, const int p_length2write = -1);
Yann 0:21c698aa86f6 174
Yann 0:21c698aa86f6 175 /** Write a string at the specified memory address
Yann 0:21c698aa86f6 176 *
Yann 0:21c698aa86f6 177 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 178 * @param p_string The string to save
Yann 0:21c698aa86f6 179 * @param p_storeLength If true, store also the length of the string in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true.
Yann 0:21c698aa86f6 180 * @param p_length2write The number of character to write, -1 for all characters
Yann 0:21c698aa86f6 181 * @return true on success, false otherwise
Yann 0:21c698aa86f6 182 * Exemple:
Yann 0:21c698aa86f6 183 * @code
Yann 0:21c698aa86f6 184 * std::string text2save("CafeDeca");
Yann 0:21c698aa86f6 185 * ...
Yann 0:21c698aa86f6 186 * myEEPROM.Write(memoryAddress, text2save);
Yann 0:21c698aa86f6 187 * ...
Yann 0:21c698aa86f6 188 * @endcode
Yann 0:21c698aa86f6 189 */
Yann 0:21c698aa86f6 190 bool Write(const short p_address, const std::string & p_string, const bool p_storeLength = true, const int p_length2write = -1);
Yann 0:21c698aa86f6 191
Yann 0:21c698aa86f6 192 /** Write a buffer of characters at the specified memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 193 *
Yann 0:21c698aa86f6 194 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 195 * @param p_datas The string to save
Yann 0:21c698aa86f6 196 * @param p_storeLength If true, store also the length of the string in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true.
Yann 0:21c698aa86f6 197 * @param length2write The number of character to write, -1 for all characters
Yann 0:21c698aa86f6 198 * @return true on success, false otherwise
Yann 0:21c698aa86f6 199 */
Yann 0:21c698aa86f6 200 bool Write(const short p_address, const char *p_datas, const bool p_storeLength = true, const int p_length2write = -1);
Yann 0:21c698aa86f6 201
Yann 0:21c698aa86f6 202 /** Read a byte from the specified memory address
Yann 0:21c698aa86f6 203 *
Yann 0:21c698aa86f6 204 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 205 * @param p_byte The byte value to read
Yann 0:21c698aa86f6 206 * @return true on success, false otherwise
Yann 0:21c698aa86f6 207 * Exemple:
Yann 0:21c698aa86f6 208 * @code
Yann 0:21c698aa86f6 209 * unsigned char value;
Yann 0:21c698aa86f6 210 * ...
Yann 0:21c698aa86f6 211 * myEEPROM.Read(memoryAddress, (unsigned char *)&value);
Yann 0:21c698aa86f6 212 * ...
Yann 0:21c698aa86f6 213 * @endcode
Yann 0:21c698aa86f6 214 */
Yann 0:21c698aa86f6 215 bool Read(const short p_address, unsigned char *p_value);
Yann 0:21c698aa86f6 216
Yann 0:21c698aa86f6 217 /** Read a short from the specified memory address
Yann 0:21c698aa86f6 218 *
Yann 0:21c698aa86f6 219 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 220 * @param p_short The short value to read
Yann 0:21c698aa86f6 221 * @return true on success, false otherwise
Yann 0:21c698aa86f6 222 * Exemple:
Yann 0:21c698aa86f6 223 * @code
Yann 0:21c698aa86f6 224 * short value;
Yann 0:21c698aa86f6 225 * ...
Yann 0:21c698aa86f6 226 * myEEPROM.Read(memoryAddress, (short *)&value);
Yann 0:21c698aa86f6 227 * ...
Yann 0:21c698aa86f6 228 * @endcode
Yann 0:21c698aa86f6 229 */
Yann 0:21c698aa86f6 230 bool Read(const short p_address, short *p_short, C24LCXX_I2C::Mode p_mode = BigEndian);
Yann 0:21c698aa86f6 231
Yann 0:21c698aa86f6 232 /** Read an integer from the specified memory address
Yann 0:21c698aa86f6 233 *
Yann 0:21c698aa86f6 234 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 235 * @param p_int The integer value to read
Yann 0:21c698aa86f6 236 * @return true on success, false otherwise
Yann 0:21c698aa86f6 237 * Exemple:
Yann 0:21c698aa86f6 238 * @code
Yann 0:21c698aa86f6 239 * int value;
Yann 0:21c698aa86f6 240 * ...
Yann 0:21c698aa86f6 241 * myEEPROM.Read(memoryAddress, (int *)&value);
Yann 0:21c698aa86f6 242 * ...
Yann 0:21c698aa86f6 243 * @endcode
Yann 0:21c698aa86f6 244 */
Yann 0:21c698aa86f6 245 bool Read(const short p_address, int *p_int, C24LCXX_I2C::Mode p_mode = BigEndian);
Yann 0:21c698aa86f6 246
Yann 0:21c698aa86f6 247 /** Read a buffer of bytes from the specified memory address and store it into a std::vector<unsigned char> object
Yann 0:21c698aa86f6 248 *
Yann 0:21c698aa86f6 249 * Note that the size of the buffer object is used for the number of bytes to read
Yann 0:21c698aa86f6 250 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 251 * @param p_datas The buffer to fill
Yann 0:21c698aa86f6 252 * @param p_readLengthFirst If true, read the length first and p_length2write parameter is ignored, otherwise the length is provided by p_length2write parameter. Default value: true
Yann 1:bdf87ab4cdb8 253 * @param p_length2read The number of character to write, -1 to use the size of the string buffer
Yann 0:21c698aa86f6 254 * @return true on success, false otherwise
Yann 0:21c698aa86f6 255 * Exemple:
Yann 0:21c698aa86f6 256 * @code
Yann 0:21c698aa86f6 257 * std::vector<unsigned char> datas(bufferLength);
Yann 0:21c698aa86f6 258 * ...
Yann 0:21c698aa86f6 259 * myEEPROM.Read(memoryAddress, datas);
Yann 0:21c698aa86f6 260 * ...
Yann 0:21c698aa86f6 261 * @endcode
Yann 0:21c698aa86f6 262 */
Yann 1:bdf87ab4cdb8 263 bool Read(const short p_address, std::vector<unsigned char> & p_datas, bool p_readLengthFirst = true, int p_length2read = -1);
Yann 0:21c698aa86f6 264
Yann 0:21c698aa86f6 265 /** Read a buffer of characters from the specified memory address and store it into a string object
Yann 0:21c698aa86f6 266 *
Yann 0:21c698aa86f6 267 * Note that the size of the string object is used for the number of characters to read
Yann 0:21c698aa86f6 268 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 269 * @param p_string The string buffer to fill
Yann 0:21c698aa86f6 270 * @param p_readLengthFirst If true, read the length first and p_length2write parameter is ignored, otherwise the length is provided by p_length2write parameter. Default value: true
Yann 0:21c698aa86f6 271 * @param p_length2write The number of character to write, -1 to use the size of the string buffer
Yann 0:21c698aa86f6 272 * @return true on success, false otherwise
Yann 0:21c698aa86f6 273 * Exemple:
Yann 0:21c698aa86f6 274 * @code
Yann 0:21c698aa86f6 275 * std::string readtext;
Yann 0:21c698aa86f6 276 * ...
Yann 0:21c698aa86f6 277 * myEEPROM.Read(memoryAddress, readtext);
Yann 0:21c698aa86f6 278 * ...
Yann 0:21c698aa86f6 279 * @endcode
Yann 0:21c698aa86f6 280 */
Yann 0:21c698aa86f6 281 bool Read(const short p_address, std::string & p_string, bool p_readLengthFirst = true, int p_length2write = -1);
Yann 0:21c698aa86f6 282
charly 4:2add27250e69 283 /** Read a buffer of characters from the specified memory address and store it into char array
charly 4:2add27250e69 284 *
charly 4:2add27250e69 285 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
charly 4:2add27250e69 286 * @param p_datas The string buffer to fill
charly 4:2add27250e69 287 * @param p_readLengthFirst If true, read the length first and p_length2write parameter is ignored, otherwise the length is provided by p_length2write parameter. Default value: true
charly 4:2add27250e69 288 * @param p_length2write The number of character to write, -1 to use the size of the string buffer
charly 4:2add27250e69 289 * @return true on success, false otherwise
charly 4:2add27250e69 290 * Exemple:
charly 4:2add27250e69 291 * @code
charly 4:2add27250e69 292 * char[255] readtext;
charly 4:2add27250e69 293 * ...
charly 4:2add27250e69 294 * myEEPROM.Read(memoryAddress, readtext);
charly 4:2add27250e69 295 * ...
charly 4:2add27250e69 296 * @endcode
charly 4:2add27250e69 297 */
charly 4:2add27250e69 298 bool Read(const short p_address, unsigned char * p_datas, bool p_readLengthFirst = true, int p_length2write = -1);
charly 4:2add27250e69 299
Yann 0:21c698aa86f6 300 /** Activate or deactivate write protect (pin 7)
Yann 0:21c698aa86f6 301 *
Yann 0:21c698aa86f6 302 * Note that a voltage of 3.3V apply to WP input of 24LCxx device is enough to enable write protect
Yann 0:21c698aa86f6 303 * @param p_writeProtect: Set to true to activate write protection, false otherwise
Yann 0:21c698aa86f6 304 * @return true on success, false otherwise
Yann 0:21c698aa86f6 305 */
Yann 0:21c698aa86f6 306 bool WriteProtect(const bool p_writeProtect);
Yann 0:21c698aa86f6 307
Yann 0:21c698aa86f6 308 /** Indicate the current WP state indicator (pin 7)
Yann 0:21c698aa86f6 309 * @return true is write protected, false otherwise
Yann 0:21c698aa86f6 310 */
Yann 0:21c698aa86f6 311 inline bool IsWriteProtected() {
Yann 0:21c698aa86f6 312 return (_wp != NULL) ? (bool)(_wp->read() == 1) : false;
Yann 0:21c698aa86f6 313 }
Yann 0:21c698aa86f6 314
Yann 0:21c698aa86f6 315 #if defined(__DEBUG)
Yann 0:21c698aa86f6 316 /** Dump a memory area
Yann 0:21c698aa86f6 317 *
Yann 0:21c698aa86f6 318 * Note that this method is available only on debug mode
Yann 0:21c698aa86f6 319 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:21c698aa86f6 320 * @param p_count The number of bytes toi dump
Yann 0:21c698aa86f6 321 * @return true on success, false otherwise
Yann 0:21c698aa86f6 322 */
Yann 0:21c698aa86f6 323 void DumpMemoryArea(const int p_address, const int p_count);
Yann 0:21c698aa86f6 324 /** For debug purpose only
Yann 0:21c698aa86f6 325 */
Yann 0:21c698aa86f6 326 inline std::string & ToString() { return _internalId; };
Yann 0:21c698aa86f6 327 #else // __DEBUG
Yann 0:21c698aa86f6 328 inline void DumpMemoryArea(const int p_address, const int p_count) {};
Yann 0:21c698aa86f6 329 #endif // _DEBUG
Yann 0:21c698aa86f6 330
Yann 0:21c698aa86f6 331 private:
charly 4:2add27250e69 332
charly 4:2add27250e69 333 /* write to EEPROM. Take care of pageBoundaries */
charly 4:2add27250e69 334 int i2cWrite(short address, const char *data, int length);
charly 4:2add27250e69 335
Yann 0:21c698aa86f6 336 /** Internal reference identifier
Yann 0:21c698aa86f6 337 */
Yann 0:21c698aa86f6 338 std::string _internalId;
charly 4:2add27250e69 339
charly 4:2add27250e69 340 /** pageSize of device in Bytes
charly 4:2add27250e69 341 */
charly 4:2add27250e69 342 uint8_t _pageSize;
charly 4:2add27250e69 343
charly 4:2add27250e69 344 /** Device Size of Device in Kbits
charly 4:2add27250e69 345 */
charly 4:2add27250e69 346 uint32_t _deviceSize;
charly 4:2add27250e69 347
Yann 0:21c698aa86f6 348
Yann 0:21c698aa86f6 349 }; // End of class C24LCXX_I2C
Yann 0:21c698aa86f6 350
Yann 0:21c698aa86f6 351 } // End of namespace _24LCXX_I2C
Yann 0:21c698aa86f6 352
Yann 0:21c698aa86f6 353 using namespace _24LCXX_I2C;
Yann 0:21c698aa86f6 354
Yann 0:21c698aa86f6 355 #endif // __24LCXX_I2C_H__