at25xxx.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 ML!PA Consulting GmbH
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 AT25XXX_H
24 #define AT25XXX_H
25 
26 #include <stdint.h>
27 #include <stdbool.h>
28 
29 #include "periph/spi.h"
30 #include "periph/gpio.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
39 typedef struct {
43  gpio_t wp_pin;
44  gpio_t hold_pin;
45  uint32_t size;
46  uint16_t page_size;
48 
52 typedef struct {
54 } at25xxx_t;
55 
65 int at25xxx_init(at25xxx_t *dev, const at25xxx_params_t *params);
66 
75 uint8_t at25xxx_read_byte(const at25xxx_t *dev, uint32_t pos);
76 
88 int at25xxx_read(const at25xxx_t *dev, uint32_t pos, void *data, size_t len);
89 
97 void at25xxx_write_byte(const at25xxx_t *dev, uint32_t pos, uint8_t data);
98 
110 int at25xxx_write(const at25xxx_t *dev, uint32_t pos, const void *data, size_t len);
111 
125 int at25xxx_write_page(const at25xxx_t *dev, uint32_t page, uint32_t offset,
126  const void *data, size_t len);
127 
140 int at25xxx_set(const at25xxx_t *dev, uint32_t pos, uint8_t val, size_t len);
141 
154 int at25xxx_clear(const at25xxx_t *dev, uint32_t pos, size_t len);
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* AT25XXX_H */
at25xxx_params_t::spi_clk
spi_clk_t spi_clk
SPI clock speed to use.
Definition: at25xxx.h:41
at25xxx_params_t::cs_pin
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition: at25xxx.h:42
spi.h
Low-level SPI peripheral driver interface definition.
at25xxx_t::params
at25xxx_params_t params
parameters
Definition: at25xxx.h:53
at25xxx_params_t::spi
spi_t spi
SPI bus the device is connected to.
Definition: at25xxx.h:40
at25xxx_t
struct that represents an AT25XXX device
Definition: at25xxx.h:52
at25xxx_params_t::size
uint32_t size
Size of the EEPROM in bytes.
Definition: at25xxx.h:45
at25xxx_write
int at25xxx_write(const at25xxx_t *dev, uint32_t pos, const void *data, size_t len)
Sequentially write len bytes from a given position pos.
at25xxx_write_byte
void at25xxx_write_byte(const at25xxx_t *dev, uint32_t pos, uint8_t data)
Write a byte at a given position pos.
at25xxx_params_t::page_size
uint16_t page_size
Page Size of the EEPROM in bytes.
Definition: at25xxx.h:46
spi_cs_t
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:126
at25xxx_set
int at25xxx_set(const at25xxx_t *dev, uint32_t pos, uint8_t val, size_t len)
Set len bytes from a given position pos to the value val.
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
at25xxx_read_byte
uint8_t at25xxx_read_byte(const at25xxx_t *dev, uint32_t pos)
Read a byte at a given position pos.
at25xxx_params_t::wp_pin
gpio_t wp_pin
GPIO pin connected to the write-protect pin.
Definition: at25xxx.h:43
at25xxx_params_t::hold_pin
gpio_t hold_pin
GPIO pin connected to the hold pin.
Definition: at25xxx.h:44
gpio.h
Low-level GPIO peripheral driver interface definitions.
at25xxx_read
int at25xxx_read(const at25xxx_t *dev, uint32_t pos, void *data, size_t len)
Sequentially read len bytes from a given position pos.
at25xxx_write_page
int at25xxx_write_page(const at25xxx_t *dev, uint32_t page, uint32_t offset, const void *data, size_t len)
Sequentially write len bytes to a given page.
at25xxx_params_t
struct holding all params needed for device initialization
Definition: at25xxx.h:39
at25xxx_clear
int at25xxx_clear(const at25xxx_t *dev, uint32_t pos, size_t len)
Set len bytes from position pos to 0.
at25xxx_init
int at25xxx_init(at25xxx_t *dev, const at25xxx_params_t *params)
Initialize an AT25XXX device handle with AT25XXX parameters.
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118