├── lint.xml ├── assets ├── dump.png ├── set.png ├── detect.png └── i2c-command-line-tools.png ├── ic_launcher-web.png ├── libs └── android-support-v4.jar ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── values │ ├── integers.xml │ ├── dimens.xml │ ├── styles.xml │ ├── array.xml │ └── strings.xml └── layout │ ├── dialog_i2c_info.xml │ ├── dialog_i2c_set.xml │ └── activity_main.xml ├── project.properties ├── proguard-project.txt ├── AndroidManifest.xml ├── bin └── AndroidManifest.xml ├── src └── com │ └── mitac │ └── android │ └── i2ctool │ ├── LogFileHelper.java │ ├── I2cSetDialog.java │ ├── I2cInfo.java │ ├── I2cToolHelper.java │ ├── I2cInfoDialog.java │ ├── I2cParserHelper.java │ └── MainActivity.java └── README.md /lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /assets/dump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/assets/dump.png -------------------------------------------------------------------------------- /assets/set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/assets/set.png -------------------------------------------------------------------------------- /assets/detect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/assets/detect.png -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/ic_launcher-web.png -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/libs/android-support-v4.jar -------------------------------------------------------------------------------- /assets/i2c-command-line-tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/assets/i2c-command-line-tools.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li2/android-i2c-tool/HEAD/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 512 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/array.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0.5 5 | 1 6 | 1.5 7 | 2 8 | 5 9 | 10 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mitac I2C Tool 5 | Hello world 6 | Dump 7 | Set 8 | Detect 9 | Clean 10 | Data Address: 0x 11 | Value: 0x 12 | 13 | 14 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-22 15 | android.library.reference.1=../../android-sdk/extras/android/support/v7/appcompat 16 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /bin/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /res/layout/dialog_i2c_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 17 | 18 | 23 | 24 | 31 | 32 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /res/layout/dialog_i2c_set.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 18 | 19 | 28 | 29 | 30 | 36 | 37 | 41 | 42 | 51 | 52 | 53 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/com/mitac/android/i2ctool/LogFileHelper.java: -------------------------------------------------------------------------------- 1 | package com.mitac.android.i2ctool; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileWriter; 6 | import java.io.IOException; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | import java.util.Locale; 10 | 11 | import android.os.Environment; 12 | import android.util.Log; 13 | 14 | public class LogFileHelper { 15 | 16 | private static final String TAG = "i2c_LogFileHelper"; 17 | 18 | public static final String TIME_FORMATTER_YMDHMS = "yyyy-MM-dd HH:mm:ss"; 19 | public static final String TIME_FORMATTER_HMS = "HH:mm:ss"; 20 | 21 | private static final String LOG_FILE_SUBDIR = "/i2clog"; 22 | 23 | private static LogFileHelper sLogFileHelper; 24 | private File mLogDirectory; 25 | 26 | private LogFileHelper() { 27 | super(); 28 | mLogDirectory = new File(getInnerSDCardPath() + LOG_FILE_SUBDIR); 29 | mLogDirectory.mkdirs(); 30 | } 31 | 32 | public static LogFileHelper get() { 33 | if (sLogFileHelper == null) { 34 | sLogFileHelper = new LogFileHelper(); 35 | } 36 | return sLogFileHelper; 37 | } 38 | 39 | public File createFile(String filename) { 40 | File file = new File(mLogDirectory, filename); 41 | writeFile(file, "\r\n" + timestamp(TIME_FORMATTER_YMDHMS) + "\r\n\r\n" ); 42 | return file; 43 | } 44 | 45 | /** 46 | * Method to write ascii text characters to file on SD card. Note that you 47 | * must add a WRITE_EXTERNAL_STORAGE permission to the manifest file or this 48 | * method will throw a FileNotFound Exception because you won't have write 49 | * permission. 50 | */ 51 | public void writeFile(File file, String content) { 52 | if (file == null) { 53 | Log.e(TAG, "File not created."); 54 | } 55 | 56 | try { 57 | FileWriter out = new FileWriter(file, true); 58 | out.write("\r\n" + content); 59 | out.flush(); 60 | out.close(); 61 | } catch (FileNotFoundException e) { 62 | e.printStackTrace(); 63 | Log.e(TAG, "File not found. Did you add a WRITE_EXTERNAL_STORAGE permission to the manifest?"); 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | //Get inner SDCard path 70 | public String getInnerSDCardPath() { 71 | return Environment.getExternalStorageDirectory().getPath(); 72 | } 73 | 74 | public String timestamp(String formatter) { 75 | SimpleDateFormat sdf = new SimpleDateFormat(formatter, Locale.US); 76 | Date date = new Date(); 77 | return sdf.format(date); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Android I2C Tool Manual 2 | 3 | This tool is to 4 | 5 | - detect Android I2C devices, 6 | - dump and set the values of I2C device registers periodically or just one time. 7 | - log device registers values. 8 | 9 | The core part is running linux commannd line tool through `Runtime.getRuntime().exec()`, then read and parse the stand out/error and then write to log. 10 | 11 | ### Setup 12 | 13 | 1. Build the [i2c linux command line tool](https://github.com/suapapa/i2c-tools) in target Android BSP to generate binary files: `i2cdump`, `i2cset`. 14 | 2. Root Android device. 15 | 3. Upload these two files to target device path `/system/xbin`, and modify the permission as 755; 16 | 17 | ```sh 18 | adb-platform-tools>adb remount 19 | adb-platform-tools>adb push i2cdump /system/xbin 20 | adb-platform-tools>adb push i2cset /system/xbin 21 | adb-platform-tools>adb shell chmod 755 /system/xbin/i2c* 22 | ``` 23 | 4. If encounter the following error: 24 | 25 | ```sh 26 | Error: Could not open file `/dev/i2c-2': Permission denied, Run as root? 27 | ``` 28 | then need to modify the permission of Android I2C device file:`root@android:/ # chmod 666 /dev/i2c*` 29 | 30 | 31 | ![i2c-command-line-tools](https://github.com/li2/Android_I2C_Tool/blob/master/assets/i2c-command-line-tools.png) 32 | 33 | 34 | ### Detect I2C bus and chips on target Android device 35 | 36 | ![i2c-detect](https://github.com/li2/Android_I2C_Tool/blob/master/assets/detect.png) 37 | 38 | 39 | ### Dump all registers of specific I2C chip 40 | 41 | 1. click right button to popup a I2C device selector dialog, then set bus number, device addres, read mode; 42 | 2. enable read periodically; 43 | 3. enable Log, 44 | 45 | log path :/mnt/sdcard/i2clog/i2c_log_parsed.txt and i2c_log_raw.txt 46 | 47 | ```sh 48 | 14:54:59 - 49 | 24 02 00 00 64 00 12 0c 3f 10 88 02 8c 0b 8c 0b 50 | c9 0c c9 0c 08 00 ff ff c9 0c fa ff 27 0b 5b fd 51 | 27 0b c9 0c 21 00 00 00 12 0c 02 00 64 00 60 00 52 | 68 10 fa 05 ff ff 5e 00 53 00 76 11 f4 0b 00 00 53 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 54 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 | 00 00 0a 42 51 32 37 35 34 58 2d 47 31 ff 00 00 56 | 00 00 00 00 00 00 00 00 XX XX 95 ff 3f 10 12 0c 57 | 24 02 00 00 64 00 12 0c 3f 10 88 02 8c 0b 8c 0b 58 | c9 0c c9 0c 08 00 ff ff c9 0c fa ff 27 0b 5b fd 59 | 27 0b c9 0c 21 00 00 00 12 0c 02 00 64 00 60 00 60 | 68 10 fa 05 ff ff 5e 00 53 00 76 11 f4 0b 00 00 61 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 62 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 63 | 00 00 0a 42 51 32 37 35 34 58 2d 47 31 ff 00 00 64 | 00 00 00 00 00 00 00 00 XX XX 95 ff 3f 10 12 0c 65 | 14:55:00 - 66 | ``` 67 | ![i2c-dump](https://github.com/li2/Android_I2C_Tool/blob/master/assets/dump.png) 68 | 69 | 70 | ### Set value to specific I2C device register 71 | 72 | ![i2c-set](https://github.com/li2/Android_I2C_Tool/blob/master/assets/set.png) 73 | 74 | 75 | ## About 76 | 77 | App可以用于探测Android设备I2C总线、读取/设置I2C设备寄存器值,并写入log,硬件工程师可以直接把log导入excel,就可以进一步分析数据。 78 | 方便不熟悉命令行和ADB的硬件工程师测试。 79 | 80 | 核心是通过`Runtime.getRuntime().exec()`调用命令行工具,然后读取进程的标准输出/标准错误。核心代码在`I2cToolHelper.java`和`I2cParserHelper.java` 81 | 82 | 之所以开发这个App,是因为我负责的驱动模块出现了问题,需要和硬件工程师排一起查软、硬问题。因为硬件工程师不熟悉命令行、ADB,并且使用ADB打印的log不便于处理。 83 | 84 | 第一版于2013.08开发完成,这是第一次开发Android,所有细节都得搜索,很琐碎很差劲,至于有多差劲,可以看代码:[branch-v1](https://github.com/li2/Android_I2C_Tool/tree/v1), 85 | 第二版于2015.10开发完成,重构了之前的代码。 86 | 87 | 之所以开源这个App,是因为没有上述提到的开源的命令行工具,这个App没有任何作用。 88 | 希望对别人有所帮助。 89 | 90 | weiyi.just2@gmail.com 91 | li2.me 92 | -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 14 | 15 | 23 | 24 | 25 | 26 | 32 | 33 | 38 | 39 | 44 | 45 |