a simple wrapper above I2C to provider EEPROM access API

Dependents:   ou_mbed_oled ou_mbed_eeprom ou_mbed_tmp102

Revision:
1:0c876c06b026
Parent:
0:3de36cc169a3
Child:
2:ce12a405cd3a
--- a/eeprom.h	Fri Jun 15 13:02:30 2018 +0000
+++ b/eeprom.h	Fri Jun 15 23:03:32 2018 +0000
@@ -1,17 +1,46 @@
-
-
-
+/** A class for eeprom accesss operation
+ *
+ *  @author  Poushen Ou
+ *  @version 1.0
+ *  @date    15-Jun-2018
+ *
+ *  This code provide classic access operation for I2C EEPROM
+ *
+ *  About I2C EEPROM 24FC256:
+ *      http://ww1.microchip.com/downloads/en/DeviceDoc/21203M.pdf
+ */
 
 #include "mbed.h"
 
 #define EEPROM_ADDR 0xA0
 
-enum {
-    ONE_BYTE_ADDRESS = 1,
-    TWO_BYTES_ADDRESS,
-    THREE_BYTES_ADDRESS
-};
-
+/** eeprom Class Library
+ * to provide very simple interface for mbed
+ *
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "eeprom.h"
+ *
+ * // make eeprom instance using I2C object.
+ * // with default slave address 0xA0 (0x50 in 7bit format)
+ * // test ok with 24FC256 EEPROM
+ * I2C i2c(dp5,dp27);
+ * eeprom epm(i2c);
+ *
+ * int main()
+ * {
+ *     epm.write_address(12288, TWO_BYTES_ADDRESS);
+ * 
+ *     for (int i=0; i< 64; i++) {
+ *       printf("%.2x ", epm.current_read());
+ *     }
+ *     printf("\n\r");
+ *
+ *     while(1);
+ * }
+ * @endcode
+ */
 class eeprom
 {
 public:
@@ -25,55 +54,62 @@
     /** Initialization */
     void init(void);
     
-    /** Write address
+    /** Write address with specify address size
      *  
      * @param address eeprom memory address
-     * @param address_size should be 1 - 3
+     * @param address_size should be 1 - 3(ONE_BYTE_ADDRESS, TWO_BYTES_ADDRESS, THREE_BYTES_ADDRESS)
      */
     void write_address(int address, int address_size, bool repeated=false);
 
-    /** Current read
+    /** Current read, read the current memory data
      *
-     * @param data the current memory data
+     * @return the current memory data
      */
-    void current_read(uint8_t *data);
+    uint8_t current_read(void);
     
-    /** Sequential read
+    /** Sequential read, read one or many bytes from current memory address
      *
      * @param buffer the start address point to buffer
      * @param buffer_size the length of buffer
      */
     void sequential_read(uint8_t *buffer, int buffer_size);
     
-    /** Random read
+    /** Random read, read one or more memory data from assign memory address
      *
      * @param address eeprom memory address
-     * @param address_size should be 1 - 3
+     * @param address_size should be 1 - 3 (ONE_BYTE_ADDRESS, TWO_BYTES_ADDRESS, THREE_BYTES_ADDRESS)
      * @param buffer the start address point to buffer
      * @param buffer_size the length of buffer
      */
      void random_read(int address, int address_size, uint8_t *buffer, int buffer_size);
      
-    /** byte write
+    /** byte write, write one byte to assign memory address
      *
      * @param address eeprom memory address
-     * @param address_size should be 1 - 3
+     * @param address_size should be 1 - 3(ONE_BYTE_ADDRESS, TWO_BYTES_ADDRESS, THREE_BYTES_ADDRESS)
      * @param data the byte data to write
      */
     void byte_write(int address, int address_size, uint8_t data, bool repeated=false);
     
-    /** page write
+    /** page write, write many bytes to assign memory address
+     * , do not deal with page size and aligned problem, be careful to use!!!
      *
      * @param address eeprom memory address
-     * @param address_size should be 1 - 3
+     * @param address_size should be 1 - 3(ONE_BYTE_ADDRESS, TWO_BYTES_ADDRESS, THREE_BYTES_ADDRESS)
      * @param buffer the page data to write
      */
     void page_write(int address, int address_size, uint8_t *buffer, int buffer_size, bool repeated=false);
     
-    /** ack polling */
+    /** ack polling, wait for EEPROM write completed */
     void ack_polling(void);
 
 private:
     I2C &i2c;
     char adr;
-};
\ No newline at end of file
+};
+
+enum {
+    ONE_BYTE_ADDRESS = 1,
+    TWO_BYTES_ADDRESS,
+    THREE_BYTES_ADDRESS
+};