Simplified access to Ramtron (Cypress) FM24Vxx F-RAM devices

Dependents:   FM24Vxx_I2CApp

Committer:
Yann
Date:
Wed Apr 03 12:51:20 2013 +0000
Revision:
1:6a16bddd7222
Parent:
0:fa858f79d48d
Child:
2:bf7d1264d3ff
Validate library and test application with FM24V10-G device

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yann 0:fa858f79d48d 1 /* mbed simplified access to RAMTRON FV24xx Serial 3V F-RAM Memory (I2C)
Yann 0:fa858f79d48d 2 * Copyright (c) 2013 ygarcia, MIT License
Yann 0:fa858f79d48d 3 *
Yann 0:fa858f79d48d 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Yann 0:fa858f79d48d 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Yann 0:fa858f79d48d 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Yann 0:fa858f79d48d 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Yann 0:fa858f79d48d 8 * furnished to do so, subject to the following conditions:
Yann 0:fa858f79d48d 9 *
Yann 0:fa858f79d48d 10 * The above copyright notice and this permission notice shall be included in all copies or
Yann 0:fa858f79d48d 11 * substantial portions of the Software.
Yann 0:fa858f79d48d 12 *
Yann 0:fa858f79d48d 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Yann 0:fa858f79d48d 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Yann 0:fa858f79d48d 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Yann 0:fa858f79d48d 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Yann 0:fa858f79d48d 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Yann 0:fa858f79d48d 18 */
Yann 0:fa858f79d48d 19 #if !defined(__FM24VXX_I2C_H__)
Yann 0:fa858f79d48d 20 #define __FM24VXX_I2C_H__
Yann 0:fa858f79d48d 21
Yann 0:fa858f79d48d 22 #include <string>
Yann 0:fa858f79d48d 23 #include <vector>
Yann 0:fa858f79d48d 24
Yann 0:fa858f79d48d 25 #include "FM24Vxx_IDs.h"
Yann 1:6a16bddd7222 26 #include "FM24Vxx_SN.h"
Yann 0:fa858f79d48d 27 #include "Debug.h" // Include mbed header + debug primitives. See DebugLibrary
Yann 0:fa858f79d48d 28
Yann 0:fa858f79d48d 29 namespace _FM24VXX_I2C {
Yann 0:fa858f79d48d 30 /** This class provides simplified I2C access to a RAMTRON FV24xx Serial 3V F-RAM Memory device. V0.0.0.1
Yann 0:fa858f79d48d 31 *
Yann 0:fa858f79d48d 32 * Note that RAMTRON FV24xx Serial 3V F-RAM Memory device could be powered at 3.3V or less only.
Yann 0:fa858f79d48d 33 * Note that this header file include following headers:
Yann 0:fa858f79d48d 34 * - <string>
Yann 0:fa858f79d48d 35 * - <vector>
Yann 0:fa858f79d48d 36 * - <mbed.h>
Yann 0:fa858f79d48d 37 *
Yann 0:fa858f79d48d 38 * @author Yann Garcia (Don't hesitate to contact me: garcia.yann@gmail.com)
Yann 0:fa858f79d48d 39 */
Yann 0:fa858f79d48d 40 class CFM24VXX_I2C {
Yann 0:fa858f79d48d 41 /** Reference counter used to guarentee unicity of the instance of I2C class
Yann 0:fa858f79d48d 42 */
Yann 0:fa858f79d48d 43 static unsigned char I2CModuleRefCounter;
Yann 0:fa858f79d48d 44
Yann 0:fa858f79d48d 45 /** Device address input: A1, A2 (Pins <2,3>). See FM24V10_ds.pdf - Clause Pin Configuration
Yann 0:fa858f79d48d 46 */
Yann 0:fa858f79d48d 47 unsigned char _slaveAddress;
Yann 0:fa858f79d48d 48 /** WP state indicator (pin 7); true is write protected, false otherwise
Yann 0:fa858f79d48d 49 */
Yann 0:fa858f79d48d 50 DigitalOut *_wp;
Yann 0:fa858f79d48d 51 /** An unique instance of I2C class
Yann 0:fa858f79d48d 52 */
Yann 0:fa858f79d48d 53 I2C *_i2cInstance;
Yann 1:6a16bddd7222 54 /** Device ID
Yann 0:fa858f79d48d 55 */
Yann 0:fa858f79d48d 56 CFM24VXX_IDs *_deviceID;
Yann 1:6a16bddd7222 57 /** Serial number
Yann 1:6a16bddd7222 58 */
Yann 1:6a16bddd7222 59 CFM24VXX_SN *_sn;
Yann 0:fa858f79d48d 60 public:
Yann 0:fa858f79d48d 61 /** Memory storage mode
Yann 0:fa858f79d48d 62 */
Yann 0:fa858f79d48d 63 enum Mode {
Yann 0:fa858f79d48d 64 LittleEndian, //<! Little Endian mode: 0xA0B70708 is stored as 08: MSB and A0 LSB
Yann 0:fa858f79d48d 65 BigEndian //<! Little Endian mode: 0xA0B70708 is stored as AO: MSB and 08 LSB
Yann 0:fa858f79d48d 66 };
Yann 0:fa858f79d48d 67 public:
Yann 0:fa858f79d48d 68 /** Constructor with Write Protect command pin wired. Use it to manage the first I2C module
Yann 0:fa858f79d48d 69 *
Yann 0:fa858f79d48d 70 * @param p_sda: MBed pin for SDA
Yann 0:fa858f79d48d 71 * @param p_scl: MBed pin for SCL
Yann 0:fa858f79d48d 72 * @param p_address: Device address input: A1, A2 (Pins <2,3>)
Yann 0:fa858f79d48d 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:fa858f79d48d 74 * @param p_frequency: Frequency of the I2C interface (SCL), default value is 400KHz
Yann 0:fa858f79d48d 75 * Example:
Yann 0:fa858f79d48d 76 * - If A1 pin is tired to Vdd and A2 is tired to Vss, address shall '00000001'B
Yann 0:fa858f79d48d 77 */
Yann 0:fa858f79d48d 78 CFM24VXX_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);
Yann 0:fa858f79d48d 79
Yann 0:fa858f79d48d 80 /** Destructor
Yann 0:fa858f79d48d 81 */
Yann 0:fa858f79d48d 82 virtual ~CFM24VXX_I2C();
Yann 0:fa858f79d48d 83
Yann 0:fa858f79d48d 84 /** Used to return the unique instance of I2C instance
Yann 0:fa858f79d48d 85 */
Yann 0:fa858f79d48d 86 inline const I2C * operator * () { return (const I2C *)_i2cInstance; };
Yann 0:fa858f79d48d 87
Yann 0:fa858f79d48d 88 /** Used to return the unique device identifier
Yann 0:fa858f79d48d 89 */
Yann 1:6a16bddd7222 90 inline const CFM24VXX_IDs * GetDeviceID() { return (const CFM24VXX_IDs *)_deviceID; };
Yann 0:fa858f79d48d 91
Yann 1:6a16bddd7222 92 /**
Yann 1:6a16bddd7222 93 * Used to return the serial number
Yann 1:6a16bddd7222 94 * Note This functionality is available only for the FM24VN10. In other case, it will return 0xff
Yann 1:6a16bddd7222 95 * @remark See FM24V10_ds.pdf Page 10/16 Clause Unique Serial Number (FM24VN10 only)
Yann 1:6a16bddd7222 96 */
Yann 1:6a16bddd7222 97 inline const CFM24VXX_SN * GetSerialNumber() { return (const CFM24VXX_SN *)_sn; };
Yann 1:6a16bddd7222 98
Yann 0:fa858f79d48d 99 /**
Yann 0:fa858f79d48d 100 * Used to swith high speed mode
Yann 0:fa858f79d48d 101 * @param highSpeedMode Set to true to switch to high speed mode
Yann 0:fa858f79d48d 102 * @remark See FM24V10_ds.pdf Page 4/16 Clause High Speed Mode (HS-mode)
Yann 0:fa858f79d48d 103 */
Yann 0:fa858f79d48d 104 inline void SwitchSpeedMode(const bool highSpeedMode) { /* FIXME To be done */ };
Yann 0:fa858f79d48d 105
Yann 0:fa858f79d48d 106 /**
Yann 0:fa858f79d48d 107 * Used to enter in sleep mode
Yann 0:fa858f79d48d 108 * @remark See FM24V10_ds.pdf Page 8/16 Clause Sleep Mode
Yann 0:fa858f79d48d 109 */
Yann 0:fa858f79d48d 110 inline void EnterSleepMode() { /* FIXME To be done */ };
Yann 0:fa858f79d48d 111
Yann 0:fa858f79d48d 112 /**
Yann 1:6a16bddd7222 113 * Used to leave sleep mode
Yann 0:fa858f79d48d 114 * @remark See FM24V10_ds.pdf Page 8/16 Clause Sleep Mode
Yann 0:fa858f79d48d 115 */
Yann 0:fa858f79d48d 116 inline void LeaveSpeedMode() { /* FIXME To be done */ };
Yann 0:fa858f79d48d 117
Yann 0:fa858f79d48d 118 /**
Yann 0:fa858f79d48d 119 * Used to select memory page
Yann 0:fa858f79d48d 120 * @param memoryPage The selected memory page (0 or 1)
Yann 0:fa858f79d48d 121 * @remark See FM24V10_ds.pdf Page 3/16 Clause Memory Architecture
Yann 0:fa858f79d48d 122 */
Yann 1:6a16bddd7222 123 inline void SelectMemoryPage(const unsigned char memoryPage) { _slaveAddress |= ((memoryPage & 0x01) << 1); };
Yann 0:fa858f79d48d 124
Yann 0:fa858f79d48d 125 /** Erase of memory area starting at the specified address, using the specified pattern to fill the memory area
Yann 0:fa858f79d48d 126 *
Yann 0:fa858f79d48d 127 * @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:fa858f79d48d 128 * @param p_count The size of the memory area to erase
Yann 0:fa858f79d48d 129 * @param p_pattern The pattern value to use to fill the memory area. Default vqlue: 0x00
Yann 0:fa858f79d48d 130 * @return true on success, false otherwise
Yann 0:fa858f79d48d 131 * Exemple:
Yann 0:fa858f79d48d 132 * @code
Yann 0:fa858f79d48d 133 * ...
Yann 0:fa858f79d48d 134 * myEEPROM.EraseMemoryArea(0, 1024); // Set to 0x00 the first 1Kb memory
Yann 0:fa858f79d48d 135 * ...
Yann 0:fa858f79d48d 136 * @endcode
Yann 0:fa858f79d48d 137 */
Yann 0:fa858f79d48d 138 bool EraseMemoryArea(const short p_startAddress, const int p_count, const unsigned char p_pattern = 0x00);
Yann 0:fa858f79d48d 139
Yann 0:fa858f79d48d 140 /** Write a byte at the specified memory address
Yann 0:fa858f79d48d 141 *
Yann 0:fa858f79d48d 142 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 143 * @param p_byte The byte value to save
Yann 0:fa858f79d48d 144 * @return true on success, false otherwise
Yann 0:fa858f79d48d 145 * Exemple:
Yann 0:fa858f79d48d 146 * @code
Yann 0:fa858f79d48d 147 * unsigned char value = 0xaa;
Yann 0:fa858f79d48d 148 * ...
Yann 0:fa858f79d48d 149 * myEEPROM.Write(memoryAddress, value);
Yann 0:fa858f79d48d 150 * ...
Yann 0:fa858f79d48d 151 * @endcode
Yann 0:fa858f79d48d 152 */
Yann 0:fa858f79d48d 153 bool Write(const short p_address, const unsigned char p_byte);
Yann 0:fa858f79d48d 154
Yann 0:fa858f79d48d 155 /** Write a short at the specified memory address according to the specified mode
Yann 0:fa858f79d48d 156 *
Yann 0:fa858f79d48d 157 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 158 * @param p_short The short value to save
Yann 0:fa858f79d48d 159 * @param p_mode The storage mode. Default value: BigEndian
Yann 0:fa858f79d48d 160 * @return true on success, false otherwise
Yann 0:fa858f79d48d 161 * Exemple:
Yann 0:fa858f79d48d 162 * @code
Yann 0:fa858f79d48d 163 * short value = 0xcafe;
Yann 0:fa858f79d48d 164 * ...
Yann 0:fa858f79d48d 165 * myEEPROM.Write(memoryAddress, value, LittleEndian);
Yann 0:fa858f79d48d 166 * ...
Yann 0:fa858f79d48d 167 * @endcode
Yann 0:fa858f79d48d 168 */
Yann 0:fa858f79d48d 169 bool Write(const short p_address, const short p_short, const CFM24VXX_I2C::Mode p_mode = BigEndian);
Yann 0:fa858f79d48d 170
Yann 0:fa858f79d48d 171 /** Write an integer at the specified memory address according to the specified mode
Yann 0:fa858f79d48d 172 *
Yann 0:fa858f79d48d 173 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 174 * @param p_int The integer value to save
Yann 0:fa858f79d48d 175 * @param p_mode The storage mode. Default value: BigEndian
Yann 0:fa858f79d48d 176 * @return true on success, false otherwise
Yann 0:fa858f79d48d 177 * Exemple:
Yann 0:fa858f79d48d 178 * @code
Yann 0:fa858f79d48d 179 * int value = 0xcafedeca;
Yann 0:fa858f79d48d 180 * ...
Yann 0:fa858f79d48d 181 * myEEPROM.Write(memoryAddress, value, LittleEndian);
Yann 0:fa858f79d48d 182 * ...
Yann 0:fa858f79d48d 183 * @endcode
Yann 0:fa858f79d48d 184 */
Yann 0:fa858f79d48d 185 bool Write(const short p_address, const int p_int, const CFM24VXX_I2C::Mode p_mode = BigEndian);
Yann 0:fa858f79d48d 186
Yann 0:fa858f79d48d 187 /** Write a buffer of bytes at the specified memory address
Yann 0:fa858f79d48d 188 *
Yann 0:fa858f79d48d 189 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 190 * @param p_datas The string to save
Yann 0:fa858f79d48d 191 * @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:fa858f79d48d 192 * @param p_length2write The number of bytes to write, -1 for all characters. Default value: -1
Yann 0:fa858f79d48d 193 * @return true on success, false otherwise
Yann 0:fa858f79d48d 194 */
Yann 0:fa858f79d48d 195 bool Write(const short p_address, const std::vector<unsigned char> & p_datas, bool p_storeLength = true, const int p_length2write = -1);
Yann 0:fa858f79d48d 196
Yann 0:fa858f79d48d 197 /** Write a buffer of bytes at the specified memory address
Yann 0:fa858f79d48d 198 *
Yann 0:fa858f79d48d 199 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 200 * @param p_datas The buffer of bytes to save
Yann 0:fa858f79d48d 201 * @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:fa858f79d48d 202 * @param p_length2write The number of bytes to write, -1 for all bytes. Default value: -1
Yann 0:fa858f79d48d 203 * @return true on success, false otherwise
Yann 0:fa858f79d48d 204 */
Yann 0:fa858f79d48d 205 bool Write(const short p_address, const unsigned char *p_datas, bool p_storeLength = true, const int p_length2write = -1);
Yann 0:fa858f79d48d 206
Yann 0:fa858f79d48d 207 /** Write a string at the specified memory address
Yann 0:fa858f79d48d 208 *
Yann 0:fa858f79d48d 209 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 210 * @param p_string The string to save
Yann 0:fa858f79d48d 211 * @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:fa858f79d48d 212 * @param p_length2write The number of character to write, -1 for all characters
Yann 0:fa858f79d48d 213 * @return true on success, false otherwise
Yann 0:fa858f79d48d 214 * Exemple:
Yann 0:fa858f79d48d 215 * @code
Yann 0:fa858f79d48d 216 * std::string text2save("CafeDeca");
Yann 0:fa858f79d48d 217 * ...
Yann 0:fa858f79d48d 218 * myEEPROM.Write(memoryAddress, text2save);
Yann 0:fa858f79d48d 219 * ...
Yann 0:fa858f79d48d 220 * @endcode
Yann 0:fa858f79d48d 221 */
Yann 0:fa858f79d48d 222 bool Write(const short p_address, const std::string & p_string, const bool p_storeLength = true, const int p_length2write = -1);
Yann 0:fa858f79d48d 223
Yann 0:fa858f79d48d 224 /** 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:fa858f79d48d 225 *
Yann 0:fa858f79d48d 226 * Note that the length of the buffer is not saved and the string is saved in Big Endian mode
Yann 0:fa858f79d48d 227 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 228 * @param p_datas The string to save
Yann 0:fa858f79d48d 229 * @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:fa858f79d48d 230 * @param length2write The number of character to write, -1 for all characters
Yann 0:fa858f79d48d 231 * @return true on success, false otherwise
Yann 0:fa858f79d48d 232 */
Yann 0:fa858f79d48d 233 bool Write(const short p_address, const char *p_datas, const bool p_storeLength = true, const int p_length2write = -1);
Yann 0:fa858f79d48d 234
Yann 0:fa858f79d48d 235 /** Read a byte from the specified memory address
Yann 0:fa858f79d48d 236 *
Yann 0:fa858f79d48d 237 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 238 * @param p_byte The byte value to read
Yann 0:fa858f79d48d 239 * @return true on success, false otherwise
Yann 0:fa858f79d48d 240 * Exemple:
Yann 0:fa858f79d48d 241 * @code
Yann 0:fa858f79d48d 242 * unsigned char value;
Yann 0:fa858f79d48d 243 * ...
Yann 0:fa858f79d48d 244 * myEEPROM.Read(memoryAddress, (unsigned char *)&value);
Yann 0:fa858f79d48d 245 * ...
Yann 0:fa858f79d48d 246 * @endcode
Yann 0:fa858f79d48d 247 */
Yann 0:fa858f79d48d 248 bool Read(const short p_address, unsigned char *p_value);
Yann 0:fa858f79d48d 249
Yann 0:fa858f79d48d 250 /** Read a short from the specified memory address
Yann 0:fa858f79d48d 251 *
Yann 0:fa858f79d48d 252 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 253 * @param p_short The short value to read
Yann 0:fa858f79d48d 254 * @return true on success, false otherwise
Yann 0:fa858f79d48d 255 * Exemple:
Yann 0:fa858f79d48d 256 * @code
Yann 0:fa858f79d48d 257 * short value;
Yann 0:fa858f79d48d 258 * ...
Yann 0:fa858f79d48d 259 * myEEPROM.Read(memoryAddress, (short *)&value);
Yann 0:fa858f79d48d 260 * ...
Yann 0:fa858f79d48d 261 * @endcode
Yann 0:fa858f79d48d 262 */
Yann 0:fa858f79d48d 263 bool Read(const short p_address, short *p_short, CFM24VXX_I2C::Mode p_mode = BigEndian);
Yann 0:fa858f79d48d 264
Yann 0:fa858f79d48d 265 /** Read an integer from the specified memory address
Yann 0:fa858f79d48d 266 *
Yann 0:fa858f79d48d 267 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 268 * @param p_int The integer value to read
Yann 0:fa858f79d48d 269 * @return true on success, false otherwise
Yann 0:fa858f79d48d 270 * Exemple:
Yann 0:fa858f79d48d 271 * @code
Yann 0:fa858f79d48d 272 * int value;
Yann 0:fa858f79d48d 273 * ...
Yann 0:fa858f79d48d 274 * myEEPROM.Read(memoryAddress, (int *)&value);
Yann 0:fa858f79d48d 275 * ...
Yann 0:fa858f79d48d 276 * @endcode
Yann 0:fa858f79d48d 277 */
Yann 0:fa858f79d48d 278 bool Read(const short p_address, int *p_int, CFM24VXX_I2C::Mode p_mode = BigEndian);
Yann 0:fa858f79d48d 279
Yann 0:fa858f79d48d 280 /** Read a buffer of bytes from the specified memory address and store it into a std::vector<unsigned char> object
Yann 0:fa858f79d48d 281 *
Yann 0:fa858f79d48d 282 * Note that the size of the buffer object is used for the number of bytes to read
Yann 0:fa858f79d48d 283 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 284 * @param p_datas The buffer to fill
Yann 0:fa858f79d48d 285 * @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:fa858f79d48d 286 * @param p_length2read The number of character to write, -1 to use the size of the string buffer
Yann 0:fa858f79d48d 287 * @return true on success, false otherwise
Yann 0:fa858f79d48d 288 * Exemple:
Yann 0:fa858f79d48d 289 * @code
Yann 0:fa858f79d48d 290 * std::vector<unsigned char> datas(bufferLength);
Yann 0:fa858f79d48d 291 * ...
Yann 0:fa858f79d48d 292 * myEEPROM.Read(memoryAddress, datas);
Yann 0:fa858f79d48d 293 * ...
Yann 0:fa858f79d48d 294 * @endcode
Yann 0:fa858f79d48d 295 */
Yann 0:fa858f79d48d 296 bool Read(const short p_address, std::vector<unsigned char> & p_datas, bool p_readLengthFirst = true, int p_length2read = -1);
Yann 0:fa858f79d48d 297
Yann 0:fa858f79d48d 298 /** Read a buffer of characters from the specified memory address and store it into a string object
Yann 0:fa858f79d48d 299 *
Yann 0:fa858f79d48d 300 * Note that the size of the string object is used for the number of characters to read
Yann 0:fa858f79d48d 301 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 302 * @param p_string The string buffer to fill
Yann 0:fa858f79d48d 303 * @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:fa858f79d48d 304 * @param p_length2write The number of character to write, -1 to use the size of the string buffer
Yann 0:fa858f79d48d 305 * @return true on success, false otherwise
Yann 0:fa858f79d48d 306 * Exemple:
Yann 0:fa858f79d48d 307 * @code
Yann 0:fa858f79d48d 308 * std::string readtext;
Yann 0:fa858f79d48d 309 * ...
Yann 0:fa858f79d48d 310 * myEEPROM.Read(memoryAddress, readtext);
Yann 0:fa858f79d48d 311 * ...
Yann 0:fa858f79d48d 312 * @endcode
Yann 0:fa858f79d48d 313 */
Yann 0:fa858f79d48d 314 bool Read(const short p_address, std::string & p_string, bool p_readLengthFirst = true, int p_length2write = -1);
Yann 0:fa858f79d48d 315
Yann 0:fa858f79d48d 316 /** Activate or deactivate write protect (pin 7)
Yann 0:fa858f79d48d 317 *
Yann 0:fa858f79d48d 318 * @param p_writeProtect: Set to true to activate write protection, false otherwise
Yann 0:fa858f79d48d 319 * @return true on success, false otherwise
Yann 0:fa858f79d48d 320 */
Yann 0:fa858f79d48d 321 bool WriteProtect(const bool p_writeProtect);
Yann 0:fa858f79d48d 322
Yann 0:fa858f79d48d 323 /** Indicate the current WP state indicator (pin 7)
Yann 0:fa858f79d48d 324 * @return true is write protected, false otherwise
Yann 0:fa858f79d48d 325 */
Yann 0:fa858f79d48d 326 inline bool IsWriteProtected() {
Yann 0:fa858f79d48d 327 return (_wp != NULL) ? (bool)(_wp->read() == 1) : false;
Yann 0:fa858f79d48d 328 }
Yann 0:fa858f79d48d 329
Yann 0:fa858f79d48d 330 #if defined(__DEBUG)
Yann 0:fa858f79d48d 331 /** Dump a memory area
Yann 0:fa858f79d48d 332 *
Yann 0:fa858f79d48d 333 * Note that this method is available only on debug mode
Yann 0:fa858f79d48d 334 * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
Yann 0:fa858f79d48d 335 * @param p_count The number of bytes toi dump
Yann 0:fa858f79d48d 336 * @return true on success, false otherwise
Yann 0:fa858f79d48d 337 */
Yann 0:fa858f79d48d 338 void DumpMemoryArea(const int p_address, const int p_count);
Yann 0:fa858f79d48d 339 /** For debug purpose only
Yann 0:fa858f79d48d 340 */
Yann 0:fa858f79d48d 341 inline std::string & ToString() { return _internalId; };
Yann 0:fa858f79d48d 342 #else // __DEBUG
Yann 0:fa858f79d48d 343 inline void DumpMemoryArea(const int p_address, const int p_count) {};
Yann 0:fa858f79d48d 344 #endif // _DEBUG
Yann 0:fa858f79d48d 345
Yann 0:fa858f79d48d 346 private:
Yann 0:fa858f79d48d 347 /** Internal reference identifier
Yann 0:fa858f79d48d 348 */
Yann 0:fa858f79d48d 349 std::string _internalId;
Yann 0:fa858f79d48d 350
Yann 0:fa858f79d48d 351 private:
Yann 1:6a16bddd7222 352
Yann 1:6a16bddd7222 353 /** Retrieve device identifiers
Yann 0:fa858f79d48d 354 * @remark See FM24V10_ds.pdf Page 9/16 Clause Device ID
Yann 0:fa858f79d48d 355 */
Yann 1:6a16bddd7222 356 bool GetDevideIDs();
Yann 0:fa858f79d48d 357
Yann 1:6a16bddd7222 358 /**
Yann 1:6a16bddd7222 359 * Used to return the serial number
Yann 1:6a16bddd7222 360 * Note This functionality is available only for the FM24VN10. In other case, it will return 0xff
Yann 1:6a16bddd7222 361 * @remark See FM24V10_ds.pdf Page 10/16 Clause Unique Serial Number (FM24VN10 only)
Yann 1:6a16bddd7222 362 */
Yann 1:6a16bddd7222 363 bool GetSerialNumbers();
Yann 1:6a16bddd7222 364
Yann 1:6a16bddd7222 365 /**
Yann 1:6a16bddd7222 366 * Function to Calculate CRC
Yann 1:6a16bddd7222 367 * @param pdatas The read Serial Number
Yann 1:6a16bddd7222 368 * @param length The number of bytes in the pdatas array. Default: 7 bytes length
Yann 1:6a16bddd7222 369 * @return The 8-bits length checksum
Yann 1:6a16bddd7222 370 * @see See FM24V10_ds.pdf Page 10/16 Clause Unique Serial Number (FM24VN10 only)
Yann 1:6a16bddd7222 371 */
Yann 1:6a16bddd7222 372 unsigned char ChecksumSN(const unsigned char *pdatas, const unsigned int length = 7);
Yann 1:6a16bddd7222 373
Yann 0:fa858f79d48d 374 }; // End of class CFM24VXX_I2C
Yann 0:fa858f79d48d 375
Yann 0:fa858f79d48d 376 }; // End of namespace _FM24VXX_I2C
Yann 0:fa858f79d48d 377
Yann 0:fa858f79d48d 378 using namespace _FM24VXX_I2C;
Yann 0:fa858f79d48d 379
Yann 0:fa858f79d48d 380 #endif // __FM24VXX_I2C_H__