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
--- a/eeprom.cpp	Fri Jun 15 13:02:30 2018 +0000
+++ b/eeprom.cpp	Fri Jun 15 23:03:32 2018 +0000
@@ -8,35 +8,20 @@
 
 void eeprom::init(void)
 {
+    i2c.frequency(400*1000);
 }
 
 void eeprom::write_address(int address, int address_size, bool repeated)
-{   /*
-    uint8_t mem_address[] = {0, 0, 0};
-    
-    switch (address_size) {
-        case ONE_BYTE_ADDRESS:
-            mem_address[0] = address & 0xFF;
-            break;
-        case TWO_BYTES_ADDRESS:
-            mem_address[0] = (address >> 8) & 0xFF;
-            mem_address[1] = address & 0xFF;
-            break;
-        case THREE_BYTES_ADDRESS:
-            mem_address[0] = (address >> 16) & 0xFF;
-            mem_address[1] = (address >> 8) & 0xFF;
-            mem_address[2] = address & 0xFF;
-            break;
-    }
-    i2c.write((int)adr,(char *)mem_address,address_size,repeated);
-    */
+{   
     uint8_t buffer[4] = { 0, 0, 0, 0 };
     page_write(address, address_size, buffer, 0);
 }
 
-void eeprom::current_read(uint8_t *data)
+uint8_t eeprom::current_read(void)
 {
-    i2c.read((int)adr,(char *)data,1);
+    uint8_t data;
+    i2c.read((int)adr,(char *)&data,1);
+    return data;
 }
 
 void eeprom::sequential_read(uint8_t *buffer, int buffer_size)
@@ -51,26 +36,7 @@
 }
 
 void eeprom::byte_write(int address, int address_size, uint8_t data, bool repeated)
-{   /*
-    uint8_t mem_address[] = {0, 0, 0, 0};
-    mem_address[3] = data;
-    
-    switch (address_size) {
-        case ONE_BYTE_ADDRESS:
-            mem_address[2] = address & 0xFF;
-            break;
-        case TWO_BYTES_ADDRESS:
-            mem_address[1] = (address >> 8) & 0xFF;
-            mem_address[2] = address & 0xFF;
-            break;
-        case THREE_BYTES_ADDRESS:
-            mem_address[0] = (address >> 16) & 0xFF;
-            mem_address[1] = (address >> 8) & 0xFF;
-            mem_address[2] = address & 0xFF;
-            break;
-    }
-    i2c.write((int)adr,(char *)(mem_address + (3 - address_size)),address_size+1,repeated);
-    */
+{   
     uint8_t buffer[4] = { 0, 0, 0, 0 };
     buffer[3] = data;
     page_write(address, address_size, buffer, 1);
@@ -102,8 +68,7 @@
     int ack;
     
     do {
-        ack = i2c.write((int)adr, (char *)buffer, 1);
+        ack = i2c.write((int)adr, (char *)buffer, 1, true);
     } while(ack == 1);
+    i2c.stop();
 }
-
-