linux ir驱动学习笔记

这篇博客主要介绍了Linux红外(IR)驱动的学习,包括REC、RC5/RC6、SONY等常见红外协议,以及IR驱动在Linux系统中的代码路径和设备读取。通过keymaps理解按键映射,并探讨了ir模块的整体框架,强调了ir作为input子系统的一部分。文章还提到了编译配置的步骤,如在make menuconfig中选择编码方式和驱动设备。同时,提供了测试代码和查看IR设备的命令,以及相关参考资料。
摘要由CSDN通过智能技术生成

ir(infrared remote)红外协议协议主要有REC、RC5/RC6、SONY等。

代码路径:/drivers/media/rc

 

keymaps是一些rc_map_table的按键映射,每个遥控器都不一样。

 

ir模块整体框架如下

 

进行设备读取信息操作时,对象是/dev/input/eventX,原因是ir属于input子系统。

 

编译配置

make menuconfig

选择如下,选择编码方式和具体的驱动设备。

 

 

event事件结构如下

struct input_event {  
    struct timeval time;  
    __u16 type;  
    __u16 code;  
    __s32 value;  
};
 

测试代码如下

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <linux/rtc.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <linux/input.h>  

#define DEVICE_NAME "Power Button"

/* get the path of the input device */
int get_event_num(char *path_name)
{
	char dev_name[32];
	char path[32];
	int i, fd;

	for (i = 0; i < 32; i++) {
		sprintf(path, "/dev/input/event%d", i);
		if ((fd = open(path, O_RDONLY, 0)) >= 0) {
			ioctl(fd, EVIOCGNAME(sizeof(dev_name)), dev_name);
			printf("dev_name is %s\n", dev_name);
			printf("path is %s\n", path);
		}
		if (strcmp(dev_name, DEVICE_NAME) == 0) {
			printf("find device\n");
			strcpy(path_name, path);
			break;
		}
	}
	close(fd);

	return 0;
}

/* Get key events of input device */
int keyscan(char *path)
{  
	int ret = -1;
	int i = 0; 
	int key_fd = -1;
	struct input_event key_event  = {0};

	key_fd = open(path, O_RDONLY);
	if(key_fd < 0)
	{  
		printf("---open device error!---\n");
		return -1;
	}
	printf("---open device success!---\n");
	
	while(1)
	{
		ret = lseek(key_fd, 0, SEEK_SET);
		ret = read(key_fd, &key_event, sizeof(key_event));
		
		if(ret) {
			if(key_event.type == EV_KEY  && (key_event.value == 0 || key_event.value == 1)) {
				printf("key %d %s\n", key_event.code, (key_event.value) ? "pressed" : "released");
				if(key_event.code == KEY_ESC)
					break;
			}
		}
	}
	close(key_fd);
	return ret;
}
 
int main(int arg, char *arc[])  
{
	printf("---This is a key event test!---\n");
	char path[32];
	get_event_num(path);
	keyscan(path);
	printf("---end!---\n");
	
	return 0;
}
 

查看具体的ir设备命令如下

cat /proc/bus/input/devices

安卓命令

dumpsys input

显示和input相关的设备,ir是挂在input下面的。

 

参考:

https://blog.csdn.net/lanmanck/article/details/8423669

https://blog.csdn.net/piaomiaoju/article/details/35288273

https://blog.csdn.net/cpongo3/article/details/93996024

https://www.cnblogs.com/yangwindsor/articles/3454955.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值