PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
nRF5 I2C

I2C bus driver for the nRF5 TWIM peripheral. More...

Data Structures

struct  pbl_i2c_nrf5
 nRF5 I2C bus. More...
 

Macros

#define I2C_NRF5_BOUNCE_BUF_SIZE   16
 Longest write made of several messages, which the driver gathers in one buffer.
 
#define PBL_I2C_NRF5_DEFINE(sym, _name, _base, _irq, _clock_hz, _scl, _sda)
 Define a bus on an nRF5 TWIM instance.
 

Functions

void pbl_i2c_nrf5_irq_handler (const struct pbl_i2c_nrf5 *i2c)
 TWIM interrupt handler, connected by PBL_I2C_NRF5_DEFINE().
 

Detailed Description

I2C bus driver for the nRF5 TWIM peripheral.

The TWIM issues one write, one read, or a write then a read after a repeated START; writes continued with PBL_I2C_MSG_NOSTART are gathered in a buffer of I2C_NRF5_BOUNCE_BUF_SIZE bytes. Other sequences fail with -ENOTSUP.

SCL and SDA are configured as open-drain inputs with their wiring flags, e.g. the pull-up, and keep that configuration while the bus is disabled. An instance connects its TWIM interrupt itself, with priority CONFIG_I2C_NRF5_IRQ_PRIO:

PBL_I2C_NRF5_DEFINE(s_i2c0, "i2c0", 0x40003000,
PBL_SOC_IRQN_SPI0_SPIM0_SPIS0_TWI0_TWIM0_TWIS0, 400000, PBL_GPIO(&dt_gpio0, 25,
#define PBL_GPIO(_port, _pin, _flags)
Initializer for a struct pbl_gpio.
Definition gpio.h:158
#define PBL_GPIO_PULL_UP
Enable the pull-up.
Definition gpio.h:52
#define PBL_I2C_NRF5_DEFINE(sym, _name, _base, _irq, _clock_hz, _scl, _sda)
Define a bus on an nRF5 TWIM instance.
Definition nrf5.h:81

Data Structure Documentation

◆ pbl_i2c_nrf5

struct pbl_i2c_nrf5

nRF5 I2C bus.

Data Fields
uintptr_t base Registers.
struct pbl_i2c_bus bus I2C bus.
uint32_t clock_hz Bus clock frequency, in Hz.
pbl_irq_t irq Interrupt line.
struct pbl_gpio scl SCL pin.
struct pbl_gpio sda SDA pin.
struct pbl_i2c_nrf5_state * state Driver runtime state.

Macro Definition Documentation

◆ I2C_NRF5_BOUNCE_BUF_SIZE

#define I2C_NRF5_BOUNCE_BUF_SIZE   16

Longest write made of several messages, which the driver gathers in one buffer.

◆ PBL_I2C_NRF5_DEFINE

#define PBL_I2C_NRF5_DEFINE (   sym,
  _name,
  _base,
  _irq,
  _clock_hz,
  _scl,
  _sda 
)
Value:
static struct pbl_i2c_nrf5_state sym##_nrf5_state; \
PBL_DEVICE_INSTANCE(sym, struct pbl_i2c_nrf5, struct pbl_i2c_bus, bus){ \
.bus = PBL_I2C_BUS_INIT(sym, _name, nullptr, &pbl_i2c_nrf5_ops), \
.state = &sym##_nrf5_state, \
.base = (_base), \
.irq = (_irq), \
.clock_hz = (_clock_hz), \
.scl = _scl, \
.sda = _sda, \
}; \
PBL_IRQ_CONNECT_NUM(_irq, CONFIG_I2C_NRF5_IRQ_PRIO, pbl_i2c_nrf5_irq_handler, &sym##_inst, 0)
nRF5 I2C bus.
Definition nrf5.h:49
void pbl_i2c_nrf5_irq_handler(const struct pbl_i2c_nrf5 *i2c)
TWIM interrupt handler, connected by PBL_I2C_NRF5_DEFINE().
An I2C controller.
Definition i2c.h:113
#define PBL_I2C_BUS_INIT(sym, _name, _parent, _ops)
Initializer for the struct pbl_i2c_bus of bus sym.
Definition i2c.h:155
#define PBL_I2C_BUS_STATE_DEFINE(sym)
Define the class state of bus sym, for the PBL_I2C_*_DEFINE() macro of a driver.
Definition i2c.h:143

Define a bus on an nRF5 TWIM instance.

Parameters
symSymbol of the bus, a struct pbl_i2c_bus.
_nameName.
_baseRegisters.
_irqInterrupt line, a plain number.
_clock_hzBus clock frequency: 100000, 250000 or 400000.
_sclSCL pin, from PBL_GPIO().
_sdaSDA pin, from PBL_GPIO().

Function Documentation

◆ pbl_i2c_nrf5_irq_handler()

void pbl_i2c_nrf5_irq_handler ( const struct pbl_i2c_nrf5 *  i2c)

TWIM interrupt handler, connected by PBL_I2C_NRF5_DEFINE().

Parameters
i2cBus.