1.修改内核配置文件,使内核支持GPIO模拟I2C
//开启方式
make menuconfig
Device Drivers --->
<*> I2C support --->
I2C Hardware Bus support --->
<*> GPIO-based bitbanging I2C
2.对应的dts里面增加GPIO模拟I2C的设备树
注意头文件:#include <dt-bindings/gpio/gpio.h>
i2c@0 {
compatible = "i2c-gpio";
sda-gpios = <&gpio_chip16 3 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
scl-gpios = <&gpio_chip16 4 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
i2c-gpio,delay-us = <2>; /* ~100 kHz */
#address-cells = <0>;
#size-cells = <0>;
};
编译后烧写,会发现/dev下多了一个i2c总线,多出来的那个就是了。