由于 busybox 并没有把 i2cdump 放入, 所以决定另行开发程式, 依照以往的经验 EDID 会在 /dev/i2c-2 , slave address 0x50,

准备进行 i2c bus 的读取:


1. open file: /dev/i2c-2

2. set slave address: 0x50

file = open("/dev/i2c-2", O_RDWR);if (file < 0) exit(1);if (ioctl(file, I2C_SLAVE, 0x50)<0) {fprintf(stderr,"Error: Could not set address\n");exit(1);}printf("Version: %s\n", VERSION);printf("[VID]=0x%02x 0x%02x\n", i2c_smbus_read_byte_data(file, 8), i2c_smbus_read_byte_data(file, 9));printf("[PID]=0x%02x 0x%02x\n", i2c_smbus_read_byte_data(file, 10), i2c_smbus_read_byte_data(file, 11));

3. 由于知道 vid 在 0x08, 0x09 的位置, 而 pid 在 0x0a, 0x0b 的位置, 藉由呼叫 i2c_smbus_read_byte_data 得出其值

i2c_smbus_read_byte_data 定义于: linux/i2c-dev.h

static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command){union i2c_smbus_data data;if (i2c_smbus_access(file,I2C_SMBUS_READ,command,                     I2C_SMBUS_BYTE_DATA,&data))return -1;elsereturn 0x0FF & data.byte;}

其中 I2C 存取模式为

#define I2C_SMBUS_READ1

而 I2C transaction type 为

#define I2C_SMBUS_BYTE_DATA    2 

i2c_smbus_access(file, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &data)可理解为从 file 中读取位置 command, 长度为 I2C_SMBUS_BYTE_DATA, 并将

其值传回 data.byte

static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,                                      int size, union i2c_smbus_data *data){struct i2c_smbus_ioctl_data args;args.read_write = read_write;args.command = command;args.size = size;args.data = data;return ioctl(file,I2C_SMBUS,&args);}


#define I2C_SMBUS0x0720/* SMBus-level access */


源头即是 IOCTL 呼叫, 通道为 I2C_SMBUS, 而 args 则定义了:读或写, 位置, 长度, 以及回传值的资讯内容.


执行后可看到:





更多相关文章

  1. Android,自定义ViewGroup实现titleBar
  2. [置顶] Canvas开篇之drawBitmap方法讲解
  3. android——代码实现在指定位置显示View
  4. Android(安卓)解决离线路由GraphHopper 偏僻位置导航失败 抛出Po
  5. Jsp读取数据库返回json数据,Android客户端接收json
  6. Android_OTT的update升级包版本信息的读取
  7. Android版百度地图的移动定位开发过程
  8. android读取原始的xml文件
  9. Android(安卓)实现模拟地图定位功能

随机推荐

  1. android支付宝问题2013-07-17
  2. iOS和Android对比系列(二):页面跳转和传参
  3. 签名keystore一系列
  4. AArch64 是什么
  5. Android设备指纹大全
  6. Android(安卓)studio 打包aar
  7. Android(安卓)Gradle
  8. Android计步器开发
  9. Android无EditText时获取扫描设备的扫描
  10. 【链接】android图片压缩总结