I2C tool for Linux I2C interface Read and Write__linux

Source: Internet
Author: User
Tags asop


(I2C source Download Https://github.com/groeck/i2c-tools)

I2ctool for Android

December 1, 2014

11:36

The ANDROID.MK code is as follows

Local_path:= $ (call My-dir)

Include $ (clear_vars)

Local_module_tags: = Optional
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: = Optional
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: = Optional
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: = Optional
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: = Optional
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 Documents

I had test it on my environment, it can compile I2ctools

The reference web site is

Http://boundarydevices.com/i2c-tools-under-android/

Compiler step:

1.enter Asop.

2. $source build/envsetup.sh

3. $lunch xxxxx

4.copy i2c-tools-3.1.0 folder to Asop/tools/external

5.create android.mk file (content same as your) ini2c-tools-3.1.0

6.enter i2c-tools-3.1.0 folder,then Type $mm

7.you'll to the I2ctools was builded inout/target/product/xxxx/system/bin/i2cset

Source Documents

3. All the smooth generation of i2cdetect,i2cdump,i2cset,i2cget and other command tools;

4.adbpush I2cdetect/system/bin

Adbpush I2cdump/system/bin

Adbpush I2cset/system/bin

ADB push I2cget/system/bin

-----------------------Below is an example of the use of these four commands

The i2c-tools contains four files.

· i2cdetect– used to list I2C bus and all the above devices.

· i2cdump– displays the value of all register on the device

· i2cget– read the value of a register on the device

· i2cset– wrote a register on the device

Here's what I got with BeagleBoard.

/system/bin # I2cdetect-l

i2c-0 I2C S3C2410-I2C I2C Adapter

I2c-1 I2C S3C2410-I2C I2C Adapter

I2c-2 I2C S3C2410-I2C I2C Adapter

/system/bin #

See there are three I2C bus

/system/bin # I2cdetect-y-R 0

0 1 2 3 4 5 6 7 8 a B c D E F

of:--------------------------

:--------------------UU----------

--------------------------------

------------------------------

:--------------------------------

:--------------------------------

--------------------------------

M:----------------

/system/bin #

See what devices and device addresses are on bus 0 above;

/system/bin # i2cdump-f-y 0 0x34

No size specified (using byte-dataaccess)

0 1 2 3 4 5 6 7 8 9 a B c D E F 0123456789abcdef

00:38 the 0000 of all of the 8p.! ............

10:05 5f 00 00 00 00 00 00 00 00 0000 00 00 00? _.............

20:00, FF 68 00 0000 00 00 00 ...? ... h.h .....

30:61 C9 9d A5 1f all 5FFC a? B? E "???? H??..

40:d8 ff?.?? (0060) (a) ....???. `...

50:CF 0e 0e 1f??..?? (0000) . ... q?

60:a2 the??.? of the same as 0000 ............

70:0C A1 D0 000f # a2 00? '? .....??..???.

80:E0 FD (0000) for the???? 2..........!

90:07 a5 (0000) and other????.? ..........

a0:00 1d CD/000e A2 0b ...?????..???? of the.

b0:00 of Bad2 0d ..... of the?????.. of ......

C0:01 0d 1a 2e (3d49) 5c???????? $.5=it\c

d0:00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 .... .....

e0:00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 .... .....

The f0:41 A.??????? ............

/system/bin #

Read Device 0x34 Register contents

/system/bin # i2cget-f-y 0 0x34 0x28

0xFF

/system/bin #

Read the value of the 0x28 register individually

/system/bin #

/system/bin #

/system/bin # i2cset-f-y 0 0x34 0X280XFB

/system/bin #

Write the value of the 0x28 register individually

/system/bin # i2cget-f-y 0 0x34 0x28

0xfb

/system/bin #

You can see that the register value has been changed from 0xFF to 0XFB

Source Documents

When dealing with audio messages, I usually find a way to read the values of the register in codec. Luckily Linux also has this kind of tool –I2C tools. First to lm-sensors download Soure code, and then cross compile into the arm of the file, you can put the board to try to see.

The i2c-tools contains four files.

i2cdetect– used to list I2C bus and all the above devices.

i2cdump– displays the value of all register on the device

i2cget– read the value of a register on the device

i2cset– wrote a register on the device

Here's what I got with BeagleBoard.

Root@android:/temp #./i2cdetect-l

I2c-1 I2C OMAP I2C Adapter I2C

I2c-2 I2C OMAP I2C Adapter I2C

I2c-3 I2C OMAP I2C Adapter I2C

There are three groups of I2C bus on the beagleboad.

I2cdetect can also be used to see those devices on the bus.

Root@android:/temp #/i2cdetect-y-R 1

0 1 2 3 4 5 6 7 8 a B c D E F

of:--------------------------

Ten:--------------------------------

--------------------------------

--------------------------------

-----------------uu uu uu--------

:--------------------------------

--------------------------------

M:----------------

This means that there are four devices on the bus, the address is 0x48,0x49, 0x4a, 0x4b.

We are looking for the Codec,beagleboard on the codec is TI's TPS65950, from Technicalreference manual can know codec on the I2C site is 0x49.

Then use I2cdump to see the value of all register in codec

[

Root@android:/temp #/i2cdump-f-y 1 0x49

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:00 a 0f 0f 0f 0f ..... the????.. of .......

10:3f 3f 3f 3f???? (in more) %.... 2222..U

20:00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 ...? ....

?.... y?...?. (30:13), at the same. Di?.

40:00 a 1b ..... ....... 2....

50:00 F0 1a 1a E1, at the??? of the ...??.?? ...

All the 60:14 in the same-all other?...............

70:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .... .....

80:00 2f FF FF FF FF FF ff...../.?? .......

00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ...? .......

00 00 00 00 00 00 00 00 00 04 18 50 01 44 05 ..... P? D?

b0:00 FE FF (+) FF FF (+)?.? .....? ...

All of the?....? in all its other c0:03 ..........

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..... .....

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..... .....

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..... .....

Then I use I2cset to change the headset gain to see if it will change the volume of playback. First use the following instructions to play the WAV file, I use the sample rate 44.1k file, other sample rate WAV may not play.

Root@android:/temp #./tinymix 13 1

Root@android:/temp #./tinymix 45 1

Root@android:/temp #./tinymix 48 1

Root@android:/temp #/tinyplay 440.wav

Playing sample:2 ch, 44100 Hz, bit

The address of headset gain's register is 0x23, which opens another ADB shell during the playback process, with i2cset to increase gain

Root@android:/temp #/i2cset-f-y 1 0x49 0x23 5

The volume is getting bigger!

The use of I2cget is like I2cget, and there is little to be said.

Source Documents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.