This class provides simplified I2C access to a Microchip 24LCxx Serial EEPROM device: - Rename the class (C2424 -> C24) - Add EraseMemoryArea method - Add DumpMemoryArea method only accessible in DEBUG mode - Add 'const' qualifier in parameters
Fork of 24LCxx_I2C by
24LCxx_I2C.h@5:2f61885d8bc3, 2018-09-13 (annotated)
- Committer:
- acesrobertm
- Date:
- Thu Sep 13 09:56:13 2018 -0500
- Revision:
- 5:2f61885d8bc3
- Parent:
- 4:650f3259bd4f
away auto close feature added and enabled readers 2 and 3
Who changed what in which revision?
User | Revision | Line number | New 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 | |
acesrobertm | 3:5df584fbabfe | 22 | #include "mbed.h" |
Yann | 0:21c698aa86f6 | 23 | |
Yann | 0:21c698aa86f6 | 24 | namespace _24LCXX_I2C { |
acesrobertm | 4:650f3259bd4f | 25 | class C24LCXX_I2C { |
Yann | 0:21c698aa86f6 | 26 | /** 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 | 27 | */ |
Yann | 0:21c698aa86f6 | 28 | unsigned char _slaveAddress; |
Yann | 0:21c698aa86f6 | 29 | /** WP state indicator (pin 7); true is write protected, false otherwise |
Yann | 0:21c698aa86f6 | 30 | */ |
Yann | 0:21c698aa86f6 | 31 | DigitalOut *_wp; |
Yann | 0:21c698aa86f6 | 32 | /** An unique instance of I2C class |
Yann | 0:21c698aa86f6 | 33 | */ |
Yann | 0:21c698aa86f6 | 34 | I2C *_i2cInstance; |
Yann | 0:21c698aa86f6 | 35 | public: |
Yann | 0:21c698aa86f6 | 36 | /** Memory storage mode |
Yann | 0:21c698aa86f6 | 37 | */ |
Yann | 0:21c698aa86f6 | 38 | enum Mode { |
Yann | 0:21c698aa86f6 | 39 | LittleEndian, //<! Little Endian mode: 0xA0B70708 is stored as 08: MSB and A0 LSB |
Yann | 0:21c698aa86f6 | 40 | BigEndian //<! Little Endian mode: 0xA0B70708 is stored as AO: MSB and 08 LSB |
Yann | 0:21c698aa86f6 | 41 | }; |
Yann | 0:21c698aa86f6 | 42 | public: |
acesrobertm | 5:2f61885d8bc3 | 43 | C24LCXX_I2C(const PinName p_sda, const PinName p_scl, const unsigned char p_address, const uint32_t p_frequency = 400000); |
Yann | 0:21c698aa86f6 | 44 | virtual ~C24LCXX_I2C(); |
Yann | 0:21c698aa86f6 | 45 | |
acesrobertm | 5:2f61885d8bc3 | 46 | bool Write(const uint16_t p_address, const uint8_t p_byte); |
acesrobertm | 5:2f61885d8bc3 | 47 | bool Write(const uint16_t p_address, const uint16_t p_short, const C24LCXX_I2C::Mode p_mode = BigEndian); |
acesrobertm | 5:2f61885d8bc3 | 48 | bool Write(const uint16_t p_address, const uint32_t p_int, const C24LCXX_I2C::Mode p_mode = BigEndian); |
acesrobertm | 5:2f61885d8bc3 | 49 | bool Read(const uint16_t p_address, unsigned char *p_value); |
acesrobertm | 5:2f61885d8bc3 | 50 | bool Read(const uint16_t p_address, uint16_t *p_short, C24LCXX_I2C::Mode p_mode = BigEndian); |
acesrobertm | 5:2f61885d8bc3 | 51 | bool Read(const uint16_t p_address, uint32_t *p_int, C24LCXX_I2C::Mode p_mode = BigEndian); |
Yann | 0:21c698aa86f6 | 52 | |
Yann | 0:21c698aa86f6 | 53 | private: |
Yann | 0:21c698aa86f6 | 54 | }; // End of class C24LCXX_I2C |
Yann | 0:21c698aa86f6 | 55 | |
Yann | 0:21c698aa86f6 | 56 | } // End of namespace _24LCXX_I2C |
Yann | 0:21c698aa86f6 | 57 | |
Yann | 0:21c698aa86f6 | 58 | using namespace _24LCXX_I2C; |
Yann | 0:21c698aa86f6 | 59 | |
Yann | 0:21c698aa86f6 | 60 | #endif // __24LCXX_I2C_H__ |