1. Home
  2. Software Development for MediaTek X20
  3. How to debug I2C
  4. 2.I2C code

2.I2C code

2.1 Define I2C driver

Before the definition of I2C driver, Define of_device_id and i2c_device_id.Of_device_id is used to call the device information defined in the DTS file in the device drive, which is defined as follows:

Note: id_table indicates the device supported by the device drive.

2.2 Registered I2C driver

i2c_add_driver(&mt8193_i2c_driver);

When callIing i2c_add_driver to registered I2C driver,OS will traverse the I2C device.if the I2C driver support the traversal of the device, it will call the probe function of the device driver.

2.3 I2C communication

After registering a good I2C driver, you can exchange data by I2C.

So Host can use the API (mt8193_i2c_read ,mt8193_i2c_write) to communicate with the slave.

Was this article helpful to you? Yes 1 No

How can we help?