at24cxxx.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
23 #ifndef AT24CXXX_H
24 #define AT24CXXX_H
25 
26 #include <stdint.h>
27 
28 #include "periph/gpio.h"
29 #include "periph/i2c.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 enum {
39  AT24CXXX_OK,
40  AT24CXXX_I2C_ERROR
41 };
42 
46 typedef struct at24cxxx_params {
48  gpio_t pin_wp;
49  uint32_t eeprom_size;
50  uint8_t dev_addr;
51  uint8_t page_size;
52  uint8_t max_polls;
54 
58 typedef struct {
60 } at24cxxx_t;
61 
72 int at24cxxx_init(at24cxxx_t *dev, const at24cxxx_params_t *params);
73 
85 int at24cxxx_read_byte(const at24cxxx_t *dev, uint32_t pos, void *dest);
86 
99 int at24cxxx_read(const at24cxxx_t *dev, uint32_t pos, void *data,
100  size_t len);
101 
113 int at24cxxx_write_byte(const at24cxxx_t *dev, uint32_t pos, uint8_t data);
114 
129 int at24cxxx_write(const at24cxxx_t *dev, uint32_t pos, const void *data,
130  size_t len);
131 
146 int at24cxxx_write_page(const at24cxxx_t *dev, uint32_t page, uint32_t offset,
147  const void *data, size_t len);
148 
164 int at24cxxx_set(const at24cxxx_t *dev, uint32_t pos, uint8_t val,
165  size_t len);
166 
179 int at24cxxx_clear(const at24cxxx_t *dev, uint32_t pos, size_t len);
180 
190 int at24cxxx_erase(const at24cxxx_t *dev);
191 
201 
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif /* AT24CXXX_H */
217 
at24cxxx_set
int at24cxxx_set(const at24cxxx_t *dev, uint32_t pos, uint8_t val, size_t len)
Set len bytes from a given position pos to the value val.
at24cxxx_erase
int at24cxxx_erase(const at24cxxx_t *dev)
Set the entire EEPROM memory to AT24CXXX_CLEAR_BYTE.
at24cxxx_init
int at24cxxx_init(at24cxxx_t *dev, const at24cxxx_params_t *params)
Initialize an AT24CXXX device handle with AT24CXXX parameters.
at24cxxx_params_t
struct at24cxxx_params at24cxxx_params_t
Struct that holds initialization parameters.
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
at24cxxx_params::dev_addr
uint8_t dev_addr
I2C device address.
Definition: at24cxxx.h:50
at24cxxx_enable_write_protect
int at24cxxx_enable_write_protect(const at24cxxx_t *dev)
Enable write protection.
at24cxxx_params::page_size
uint8_t page_size
page size
Definition: at24cxxx.h:51
at24cxxx_clear
int at24cxxx_clear(const at24cxxx_t *dev, uint32_t pos, size_t len)
Set len bytes from position pos to AT24CXXX_CLEAR_BYTE.
at24cxxx_disable_write_protect
int at24cxxx_disable_write_protect(const at24cxxx_t *dev)
Disable write protection.
at24cxxx_params::pin_wp
gpio_t pin_wp
write protect pin
Definition: at24cxxx.h:48
at24cxxx_params::eeprom_size
uint32_t eeprom_size
EEPROM memory capacity.
Definition: at24cxxx.h:49
at24cxxx_write_byte
int at24cxxx_write_byte(const at24cxxx_t *dev, uint32_t pos, uint8_t data)
Write a byte at a given position pos.
at24cxxx_read
int at24cxxx_read(const at24cxxx_t *dev, uint32_t pos, void *data, size_t len)
Sequentially read len bytes from a given position pos.
at24cxxx_params::max_polls
uint8_t max_polls
number of ACK poll attempts
Definition: at24cxxx.h:52
at24cxxx_write
int at24cxxx_write(const at24cxxx_t *dev, uint32_t pos, const void *data, size_t len)
Sequentially write len bytes from a given position pos.
at24cxxx_write_page
int at24cxxx_write_page(const at24cxxx_t *dev, uint32_t page, uint32_t offset, const void *data, size_t len)
Sequentially write len bytes to a given page.
gpio.h
Low-level GPIO peripheral driver interface definitions.
at24cxxx_t
Struct that represents an AT24CXXX device.
Definition: at24cxxx.h:58
at24cxxx_params::i2c
i2c_t i2c
I2C bus number.
Definition: at24cxxx.h:47
at24cxxx_t::params
at24cxxx_params_t params
parameters
Definition: at24cxxx.h:59
i2c.h
Low-level I2C peripheral driver interface definition.
at24cxxx_params
Struct that holds initialization parameters.
Definition: at24cxxx.h:46
at24cxxx_read_byte
int at24cxxx_read_byte(const at24cxxx_t *dev, uint32_t pos, void *dest)
Read a byte at a given position pos.