PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
i2c.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <pbl/device.h>
#include <pbl/kernel/mutex.h>
#include <pbl/kernel/sem.h>
#include <pbl/util/bits.h>

Data Structures

struct  pbl_i2c_msg
 A message of a transfer. More...
 
struct  pbl_i2c_bus_ops
 Bus driver operations. More...
 
struct  pbl_i2c_bus
 An I2C controller. More...
 
struct  pbl_i2c_dev
 A peripheral on a bus. More...
 

Macros

#define PBL_I2C_DEV(_bus, _addr)   {.bus = (_bus), .addr = (_addr)}
 Initializer for a struct pbl_i2c_dev.
 
#define PBL_I2C_BUS_STATE_DEFINE(sym)
 Define the class state of bus sym, for the PBL_I2C_*_DEFINE() macro of a driver.
 
#define PBL_I2C_BUS_INIT(sym, _name, _parent, _ops)
 Initializer for the struct pbl_i2c_bus of bus sym.
 
Message flags
#define PBL_I2C_MSG_WRITE   0U
 Write to the device.
 
#define PBL_I2C_MSG_READ   PBL_BIT(0)
 Read from the device.
 
#define PBL_I2C_MSG_NOSTART   PBL_BIT(1)
 Continue the previous write without a repeated START or address.
 
#define PBL_I2C_MSG_DMA_SAFE   PBL_BIT(2)
 The buffer may be accessed through DMA: aligned to PBL_DCACHE_LINE_SIZE and owning the whole cache lines it covers, PBL_DCACHE_ROUND_UP(len) bytes.
 

Functions

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.
 

Variables

const struct pbl_device_class pbl_i2c_bus_class
 Class of the I2C buses.