I2C API 参考
I2C
-
struct wm_drv_i2c_config_t
driver i2c device structure
If the address of the upper 4 bits of eeprom is 1010, the address of the lower 3 bits is 0, and the read/write bits are not required, then the address is 0x50
备注
The 7 bits address without read/write bit
Public Members
-
uint16_t addr
i2c device 7 bits raw address
-
wm_i2c_speed_t speed_hz
scl clock speed, unit hz
-
uint16_t addr
-
wm_device_t *wm_drv_i2c_init(const char *device_name)
i2c drvier initialize
- 参数:
device_name – [in] The i2c controler name, defined in device table
- 返回:
!0 : i2c controler handle, return previous handle if called twice
NULL: fail
-
int wm_drv_i2c_deinit(wm_device_t *device)
i2c drvier deinitialize
- 参数:
device – [in] The i2c controler device,
wm_device_t
- 返回:
WM_ERR_SUCCESS : deinitialize ok
WM_ERR_INVALID_PARAM: bad param
-
int wm_drv_i2c_read(wm_device_t *device, wm_drv_i2c_config_t *config, const void *sub_addr, uint32_t sub_addr_size, void *read_buf, uint32_t read_size)
i2c drvier write read api
备注
The second and third param, sometime used to write the device sub address or command, If the sub address is a variable with more than 1 byte, you need to pay attention to the big-endian conversion
- 参数:
device – [in] The i2c controler device,
wm_device_t
config – [in] The i2c target device config,
sub_addr – [in] The device sub address, such as eeprom offset
sub_addr_size – [in] The device sub address size
read_buf – [out] The read buffer
read_size – [in] The data size of read buffer
- 返回:
WM_ERR_SUCCESS : read ok
WM_ERR_FAILED : read fail
WM_ERR_INVALID_PARAM: bad param
-
int wm_drv_i2c_write(wm_device_t *device, wm_drv_i2c_config_t *config, const void *sub_addr, uint32_t sub_addr_size, const void *data, uint32_t data_size)
i2c drvier write api
备注
The second and third param, sometime used to write the device sub address or command, If the sub address is a variable with more than 1 byte, you need to pay attention to the big-endian conversion
备注
The fouth param data set to NULL and the fifth param data_size set to 0 if only one address need send
- 参数:
device – [in] The i2c controler device,
wm_device_t
config – [in] The i2c target device config,
sub_addr – [in] The device sub address, such as eeprom offset
sub_addr_size – [in] The device sub address size
data – [in] The write data
data_size – [in] The size of write data
- 返回:
WM_ERR_SUCCESS : write ok
WM_ERR_FAILED : write fail
WM_ERR_INVALID_PARAM: bad param