(i2c源码下载 https://github.com/groeck/i2c-tools)
I2ctool for android
2014年12月1日
11:36
Android.mk 代码如下
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional
源文档 <http://stackoverflow.com/questions/19763831/building-i2c-tools-on-android>
|
I had test it on my environment, it can compile i2ctools
the reference web site is
http://boundarydevices.com/i2c-tools-under-android/
compiler step:
1.enter ASOP.
2.$source build/envsetup.sh
3.$lunch xxxxx
4.copy i2c-tools-3.1.0 folder to ASOP/tools/external
5.create Android.mk file (content same as your) ini2c-tools-3.1.0
6.enter i2c-tools-3.1.0 folder,then type $mm
7.you will see the i2ctools was builded inout/target/product/xxxx/system/bin/i2cset
源文档 <http://stackoverflow.com/questions/19763831/building-i2c-tools-on-android>
3.一切顺利生成i2cdetect,i2cdump,i2cset,i2cget等命令工具;
4.adbpush i2cdetect /system/bin
adbpush i2cdump /system/bin
adbpush i2cset /system/bin
adb push i2cget /system/bin
-----------------------下面是关于这四个命令的用法举例
i2c-tools中含有四個執行檔
· i2cdetect – 用來列舉I2C bus和上面所有的裝置
· i2cdump – 顯示裝置上所有register的值
· i2cget – 讀取裝置上某個register的值
· i2cset – 寫入裝置上某個register
以下是我用beagleboard得到的結果
/system/bin # i2cdetect -l
i2c-0 i2c s3c2410-i2c I2C adapter
i2c-1 i2c s3c2410-i2c I2C adapter
i2c-2 i2c s3c2410-i2c I2C adapter
/system/bin #
看到有三条I2C总线
/system/bin # i2cdetect -y -r 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- UU ---- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- ---- -- -- --
30: -- -- -- -- 34 -- -- -- -- -- -- ---- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- ---- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- ---- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- ---- -- -- --
70: -- -- -- -- -- -- -- --
/system/bin #
查看总线0上面有哪些设备以及设备地址;
/system/bin # i2cdump -f -y 0 0x34
No size specified (using byte-dataaccess)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 38 70 00 21 00 00 00 00 00 00 00 0000 00 00 00 8p.!............
10: 05 00 5f 00 00 00 00 00 00 00 00 0000 00 00 00 ?._.............
20: 00 00 00 16 00 00 00 68 ff 68 00 0000 00 00 00 ...?...h.h......
30: 61 02 42 c9 45 22 9d 08 a5 1f 68 5ffc 16 00 00 a?B?E"????h_??..
40: d8 ff 03 01 00 00 00 00 08 08 02 0060 00 00 00 ?.??....???.`...
50: cf 0e 00 00 0e 1f 00 00 00 00 00 0000 00 71 04 ??..??........q?
60: a2 05 00 08 00 00 00 00 00 00 00 0000 00 00 00 ??.?............
70: 0c 27 a1 00 00 00 00 00 d0 02 00 000f 17 a2 00 ?'?.....??..???.
80: e0 fd 83 80 32 00 ff 00 00 00 00 0000 00 00 21 ????2..........!
90: 07 a5 07 07 00 02 00 00 00 00 00 0000 00 00 00 ????.?..........
a0: 00 00 00 00 00 01 1d 01 cd 06 00 000e 12 a2 0b .....?????..????
b0: 00 00 00 00 00 00 00 00 00 14 80 bad2 0d 00 00 .........?????..
c0: 01 01 02 04 07 0d 10 1a 24 2e 35 3d49 54 5c 63 ????????$.5=IT\c
d0: 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 ................
f0: 41 00 80 03 00 00 00 00 00 00 00 0000 00 00 00 A.??............
/system/bin #
读设备0x34的寄存器内容
/system/bin # i2cget -f -y 0 0x34 0x28
0xff
/system/bin #
单独读0x28寄存器的值
/system/bin #
/system/bin #
/system/bin # i2cset -f -y 0 0x34 0x280xfb
/system/bin #
单独写0x28寄存器的值
/system/bin # i2cget -f -y 0 0x34 0x28
0xfb
/system/bin #
可以看出寄存器值已经由0xff改成为0xfb
源文档 <http://blog.csdn.net/mk1111/article/details/8514841>
在處理音訊相關的問題時,我通常會找個方法來讀寫codec中register的值。幸好linux上也有這樣的工具– i2c tools。先到lm-sensors下載soure code,然後cross compile成arm的執行檔,就可以放到板子來試試看了。
i2c-tools中含有四個執行檔
i2cdetect –用來列舉I2C bus和上面所有的裝置
i2cdump –顯示裝置上所有register的值
i2cget –讀取裝置上某個register的值
i2cset –寫入裝置上某個register
以下是我用beagleboard得到的結果
root@android:/temp # ./i2cdetect -l
i2c-1 i2c OMAP I2C adapter I2C adapter
i2c-2 i2c OMAP I2C adapter I2C adapter
i2c-3 i2c OMAP I2C adapter I2C adapter
原來beagleboad上有三組I2C bus。
i2cdetect也可以用來看bus上有那些裝置
root@android:/temp # ./i2cdetect -y -r 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- UU UU UU UU -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
這表示bus上有四備裝置,位址分別是0×48,0×49, 0x4a, 0x4b。
我們要找的是codec,beagleboard上的codec是TI的TPS65950,從technicalreference manual可以得知codec在I2C上的位址是0×49。
然後用i2cdump來看codec中所有register的值
[
root@android:/temp # ./i2cdump -f -y 1 0x49
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 00 00 00 00 00 00 00 00 00 00 0f 0f 0f 0f 00 00..........????..
10: 3f 3f 3f 3f 25 00 00 00 00 32 32 32 32 00 00 55????%....2222..U
20: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00...........?....
30: 13 00 00 00 00 79 11 00 00 00 06 00 44 69 02 00?....y?...?.Di?.
40: 00 00 00 00 32 00 00 00 00 00 00 00 00 00 00 1b....2..........?
50: 00 00 03 f0 05 00 00 00 1a 1a 00 e1 93 00 00 00..???...??.??...
60: 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00?...............
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00................
80: 00 00 00 00 00 2f 00 09 10 ff ff ff ff ff ff ff...../.??.......
90: ff 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00........?.......
a0: 00 00 00 00 00 00 00 00 00 00 04 18 50 01 44 05..........??P?D?
b0: 00 00 00 00 fe ff 03 00 00 00 ff ff 03 00 00 00....?.?.....?...
c0: 03 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00?....?..........
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00................
再來我用i2cset來改變headset gain看看會不會改變播放的音量。先用以下的指令來播放wav檔,我是用sample rate 44.1k的檔案,其它sample rate的wav可能無法播放。
root@android:/temp # ./tinymix 13 1
root@android:/temp # ./tinymix 45 1
root@android:/temp # ./tinymix 48 1
root@android:/temp # ./tinyplay 440.wav
Playing sample: 2 ch, 44100 hz, 16 bit
headset gain的register的位址是0×23,在播放的過程中打開另一個adb shell,用i2cset來增加gain
root@android:/temp # ./i2cset -f -y 1 0x49 0x23 5
音量果然變大了!
i2cget的用法類似i2cget,這裡就不多做說明了。
源文档 <http://blog.chinaunix.net/uid-26895763-id-3478882.html>