FD32M0P Microcontroller SDK
Loading...
Searching...
No Matches
i2c.c File Reference
#include "i2c.h"
Include dependency graph for i2c.c:

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.

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.