VSF Documented
Macros | Functions
i2c_common.c File Reference
#include "hal/driver/driver.h"

Macros

#define VSF_I2C_CFG_FUNCTION_RENAME   DISABLED
 

Functions

vsf_err_t vsf_i2c_init (vsf_i2c_t *i2c_ptr, vsf_i2c_cfg_t *cfg_ptr)
 Initialize a I2C instance.
 
void vsf_i2c_fini (vsf_i2c_t *i2c_ptr)
 Finalize a I2C instance.
 
vsf_err_t vsf_i2c_get_configuration (vsf_i2c_t *i2c_ptr, vsf_i2c_cfg_t *cfg_ptr)
 Get current configuration of a I2C instance.
 
fsm_rt_t vsf_i2c_enable (vsf_i2c_t *i2c_ptr)
 Enable a I2C instance.
 
fsm_rt_t vsf_i2c_disable (vsf_i2c_t *i2c_ptr)
 Disable a I2C instance.
 
void vsf_i2c_irq_enable (vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
 I2C instance enables interrupts.
 
void vsf_i2c_irq_disable (vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
 I2C instance disables interrupts.
 
vsf_i2c_irq_mask_t vsf_i2c_irq_clear (vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
 Clear interrupt flags of I2C instance and return previous state.
 
vsf_i2c_status_t vsf_i2c_status (vsf_i2c_t *i2c_ptr)
 Get the status of I2C instance.
 
vsf_i2c_capability_t vsf_i2c_capability (vsf_i2c_t *i2c_ptr)
 Get the capabilities of I2C instance.
 
fsm_rt_t vsf_i2c_master_fifo_transfer (vsf_i2c_t *i2c_ptr, uint16_t address, vsf_i2c_cmd_t cmd, uint_fast16_t count, uint8_t *buffer_ptr, vsf_i2c_cmd_t *cur_cmd_ptr, uint_fast16_t *offset_ptr)
 I2C instance as master mode performs a FIFO transfer.
 
uint_fast16_t vsf_i2c_slave_fifo_transfer (vsf_i2c_t *i2c_ptr, bool transmit_or_receive, uint_fast16_t count, uint8_t *buffer_ptr)
 I2C instance as slave mode performs a FIFO transfer.
 
vsf_err_t vsf_i2c_master_request (vsf_i2c_t *i2c_ptr, uint16_t address, vsf_i2c_cmd_t cmd, uint_fast16_t count, uint8_t *buffer_ptr)
 I2C instance as master mode requests a transfer.
 
vsf_err_t vsf_i2c_slave_request (vsf_i2c_t *i2c_ptr, bool transmit_or_receive, uint_fast16_t count, uint8_t *buffer_ptr)
 I2C instance as slave mode requests a transfer.
 
uint_fast32_t vsf_i2c_master_get_transferred_count (vsf_i2c_t *i2c_ptr)
 get the counter of transfers for current request by the I2C master
 
uint_fast32_t vsf_i2c_slave_get_transferred_count (vsf_i2c_t *i2c_ptr)
 get the counter of transfers for current request by the I2C slave
 
vsf_err_t vsf_i2c_ctrl (vsf_i2c_t *i2c_ptr, vsf_i2c_ctrl_t ctrl, void *param)
 Calls the specified I2C command.
 

Macro Definition Documentation

◆ VSF_I2C_CFG_FUNCTION_RENAME

#define VSF_I2C_CFG_FUNCTION_RENAME   DISABLED

Function Documentation

◆ vsf_i2c_init()

vsf_err_t vsf_i2c_init ( vsf_i2c_t i2c_ptr,
vsf_i2c_cfg_t cfg_ptr 
)

Initialize a I2C instance.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
[in]cfg_ptra pointer to configuration structure vsf_i2c_cfg_t
Returns
vsf_err_t: VSF_ERR_NONE if initialization successful, otherwise returns error code
Note
It is not necessary to call vsf_i2c_fini() to deinitialization. vsf_i2c_init() should be called before any other I2C API except vsf_i2c_capability().

◆ vsf_i2c_fini()

void vsf_i2c_fini ( vsf_i2c_t i2c_ptr)

Finalize a I2C instance.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
Returns
none

◆ vsf_i2c_get_configuration()

vsf_err_t vsf_i2c_get_configuration ( vsf_i2c_t i2c_ptr,
vsf_i2c_cfg_t cfg_ptr 
)

Get current configuration of a I2C instance.

Parameters
[in]i2c_ptrPointer to I2C instance
[out]cfg_ptrPointer to I2C configuration structure to store current settings
Returns
vsf_err_t VSF_ERR_NONE if successful, otherwise an error code
Note
This function retrieves the current configuration of the I2C instance

◆ vsf_i2c_enable()

fsm_rt_t vsf_i2c_enable ( vsf_i2c_t i2c_ptr)

Enable a I2C instance.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
Returns
fsm_rt_t: fsm_rt_cpl if I2C was enabled, fsm_rt_on_going if I2C is still enabling

◆ vsf_i2c_disable()

fsm_rt_t vsf_i2c_disable ( vsf_i2c_t i2c_ptr)

Disable a I2C instance.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
Returns
fsm_rt_t: fsm_rt_cpl if I2C was disabled, fsm_rt_on_going if I2C is still disabling

◆ vsf_i2c_irq_enable()

void vsf_i2c_irq_enable ( vsf_i2c_t i2c_ptr,
vsf_i2c_irq_mask_t  irq_mask 
)

I2C instance enables interrupts.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
[in]irq_maskone or more values of enum vsf_i2c_irq_mask_t
Returns
none

◆ vsf_i2c_irq_disable()

void vsf_i2c_irq_disable ( vsf_i2c_t i2c_ptr,
vsf_i2c_irq_mask_t  irq_mask 
)

I2C instance disables interrupts.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
[in]irq_maskone or more values of enum vsf_i2c_irq_mask_t
Returns
none

◆ vsf_i2c_irq_clear()

vsf_i2c_irq_mask_t vsf_i2c_irq_clear ( vsf_i2c_t i2c_ptr,
vsf_i2c_irq_mask_t  irq_mask 
)

Clear interrupt flags of I2C instance and return previous state.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
[in]irq_maskone or more values of enum vsf_i2c_irq_mask_t to clear
Returns
vsf_i2c_irq_mask_t: the interrupt mask state before clearing
Note
This function attempts to clear the specified interrupt flags if they are set, and returns the state of those flags before clearing. For each bit in irq_mask:
  • If the corresponding bit in the return value is 1: the interrupt flag was set and has been cleared by this function
  • If the corresponding bit in the return value is 0: the interrupt flag was not set (either no interrupt occurred, or it was already cleared by an interrupt handler) This is useful for polling operations and determining if interrupts occurred. Note that if interrupts are enabled and an interrupt handler is active, the interrupt handler may clear the interrupt flags automatically.

◆ vsf_i2c_status()

vsf_i2c_status_t vsf_i2c_status ( vsf_i2c_t i2c_ptr)

Get the status of I2C instance.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
Returns
vsf_i2c_status_t: all status of current I2C

◆ vsf_i2c_capability()

vsf_i2c_capability_t vsf_i2c_capability ( vsf_i2c_t i2c_ptr)

Get the capabilities of I2C instance.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
Returns
vsf_i2c_capability_t: all capabilities of current I2C vsf_i2c_capability_t

◆ vsf_i2c_master_fifo_transfer()

fsm_rt_t vsf_i2c_master_fifo_transfer ( vsf_i2c_t i2c_ptr,
uint16_t  address,
vsf_i2c_cmd_t  cmd,
uint_fast16_t  count,
uint8_t buffer_ptr,
vsf_i2c_cmd_t cur_cmd_ptr,
uint_fast16_t offset_ptr 
)

I2C instance as master mode performs a FIFO transfer.

Parameters
[in,out]i2c_ptra pointer to structure vsf_i2c_t
[in]addressaddress of I2C transfer
[in]cmdI2C command
[in]countnumber of data to transfer
[in,out]buffer_ptrI2C transfer buffer (must not be NULL when count is non-zero)
[in,out]cur_cmd_ptrcurrent I2C command pointer (must be cleared before first call)
[in,out]offset_ptrcurrent offset pointer (must be cleared before first call)
Returns
fsm_rt_t: transfer status
  • fsm_rt_cpl: transfer completed successfully
  • fsm_rt_err: master write received NAK (Not Acknowledge)
  • fsm_rt_on_going: transfer in progress, need to call again
Note
When count is non-zero, buffer_ptr must not be NULL. The variables pointed to by cur_cmd_ptr and offset_ptr must be cleared before the first call. When fsm_rt_on_going is returned, continue calling this function until completion.

◆ vsf_i2c_slave_fifo_transfer()

uint_fast16_t vsf_i2c_slave_fifo_transfer ( vsf_i2c_t i2c_ptr,
bool  transmit_or_receive,
uint_fast16_t  count,
uint8_t buffer_ptr 
)

I2C instance as slave mode performs a FIFO transfer.

Parameters
[in,out]i2c_ptra pointer to structure vsf_i2c_t
[in]transmit_or_receivetrue for transmit, false for receive
[in]countnumber of data to transfer
[in,out]buffer_ptrI2C transfer buffer
[in,out]offset_ptrcurrent offset pointer
Returns
uint_fast16_t: number of bytes transferred from current I2C

◆ vsf_i2c_master_request()

vsf_err_t vsf_i2c_master_request ( vsf_i2c_t i2c_ptr,
uint16_t  address,
vsf_i2c_cmd_t  cmd,
uint_fast16_t  count,
uint8_t buffer_ptr 
)

I2C instance as master mode requests a transfer.

Parameters
[in,out]i2c_ptra pointer to structure vsf_i2c_t
[in]addressaddress of I2C transfer
[in]cmdI2C command
[in]countnumber of data to transfer
[in,out]buffer_ptrI2C transfer buffer
Returns
vsf_err_t: VSF_ERR_NONE if successful, or a negative error code

◆ vsf_i2c_slave_request()

vsf_err_t vsf_i2c_slave_request ( vsf_i2c_t i2c_ptr,
bool  transmit_or_receive,
uint_fast16_t  count,
uint8_t buffer_ptr 
)

I2C instance as slave mode requests a transfer.

Parameters
[in,out]i2c_ptra pointer to structure vsf_i2c_t
[in]transmit_or_receivetrue for transmit, false for receive
[in]countnumber of data to transfer
[in,out]buffer_ptrI2C transfer buffer
Returns
vsf_err_t: VSF_ERR_NONE if successful, or a negative error code

◆ vsf_i2c_master_get_transferred_count()

uint_fast32_t vsf_i2c_master_get_transferred_count ( vsf_i2c_t i2c_ptr)

get the counter of transfers for current request by the I2C master

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
Returns
uint_fast16_t: number of data transferred
Note
This API can be used between slave NAK and the next transmission

◆ vsf_i2c_slave_get_transferred_count()

uint_fast32_t vsf_i2c_slave_get_transferred_count ( vsf_i2c_t i2c_ptr)

get the counter of transfers for current request by the I2C slave

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
Returns
uint_fast16_t: number of data transferred

◆ vsf_i2c_ctrl()

vsf_err_t vsf_i2c_ctrl ( vsf_i2c_t i2c_ptr,
vsf_i2c_ctrl_t  ctrl,
void *  param 
)

Calls the specified I2C command.

Parameters
[in]i2c_ptra pointer to structure vsf_i2c_t
[in]ctrlI2C control command vsf_i2c_ctrl_t
[in,out]paramthe parameter of the command, its use is determined by the command
Returns
vsf_err_t: returns VSF_ERR_NONE if successful, or a negative error code
Generated from commit: vsfteam/vsf@3f091ef