I2CHelper


I2CHelper是一个简单的I2C调试工具,它可以用来设置读取、设置相关的寄存器。功能和著名的i2c-tool类似。

准备工作

在这里主要介绍如何在android里面进行使用。

首先,由于涉及到权限问题,我们需要通过adb进行root以及remount,如:

adb root
adb remount

接下来,就可以将I2CHelper push到/system/bin里面了:

adb push I2CHelper /system/bin

用法

从这里开始,我们来看一下如何正确使用此应用程序来进行相关的设置。

help

默认的模式,如果不带任何参数的话,那么就会进入如下模式。

命令行的用法如下:

adb shell ./system/bin/I2CHelper

或是带“help”参数,如:

adb shell ./system/bin/I2CHelper help

detect

该功能主要用来检测I2C总线上有哪些设备,以及该设备的地址是什么。该模式的参数只有一个,便是detect,如:

adb shell ./system/bin/I2CHelper detect

在某个android平台上的运行结果如下所示:

|-------|--------------|---------------|--------------|-----------------|
|  BUS  | 7BIT ADDRESS | WRITE ADDRESS | READ ADDRESS | POSSIBLE DEVICE |
|-------|--------------|---------------|--------------|-----------------|
| i2c-0 | 0x0C         | 0x18          | 0x19         | Unknow          |
| i2c-0 | 0x44         | 0x88          | 0x89         | Unknow          |
| i2c-0 | 0x5D         | 0xBA          | 0xBB         | GM7150,TVP5151  |
| i2c-1 | 0x5D         | 0xBA          | 0xBB         | GM7150,TVP5151  |
| i2c-2 | 0x28         | 0x50          | 0x51         | Unknow          |
| i2c-2 | 0x5D         | 0xBA          | 0xBB         | GM7150,TVP5151  |
|-------|--------------|---------------|--------------|-----------------|

get

该模式主要是用来获取设备的某个寄存器的数值,其功能参数为:

I2CHelper get [BUS][7-BIT ADDR][REG]

假如某个I2C设备挂载在dev/i2c-2上,其地址为0x5D,我们想获取它0x21寄存器的数值,那么我们可以执行如下命令:

adb shell ./system/bin/I2CHelper get 2 0x5D 0x21

输出结果如下所示:

|-------|--------------|------------------|-------|
|  BUS  | 7BIT ADDRESS | REGISTER ADDRESS | VALUE |
|-------|--------------|------------------|-------|
| i2c-2 | 0x5D         | 0x21             | 0xE   |
|-------|--------------|------------------|-------|

set

该模式主要是用来设置寄存器的数值,其功能参数为:

I2CHelper set [BUS][7-BIT ADDR][REG][VAL]

假如某个I2C设备挂载在dev/i2c-2上,其地址为0x5D,我们想设置它0x21寄存器的数值为0x0A,那么我们可以执行如下命令:

adb shell ./system/bin/I2CHelper set 2 0x5D 0x21 0x0A

命令执行的结果如下所示:

|-------|--------------|------------------|-----------|-----------|
|  BUS  | 7BIT ADDRESS | REGISTER ADDRESS | OLD VALUE | NEW VALUE |
|-------|--------------|------------------|-----------|-----------|
| i2c-2 | 0x5D         | 0x21             | 0xE       | 0xA       |
|-------|--------------|------------------|-----------|-----------|

dump

该模式主要是用来dump出整个I2C设备的所有寄存器的数值,其功能参数为:

I2CHelper dump [BUS][7-BIT ADDR][File --Option]

其中File这个参数是可选的。如果有此参数的话,会将相关的数值保存到文件中,以便于“load”模式使用。

假如某个I2C设备挂载在dev/i2c-2上,其地址为0x5D,我们想将它寄存器全部dump出来,那么执行如下命令:

adb shell ./system/bin/I2CHelper dump 2 0x5D

如果将dump的数据保存到文件中,则加上文件路径:

adb shell ./system/bin/I2CHelper dump 2 0x5D /sdcard/dump.txt

执行结果如下所示:

Bus: i2c-2
Address: 0x5D
|---|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
|   | 0  | 1  | 2  | 3  | 4  | 5  | 6  | 7  | 8  | 9  | A  | B  | C  | D  | E  | F  |
|---|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
| 0 | 00 | 15 | 00 | AF | C0 | 00 | 10 | 60 | 00 | 70 | 80 | 00 | 80 | 40 | 00 | 02 |
| 1 | 1E | 00 | 00 | 00 | 00 | 01 | 6E | 05 | 00 | 00 | 0C | 14 | 00 | 00 | 00 | 00 |
| 2 | 0E | 0E | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 3 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 4 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 5 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 6 | 00 | 00 | 01 | 00 | 00 | 04 | 04 | 08 | 15 | 00 | 0C | 32 | 0F | DA | 03 | 00 |
| 7 | FF | 06 | 06 | 10 | 00 | 04 | 00 | 08 | 40 | 04 | 00 | 00 | 03 | 0A | 01 | 74 |
| 8 | 71 | 50 | 03 | 00 | 02 | 71 | 11 | 00 | 60 | 40 | FF | 00 | 83 | 00 | 00 | 00 |
| 9 | 05 | 00 | 40 | 03 | 02 | 02 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| A | 55 | AA | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| B | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| C | 00 | 00 | 04 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| D | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| E | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| F | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
|---|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
Succeed to save the dump value to /sdcard/dump.txt

load

该模式主要是将dump出来的数据回写到I2C设备中。使用该命令的前提是,我们之前已经通过dump命令将数据保存了起来。load的命令用法如下:

I2CHelper load [BUS][7-BIT ADDR][File]

假如数据是保存在/sdcard/dump.txt文件中,那么我们可以执行如下命令读取并写回到设备中:

adb shell ./system/bin/I2CHelper load 2 0x5D /sdcard/dump.txt

执行结果如下所示:

Bus: i2c-2
Address: 0x5D

[Comment]
00~FF: The value succeed to set
XX: The value failed to set
II: The value ignore to set,because there is error in the dump file
|---|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
|   | 0  | 1  | 2  | 3  | 4  | 5  | 6  | 7  | 8  | 9  | A  | B  | C  | D  | E  | F  |
|---|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
| 0 | 00 | 15 | 00 | AF | C0 | 00 | 10 | 60 | 00 | 70 | 80 | 00 | 80 | 40 | 00 | 02 |
| 1 | 1E | 00 | 00 | 00 | 00 | 01 | 6E | 05 | 00 | 00 | 0C | 14 | 00 | 00 | 00 | 00 |
| 2 | 0E | 0E | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 3 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 4 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 5 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 6 | 00 | 00 | 01 | 00 | 00 | 04 | 04 | 08 | 15 | 00 | 0C | 32 | 0F | DA | 03 | 00 |
| 7 | FF | 06 | 06 | 10 | 00 | 04 | 00 | 08 | 40 | 04 | 00 | 00 | 03 | 0A | 01 | 74 |
| 8 | 71 | 50 | 03 | 00 | 02 | 71 | 11 | 00 | 60 | XX | FF | 00 | 83 | 00 | 00 | 00 |
| 9 | 05 | 00 | 40 | 03 | 02 | 02 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| A | 55 | AA | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| B | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| C | 00 | 00 | 04 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| D | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| E | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| F | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
|---|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|

这里稍微需要注意一下结果。如果数值是“0x00~0xFF”的话,那么意味着是正常写进去的;如果是“XX”,则是写入失败的,很可能是这个设备的这个寄存器是不允许写的;如果是“II”的话,意味着保存的数据当中,该地址的数据是不正确的,所以是没有往设备中写入。