24LCXXX I2C eeprom library

Dependents:   flw

Fork of _24LCXXX by Hiroshi M

Committer:
Backstrom
Date:
Thu Feb 26 07:41:08 2015 +0000
Revision:
2:81497827f2ee
Parent:
1:c2bb7538cb69
Fixing page write and some cleanup

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 * ----------- ----------- -----------------------
Backstrom 2:81497827f2ee 14 * 2015/02/26 Akafugu Fixing page write
bant62 0:859387a87312 15 * 2012/12/06 Hiroshi M init
bant62 0:859387a87312 16 *****************************************************************************
bant62 0:859387a87312 17 *
bant62 0:859387a87312 18 * Copyright (C) 2013 Hiroshi M, MIT License
bant62 0:859387a87312 19 *
bant62 0:859387a87312 20 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bant62 0:859387a87312 21 * and associated documentation files (the "Software"), to deal in the Software without restriction,
bant62 0:859387a87312 22 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
bant62 0:859387a87312 23 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
bant62 0:859387a87312 24 * furnished to do so, subject to the following conditions:
bant62 0:859387a87312 25 *
bant62 0:859387a87312 26 * The above copyright notice and this permission notice shall be included in all copies or
bant62 0:859387a87312 27 * substantial portions of the Software.
bant62 0:859387a87312 28 *
bant62 0:859387a87312 29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bant62 0:859387a87312 30 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bant62 0:859387a87312 31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bant62 0:859387a87312 32 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bant62 0:859387a87312 33 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bant62 0:859387a87312 34 *
bant62 0:859387a87312 35 **/
bant62 0:859387a87312 36
bant62 0:859387a87312 37 #ifndef __24LCXXX_H_
bant62 0:859387a87312 38 #define __24LCXXX_H_
bant62 0:859387a87312 39
bant62 0:859387a87312 40 /* Includes ----------------------------------------------------------------- */
bant62 0:859387a87312 41 #include "mbed.h"
bant62 0:859387a87312 42
bant62 0:859387a87312 43 /* typedef ------------------------------------------------------------------ */
bant62 0:859387a87312 44
bant62 0:859387a87312 45 /* define ------------------------------------------------------------------- */
bant62 0:859387a87312 46 #define I2C_ADDR_24LCXXX 0x50
perjg 1:c2bb7538cb69 47 #define __24LC512__
bant62 0:859387a87312 48
bant62 0:859387a87312 49 #if defined(__24LC64__)
bant62 0:859387a87312 50 #define MAXADR_24LCXXX 8192
bant62 0:859387a87312 51 #define PAGE_SIZE_24LCXXX 32
bant62 0:859387a87312 52 #endif
bant62 0:859387a87312 53
bant62 0:859387a87312 54 #if defined(__24LC128__)
bant62 0:859387a87312 55 #define MAXADR_24LCXXX 16384
bant62 0:859387a87312 56 #define PAGE_SIZE_24LCXXX 64
bant62 0:859387a87312 57 #endif
bant62 0:859387a87312 58
bant62 0:859387a87312 59 #if defined(__24LC256__)
bant62 0:859387a87312 60 #define MAXADR_24LCXXX 32768
bant62 0:859387a87312 61 #define PAGE_SIZE_24LCXXX 64
bant62 0:859387a87312 62 #endif
bant62 0:859387a87312 63
perjg 1:c2bb7538cb69 64 #if defined(__24LC512__)
perjg 1:c2bb7538cb69 65 #define MAXADR_24LCXXX 65536
perjg 1:c2bb7538cb69 66 #define PAGE_SIZE_24LCXXX 128
perjg 1:c2bb7538cb69 67 #endif
perjg 1:c2bb7538cb69 68
bant62 0:859387a87312 69 /* macro -------------------------------------------------------------------- */
bant62 0:859387a87312 70 /* variables ---------------------------------------------------------------- */
bant62 0:859387a87312 71 /* class -------------------------------------------------------------------- */
bant62 0:859387a87312 72
bant62 0:859387a87312 73 class _24LCXXX
bant62 0:859387a87312 74 {
Backstrom 2:81497827f2ee 75 public:
Backstrom 2:81497827f2ee 76 _24LCXXX(I2C *i2c, const int address=I2C_ADDR_24LCXXX );
Backstrom 2:81497827f2ee 77 _24LCXXX(I2C *i2c, Serial *pc, const int address=I2C_ADDR_24LCXXX );
Backstrom 2:81497827f2ee 78 int nbyte_read( int mem_addr, void *data, int size );
Backstrom 2:81497827f2ee 79 int byte_write( int mem_addr, char data );
Backstrom 2:81497827f2ee 80 int nbyte_write( int mem_addr, char *data, int size );
Backstrom 2:81497827f2ee 81 int nbyte_set( int mem_addr, char data, int size );
Backstrom 2:81497827f2ee 82
bant62 0:859387a87312 83 private:
bant62 0:859387a87312 84 int _i2c_address;
bant62 0:859387a87312 85 I2C *_i2c;
bant62 0:859387a87312 86 Serial *_pc;
bant62 0:859387a87312 87 bool _debug;
bant62 0:859387a87312 88
Backstrom 2:81497827f2ee 89 int page_block( int mem_addr, char *data, uint16_t length, bool incrBuffer );
Backstrom 2:81497827f2ee 90 int page_write( int mem_addr, char *data, uint16_t length);
bant62 0:859387a87312 91 };
bant62 0:859387a87312 92
Backstrom 2:81497827f2ee 93 #endif /* __24LCXXX_H_ */