i2c.h File Reference
#include "pico.h"
#include "pico/time.h"
#include "hardware/structs/i2c.h"
#include "hardware/regs/dreq.h"
Include dependency graph for i2c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  i2c_inst
 

Macros

#define PARAM_ASSERTIONS_ENABLED_I2C   0
 

Typedefs

typedef struct i2c_inst i2c_inst_t
 

Functions

uint i2c_init (i2c_inst_t *i2c, uint baudrate)
 Initialise the I2C HW blockPut the I2C hardware into a known state, and enable it. Must be called before other functions. By default, the I2C is configured to operate as a master. More...
 
void i2c_deinit (i2c_inst_t *i2c)
 Disable the I2C HW block. More...
 
uint i2c_set_baudrate (i2c_inst_t *i2c, uint baudrate)
 Set I2C baudrateSet I2C bus frequency as close as possible to requested, and return actual rate set. Baudrate may not be as exactly requested due to clocking limitations. More...
 
void i2c_set_slave_mode (i2c_inst_t *i2c, bool slave, uint8_t addr)
 Set I2C port to slave mode. More...
 
static uint i2c_hw_index (i2c_inst_t *i2c)
 Convert I2C instance to hardware instance number. More...
 
static i2c_hw_ti2c_get_hw (i2c_inst_t *i2c)
 
static i2c_inst_ti2c_get_instance (uint instance)
 
int i2c_write_blocking_until (i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop, absolute_time_t until)
 Attempt to write specified number of bytes to address, blocking until the specified absolute time is reached. More...
 
int i2c_read_blocking_until (i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop, absolute_time_t until)
 Attempt to read specified number of bytes from address, blocking until the specified absolute time is reached. More...
 
static int i2c_write_timeout_us (i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop, uint timeout_us)
 Attempt to write specified number of bytes to address, with timeout. More...
 
int i2c_write_timeout_per_char_us (i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop, uint timeout_per_char_us)
 
static int i2c_read_timeout_us (i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop, uint timeout_us)
 Attempt to read specified number of bytes from address, with timeout. More...
 
int i2c_read_timeout_per_char_us (i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop, uint timeout_per_char_us)
 
int i2c_write_blocking (i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop)
 Attempt to write specified number of bytes to address, blocking. More...
 
int i2c_read_blocking (i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop)
 Attempt to read specified number of bytes from address, blocking. More...
 
static size_t i2c_get_write_available (i2c_inst_t *i2c)
 Determine non-blocking write space available. More...
 
static size_t i2c_get_read_available (i2c_inst_t *i2c)
 Determine number of bytes received. More...
 
static void i2c_write_raw_blocking (i2c_inst_t *i2c, const uint8_t *src, size_t len)
 Write direct to TX FIFO. More...
 
static void i2c_read_raw_blocking (i2c_inst_t *i2c, uint8_t *dst, size_t len)
 Read direct from RX FIFO. More...
 
static uint8_t i2c_read_byte_raw (i2c_inst_t *i2c)
 Pop a byte from I2C Rx FIFO.This function is non-blocking and assumes the Rx FIFO isn't empty. More...
 
static void i2c_write_byte_raw (i2c_inst_t *i2c, uint8_t value)
 Push a byte into I2C Tx FIFO.This function is non-blocking and assumes the Tx FIFO isn't full. More...
 
static uint i2c_get_dreq (i2c_inst_t *i2c, bool is_tx)
 Return the DREQ to use for pacing transfers to/from a particular I2C instance. More...
 
#define i2c0   (&i2c0_inst)
 Identifier for I2C HW Block 0.
 
#define i2c1   (&i2c1_inst)
 Identifier for I2C HW Block 1.
 
i2c_inst_t i2c0_inst
 
i2c_inst_t i2c1_inst