How to enable I2C and GPIO on Android

Which system do you use? Android, Ubuntu, OOWOW or others?

Android

Which version of system do you use? Khadas official images, self built images, or others?

Khadas official images

Please describe your issue below:

I want to use I2C and GPIO interfaces. However on android I can use only 2 GPIO. I2C is unavailable at all.

How can I enable I2C on vim 4? And how can I enable some more GPIO? I need at least 5 GPIO and 1 I2C.
If it can be done only with rom building, can you help me with modifying files?

Figure I2CM_ A interface. The code is available by default.


VIM4:/ # i2cdetect -l
i2c-3   i2c             Meson I2C adapter                       I2C Adapter
i2c-1   i2c             Meson I2C adapter                       I2C Adapter
i2c-6   i2c             Meson I2C adapter                       I2C Adapter
i2c-2   i2c             Meson I2C adapter                       I2C Adapter
i2c-0   i2c             Meson I2C adapter                       I2C Adapter
i2c-5   i2c             Meson I2C adapter                       I2C Adapter
VIM4:/ #
VIM4:/ # i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
VIM4:/ #

Please refer to this link for modification.

1 Like

@goenjoy thanks for your help, I2C is working good.
However I’ve tried to revert common and build rom to make gpio work. It’s build success and flashed success to. However I see only boot logo for 3 seconds on hdmi screen. After this 3 seconds I see only black screen. Also I a have no image on touch screen

@Y2Kot Please post the whole compilation command step.

@goenjoy

cd bootloader/uboot
./mk kvim4 --avb2 --vab
./mk kvim4 -v 5.4 -j20
. build/envsetup.sh
lunch kvim4-userdebug
make -j20 otapackage

also, before build, I execute
git revert bc1bdb7ebee07dfef5c57f712b8e747f7cf29f8a
in MY_DIR/common folder

@goenjoy can you explain, how shout I make to enable 5 GPIO and 1 I2C:

&i2c0 {
	status = "okay";
	pinctrl-names="default";
	pinctrl-0=<&i2c0_pins1>;
	clock-frequency = <100000>; /* default 100k */
};

&i2c1 {
	status = "okay";
	pinctrl-names="default";
	pinctrl-0=<&i2c1_pins1>;

    es8316: es8316@10 {
        compatible = "everest,es8316";
        #sound-dai-cells = <0>;
        reg = <0x10>;
        status = "okay";
        io-channels = <&saradc 3>;
        io-channel-names = "jack-chan-3";
        hp_val = <784>; //val=voltage/1800mV*1023
        hp_tolerance = <50>;
        spk-con-gpio = <&gpio GPIOT_9 0>;
      };
};

Am I correct?

@Y2Kot Have you compiled and upgraded before? Can it boot and enter the desktop? In addition, please make sure that the downloaded code is accurate.

./mk kvim4 -v 5.4 -j20

Please paste the LOG in the last paragraph of the above command.

@goenjoy no, I’m compiling for the first time. Its show khadas logo and blackscreen, I didn’t see desktop.
I think that problem was in command:
git revert bc1bdb7ebee07dfef5c57f712b8e747f7cf29f8a
and now I’m fully download code again to make manual changes in kvim4.dts as I print above. Am I correct? or git revert bc1bdb7ebee07dfef5c57f712b8e747f7cf29f8a is a right command?

I’ll send log after download will complete

@goenjoy here is my kernel build log kernel_build.log · GitHub
I noticed that my update.img have 1.8gb size, however your image is 2.1gb. Can I missed some files?

@Y2Kot The LOG you posted is uboot, not kernel. So I suspect you haven’t compiled the kernel.

./mk kvim4 -v 5.4 -jN

@goenjoy
does kernel build must be called from project_root directory? If so I have build error: kernel · GitHub

yes

https://docs.khadas.com/products/sbc/vim4/development/android/install-toolchains
Have you installed the tool chain in strict accordance with the document?
If the installation is successful, it is the problem of downloading the code. Have you performed step 4 in the download document?
https://docs.khadas.com/products/sbc/vim4/development/android/download-android-source-code

after installing sudo apt-get install gcc-5-aarch64-linux-gnu kernel build successfully and I load into desktop. Thank you for help! I2C and GPIO also works

@goenjoy i2cget binary file from vim4 can’t read word from i2c. Is it possible to get binaries for i2cget, i2cset from vim3? They works well

@Y2Kot I2C Usage | Khadas Documentation

@goenjoy the i2cget app in vim4 can’t read WORD from register, only one byte, however i2cget app from vim3 can do it.

@goenjoy where I should change i2cget binary to put it from vim3 rom to vim4?

@Y2Kot

find . -iname "i2cget"
1 Like

@goenjoy I wrote about this.

I found TODO:

i2cget non-byte modes? default to current read address?

Is it possible to implement word read?