I2C controller class.
More...
|
| int | pbl_i2c_bus_dev_init (const struct pbl_device *dev) |
| | Device init of every bus: sets the class state up, then calls the driver's init.
|
| |
| void | pbl_i2c_bus_complete (const struct pbl_i2c_bus *bus, int status) |
| | Report the outcome of the transfer in flight.
|
| |
| int | pbl_i2c_transfer (const struct pbl_i2c_dev *dev, struct pbl_i2c_msg *msgs, uint8_t num_msgs) |
| | Transfer messages to or from a device.
|
| |
| static int | pbl_i2c_write (const struct pbl_i2c_dev *dev, const void *buf, uint32_t len) |
| | Write data.
|
| |
| static int | pbl_i2c_read (const struct pbl_i2c_dev *dev, void *buf, uint32_t len) |
| | Read data.
|
| |
| static int | pbl_i2c_write_read (const struct pbl_i2c_dev *dev, const void *wbuf, uint32_t wlen, void *rbuf, uint32_t rlen) |
| | Write data, then read data after a repeated START.
|
| |
| static int | pbl_i2c_burst_read (const struct pbl_i2c_dev *dev, uint8_t reg, void *buf, uint32_t len) |
| | Read consecutive registers.
|
| |
| static int | pbl_i2c_burst_write (const struct pbl_i2c_dev *dev, uint8_t reg, const void *buf, uint32_t len) |
| | Write consecutive registers.
|
| |
| static int | pbl_i2c_reg_read_byte (const struct pbl_i2c_dev *dev, uint8_t reg, uint8_t *val) |
| | Read a register.
|
| |
| static int | pbl_i2c_reg_write_byte (const struct pbl_i2c_dev *dev, uint8_t reg, uint8_t val) |
| | Write a register.
|
| |
| int | pbl_i2c_reg_update_byte (const struct pbl_i2c_dev *dev, uint8_t reg, uint8_t mask, uint8_t val) |
| | Update bits of a register.
|
| |
I2C controller class.
An I2C controller is a struct pbl_i2c_bus device, and a peripheral on it a struct pbl_i2c_dev: bus plus 7-bit address. A transfer is a list of messages, each a read or a write, sent as one bus transaction: a START, a repeated START between messages and a STOP after the last one. A write flagged PBL_I2C_MSG_NOSTART continues the previous write instead, e.g. data after a register address. Transfers block the calling task, are serialized per bus and must not be issued from ISRs. The controller is powered for the duration of each transfer.
uint8_t id;
uint8_t xyz[6];
int ret;
if (ret != 0) {
return ret;
}
A peripheral on a bus.
Definition i2c.h:123
static int pbl_i2c_burst_read(const struct pbl_i2c_dev *dev, uint8_t reg, void *buf, uint32_t len)
Read consecutive registers.
Definition i2c.h:247
static int pbl_i2c_reg_read_byte(const struct pbl_i2c_dev *dev, uint8_t reg, uint8_t *val)
Read a register.
Definition i2c.h:279
#define PBL_I2C_DEV(_bus, _addr)
Initializer for a struct pbl_i2c_dev.
Definition i2c.h:136
Calls return 0 or a negative errno: -ENXIO when the address is not acknowledged, -EIO on a data NACK or a bus error, -ETIMEDOUT when the transfer does not finish, -ENOTSUP when the controller cannot issue the message sequence and -EINVAL for an invalid one.
◆ pbl_i2c_msg
| Data Fields |
|
uint8_t * |
buf |
Data to write or buffer to read into. |
|
uint32_t |
flags |
Message flags. |
|
uint32_t |
len |
Number of bytes. |
◆ pbl_i2c_bus
| Data Fields |
|
struct pbl_device |
dev |
Device. |
|
const struct pbl_i2c_bus_ops * |
ops |
Driver operations. |
|
struct pbl_i2c_bus_state * |
state |
Runtime state. |
◆ pbl_i2c_dev
| Data Fields |
|
uint16_t |
addr |
7-bit address. |
|
const struct pbl_i2c_bus * |
bus |
Bus. |
◆ PBL_I2C_BUS_INIT
| #define PBL_I2C_BUS_INIT |
( |
|
sym, |
|
|
|
_name, |
|
|
|
_parent, |
|
|
|
_ops |
|
) |
| |
Value: { \
.ops = (_ops), \
.state = &sym##_i2c_state, \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153
int pbl_i2c_bus_dev_init(const struct pbl_device *dev)
Device init of every bus: sets the class state up, then calls the driver's init.
const struct pbl_device_class pbl_i2c_bus_class
Class of the I2C buses.
Initializer for the struct pbl_i2c_bus of bus sym.
- Parameters
-
| sym | Symbol of the bus instance, with its state defined by PBL_I2C_BUS_STATE_DEFINE(). |
| _name | Name. |
| _parent | Parent device, or NULL. |
| _ops | Driver operations. |
◆ PBL_I2C_BUS_STATE_DEFINE
| #define PBL_I2C_BUS_STATE_DEFINE |
( |
|
sym | ) |
|
Value:
static struct pbl_i2c_bus_state sym##_i2c_state
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132
Define the class state of bus sym, for the PBL_I2C_*_DEFINE() macro of a driver.
- Parameters
-
| sym | Symbol of the bus instance. |
◆ PBL_I2C_DEV
| #define PBL_I2C_DEV |
( |
|
_bus, |
|
|
|
_addr |
|
) |
| {.bus = (_bus), .addr = (_addr)} |
Initializer for a struct pbl_i2c_dev.
- Parameters
-
| _bus | Bus. |
| _addr | 7-bit address. |
◆ PBL_I2C_MSG_DMA_SAFE
| #define PBL_I2C_MSG_DMA_SAFE PBL_BIT(2) |
◆ PBL_I2C_MSG_NOSTART
| #define PBL_I2C_MSG_NOSTART PBL_BIT(1) |
Continue the previous write without a repeated START or address.
Writes only.
◆ PBL_I2C_MSG_READ
| #define PBL_I2C_MSG_READ PBL_BIT(0) |
◆ PBL_I2C_MSG_WRITE
| #define PBL_I2C_MSG_WRITE 0U |
◆ pbl_i2c_burst_read()
| static int pbl_i2c_burst_read |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
uint8_t |
reg, |
|
|
void * |
buf, |
|
|
uint32_t |
len |
|
) |
| |
|
inlinestatic |
◆ pbl_i2c_burst_write()
| static int pbl_i2c_burst_write |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
uint8_t |
reg, |
|
|
const void * |
buf, |
|
|
uint32_t |
len |
|
) |
| |
|
inlinestatic |
◆ pbl_i2c_bus_complete()
| void pbl_i2c_bus_complete |
( |
const struct pbl_i2c_bus * |
bus, |
|
|
int |
status |
|
) |
| |
Report the outcome of the transfer in flight.
Called by the bus driver, typically from its interrupt handler.
- Parameters
-
| bus | Bus. |
| status | 0 or a negative errno, see I2C. |
◆ pbl_i2c_bus_dev_init()
| int pbl_i2c_bus_dev_init |
( |
const struct pbl_device * |
dev | ) |
|
Device init of every bus: sets the class state up, then calls the driver's init.
- Parameters
-
- Returns
- 0 or a negative errno.
◆ pbl_i2c_read()
| static int pbl_i2c_read |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
void * |
buf, |
|
|
uint32_t |
len |
|
) |
| |
|
inlinestatic |
◆ pbl_i2c_reg_read_byte()
| static int pbl_i2c_reg_read_byte |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
uint8_t |
reg, |
|
|
uint8_t * |
val |
|
) |
| |
|
inlinestatic |
Read a register.
- Parameters
-
| dev | Device. |
| reg | Register address. |
| [out] | val | Register value. |
- Returns
- 0 or a negative errno.
References pbl_i2c_burst_read().
◆ pbl_i2c_reg_update_byte()
| int pbl_i2c_reg_update_byte |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
uint8_t |
reg, |
|
|
uint8_t |
mask, |
|
|
uint8_t |
val |
|
) |
| |
Update bits of a register.
Reads the register and writes it back, if it changes, with the mask bits set to val. Not atomic with respect to other users of the device.
- Parameters
-
| dev | Device. |
| reg | Register address. |
| mask | Bits to update. |
| val | New value of the mask bits. |
- Returns
- 0 or a negative errno.
◆ pbl_i2c_reg_write_byte()
| static int pbl_i2c_reg_write_byte |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
uint8_t |
reg, |
|
|
uint8_t |
val |
|
) |
| |
|
inlinestatic |
◆ pbl_i2c_transfer()
◆ pbl_i2c_write()
| static int pbl_i2c_write |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
const void * |
buf, |
|
|
uint32_t |
len |
|
) |
| |
|
inlinestatic |
◆ pbl_i2c_write_read()
| static int pbl_i2c_write_read |
( |
const struct pbl_i2c_dev * |
dev, |
|
|
const void * |
wbuf, |
|
|
uint32_t |
wlen, |
|
|
void * |
rbuf, |
|
|
uint32_t |
rlen |
|
) |
| |
|
inlinestatic |
◆ pbl_i2c_bus_class