I.MX6 Android i2c-tools porting

简介: /************************************************************************** * I.MX6 Android i2c-tools porting * 说明: * 判断I2C总线设备是否存在,每次都去查dmesg,实在是烦了,于是还是移植 * 一个i2c-tools比较好,不用翻那长长内核信息。
/**************************************************************************
 *                   I.MX6 Android i2c-tools porting
 * 说明:
 *     判断I2C总线设备是否存在,每次都去查dmesg,实在是烦了,于是还是移植
 * 一个i2c-tools比较好,不用翻那长长内核信息。
 *  
 *                                        2016-3-31 深圳 南山平山村 曾剑锋
 *************************************************************************/


一、参考资料:
    1. Android 平台下使用 i2c-tools
        http://my.oschina.net/luoly/blog/368881
    2. 树莓派学习笔记——I2C Tools 学习笔记
        http://blog.csdn.net/xukai871105/article/details/15029843
    3. Linux I2C工具查看配置I2C设备 
        http://blog.chinaunix.net/uid-26895763-id-3478882.html

二、download:
    groeck/i2c-tools:
        https://github.com/groeck/i2c-tools

三、Decompress:
    zengjf@zengjf:~$ unzip i2c-tools-master.zip
    zengjf@zengjf:~$ mv i2c-tools-master ~/myandroid/external/i2c-tools/
    
四、cat external/i2c-tools/Android.mk
    # 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/util.c tools/i2cbusses.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)

五、compile error:
    1. 现象:
        ......
        PRODUCT_COPY_FILES frameworks/base/data/sounds/ringtones/ogg/Solarium.ogg:system/media/audio/ringtones/Solarium.ogg ignored.
        No private recovery resources for TARGET_DEVICE sabresd_6dq
        make: Entering directory `/home/zengjf/myandroid'
        target thumb C: i2c-tools <= /home/zengjf/myandroid/external/i2c-tools//lib/smbus.c
        target StaticLib: i2c-tools (out/target/product/sabresd_6dq/obj/STATIC_LIBRARIES/i2c-tools_intermediates/i2c-tools.a)
        target thumb C: i2cdetect <= /home/zengjf/myandroid/external/i2c-tools/lib/smbus.c
        target thumb C: i2cdetect <= /home/zengjf/myandroid/external/i2c-tools/tools/i2cdetect.c
        /home/zengjf/myandroid/external/i2c-tools/tools/i2cdetect.c:157:13: error: 'I2C_FUNC_SMBUS_PEC' undeclared here (not in a function)
        make: *** [out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdetect_intermediates/tools/i2cdetect.o] Error 1
        make: Leaving directory `/home/zengjf/myandroid'
    2. 解决办法:
        cat external/i2c-tools/include/i2c/smbus.h
            .....
            /* Compatibility defines  添加宏声明*/
            #ifndef I2C_SMBUS_I2C_BLOCK_BROKEN
            #define I2C_SMBUS_I2C_BLOCK_BROKEN I2C_SMBUS_I2C_BLOCK_DATA
            #endif
            #ifndef I2C_FUNC_SMBUS_PEC
            #define I2C_FUNC_SMBUS_PEC I2C_FUNC_SMBUS_HWPEC_CALC
            #endif
            
            extern __s32 i2c_smbus_access(int file, char read_write, __u8 command,
                              int size, union i2c_smbus_data *data);
            
            extern __s32 i2c_smbus_write_quick(int file, __u8 value);
            ......
    3. 正常现象:
        No private recovery resources for TARGET_DEVICE sabresd_6dq
        make: Entering directory `/home/zengjf/myandroid'
        target thumb C: i2cdetect <= /home/zengjf/myandroid/external/i2c-tools/tools/i2cdetect.c
        target Executable: i2cdetect (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdetect_intermediates/LINKED/i2cdetect)
        target Symbolic: i2cdetect (out/target/product/sabresd_6dq/symbols/system/bin/i2cdetect)
        Export includes file: /home/zengjf/myandroid/external/i2c-tools/Android.mk -- out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdetect_intermediates/export_includes
        target Strip: i2cdetect (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdetect_intermediates/i2cdetect)
        Install: out/target/product/sabresd_6dq/system/bin/i2cdetect
        Import includes file: out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cget_intermediates/import_includes
        target thumb C: i2cget <= /home/zengjf/myandroid/external/i2c-tools/tools/i2cget.c
        target Executable: i2cget (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cget_intermediates/LINKED/i2cget)
        target Symbolic: i2cget (out/target/product/sabresd_6dq/symbols/system/bin/i2cget)
        Export includes file: /home/zengjf/myandroid/external/i2c-tools/Android.mk -- out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cget_intermediates/export_includes
        target Strip: i2cget (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cget_intermediates/i2cget)
        Install: out/target/product/sabresd_6dq/system/bin/i2cget
        Import includes file: out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cset_intermediates/import_includes
        target thumb C: i2cset <= /home/zengjf/myandroid/external/i2c-tools/tools/i2cset.c
        target Executable: i2cset (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cset_intermediates/LINKED/i2cset)
        target Symbolic: i2cset (out/target/product/sabresd_6dq/symbols/system/bin/i2cset)
        Export includes file: /home/zengjf/myandroid/external/i2c-tools/Android.mk -- out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cset_intermediates/export_includes
        target Strip: i2cset (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cset_intermediates/i2cset)
        Install: out/target/product/sabresd_6dq/system/bin/i2cset
        Import includes file: out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdump_intermediates/import_includes
        target thumb C: i2cdump <= /home/zengjf/myandroid/external/i2c-tools/tools/i2cdump.c
        target Executable: i2cdump (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdump_intermediates/LINKED/i2cdump)
        target Symbolic: i2cdump (out/target/product/sabresd_6dq/symbols/system/bin/i2cdump)
        Export includes file: /home/zengjf/myandroid/external/i2c-tools/Android.mk -- out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdump_intermediates/export_includes
        target Strip: i2cdump (out/target/product/sabresd_6dq/obj/EXECUTABLES/i2cdump_intermediates/i2cdump)
        Install: out/target/product/sabresd_6dq/system/bin/i2cdump
        make: Leaving directory `/home/zengjf/myandroid'
        zengjf@zengjf:~/myandroid$ 
    4. adb push <编译出来的可执行程序> /data/local

六、i2cdetect test:
    1. test1:
        1|root@android:/data/local # ./i2cdetect -l                                    
        i2c-3   i2c             i2c-gpio3        I2C adapter
        i2c-0   i2c             imx-i2c          I2C adapter
        i2c-1   i2c             imx-i2c          I2C adapter
        i2c-2   i2c             imx-i2c          I2C adapter
        root@android:/data/local # 
    2. test2:
        root@android:/data/local # ./i2cdetect -y -r 2                                 
 1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
        00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
        10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        50: UU -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- 
        60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
        70: -- -- -- -- -- -- -- --

七、i2cget test:
    1|root@android:/data/local # ./i2cget -y 1 0x08 0x03                           
    Error: Could not set address to 0x08: Device or resource busy
    1|root@android:/data/local # ./i2cget -f -y 1 0x08 0x03                        
    0x21
    1|root@android:/data/local # 

 

目录
相关文章
|
Android开发
【错误记录】Android Studio 编译报错 ( Installed Build Tools revision 31.0.0 is corrupted )
【错误记录】Android Studio 编译报错 ( Installed Build Tools revision 31.0.0 is corrupted )
945 0
【错误记录】Android Studio 编译报错 ( Installed Build Tools revision 31.0.0 is corrupted )
|
XML IDE 开发工具
android中tools的含义及用法
终于建了一个自己个人小站:https://huangtianyu.gitee.io,以后优先更新小站博客,欢迎进站,O(∩_∩)O~~ 第一部分 安卓开发中,在写布局代码的时候,ide可以看到布局的预览效果。
1469 0
|
开发工具 Android开发 开发者
|
Android开发
add 'tools:replace="android:value"' to element at AndroidManifest.xml:25:5-27:34 to over
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.
2025 0
|
XML Android开发 数据格式
|
Android开发 开发工具
Gradle、 Gradle Android Plugin 、 Build Tools之间关系
gradle一堆坑,原理自己找别的文章吧,看着这个配置就不会有坑了。 先看Gradle,再看 Android Plugin,参考以下图,一定能编译通过。 https://developer.
1292 0
|
XML Android开发 数据格式
Android 开发之:Tools 属性
直到今天创建项目的时候, 出现tools:showIn="@layout/activity_main"才想起要学习记录下 Tools属性的相关使用。这个Tools 是如此好使用,我却未能善用,简直抱歉。
1044 0