過程:

  1. 1.       http://www.lm-sensors.org/wiki/I2CTools 下載原始碼

在ubuntu 10.04環境下下載,檔名應為i2c-tools-3.1.0.tar.bz2

  1. 2.       編寫Android.mk並放到ASOP環境下 compile

解壓縮後產生一個目錄,名為 / i2c-tools-3.1.0

l   將/i2c-tools-3.1.0 目錄複製到ASOP下的 /tools/external/裡,所以目錄位置應為/tools/external/ i2c-tools-3.1.0,注意要更改目錄權限為 777,sudo chmod 777 -R  /tools/external/ i2c-tools-3.1.0

l   在/tools/external/ i2c-tools-3.1.0目錄下建立一個Android.mk,此為Andorid的Makefile,內容如下:

LOCAL_PATH:= $(call my-dir)

 

include $(CLEAR_VARS)

 

LOCAL_MODULE_TAGS := eng

LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/$(KERNEL_DIR)/include

LOCAL_SRC_FILES := tools/i2cbusses.c tools/util.c

LOCAL_MODULE := i2c-tools

include $(BUILD_STATIC_LIBRARY)

 

include $(CLEAR_VARS)

 

LOCAL_MODULE_TAGS := eng

LOCAL_SRC_FILES:=tools/i2cdetect.c

LOCAL_MODULE:=i2cdetect

LOCAL_CPPFLAGS += -DANDROID

LOCAL_SHARED_LIBRARIES:=libc

LOCAL_STATIC_LIBRARIES := i2c-tools

LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/$(KERNEL_DIR)/include

include $(BUILD_EXECUTABLE)

 

include $(CLEAR_VARS)

 

LOCAL_MODULE_TAGS := eng

LOCAL_SRC_FILES:=tools/i2cget.c

LOCAL_MODULE:=i2cget

LOCAL_CPPFLAGS += -DANDROID

LOCAL_SHARED_LIBRARIES:=libc

LOCAL_STATIC_LIBRARIES := i2c-tools

LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/$(KERNEL_DIR)/include

include $(BUILD_EXECUTABLE)

 

include $(CLEAR_VARS)

 

LOCAL_MODULE_TAGS := eng

LOCAL_SRC_FILES:=tools/i2cset.c

LOCAL_MODULE:=i2cset

LOCAL_CPPFLAGS += -DANDROID

LOCAL_SHARED_LIBRARIES:=libc

LOCAL_STATIC_LIBRARIES := i2c-tools

LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/$(KERNEL_DIR)/include

include $(BUILD_EXECUTABLE)

 

include $(CLEAR_VARS)

 

LOCAL_MODULE_TAGS := eng

LOCAL_SRC_FILES:=tools/i2cdump.c

LOCAL_MODULE:=i2cdump

LOCAL_CPPFLAGS += -DANDROID

LOCAL_SHARED_LIBRARIES:=libc

LOCAL_STATIC_LIBRARIES := i2c-tools

LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/$(KERNEL_DIR)/include

include $(BUILD_EXECUTABLE)

執行

$source build/envsetup.sh

$lunch [product_name]

切換目錄到 /tools/external/ i2c-tools-3.1.0

執行mm 進行 compile

$ mm

順利compile後所產生的執行檔 i2cdetect, i2cdump,i2cget,i2cset 應該位於

\out\target\product\[product_name]\system\bin\

  1. 3.       將compile後的執行檔,放置到Android裝置上執行

可先用mount | grep system指令檢查看看 /system的狀態後,再利用以下指令將之更改為 rw

1.adb shell

2.&su

         

可以先用  mount | grep system 指令看看目前裝置上的 /system 權限及存取設定,如果是像下面這樣,那就需要重新remount一下,讓/system變成可rw

1|root@msm8909:/ # mount | grep system
mount | grep system
/dev/block/bootdevice/by-name/system /system ext4 ro,seclabel,relatime,data=orde
red 0 0
     (根據不同裝置有不同的狀況)

 

3.adb remount

127|root@msm8909:/ # mount | grep system
mount | grep system
/dev/block/bootdevice/by-name/system /system ext4 rw,seclabel,relatime,data=orde
red 0 0

 

 修改將裝置上的system目錄權限,之後會將工具從PC端丟到裝置端

4.chmod 777 /system

 

利用 adb 工具將檔案push到裝置上的 /system上

.adb push i2cdetect /system

.adb push i2cdump /system

.adb push i2cset /system

.adb push i2cget /system

 

 

詳細的 i2ctools使用指令可以參考以下網站:

http://www.lm-sensors.org/wiki/i2cToolsDocumentation

 

到裝置端上的linux,切換目錄到 /system,確認檔案都有傳到裝置上後,如果沒有執行的權限

請先

#chmod 777 i2cdetect

#chmod 777 i2cdump

#chmod 777 i2cset

#chmod 777 i2cget

 

 

先用i2cdetect  Identify the I2C buses

 

.#./i2cdetect –l

./i2cdetect -y -r 0      

  1. 4.       執行結果

1|root@msm8974:/system # ./i2cdetect -l                                       

i2c-0  i2c            QUP I2C adapter                        I2C adapter

i2c-2  i2c            QUP I2C adapter                        I2C adapter

 

1|root@msm8974:/system # ./i2cdetect -y -r 0                                  

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00:          -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- 52 -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --                        

root@msm8974:/system # ./i2cdetect -y -r 2                                    

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00:          -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --                        

root@msm8974:/system # ./i2cdetect -y -r 1                                    

Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory

 

上方表示在有兩組I2C,並在i2c-2上有一個裝置的slave address是0x4a (應該為ATMEL Touch screen)

 Query the I2C bus

 

# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- 2d -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 49 -- -- -- -- -- --
50: 50 51 52 -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- 69 -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

如果在 出現Error: Can't use SMBus Quick Write command on this bus,表示無法在此bus上使用 write command

root@msm8992:/system # ./i2cdetect 2
./i2cdetect 2
Error: Can't use SMBus Quick Write command on this bus

 

Dump the I2C device registers

./i2cdump 3 0x0c
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-3, address 0xc, mode byte
Continue? [Y/n] y
y
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: f1 01 00 00 00 00 00 60 00 00 00 00 00 00 00 00 ??.....`........
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 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 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 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 ................

 

 針對某一個 i2c componment 的register 做設定寫的動作

./i2cset -f -y 1 0x63 0x0a 0x03

說明:

-y 1 表示指定i2c_1上的裝置

0x63是裝置的 i2c slave address

0x0a是裝置上的 register offset

0x03表示要在0x0a上寫的值為 0x03

 

 

 針對某一個 i2c componment 的register 做讀的動作

./i2cget -f -y 1 0x63 0x0a

說明:

-y 1 表示指定i2c_1上的裝置

0x63是裝置的 i2c slave address

0x0a是裝置上的 register offset

 

 

 

 

 

文章標籤

CuteParrot 發表在 痞客邦 留言(2) 人氣()