The latest development version of this page may be more current than this released 2.3-beta.1 version.

I2C API Reference

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

Note

The 7 bits address without read/write bit

wm_device_t *wm_drv_i2c_init(const char *device_name)

i2c drvier initialize

Parameters:

device_name[in] The i2c controler name, defined in device table

Returns:

  • !0 : i2c controler handle, return previous handle if called twice

  • NULL: fail

int wm_drv_i2c_deinit(wm_device_t *device)

i2c drvier deinitialize

Parameters:

device[in] The i2c controler device,

  • wm_device_t

Returns:

  • 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

Note

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

Parameters:
  • 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

Returns:

  • 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

Note

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

Note

The fouth param data set to NULL and the fifth param data_size set to 0 if only one address need send

Parameters:
  • 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

Returns:

  • WM_ERR_SUCCESS : write ok

  • WM_ERR_FAILED : write fail

  • WM_ERR_INVALID_PARAM: bad param