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 
68 #ifndef AT24CXXX_H
69 #define AT24CXXX_H
70 
71 #include <stdint.h>
72 
73 #include "periph/gpio.h"
74 #include "periph/i2c.h"
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
83 enum {
84  AT24CXXX_OK,
85  AT24CXXX_I2C_ERROR
86 };
87 
91 typedef struct at24cxxx_params {
93  gpio_t pin_wp;
94  uint32_t eeprom_size;
95  uint8_t dev_addr;
96  uint8_t page_size;
97  uint8_t max_polls;
99 
103 typedef struct {
105 } at24cxxx_t;
106 
117 int at24cxxx_init(at24cxxx_t *dev, const at24cxxx_params_t *params);
118 
130 int at24cxxx_read_byte(const at24cxxx_t *dev, uint32_t pos, void *dest);
131 
144 int at24cxxx_read(const at24cxxx_t *dev, uint32_t pos, void *data, size_t len);
145 
157 int at24cxxx_write_byte(const at24cxxx_t *dev, uint32_t pos, uint8_t data);
158 
173 int at24cxxx_write(const at24cxxx_t *dev, uint32_t pos, const void *data,
174  size_t len);
175 
191 int at24cxxx_set(const at24cxxx_t *dev, uint32_t pos, uint8_t val,
192  size_t len);
193 
206 int at24cxxx_clear(const at24cxxx_t *dev, uint32_t pos, size_t len);
207 
217 int at24cxxx_erase(const at24cxxx_t *dev);
218 
228 
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif /* AT24CXXX_H */
Low-level GPIO peripheral driver interface definitions.
int at24cxxx_enable_write_protect(const at24cxxx_t *dev)
Enable write protection.
int at24cxxx_write_byte(const at24cxxx_t *dev, uint32_t pos, uint8_t data)
Write a byte at a given position pos.
int at24cxxx_clear(const at24cxxx_t *dev, uint32_t pos, size_t len)
Set len bytes from position pos to AT24CXXX_CLEAR_BYTE.
struct at24cxxx_params at24cxxx_params_t
Struct that holds initialization parameters.
int at24cxxx_read_byte(const at24cxxx_t *dev, uint32_t pos, void *dest)
Read a byte at a given position pos.
int at24cxxx_erase(const at24cxxx_t *dev)
Set the entire EEPROM memory to AT24CXXX_CLEAR_BYTE.
int at24cxxx_init(at24cxxx_t *dev, const at24cxxx_params_t *params)
Initialize an AT24CXXX device handle with AT24CXXX parameters.
int at24cxxx_read(const at24cxxx_t *dev, uint32_t pos, void *data, size_t len)
Sequentially read len bytes from a given position pos.
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.
int at24cxxx_disable_write_protect(const at24cxxx_t *dev)
Disable write protection.
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.
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:145
Low-level I2C peripheral driver interface definition.
Struct that holds initialization parameters.
Definition: at24cxxx.h:91
uint32_t eeprom_size
EEPROM memory capacity.
Definition: at24cxxx.h:94
uint8_t dev_addr
I2C device address.
Definition: at24cxxx.h:95
i2c_t i2c
I2C bus number.
Definition: at24cxxx.h:92
gpio_t pin_wp
write protect pin
Definition: at24cxxx.h:93
uint8_t max_polls
number of ACK poll attempts
Definition: at24cxxx.h:97
uint8_t page_size
page size
Definition: at24cxxx.h:96
Struct that represents an AT24CXXX device.
Definition: at24cxxx.h:103
at24cxxx_params_t params
parameters
Definition: at24cxxx.h:104