I.MX6 Android i2c-tools porting

/**************************************************************************
 *                   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 # 

 

时间: 2024-10-24 10:08:14

I.MX6 Android i2c-tools porting的相关文章

I.MX6 Android Linux shell MMPF0100 i2c 设置数据

#!/system/bin/busybox ash # # I.MX6 Android Linux shell MMPF0100 i2c 设置数据 # 说明: # 本文主要记录通过shell脚本来设置MMPF0100的数据. # # 2016-4-6 深圳 南山平山村 曾剑锋 # # 检查参数个数 if [ $# -lt 3 ]; then echo "USAGE:" echo " i2cSetData.sh <curPage> <address(hex)&

I.MX6 Android Linux shell MMPF0100 i2c 获取数据

#!/system/bin/busybox ash # # I.MX6 Android Linux shell MMPF0100 i2c 获取数据 # 说明: # 本文主要记录通过shell脚本来获取MMPF0100的数据,更多的是为了更为 # 方便的获取到数据,在进行一些调试的时候能够更有效. # # 2016-4-1 深圳 南山平山村 曾剑锋 # # 检查参数个数 if [ $# -lt 3 ]; then echo "USAGE:" echo " i2cData.sh

I.MX6 Android iperf3 porting failed

/***************************************************************************** * I.MX6 Android iperf3 porting failed * 说明: * 本来想移植一下iperf3到Android系统上测试一下网卡,可能是版本高了点,最后 * 运行客户端的时候会报错,也找了一些解决办法,但还是未能解决. * * 2016-4-5 深圳 南山平山村 曾剑锋 ***********************

I.MX6 HUAWEI MU609 3G porting

/*************************************************************************** * I.MX6 HUAWEI MU609 3G porting * 声明: * 本文主要是记录移植3G模块时,查看的资料与遇到的一些问题, * 使用的解决方法. * * 2015-8-8 晴 深圳 南山平山村 曾剑锋 ****************************************************************

I.MX6 android mkuserimg.sh

/************************************************************************** * I.MX6 android mkuserimg.sh * 说明: * 修改了android源代码中的一些内容之后,如果内容过多,不能确定到底修改 * 了system目录下的哪些文件,于是可能要重新make,但这实在是让人难以接受, * 因为等待的时间会很长,于是从make命令最后看到mkuserimg.sh是用来最后对文件 * 系统进行打包的

I.MX6 Android 5.1.1 下载、编译

/************************************************************************* * I.MX6 Android 5.1.1 下载.编译 * 说明: * 这里要提到的就是4.2版本,编译中断了,你接着编好像是没事的,但是这个 * 5.1.1版本貌似就得从头再编,这个有点郁闷. * * 2016-9-9 深圳 南山平山村 曾剑锋 ***************************************************

解决错误ERROR: No suitable Java found. In order to properly use the Android Developer Tools,…

Failed to convert path to a short DOS path: C:\Windows\system32\java.exe 很多人在把ADT更新到ADT17以后使用 SDK里面的工具时遇到了这样的错误: 出错的环境是windows 7 - 64bit Failed to convert path to a short DOS path: C:\Windows\system32\java.exe ERROR: No suitable Java found. In order

eclipse-安装&amp;amp;quot;Android DDMS&amp;amp;quot;和&amp;amp;quot;Android Development Tools&amp;amp;quot;出错

问题描述 安装"Android DDMS"和"Android Development Tools"出错 eclipse-ee安装"Android DDMS"和"Android Development Tools"出错了,怎么办 解决方案 出的是什么错误呢?这个需要详细的说明一下. 解决方案二: 建议下载离线包,不然现在上不了google 解决方案三: 看一下这个.搭建android开发环境

和 Eclipse Android Developer Tools 说再见

文|Google Android 产品经理 Jamal Eason 随着 Android Studio 2.2 的发布,现在是时候告别 Eclipse Android Developer Tools 了.我们已正式终止对它们的支持与开发.最佳时机不可错过,赶紧切换到 Android Studio 并体验我们对 Android 开发工作流所做的改进吧. Android Studio 官方 Android IDE Android Studio 具有强大的代码编辑功能以及高级代码自动完成和重构功能.它