To fetch EDID from android device

来源:互联网 发布:哈根达斯 知乎 编辑:程序博客网 时间:2024/06/05 14:49


由于 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 则定义了: 读或写, 位置, 长度,  以及回传值的资讯内容.


执行后可看到:





原创粉丝点击