a simple wrapper above I2C to provider EEPROM access API

Dependents:   ou_mbed_oled ou_mbed_eeprom ou_mbed_tmp102

eeprom.h

Committer:
poushen
Date:
2018-06-15
Revision:
0:3de36cc169a3
Child:
1:0c876c06b026

File content as of revision 0:3de36cc169a3:





#include "mbed.h"

#define EEPROM_ADDR 0xA0

enum {
    ONE_BYTE_ADDRESS = 1,
    TWO_BYTES_ADDRESS,
    THREE_BYTES_ADDRESS
};

class eeprom
{
public:
    /** Create a eeprom instance connected to specified I2C pins with specified address
     *
     * @param i2c_obj I2C object (instance)
     * @param address (option) I2C-bus slave address (default: 0xA0)
     */
    eeprom(I2C &i2c_obj, char address = EEPROM_ADDR);

    /** Initialization */
    void init(void);
    
    /** Write address
     *  
     * @param address eeprom memory address
     * @param address_size should be 1 - 3
     */
    void write_address(int address, int address_size, bool repeated=false);

    /** Current read
     *
     * @param data the current memory data
     */
    void current_read(uint8_t *data);
    
    /** Sequential read
     *
     * @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
     *
     * @param address eeprom memory address
     * @param address_size should be 1 - 3
     * @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
     *
     * @param address eeprom memory address
     * @param address_size should be 1 - 3
     * @param data the byte data to write
     */
    void byte_write(int address, int address_size, uint8_t data, bool repeated=false);
    
    /** page write
     *
     * @param address eeprom memory address
     * @param address_size should be 1 - 3
     * @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 */
    void ack_polling(void);

private:
    I2C &i2c;
    char adr;
};