MTK android平台添加读写i2c设备工具

调试驱动程序的时候,我们很多时候需要读写i2c设备,如果能够有一个通用的i2c读写工具,就方便多了。
在ubuntu的时候,我使用一个i2c-tool的工具,http://dl.lm-sensors.org/i2c-tools/releases/,这个网址可以下载。
在ubuntu下面需要两个动作,第一个,重新加入内核,需要打开intel的I2c接口,第二,编译这个源码,就在tools目录下生成几个i2c工具。
同样,我们也可以编译成android版本,只需要修改Makefile中间的CC编译器的定义就可以,是的CC指向你的android编译工具,这个工具是安装NDK时候带的。例如我的系统做如下修改
==========================================================
# I2C tools for Linux
#
# Copyright (C) 2007-2012  Jean Delvare <jdelvare@suse.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

DESTDIR    =
prefix    = /usr/local
bindir    = $(prefix)/bin
sbindir    = $(prefix)/sbin
mandir    = $(prefix)/share/man
man8dir    = $(mandir)/man8
incdir    = $(prefix)/include

INSTALL        := install
INSTALL_DATA    := $(INSTALL) -m 644
INSTALL_DIR    := $(INSTALL) -m 755 -d
INSTALL_PROGRAM    := $(INSTALL) -m 755
RM        := rm -f

CC = /opt/android-toolchain/android-14/bin/arm-linux-androideabi-gcc#gcc

CFLAGS    ?= -O2
# When debugging, use the following instead
#CFLAGS    := -O -g
CFLAGS    += -Wall

KERNELVERSION    := $(shell uname -r)

.PHONY: all strip clean install uninstall

all:

EXTRA    :=
#EXTRA    += py-smbus
SRCDIRS    := include eeprom stub tools $(EXTRA)
include $(SRCDIRS:%=%/Module.mk)
============================================================================================
修改之后,执行make,就可以编译出几个android版本工具
执行file,看看文件属性
 file i2cdetect
i2cdetect: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), not stripped

确认编译的android版本。
-----------------------------------------------------------------------------------------
如果使用我们最好push到/system/bin执行如下指令
adb remount
adb push i2cdetect /system/bin
adb push i2cset /system/bin
adb push i2cget /system/bin
adb shell
cd system/bin
chmod 777 i2cdect
chmod 777 i2cset
chmod 777 i2cget
---------------------------------------------------------------------------
当然,对于android,我们需要同样打开配置文件,这样才能在/dev下打开i2c控制器的接口。
对于mtk系统,需要在./alps/mediatek/config/mt6572/autoconfig/kconfig/platform增加CONFIG_I2C_CHARDEV=y,然后重新编译之后就可以了。
然后执行i2cdetect 1,意思是扫描/dev/i2c-1后面的设备
root@android:/ # i2cdetect 1                                                   
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: UU -- -- -- -- UU -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --            
--------------------------------------------------------------------------
可以看到,i2c-1,后面挂了三个设备
38,50 55

使用最多的工具:
i2cset
Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77)
  MODE is one of:
    c (byte, no value)
    b (byte data, default)
    w (word data)
    i (I2C block data)
    s (SMBus block data)
    Append p for SMBus PEC

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值