Loading...
Searching...
No Matches
i2c.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 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 PERIPH_PIO_I2C_H
24#define PERIPH_PIO_I2C_H
25
26#include "periph/i2c.h"
27#include "periph/pio.h"
28#include "mutex.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
38
46
55
64
70unsigned pio_i2c_numof(void);
71
80
93
100
110
117
125
130
141
157 const pio_program_i2c_t *pro,
158 gpio_t sda, gpio_t scl, unsigned irq);
159
166
173
188int pio_i2c_read_regs(pio_t pio, pio_sm_t sm, uint16_t addr,
189 uint16_t reg, void *data, size_t len, uint8_t flags);
190
204static inline int pio_i2c_read_reg(pio_t pio, pio_sm_t sm, uint16_t addr,
205 uint16_t reg, void *data, uint8_t flags)
206{
207 return pio_i2c_read_regs(pio, sm, addr, reg, data, 1, flags);
208}
209
223int pio_i2c_read_bytes(pio_t pio, pio_sm_t sm, uint16_t addr,
224 void *data, size_t len, uint8_t flags);
225
238static inline int pio_i2c_read_byte(pio_t pio, pio_sm_t sm, uint16_t addr,
239 void *data, uint8_t flags)
240{
241 return pio_i2c_read_bytes(pio, sm, addr, data, 1, flags);
242}
243
257int pio_i2c_write_bytes(pio_t pio, pio_sm_t sm, uint16_t addr,
258 const void *data, size_t len, uint8_t flags);
259
272static inline int pio_i2c_write_byte(pio_t pio, pio_sm_t sm, uint16_t addr,
273 uint8_t data, uint8_t flags)
274{
275 return pio_i2c_write_bytes(pio, sm, addr, &data, 1, flags);
276}
277
292int pio_i2c_write_regs(pio_t pio, pio_sm_t sm, uint16_t addr,
293 uint16_t reg, const void *data, size_t len, uint8_t flags);
294
308static inline int pio_i2c_write_reg(pio_t pio, pio_sm_t sm, uint16_t addr,
309 uint16_t reg, uint8_t data, uint8_t flags)
310{
311 return pio_i2c_write_regs(pio, sm, addr, reg, &data, 1, flags);
312}
313
314#ifdef __cplusplus
315}
316#endif
317#endif /* PERIPH_PIO_I2C_H */
High-level PIO peripheral driver interface.
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:151
void pio_i2c_acquire(pio_i2c_bus_t *bus)
Get exclusive access to the emulated I2C bus.
pio_i2c_bus_t * pio_i2c_get(pio_i2c_t id)
Get access to a PIO I2C instance configured with PIO_I2C_CONFIG.
i2c_t pio_i2c_t
PIO I2C descriptor type compatible with i2c_t.
Definition i2c.h:37
static int pio_i2c_write_byte(pio_t pio, pio_sm_t sm, uint16_t addr, uint8_t data, uint8_t flags)
Emulate i2c_write_byte.
Definition i2c.h:272
int pio_i2c_init_program(pio_t pio)
Create, allocate, and write a PIO I2C program.
void pio_i2c_sm_unlock(pio_i2c_bus_t *i2c)
Release a PIO state machine of PIO pio.
static int pio_i2c_write_reg(pio_t pio, pio_sm_t sm, uint16_t addr, uint16_t reg, uint8_t data, uint8_t flags)
Emulate i2c_write_reg.
Definition i2c.h:308
int pio_i2c_write_bytes(pio_t pio, pio_sm_t sm, uint16_t addr, const void *data, size_t len, uint8_t flags)
Emulate i2c_write_bytes.
struct pio_i2c_bus pio_i2c_bus_t
PIO I2C emulated bus type.
unsigned pio_i2c_numof(void)
Query the number of PIO I2C instances configured with PIO_I2C_CONFIG.
pio_sm_t pio_i2c_sm_lock(pio_t pio, pio_i2c_bus_t *i2c)
Acquire a PIO state machine of PIO pio to run the PIO I2C program.
void pio_i2c_release(pio_i2c_bus_t *bus)
Release emulated I2C bus.
void pio_i2c_stop_programs(void)
Stop PIO I2C programs configured with PIO_I2C_CONFIG.
static int pio_i2c_read_byte(pio_t pio, pio_sm_t sm, uint16_t addr, void *data, uint8_t flags)
Emulate i2c_read_byte.
Definition i2c.h:238
int pio_i2c_read_regs(pio_t pio, pio_sm_t sm, uint16_t addr, uint16_t reg, void *data, size_t len, uint8_t flags)
Emulate i2c_read_regs.
static int pio_i2c_read_reg(pio_t pio, pio_sm_t sm, uint16_t addr, uint16_t reg, void *data, uint8_t flags)
Emulate i2c_read_reg.
Definition i2c.h:204
void pio_i2c_deinit_program(pio_t pio)
Free a PIO I2C program.
int pio_i2c_read_bytes(pio_t pio, pio_sm_t sm, uint16_t addr, void *data, size_t len, uint8_t flags)
Emulate i2c_read_bytes.
const pio_program_i2c_t * pio_i2c_get_program(pio_t pio)
Get const I2C program reference.
int pio_i2c_init(pio_i2c_bus_t *bus, const pio_program_i2c_t *pro, gpio_t sda, gpio_t scl, unsigned irq)
Setup a state machine to run the I2C program.
struct pio_program_i2c pio_program_i2c_t
PIO I2C program type.
int pio_i2c_write_program(pio_t pio, pio_program_i2c_t *pro)
Write a PIO I2C program to instruction memory.
void pio_i2c_start_programs(void)
Start PIO I2C programs configured with PIO_I2C_CONFIG.
int pio_i2c_write_regs(pio_t pio, pio_sm_t sm, uint16_t addr, uint16_t reg, const void *data, size_t len, uint8_t flags)
Emulate i2c_write_regs.
unsigned pio_t
PIO index type.
Definition pio.h:76
int pio_sm_t
PIO state machine index type.
Definition pio.h:81
Low-level I2C peripheral driver interface definition.
Mutex for thread synchronization.
Mutex structure.
Definition mutex.h:146
PIO I2C emulated bus type.
Definition i2c.h:50
pio_t pio
PIO index.
Definition i2c.h:51
mutex_t mtx
Mutex to protect the bus from concurrent accesses.
Definition i2c.h:53
pio_sm_t sm
State machine index.
Definition i2c.h:52
PIO I2C program type.
Definition i2c.h:42
unsigned ref_mask
Mask of referencing PIO state machines.
Definition i2c.h:44
pio_program_t base
PIO base program.
Definition i2c.h:43
Struct that models a PIO program.
Definition pio.h:86