Library to use 25LCxxx chips
Fork of 25LCxxx_SPI by
Embed:
(wiki syntax)
Show/hide line numbers
Ser25lcxxx.h
00001 /* 00002 * Ser25lcxxx library 00003 * Copyright (c) 2010 Hendrik Lipka 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 */ 00023 00024 #ifndef __SER25LCXXX_H__ 00025 #define __SER25LCXXX_H__ 00026 00027 #include "mbed.h" 00028 00029 /** 00030 A class to read and write all 25* serial SPI eeprom devices from Microchip (from 25xx010 to 25xx1024). 00031 00032 One needs to provide total size and page size, since this cannot be read from the devices, 00033 and the page size differs even by constant size (look up the data sheet for your part!) 00034 */ 00035 class Ser25LCxxx 00036 { 00037 public: 00038 /** 00039 create the handler class 00040 @param spi the SPI port where the eeprom is connected. Must be set to format(8,3), and with a speed matching the one of your device (up to 5MHz should work) 00041 @param enable the pin name for the port where /CS is connected 00042 @param bytes the size of you eeprom in bytes (NOT bits, eg. a 25LC010 has 128 bytes) 00043 @param pagesize the size of a single page, to provide overruns 00044 */ 00045 Ser25LCxxx(SPI *spi, PinName enable, uint32_t bytes, uint32_t pagesize); 00046 00047 /** 00048 destroys the handler, and frees the /CS pin 00049 */ 00050 ~Ser25LCxxx(); 00051 00052 /** 00053 read a part of the eeproms memory. The buffer will be allocated here, and must be freed by the user 00054 @param startAdr the adress where to start reading. Doesn't need to match a page boundary 00055 @param len the number of bytes to read (must not exceed the end of memory) 00056 @return NULL if the adresses are out of range, the pointer to the data otherwise 00057 */ 00058 uint8_t* read( uint32_t startAdr, uint32_t len); 00059 00060 /** 00061 writes the give buffer into the memory. This function handles dividing the write into 00062 pages, and waites until the phyiscal write has finished 00063 @param startAdr the adress where to start writing. Doesn't need to match a page boundary 00064 @param len the number of bytes to read (must not exceed the end of memory) 00065 @return false if the adresses are out of range 00066 */ 00067 bool write( uint32_t startAdr, uint32_t len, const uint8_t* data); 00068 00069 /** 00070 fills the given page with 0xFF 00071 @param pageNum the page number to clear 00072 @return if the pageNum is out of range 00073 */ 00074 bool clearPage( uint32_t pageNum); 00075 00076 /** 00077 fills the while eeprom with 0xFF 00078 */ 00079 void clearMem(); 00080 private: 00081 bool writePage( uint32_t startAdr, uint32_t len, const uint8_t* data); 00082 uint8_t readStatus(); 00083 void waitForWrite(); 00084 void enableWrite(); 00085 00086 00087 SPI* _spi; 00088 DigitalOut* _enable; 00089 uint32_t _size,_pageSize; 00090 00091 }; 00092 00093 00094 00095 #endif
Generated on Tue Aug 9 2022 16:22:07 by 1.7.2