I2C
I2C API Status
API |
BK7258 |
BK7258_cp1 |
---|---|---|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
|
Y |
Y |
I2C UNIT Number
Capability |
BK7258 |
BK7258_cp1 |
---|---|---|
UNIT Number |
3 |
3 |
I2C Pin and GPIO Map
SPI Pin |
BK7258 |
BK7258_cp1 |
---|---|---|
I2C0 SCL |
20 |
20 |
I2C0 SDA |
21 |
21 |
I2C1 SCL |
42 |
42 |
I2C1 SDA |
43 |
43 |
I2C2 SCL |
0 |
0 |
I2C2 SDA |
1 |
1 |
I2C API Reference
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.
I2C API Typedefs
Header File
Structures
-
struct i2c_mem_param_t
Macros
-
BK_ERR_I2C_NOT_INIT
I2C driver not init
-
BK_ERR_I2C_ID_NOT_INIT
I2C id not init
-
BK_ERR_I2C_SM_BUS_BUSY
I2C bus busy
-
BK_ERR_I2C_ACK_TIMEOUT
I2C receive ack timeout
-
BK_ERR_I2C_CHECK_DEFCONFIG
I2C please check defconfig
-
BK_ERR_I2C_SCL_TIMEOUT
I2C SCL timeout
Type Definitions
Enumerations
Header File
Structures
-
struct i2c_config_t
Public Members
-
uint32_t baud_rate
i2c clock rate
-
i2c_addr_mode_t addr_mode
i2c address mode
-
uint16_t slave_addr
i2c address for slave mode
-
uint32_t baud_rate
Macros
-
I2C_BAUD_RATE_50KHZ
-
I2C_BAUD_RATE_100KHZ
-
I2C_BAUD_RATE_200KHZ
-
I2C_BAUD_RATE_400KHZ
-
I2C_DEFAULT_BAUD_RATE
Type Definitions
-
typedef uint8_t i2c_unit_t
i2c uint id
Enumerations
-
enum i2c_addr_mode_t
Values:
-
enumerator I2C_ADDR_MODE_7BIT
i2c address mode 7bit
-
enumerator I2C_ADDR_MODE_10BIT
i2c address mode 10bit
-
enumerator I2C_ADDR_MODE_7BIT