Andorid 開發板爲 Freescale imx6 的 SabreSD Boardsvn
將 i2c-tools 代碼下載到 Android 源碼的 external 目錄下,我是使用 Subversion 直接從官方版本庫中檢出,固然使用別的方式下載到源代碼也是能夠的。3d
~/mydroid $ svn checkout http://lm-sensors.org/svn/i2c-tools/branches/i2c-tools-3.1 external/i2c-tools
在 i2c-tools 目錄下新建 Android.mk 文件,內容以下:code
# external/i2c-tools/Android.mk 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)
~/mydroid/external/i2c-tools $ mm
編譯後在 out/target/product/sabresd_6dq/system/bin
目錄下生成4個可執行程序:ci
製做新的 system image,而後從新燒錄 system.img開發
~/mydroid $ make snod ~/mydroid $ fastboot system out/target/product/sabresd_6dq/system.img
固然也能夠經過 adb push
之間將編譯生成的4個文件複製到 Android 平臺的 /system/bin
目錄下。 在 abd pusll
以前,要先將 system 分區 remount 成可寫入模式。rem
列舉 I2C busget
# i2cdetect -l i2c-0 i2c imx-i2c I2C adapter i2c-1 i2c imx-i2c I2C adapter i2c-2 i2c imx-i2c I2C adapter
列舉 I2C bus i2c-1
上面鏈接的全部設備源碼
# i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- UU -- -- -- -- -- -- -- 10: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- 3a -- -- -- -- -- 40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
發現 I2C 設備的位置顯示爲UU
或者表示設備地址的數值,UU
表示該設備在 driver 中被使用。io
dump I2C 設備大批量 register 的值編譯
# i2cdump -y -f 1 0x3a 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: eb 00 7f 05 3d 00 00 00 08 06 00 00 00 00 00 00 ?.??=...??...... 10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 20: 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10 ?#Eg????????vT2? 30: f0 e1 d2 c3 00 00 00 00 00 00 00 00 00 00 00 00 ????............ 40: 80 00 10 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 30 00 00 00 00 ...........0....
讀取 I2C 設備某個 register 的值
# i2cget -y -f 1 0x3a 0x02 0x7f
設置 I2C 設備某個 register 的值
# i2cset -y -f 1 0x3a 0x02 0x05