I2C API
I2C (Inter-Integrated Circuit) API interface.
Header File
Functions
-
bk_err_t bk_i2c_driver_init(void)
Init the I2C driver.
This API init the resoure common:
Init I2C driver control memory
- Attention
1. This API should be called before any other I2C APIs.
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_i2c_driver_deinit(void)
Deinit the I2C driver.
This API free all resource related to I2C and disable I2C.
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_i2c_init(i2c_id_t id, const i2c_config_t *cfg)
Init the I2C id.
This API init the I2C id:
Power up the I2C id
Configure the I2C id clock
Map the I2C id to dedicated GPIO port
Set the I2C parameters
Start the I2C id
- Attention
Multifunction GPIO initialization affects other functions
- Parameters
id – I2C id
config – I2C parameter settings
- Returns
BK_OK: succeed
BK_ERR_NULL_PARAM: I2C config paramter is NULL
BK_ERR_I2C_NOT_INIT: I2C driver not init
others: other errors.
-
bk_err_t bk_i2c_deinit(i2c_id_t id)
Deinit the I2C id.
This API deinit the I2C id:
Stop the I2C id
Disable the I2C id interrupt
Power down the I2C id
- Parameters
id – I2C id
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_i2c_master_write(i2c_id_t id, uint32_t dev_addr, const uint8_t *data, uint32_t size, uint32_t timeout_ms)
Write data to the I2C port from a given buffer and length, It shall only be called in I2C master mode.
- Parameters
id – I2C id
dev_addr – slave device address
data – pointer to the buffer
size – data length to write
timeout_ms – timeout ms
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_master_write_noaddr(i2c_id_t id, const uint8_t *data, uint32_t size, uint32_t timeout_ms)
Write data to the I2C port from a given buffer and length without slave address, It shall only be called in I2C master mode.
- Parameters
id – I2C id
data – pointer to the buffer
size – data length to write
timeout_ms – timeout ms
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_master_read(i2c_id_t id, uint32_t dev_addr, uint8_t *data, uint32_t size, uint32_t timeout_ms)
I2C read data from I2C buffer, It shall only be called in I2C master mode.
- Parameters
id – I2C id
dev_addr – slave device address
data – pointer to the buffer
size – data length to read
timeout_ms – timeout ms
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_master_read_noaddr(i2c_id_t id, uint8_t *data, uint32_t size, uint32_t timeout_ms)
I2C read data from I2C buffer without slave address, It shall only be called in I2C master mode.
- Parameters
id – I2C id
data – pointer to the buffer
size – data length to read
timeout_ms – timeout ms
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_slave_write(i2c_id_t id, const uint8_t *data, uint32_t size, uint32_t timeout_ms)
Write data to the I2C port from a given buffer and length, It shall only be called in I2C slave mode.
- Parameters
id – I2C id
data – pointer to the buffer
size – data length to write
timeout_ms – timeout ms
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_slave_read(i2c_id_t id, uint8_t *data, uint32_t size, uint32_t timeout_ms)
I2C read data from I2C buffer, It shall only be called in I2C slave mode.
- Parameters
id – I2C id
dev_addr – slave device address
data – pointer to the buffer
size – data length to read
timeout_ms – timeout ms
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_memory_write(i2c_id_t id, const i2c_mem_param_t *mem_param)
Write data to the specific memory address from a given buffer and length, It shall only be called in I2C master mode.
- Parameters
id – I2C id
mem_param – memory parameter
- Returns
BK_OK: succeed
BK_ERR_NULL_PARAM: I2C mem_param is NULL
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_memory_read(i2c_id_t id, const i2c_mem_param_t *mem_param)
I2C read data from I2C specific memory address, It shall only be called in I2C master mode.
- Parameters
id – I2C id
mem_param – memory parameter
- Returns
BK_OK: succeed
BK_ERR_NULL_PARAM: I2C mem_param is NULL
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_set_baud_rate(i2c_id_t id, uint32_t baud_rate)
I2C set baud rate.
- Parameters
id – I2C id
baud_rate – baud rate
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_set_slave_address(i2c_id_t id, uint16_t slave_addr)
Set slave address when current role is i2c slave.
- Parameters
id – I2C id
slave_addr – slave address
- Returns
BK_OK: succeed
BK_ERR_I2C_NOT_INIT: I2C driver not init
others: other errors.
-
bk_err_t bk_i2c_enable_interrupt(i2c_id_t id)
Enable I2C interrupt.
- Parameters
id – I2C id
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_i2c_disable_interrupt(i2c_id_t id)
Disable I2C interrupt.
- Parameters
id – I2C id
- Returns
BK_OK: succeed
others: other errors.
-
bool bk_i2c_is_bus_busy(i2c_id_t id)
Check if I2C is busy.
- Parameters
id – I2C id
- Returns
true: busy, false: not busy
-
uint32_t bk_i2c_get_cur_action(i2c_id_t id)
Get i2c current action, such as start,stop,send write_addr.
- Parameters
id – I2C id
- Returns
i2c action
-
void bk_i2c_timer_callback(int id, void *myTimer)
bk_i2c_timer_callback
This API set timer call back
- Returns
-
uint8_t bk_i2c_get_busstate(int id)
bk_i2c_get_busstate
This API get bus status idle or busy
- Returns
1: idle
0: busy.
-
uint8_t bk_i2c_get_transstate(int id)
bk_i2c_get_transstate
This API get bus status idle or busy
- Returns
1: ok
0: fail.
-
bk_err_t bk_i2c_init_v2(i2c_id_t id, const i2c_config_t *cfg)
Init the SIM I2C id.
This API init the I2C id:
Power up the I2C id
Configure the I2C id clock
Map the I2C id to dedicated GPIO port
Set the I2C parameters
Start the I2C id
- Attention
Multifunction GPIO initialization affects other functions
- Parameters
id – I2C id
config – I2C parameter settings
- Returns
BK_OK: succeed
BK_ERR_NULL_PARAM: I2C config paramter is NULL
BK_ERR_I2C_NOT_INIT: I2C driver not init
others: other errors.
-
bk_err_t bk_i2c_deinit_v2(i2c_id_t id)
Deinit the SIM I2C driver.
This API free all resource related to I2C and disable I2C.
- Returns
BK_OK: succeed
others: other errors.
-
bk_err_t bk_i2c_memory_write_v2(i2c_id_t id, const i2c_mem_param_t *mem_param)
Write data to the specific memory address from a given buffer and length, It shall only be called in SIM I2C master mode.
- Parameters
id – I2C id
mem_param – memory parameter
- Returns
BK_OK: succeed
BK_ERR_NULL_PARAM: I2C mem_param is NULL
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.
-
bk_err_t bk_i2c_memory_read_v2(i2c_id_t id, const i2c_mem_param_t *mem_param)
SIM I2C read data from I2C specific memory address, It shall only be called in SIM I2C master mode.
- Parameters
id – I2C id
mem_param – memory parameter
- Returns
BK_OK: succeed
BK_ERR_NULL_PARAM: I2C mem_param is NULL
BK_ERR_I2C_NOT_INIT: I2C driver not init
BK_ERR_I2C_INVALID_ID: I2C id number is invalid
BK_ERR_I2C_ID_NOT_INIT: I2C id not init
others: other errors.