To fetch EDID from android device


由于 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;
	else
		return 0x0FF & data.byte;
}

其中 I2C 存取模式为

#define I2C_SMBUS_READ	1

而 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_SMBUS	0x0720	/* SMBus-level access */


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


执行后可看到:





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值