RK3568平台 (input篇)IR红外遥控器

一.IR红外原理研究

遥控器的基带通信协议很多,大概有几十种,常用的就有 ITT 协议、NEC 协议、Sharp 协议、Philips RC-5 协议、Sony SIRC 协议等,用的最多的就是 NEC 协议了。

 一个完整的IR波形,它主要由5个部分组成:

前导码(Head Code)+ 客户码(Customer Code)+ 客户反码 + 数位码(Data Code) + 数位反码。

二.RK 平台上红外实现原理简介

PWM 有三种工作模式, reference mode, one-shot mode 和 continuousmode. 红外遥控器就采用 reference mode,这种模式下 PWM 可以捕获输入高低电平的宽度,并产生中断,CPU接收到中断后去相应的寄存器读取。
按下遥控的时候,红外接收头会产生一系列的高低电平,PWM 就会产生相应的中断,CPU 读取相应的寄存器就知道这些高低电平的时间,根据协议就可以解码出红外的用户码和键值码出来。

三.硬件原理图

 从硬件原理图可知,RK3568上的红外接的是pwm3.

三.代码调试

path:kernel/drivers/input/remotectl/rockchip_pwm_remotectl.c

static int rk_remote_print_code = 1;

设备树修改:

&pwm3 {
	compatible = "rockchip,remotectl-pwm";
	pinctrl-names = "default";
	pinctrl-0 = <&pwm3_pins>;
	remote_pwm_id = <3>;
	handle_cpu_id = <1>;
	remote_support_psci = <0>;
	status = "okay";

	ir_key1 {
		rockchip,usercode = <0x4040>;
		rockchip,key_table =
			<0xf2	KEY_REPLY>,
			<0xba	KEY_BACK>,
			<0xf4	KEY_UP>,
			<0xf1	KEY_DOWN>,
			<0xef	KEY_LEFT>,
			<0xee	KEY_RIGHT>,
			<0xbd	KEY_HOME>,
			<0xea	KEY_VOLUMEUP>,
			<0xe3	KEY_VOLUMEDOWN>,
			<0xe2	KEY_SEARCH>,
			<0xb2	KEY_POWER>,
			<0xbc	KEY_MUTE>,
			<0xec	KEY_MENU>,
			<0xbf	0x190>,
			<0xe0	0x191>,
			<0xe1	0x192>,
			<0xe9	183>,
			<0xe6	248>,
			<0xe8	185>,
			<0xe7	186>,
			<0xf0	388>,
			<0xbe	0x175>;
	};

	ir_key2 {
		rockchip,usercode = <0xff00>;
		rockchip,key_table =
			<0xef	KEY_1>,
			<0xee	KEY_2>,
			<0xed	KEY_3>,
			<0xeb	KEY_4>,
			<0xea	KEY_5>,
			<0xe9	KEY_6>,
			<0xe7	KEY_7>,
			<0xe6	KEY_8>,
			<0xe5	KEY_9>,
			<0xf2	KEY_0>,
			<0xfd	KEY_BACKSPACE>,
			<0xfe	KEY_UP>,
			<0xfb	KEY_LEFT>,
			<0xf9	KEY_RIGHT>,
			<0xf6	KEY_DOWN>,
			<0xfa	KEY_SPACE>,
			<0xff	KEY_POWER>,
			<0xf7	KEY_VOLUMEUP>,
			<0xf5	KEY_VOLUMEDOWN>,
			<0xf1	KEY_MENU>;
	};

	ir_key3 {
		rockchip,usercode = <0x1dcc>;
		rockchip,key_table =
			<0xee	KEY_REPLY>,
			<0xf0	KEY_BACK>,
			<0xf8	KEY_UP>,
			<0xbb	KEY_DOWN>,
			<0xef	KEY_LEFT>,
			<0xed	KEY_RIGHT>,
			<0xfc	KEY_HOME>,
			<0xf1	KEY_VOLUMEUP>,
			<0xfd	KEY_VOLUMEDOWN>,
			<0xb7	KEY_SEARCH>,
			<0xff	KEY_POWER>,
			<0xf3	KEY_MUTE>,
			<0xbf	KEY_MENU>,
			<0xf9	0x191>,
			<0xf5	0x192>,
			<0xb3	388>,
			<0xbe	KEY_1>,
			<0xba	KEY_2>,
			<0xb2	KEY_3>,
			<0xbd	KEY_4>,
			<0xf9	KEY_5>,
			<0xb1	KEY_6>,
			<0xfc	KEY_7>,
			<0xf8	KEY_8>,
			<0xb0	KEY_9>,
			<0xb6	KEY_0>,
			<0xb5	KEY_BACKSPACE>;
	};
};

通过红外遥控查看log打印:

 通过log得知:接的是pwm3的ir_key2。

getevent 调试命令,该命令会打印出驱动上报的所有 input 事件,如果按遥控器有打印,并且键值正确。

root@RK356X:/home/tsh/bin# ./getevent -l
add device 1: /dev/input/event2
  name:     "TSH virtual input driver"
could not open /dev/input/by-path, Is a directory
add device 2: /dev/input/event1
  name:     "adc-keys"
add device 3: /dev/input/event0
  name:     "fdd70030.pwm"
/dev/input/event2: EV_KEY       KEY_RIGHT            DOWN
/dev/input/event2: EV_SYN       SYN_REPORT           00000000
/dev/input/event2: EV_KEY       KEY_RIGHT            UP
/dev/input/event2: EV_SYN       SYN_REPORT           00000000
/dev/input/event2: EV_KEY       KEY_RIGHT            DOWN
/dev/input/event2: EV_SYN       SYN_REPORT           00000000
/dev/input/event2: EV_KEY       KEY_RIGHT            UP
/dev/input/event2: EV_SYN       SYN_REPORT           00000000
/dev/input/event2: EV_KEY       KEY_LEFT             DOWN
/dev/input/event2: EV_SYN       SYN_REPORT           00000000
/dev/input/event2: EV_KEY       KEY_LEFT             UP
/dev/input/event2: EV_SYN       SYN_REPORT           00000000
/dev/input/event2: EV_KEY       KEY_0                DOWN
/dev/input/event2: EV_SYN       SYN_REPORT           00000000

如果没有getevent到事件,无键值上报,adb执行cat proc/interrupts可以查看中断interrupt的注册使用情况。

rk356x:/ # cat proc/interrupts
           CPU0       CPU1       CPU2       CPU3       
 16:          0          0          0          0       GIC  29 Edge      arch_timer
 17:     118303      97092      81417     115531       GIC  30 Edge      arch_timer
 20:          0          0          0          0       GIC  98 Level     rk_timer
 25:          0          0          0          0       GIC  34 Level     ff250000.dma-controller
 26:          0          0          0          0       GIC  35 Level     ff250000.dma-controller
 27:        367          0          0          0       GIC  32 Level     ff600000.dma-controller
 28:          0          0          0          0       GIC  33 Level     ff600000.dma-controller
 29:          0          0          0          0       GIC  64 Level     dw-mci
 30:      14838          0          0          0       GIC  65 Level     dw-mci
 31:      34851          0          0          0       GIC  67 Level     dw-mci
 32:       4565          0          0          0       GIC  68 Level     ff100000.saradc
 33:        747          0          0          0       GIC  92 Level     ff650000.i2c
 34:          0          0          0          0       GIC  94 Level     ff140000.i2c
 35:        153          0          0          0       GIC  95 Level     ff150000.i2c
 37:          0          0          0          0       GIC  69 Level     rockchip_thermal
 38:       4352          0          0          0       GIC  59 Level     eth0
 39:          0          0          0          0       GIC  60 Level     eth0
 40:          0          0          0          0       GIC  56 Level     ehci_hcd:usb2
 41:          0          0          0          0       GIC  73 Level     ohci_hcd:usb3
 42:        151          0          0          0       GIC  57 Level     ff540000.usb, dwc2_hsotg:usb1
 43:        489          0          0          0       GIC  55 Level     dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb4
 44:         24          0          0          0       GIC  93 Level     ff660000.i2c
 45:          0          1          0          0       GIC 110 Level     rk_pwm_irq

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式_笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值