I2C EEPROM 24LCXXX Driver

Dependents:   LPC1114_EBadge

Fork of _24LCXXX by Hiroshi M

Committer:
allankliu
Date:
Mon Jun 09 11:00:20 2014 +0000
Revision:
1:6535ae170a0c
Parent:
0:859387a87312
Change eeprom to _24LCXXX libs, with software SPI bus and other changes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bant62 0:859387a87312 1 /**
bant62 0:859387a87312 2 *****************************************************************************
bant62 0:859387a87312 3 * File Name : _24LCXXX.h
bant62 0:859387a87312 4 *
bant62 0:859387a87312 5 * Title : I2C EEPROM 24LCXXX Claass Header File
bant62 0:859387a87312 6 * Revision : 0.1
bant62 0:859387a87312 7 * Notes :
bant62 0:859387a87312 8 * Target Board : mbed NXP LPC1768, mbed LPC1114FN28 etc
bant62 0:859387a87312 9 * Tool Chain : ????
bant62 0:859387a87312 10 *
bant62 0:859387a87312 11 * Revision History:
bant62 0:859387a87312 12 * When Who Description of change
bant62 0:859387a87312 13 * ----------- ----------- -----------------------
bant62 0:859387a87312 14 * 2012/12/06 Hiroshi M init
bant62 0:859387a87312 15 *****************************************************************************
bant62 0:859387a87312 16 *
bant62 0:859387a87312 17 * Copyright (C) 2013 Hiroshi M, MIT License
bant62 0:859387a87312 18 *
bant62 0:859387a87312 19 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bant62 0:859387a87312 20 * and associated documentation files (the "Software"), to deal in the Software without restriction,
bant62 0:859387a87312 21 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
bant62 0:859387a87312 22 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
bant62 0:859387a87312 23 * furnished to do so, subject to the following conditions:
bant62 0:859387a87312 24 *
bant62 0:859387a87312 25 * The above copyright notice and this permission notice shall be included in all copies or
bant62 0:859387a87312 26 * substantial portions of the Software.
bant62 0:859387a87312 27 *
bant62 0:859387a87312 28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bant62 0:859387a87312 29 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bant62 0:859387a87312 30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bant62 0:859387a87312 31 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bant62 0:859387a87312 32 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bant62 0:859387a87312 33 *
bant62 0:859387a87312 34 **/
bant62 0:859387a87312 35
bant62 0:859387a87312 36 #ifndef __24LCXXX_H_
bant62 0:859387a87312 37 #define __24LCXXX_H_
bant62 0:859387a87312 38
bant62 0:859387a87312 39 /* Includes ----------------------------------------------------------------- */
bant62 0:859387a87312 40 #include "mbed.h"
bant62 0:859387a87312 41
bant62 0:859387a87312 42 /* typedef ------------------------------------------------------------------ */
bant62 0:859387a87312 43
bant62 0:859387a87312 44 /* define ------------------------------------------------------------------- */
allankliu 1:6535ae170a0c 45 #define I2C_ADDR_24LCXXX 0x50 // by moving left, it becomes 0xA0
bant62 0:859387a87312 46 #define __24LC256__
bant62 0:859387a87312 47
bant62 0:859387a87312 48 #if defined(__24LC64__)
bant62 0:859387a87312 49 #define MAXADR_24LCXXX 8192
bant62 0:859387a87312 50 #define PAGE_SIZE_24LCXXX 32
bant62 0:859387a87312 51 #endif
bant62 0:859387a87312 52
bant62 0:859387a87312 53 #if defined(__24LC128__)
bant62 0:859387a87312 54 #define MAXADR_24LCXXX 16384
bant62 0:859387a87312 55 #define PAGE_SIZE_24LCXXX 64
bant62 0:859387a87312 56 #endif
bant62 0:859387a87312 57
bant62 0:859387a87312 58 #if defined(__24LC256__)
bant62 0:859387a87312 59 #define MAXADR_24LCXXX 32768
bant62 0:859387a87312 60 #define PAGE_SIZE_24LCXXX 64
bant62 0:859387a87312 61 #endif
bant62 0:859387a87312 62
bant62 0:859387a87312 63 /* macro -------------------------------------------------------------------- */
bant62 0:859387a87312 64 /* variables ---------------------------------------------------------------- */
bant62 0:859387a87312 65 /* class -------------------------------------------------------------------- */
bant62 0:859387a87312 66
bant62 0:859387a87312 67 class _24LCXXX
bant62 0:859387a87312 68 {
bant62 0:859387a87312 69 private:
bant62 0:859387a87312 70 int _i2c_address;
bant62 0:859387a87312 71 I2C *_i2c;
bant62 0:859387a87312 72 Serial *_pc;
bant62 0:859387a87312 73 bool _debug;
bant62 0:859387a87312 74
bant62 0:859387a87312 75 public:
bant62 0:859387a87312 76 _24LCXXX(I2C *i2c, const int address=I2C_ADDR_24LCXXX );
bant62 0:859387a87312 77 _24LCXXX(I2C *i2c, Serial *pc, const int address=I2C_ADDR_24LCXXX );
bant62 0:859387a87312 78 int byte_write( int mem_addr, char data );
bant62 0:859387a87312 79 int nbyte_write( int mem_addr, void *data, int size );
bant62 0:859387a87312 80 int page_write( int mem_addr, char *data );
bant62 0:859387a87312 81 int nbyte_read( int mem_addr, void *data, int size );
bant62 0:859387a87312 82 };
bant62 0:859387a87312 83
bant62 0:859387a87312 84 #endif /* __24LCXXX_H_ */