Loading...
Searching...
No Matches

PIO I2C program interface. More...

Detailed Description

PIO I2C program interface.

Warning
This feature is experimental!
This API is experimental and in an early state - expect changes!

Files

file  i2c.h
 PIO I2C program interface.
 

Data Structures

struct  pio_program_i2c
 PIO I2C program type. More...
 
struct  pio_i2c_bus
 PIO I2C emulated bus type. More...
 

Typedefs

typedef i2c_t pio_i2c_t
 PIO I2C descriptor type compatible with i2c_t.
 
typedef struct pio_program_i2c pio_program_i2c_t
 PIO I2C program type.
 
typedef struct pio_i2c_bus pio_i2c_bus_t
 PIO I2C emulated bus type.
 

Functions

pio_i2c_bus_tpio_i2c_get (pio_i2c_t id)
 Get access to a PIO I2C instance configured with PIO_I2C_CONFIG.
 
unsigned pio_i2c_numof (void)
 Query the number of PIO I2C instances configured with PIO_I2C_CONFIG.
 
const pio_program_i2c_tpio_i2c_get_program (pio_t pio)
 Get const I2C program reference.
 
int pio_i2c_init_program (pio_t pio)
 Create, allocate, and write a PIO I2C program.
 
void pio_i2c_deinit_program (pio_t pio)
 Free a PIO I2C program.
 
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_sm_unlock (pio_i2c_bus_t *i2c)
 Release a PIO state machine of PIO pio.
 
void pio_i2c_start_programs (void)
 Start PIO I2C programs configured with PIO_I2C_CONFIG.
 
void pio_i2c_stop_programs (void)
 Stop PIO I2C programs configured with PIO_I2C_CONFIG.
 
int pio_i2c_write_program (pio_t pio, pio_program_i2c_t *pro)
 Write a PIO I2C program to instruction memory.
 
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.
 
void pio_i2c_acquire (pio_i2c_bus_t *bus)
 Get exclusive access to the emulated I2C bus.
 
void pio_i2c_release (pio_i2c_bus_t *bus)
 Release emulated I2C bus.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Typedef Documentation

◆ pio_i2c_t

typedef i2c_t pio_i2c_t

PIO I2C descriptor type compatible with i2c_t.

Definition at line 37 of file i2c.h.

Function Documentation

◆ pio_i2c_acquire()

void pio_i2c_acquire ( pio_i2c_bus_t bus)

Get exclusive access to the emulated I2C bus.

Parameters
[in]busPIO I2C bus

◆ pio_i2c_deinit_program()

void pio_i2c_deinit_program ( pio_t  pio)

Free a PIO I2C program.

Parameters
[in]pioPIO index

◆ pio_i2c_get()

pio_i2c_bus_t * pio_i2c_get ( pio_i2c_t  id)

Get access to a PIO I2C instance configured with PIO_I2C_CONFIG.

Parameters
[in]idPIO I2C ID
Returns
PIO I2C objects

◆ pio_i2c_get_program()

const pio_program_i2c_t * pio_i2c_get_program ( pio_t  pio)

Get const I2C program reference.

Parameters
[in]pioPIO index
Returns
PIO I2C program allocated to PIO pio

◆ pio_i2c_init()

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.

Precondition
The program pro must have been allocated.
Parameters
[out]busPIO I2C bus
[in]proShared program base
[in]sdaSDA pin
[in]sclSCL pin
[in]irqIRQ line, 0 or 1
Returns
Success: 0 Failure: != 0

◆ pio_i2c_init_program()

int pio_i2c_init_program ( pio_t  pio)

Create, allocate, and write a PIO I2C program.

This function does nothing if the program is already created, allocated, and written.

Parameters
[in]pioPIO index
Returns
Success: 0 Failure: != 0

◆ pio_i2c_numof()

unsigned pio_i2c_numof ( void  )

Query the number of PIO I2C instances configured with PIO_I2C_CONFIG.

Returns
Number of PIO I2C instances

◆ pio_i2c_read_byte()

static int pio_i2c_read_byte ( pio_t  pio,
pio_sm_t  sm,
uint16_t  addr,
void *  data,
uint8_t  flags 
)
inlinestatic

Emulate i2c_read_byte.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[out]dataMemory location to store received data
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0

Definition at line 238 of file i2c.h.

◆ pio_i2c_read_bytes()

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.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[out]dataMemory location to store received data
[in]lenThe number of bytes to read into data
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0

◆ pio_i2c_read_reg()

static int pio_i2c_read_reg ( pio_t  pio,
pio_sm_t  sm,
uint16_t  addr,
uint16_t  reg,
void *  data,
uint8_t  flags 
)
inlinestatic

Emulate i2c_read_reg.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[in]regRegister address to read from (8- or 16-bit right-aligned)
[out]dataMemory location to store received data
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0

Definition at line 204 of file i2c.h.

◆ pio_i2c_read_regs()

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.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[in]regRegister address to read from (8- or 16-bit right-aligned)
[out]dataMemory location to store received data
[in]lenThe number of bytes to read into data
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0

◆ pio_i2c_release()

void pio_i2c_release ( pio_i2c_bus_t bus)

Release emulated I2C bus.

Parameters
[in]busPIO I2C bus

◆ pio_i2c_sm_lock()

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.

Parameters
[in]pioPIO index
[out]i2cPIO I2C bus
Returns
A valid state machine index or a negative number on error

◆ pio_i2c_sm_unlock()

void pio_i2c_sm_unlock ( pio_i2c_bus_t i2c)

Release a PIO state machine of PIO pio.

Parameters
[in,out]i2cPIO I2C bus

◆ pio_i2c_start_programs()

void pio_i2c_start_programs ( void  )

Start PIO I2C programs configured with PIO_I2C_CONFIG.

Note
No execution is started if "DISABLE_MODULE += pio_autostart_i2c" is set

◆ pio_i2c_write_byte()

static int pio_i2c_write_byte ( pio_t  pio,
pio_sm_t  sm,
uint16_t  addr,
uint8_t  data,
uint8_t  flags 
)
inlinestatic

Emulate i2c_write_byte.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[in]dataByte to write to the device
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0

Definition at line 272 of file i2c.h.

◆ pio_i2c_write_bytes()

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.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[in]dataArray holding the bytes to write to the device
[in]lenThe number of bytes to write
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0

◆ pio_i2c_write_program()

int pio_i2c_write_program ( pio_t  pio,
pio_program_i2c_t pro 
)

Write a PIO I2C program to instruction memory.

Parameters
[in]pioPIO index
[in,out]proAllocated PIO I2C program
Returns
Success: 0 Failure: != 0

◆ pio_i2c_write_reg()

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 
)
inlinestatic

Emulate i2c_write_reg.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[in]regregister address to read from (8- or 16-bit, right-aligned)
[in]dataArray holding the bytes to write to the device
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0

Definition at line 308 of file i2c.h.

◆ pio_i2c_write_regs()

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.

Parameters
[in]pioPIO index
[in]smPIO state machine index
[in]addr7-bit or 10-bit device address (right-aligned)
[in]regregister address to read from (8- or 16-bit, right-aligned)
[in]dataArray holding the bytes to write to the device
[in]lenThe number of bytes to write
[in]flagsOptional flags (see i2c_flags_t)
Returns
Success: 0 Failure: != 0