Toybrick EN

中文 / EN
Toybrick EN Wiki TB-RK3399ProD How to support an IR remote controller
How to support an IR remote controller

      The are a number of protocols for consumer infrared, likes RC5, SIRCS, Sy, RECS80, Denon, NEC, Motorola, Japanese, SAMSWNG  and Daewoo. We only support NEC protocol in our Rockchip platform which is most widely used in Mainland China market.

1.png

How does it work

The PWM module of Rockchip can be configured into three modes for measuring input waveform, reference, one shot and continueous mode. We use the reference mode for the IR remote controller. After the PWM module measure the last time of the input waveform, it would issue an interrupt to the CPU.

1.png


For the IR remote controller, it would send a sequence signals to the IR receiver which is connected to a PWM module in our board. We can parse signals based on the interrupt of PWM. Here is a sample of NEC protocol.

1.png

1.png

A sample configure of the device tree

  1. &pwm3 {
        status = "okay";
    pinctrl-names = "default";
        interrupts = <GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH 0>;
        compatible = "rockchip,remotectl-pwm";
        remote_pwm_id = <3>;
        handle_cpu_id = <1>;
        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 =
               <0xf9  KEY_HOME>,
               <0xbf  KEY_BACK>,
               <0xfb  KEY_MENU>,
               <0xaa  KEY_REPLY>,
               <0xb9  KEY_UP>,
               <0xe9  KEY_DOWN>,
               <0xb8  KEY_LEFT>,
               <0xea  KEY_RIGHT>,
               <0xeb  KEY_VOLUMEDOWN>,
               <0xef  KEY_VOLUMEUP>,
               <0xf7  KEY_MUTE>,
               <0xe7  KEY_POWER>,
               <0xfc  KEY_POWER>,
               <0xa9  KEY_VOLUMEDOWN>,
               <0xa8  KEY_VOLUMEDOWN>,
               <0xe0  KEY_VOLUMEDOWN>,
               <0xa5  KEY_VOLUMEDOWN>,
               <0xab  183>,
               <0xb7  388>,
               <0xe8  388>,
               <0xf8  184>,
               <0xaf  185>,
               <0xed  KEY_VOLUMEDOWN>,
               <0xee  186>,
               <0xb3  KEY_VOLUMEDOWN>,
               <0xf1  KEY_VOLUMEDOWN>,
               <0xf2  KEY_VOLUMEDOWN>,
               <0xf3  KEY_SEARCH>,
               <0xb4  KEY_VOLUMEDOWN>,
               <0xbe  KEY_SEARCH>;
        };
        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>;
        };
    };

You can find standard key value table at include/dt-bindings/input/input.h of Linux kernel.

The path of the drive file

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

How to add support for a new remote controller and debug

1. How to get a IR key of a button

Enable the debug info at kernel
echo 1 > /sys/module/rockchip_pwm_remotectl/parameters/code_print

Then press a button at your remote controller, when the receiver received that signal, you can see a message from kernel log
[19634.735833] GET USERCODE=0x4040
[19634.762463] RMC_GETDATA=e9

We should know the usercode of that remote controller is 0x4040 and the button you just press is 0xe9.

Following the procedure above, you can configure all the buttons in a controller.

2. When the kernel can't report an available value
You may need to read the driver, adjust the condition of the key value detection from PWM input.

3、Nothing is wrong at kernel but your application still won't work

Maybe it is not the fault of the kernel, we have a way to check whether userspace can receive the input event from the kernel. Using getevent command, we would know all the input events from kernel.

If you got the correct key value from kernel without missing, I could sure you should blame the Android.

  1. shell@rk3399:/ # getevent
     add device 1: /dev/input/event0
     name: "ff680000.pwm"
     /dev/input/event0: 0001 006c 00000001
     /dev/input/event0: 0000 0000 00000000
     /dev/input/event0: 0001 006c 00000000
     /dev/input/event0: 0000 0000 00000000

The above message shows that we receive a key event while its key value is 0x6c here. 00000001 for pressed and 00000000 for its released.




Products Store Community Wiki Download About TB


To Top