FD32M0P Microcontroller SDK
Loading...
Searching...
No Matches
i2c.h File Reference
#include "I2C_REGS.h"
#include "I2C_RW_API.h"
#include <stdbool.h>
Include dependency graph for i2c.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  i2c_counter_cfg_t
 I2C Counter Configuration struct. More...
struct  i2c_slv_cfg_t
 I2C Configuration in Slave Mode. More...
struct  i2c_slv_sts_t
 I2C Slave status register struct. More...

Macros

#define I2C_COUNTER_CFG_DEFAULT_100Khz
 Default Values for I2C Counter Configurations.
#define I2C_SLAVE_CFG_DEFAULT
 Default Values for I2C Slave Configurations.

Functions

void i2c_clk_cfg_set (I2C_REGS_s *regs, I2C_CLK_CTRL_CLKSEL_E clksel, uint8_t clkdiv)
 This function updates the clock settings used in I2C.
void i2c_mst_enable (I2C_REGS_s *regs)
 This function enables I2C master.
void i2c_slv_enable (I2C_REGS_s *regs)
 This function enables I2C slave.
void i2c_mst_disable (I2C_REGS_s *regs)
 This function disables I2C master.
void i2c_slv_disable (I2C_REGS_s *regs)
 This function disables I2C slave.
void i2c_counter_cfg_set (I2C_REGS_s *regs, i2c_counter_cfg_t *i2c_counter_cfg)
 This function configures the counter config register required for I2C Master/Slave.
void i2c_slv_cfg_set (I2C_REGS_s *regs, i2c_slv_cfg_t *i2c_slv_cfg)
 This function configures I2C slave.
void i2c_glitch_width_cfg_set (I2C_REGS_s *regs, uint8_t glitch_width)
 This function sets the glitch width for the glitch filter.
uint8_t i2c_txfifo_fill_nonblocking (I2C_REGS_s *regs, const uint8_t *buffer, uint8_t num_bytes)
 This function pushes bytes into TX FIFO (Non-blocking)
void i2c_txfifo_fill_blocking (I2C_REGS_s *regs, const uint8_t *buffer, uint8_t num_bytes)
 This function pushes bytes into TX FIFO (Blocking)
uint8_t i2c_rxfifo_drain_nonblocking (I2C_REGS_s *regs, uint8_t *buffer, uint8_t num_bytes)
 This function pops bytes from the RX FIFO (Non-blocking)
void i2c_rxfifo_drain_blocking (I2C_REGS_s *regs, uint8_t *buffer, uint8_t num_bytes)
 This function pops bytes from the RX FIFO (Blocking)
bool i2c_slv_rd_wr_sts_get (I2C_REGS_s *regs)
 This function reads the status register which contains wheather the slave is in read or write mode.
void i2c_slv_sts_get (I2C_REGS_s *regs, i2c_slv_sts_t *i2c_slv_sts)
 This function reads all the status registers related to I2C Slave.
void i2c_wait_for_slv_start (I2C_REGS_s *regs)
 This function is blocking. It waits until I2C slave recieves a start from the Master.
void i2c_wait_for_rx_done (I2C_REGS_s *regs)
 This function is blocking. It waits until I2C slave recieves a byte from the Master.
void i2c_wait_for_tx_done (I2C_REGS_s *regs)
 This function is blocking. It waits until I2C slave sends a byte to the Master.
void i2c_wait_for_slv_stop (I2C_REGS_s *regs)
 This function polls stop bit sent by the master.
void i2c_slv_ackval (I2C_REGS_s *regs, I2C_SLAVE_BYTE_ACK_SLV_ACKVAL_E ackval)
 This function controls whether the slave sends a ACK or a NACK.

Data Structure Documentation

◆ i2c_counter_cfg_t

struct i2c_counter_cfg_t

I2C Counter Configuration struct.

Note
This struct contains parameters for initializing I2C counters which takes care of SCL/SDA widths, clock stretch timings, start/stop/restart width smbus timeout time
Data Fields
uint8_t setup_cnt
uint8_t mst_scl_cnt_high_val
uint8_t mst_scl_cnt_low_val
uint8_t mst_scl_start_cnt
uint8_t mst_sda_stop_cnt
uint8_t mst_stop_start_buffer_cnt
uint8_t mst_restart_setup_cnt
uint32_t mst_max_clkstretch_cnt
uint32_t slv_max_clkstretch_cnt
uint32_t smbus_timeout_cnt

◆ i2c_slv_cfg_t

struct i2c_slv_cfg_t

I2C Configuration in Slave Mode.

Note
This struct contains parameters required as I2C configurations when its in slave mode
Data Fields
I2C_SLAVE_CTRL_SLV_ADDR_MODE_E slv_addr_mode
bool slv_low_pwr_wakeup_en
bool slv_def_dev_addr_en
bool slv_alres_addr_en
bool slv_def_host_addr_en
bool slv_txtrig_at_txmode
bool slv_clkstretch_en
bool slv_gencall_en
bool slv_addr2_en
uint8_t slv_addr2_mask
I2C_SLAVE_CTRL_SLV_TXWAIT_STALE_FIFO_E slv_txwait_stale_fifo
I2C_SLAVE_CTRL_SLV_TXEMPTY_INTR_ON_TX_REQ_E slv_txempty_intr_on_tx_req
uint16_t slv_addr1
uint16_t slv_addr2
bool slv_auto_ack_en
bool slv_addr_auto_ack_en
bool i2c_pec_en
bool rxfifo_en
bool txfifo_en

◆ i2c_slv_sts_t

struct i2c_slv_sts_t

I2C Slave status register struct.

Note
This struct contains Read only register data, for I2C Slave
Data Fields
bool slv_rx_req
bool slv_tx_req
bool slv_addr2_sel
bool quick_cmd_sts
bool quick_cmd_rw
bool slv_addr_match
bool slv_stale_txfifo
bool slv_txmode
bool slv_rxmode
bool slv_busbsy

Macro Definition Documentation

◆ I2C_COUNTER_CFG_DEFAULT_100Khz

#define I2C_COUNTER_CFG_DEFAULT_100Khz
Value:
{ \
.setup_cnt = 7 ,\
.mst_scl_cnt_high_val = 64 ,\
.mst_scl_cnt_low_val = 78 ,\
.mst_scl_start_cnt = 66 ,\
.mst_sda_stop_cnt = 66 ,\
.mst_stop_start_buffer_cnt = 78 ,\
.mst_restart_setup_cnt = 78 ,\
.mst_max_clkstretch_cnt = 320000 ,\
.slv_max_clkstretch_cnt = 320000 ,\
.smbus_timeout_cnt = 320000 \
}

Default Values for I2C Counter Configurations.

◆ I2C_SLAVE_CFG_DEFAULT

#define I2C_SLAVE_CFG_DEFAULT
Value:
{ \
.slv_low_pwr_wakeup_en = 1 ,\
.slv_def_dev_addr_en = 0 ,\
.slv_alres_addr_en = 0 ,\
.slv_def_host_addr_en = 0 ,\
.slv_txtrig_at_txmode = 0 ,\
.slv_clkstretch_en = 1 ,\
.slv_gencall_en = 0 ,\
.slv_addr2_en = 0 ,\
.slv_addr2_mask = 0 ,\
.slv_txempty_intr_on_tx_req = I2C_SLAVE_CTRL_SLV_TXEMPTY_INTR_ON_TX_REQ_AGNOSTIC ,\
.slv_addr1 = 0x55 ,\
.slv_addr2 = 0x52 ,\
.slv_auto_ack_en = 0 ,\
.slv_addr_auto_ack_en = 0 ,\
.i2c_pec_en = 0 ,\
.rxfifo_en = 0 ,\
.txfifo_en = 0 \
}
@ I2C_SLAVE_CTRL_SLV_ADDR_MODE_7_BIT
0x0
Definition I2C_REGS.h:1064
@ I2C_SLAVE_CTRL_SLV_TXWAIT_STALE_FIFO_NOT_TREATED_AS_EMPTY
0x0
Definition I2C_REGS.h:1072
@ I2C_SLAVE_CTRL_SLV_TXEMPTY_INTR_ON_TX_REQ_AGNOSTIC
0x0
Definition I2C_REGS.h:1080

Default Values for I2C Slave Configurations.

Function Documentation

◆ i2c_clk_cfg_set()

void i2c_clk_cfg_set ( I2C_REGS_s * regs,
I2C_CLK_CTRL_CLKSEL_E clksel,
uint8_t clkdiv )

This function updates the clock settings used in I2C.

Parameters
regs: pointer to the i2c register space
clksel: Enum for i2c clock select
clkdiv: Value for the clock divider
Return values
void

References I2C_REGS_s::CLK_CTRL.

◆ i2c_mst_enable()

void i2c_mst_enable ( I2C_REGS_s * regs)

This function enables I2C master.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_REGS_s::MASTER_CFG.

◆ i2c_slv_enable()

void i2c_slv_enable ( I2C_REGS_s * regs)

This function enables I2C slave.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_REGS_s::SLAVE_CTRL.

◆ i2c_mst_disable()

void i2c_mst_disable ( I2C_REGS_s * regs)

This function disables I2C master.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_REGS_s::MASTER_CFG.

◆ i2c_slv_disable()

void i2c_slv_disable ( I2C_REGS_s * regs)

This function disables I2C slave.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_REGS_s::SLAVE_CTRL.

◆ i2c_counter_cfg_set()

◆ i2c_slv_cfg_set()

◆ i2c_glitch_width_cfg_set()

void i2c_glitch_width_cfg_set ( I2C_REGS_s * regs,
uint8_t glitch_width )

This function sets the glitch width for the glitch filter.

Parameters
regs: pointer to the i2c register space
glitch_width: glitch width value to be programmed
Return values
void

References I2C_REGS_s::GLITCH_FILTER_CFG.

◆ i2c_txfifo_fill_nonblocking()

uint8_t i2c_txfifo_fill_nonblocking ( I2C_REGS_s * regs,
const uint8_t * buffer,
uint8_t num_bytes )

This function pushes bytes into TX FIFO (Non-blocking)

Parameters
regs: pointer to the i2c register space
buffer: pointer to the buffer space containing the data to pushed into the tx fifo
num_bytes: number of bytes to be written into the tx fifo
Return values
Thenumber of bytes written into the TX FIFO

References I2C_REGS_s::FIFO_STS, I2C_TXDATA_u::packed_byte, and I2C_REGS_s::TXDATA.

◆ i2c_txfifo_fill_blocking()

void i2c_txfifo_fill_blocking ( I2C_REGS_s * regs,
const uint8_t * buffer,
uint8_t num_bytes )

This function pushes bytes into TX FIFO (Blocking)

Parameters
regs: pointer to the i2c register space
buffer: pointer to the buffer space containing the data to pushed into the tx fifo
num_bytes: number of bytes to be written into the tx fifo
Return values
void

References I2C_REGS_s::FIFO_STS, I2C_TXDATA_u::packed_byte, and I2C_REGS_s::TXDATA.

◆ i2c_rxfifo_drain_nonblocking()

uint8_t i2c_rxfifo_drain_nonblocking ( I2C_REGS_s * regs,
uint8_t * buffer,
uint8_t num_bytes )

This function pops bytes from the RX FIFO (Non-blocking)

Parameters
regs: pointer to the i2c register space
buffer: pointer to the buffer space containing the data to be copied to from the RX FIFO
num_bytes: number of bytes to be written into the tx fifo
Return values
Thenumber of bytes read from the RX FIFO

References I2C_REGS_s::FIFO_STS, I2C_RXDATA_u::packed_byte, and I2C_REGS_s::RXDATA.

◆ i2c_rxfifo_drain_blocking()

void i2c_rxfifo_drain_blocking ( I2C_REGS_s * regs,
uint8_t * buffer,
uint8_t num_bytes )

This function pops bytes from the RX FIFO (Blocking)

Parameters
regs: pointer to the i2c register space
buffer: pointer to the buffer space containing the data to be copied to from the RX FIFO
num_bytes: number of bytes to be written into the tx fifo
Return values
void

References I2C_REGS_s::FIFO_STS, I2C_RXDATA_u::packed_byte, and I2C_REGS_s::RXDATA.

◆ i2c_slv_rd_wr_sts_get()

bool i2c_slv_rd_wr_sts_get ( I2C_REGS_s * regs)

This function reads the status register which contains wheather the slave is in read or write mode.

Parameters
regs: pointer to the i2c register space
Return values
Returns0 for write transaction and 1 for read transaction

References I2C_REGS_s::SPARE_STS.

◆ i2c_slv_sts_get()

void i2c_slv_sts_get ( I2C_REGS_s * regs,
i2c_slv_sts_t * i2c_slv_sts )

This function reads all the status registers related to I2C Slave.

Parameters
regs: pointer to the i2c register space
i2c_slv_sts: pointer to the struct which will contain the register values read
Return values
void

References i2c_slv_sts_t::quick_cmd_rw, i2c_slv_sts_t::quick_cmd_sts, I2C_REGS_s::SLAVE_STS, i2c_slv_sts_t::slv_addr2_sel, i2c_slv_sts_t::slv_addr_match, i2c_slv_sts_t::slv_busbsy, i2c_slv_sts_t::slv_rx_req, i2c_slv_sts_t::slv_rxmode, i2c_slv_sts_t::slv_stale_txfifo, i2c_slv_sts_t::slv_tx_req, and i2c_slv_sts_t::slv_txmode.

◆ i2c_wait_for_slv_start()

void i2c_wait_for_slv_start ( I2C_REGS_s * regs)

This function is blocking. It waits until I2C slave recieves a start from the Master.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_INTR_EVENT_CLEAR(), I2C_INTR_EVENT_SLV_START_IDX, and I2C_REGS_s::INTR_EVENT.

Here is the call graph for this function:

◆ i2c_wait_for_rx_done()

void i2c_wait_for_rx_done ( I2C_REGS_s * regs)

This function is blocking. It waits until I2C slave recieves a byte from the Master.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_INTR_EVENT_CLEAR(), I2C_INTR_EVENT_RX_DONE_IDX, and I2C_REGS_s::INTR_EVENT.

Here is the call graph for this function:

◆ i2c_wait_for_tx_done()

void i2c_wait_for_tx_done ( I2C_REGS_s * regs)

This function is blocking. It waits until I2C slave sends a byte to the Master.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_INTR_EVENT_CLEAR(), I2C_INTR_EVENT_TX_DONE_IDX, and I2C_REGS_s::INTR_EVENT.

Here is the call graph for this function:

◆ i2c_wait_for_slv_stop()

void i2c_wait_for_slv_stop ( I2C_REGS_s * regs)

This function polls stop bit sent by the master.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_INTR_EVENT_CLEAR(), I2C_INTR_EVENT_SLV_STOP_IDX, and I2C_REGS_s::INTR_EVENT.

Here is the call graph for this function:

◆ i2c_slv_ackval()

void i2c_slv_ackval ( I2C_REGS_s * regs,
I2C_SLAVE_BYTE_ACK_SLV_ACKVAL_E ackval )

This function controls whether the slave sends a ACK or a NACK.

Parameters
regs: pointer to the i2c register space
Return values
void

References I2C_REGS_s::SLAVE_BYTE_ACK.