IR Configuration

The Firefly-RK3399 development board comes with IR sensor (between the USB OTG and headset jack) . This article describes how to use and configure the IR to work properly.

You can do this in two parts:

  1. Modify the IR kernel driver. Works on both Linux and Android, which is low level hacking.

  2. Modify the key mapping if you are using Android, which is user space hacking.

Kernel Driver

The IR driver only supports NEC encode format. Below is the instructions of how to add your IR remote to send the right key code in Linux kernel.There is two file related:


Define Data Structure

Do as follows:Add a array as follow:

&pwm3 {
    status = "okay";
    interrupts = ;
    compatible = "rockchip,remotectl-pwm";
    remote_pwm_id = ;
    handle_cpu_id = ; 
    rockchip,usercode = ;
    rockchip,key_table = {
         {0xeb, KEY_POWER},        // Power
         {0xa3, 250},              // Settings
         {0xec, KEY_MENU},         // Menu
         {0xfc, KEY_UP},           // Up
         {0xfd, KEY_DOWN},         // Down
         {0xf1, KEY_LEFT},         // Left
         {0xe5, KEY_RIGHT},        // Right
         {0xf8, KEY_REPLY},        // Ok
         {0xb7, KEY_HOME},         // Home
         {0xfe, KEY_BACK},         // Back
         // Vol
         {0xa7, KEY_VOLUMEDOWN},   // Vol-
         {0xf4, KEY_VOLUMEUP},     // Vol+
  • Note: interrupts mean interrupts num

  • Note: remote_pwm_id mean select which PWM

  • Note: ir_key1 first is key value ,the second is key code

Get User Code and Key Value

You can get the answer in the remotectl_do_something func:

		if ((RK_PWM_TIME_BIT1_MIN period) &&(ddata->period scandata |= (0x01 count);
        if (ddata->count == 0x10) {
			DBG_CODE("USERCODE=0x%x\n", ddata->scandata);
            if (remotectl_keybd_num_lookup(ddata)) {
				ddata->state = RMC_GETDATA;
				ddata->scandata = 0;
				ddata->count = 0;
             } else {
             		if (rk_remote_print_code){
						ddata->state = RMC_GETDATA;
						ddata->scandata = 0;
						ddata->count = 0;
                        } else ddata->state = RMC_PRELOAD;

Use the following command to enable DBG_CODE printing

echo 1 > /sys/module/rockchip_pwm_remotectl/parameters/code_print

Add the Driver to Kernel

Add the driver to kernel as the following steps:

  1. Make sure the config option is written in the file drivers/input/remotectl/Kconfig, as following:

    bool "rockchip remoctrl pwm capture"
default n
  1. Edit drivers/input/remotectl/Makefile. Add object file as following:

obj-$(CONFIG_ROCKCHIP_REMOTECTL_PWM)+= rockchip_pwm_remotectl.o
  1. Use make menuconfig, and select in the IR support:

Device Drivers
  --->Input device support
  ----->  [*]   rockchip remotectl
  ------->[*]   rockchip remoctrl pwm capture


Android Key Remapping

/system/usr/keylayout/ff420030_pwm.kl is a file mapping scancodes in kernel to keycodes in Android. You can add or modify it to match your IR remote’s keys.You can modify this file via adb and reboot to take effect.

The contents of this file are as follows:

key 28    ENTER
key 116   POWER             WAKE
key 158   BACK
key 139   MENU
key 217   SEARCH
key 232   DPAD_CENTER
key 108   DPAD_DOWN
key 103   DPAD_UP
key 102   HOME
key 105   DPAD_LEFT
key 106   DPAD_RIGHT
key 115   VOLUME_UP
key 114   VOLUME_DOWN
key 143   NOTIFICATION      WAKE
key 113   VOLUME_MUTE
key 64    TV_MEDIA_PLAY
key 65    TV_MEDIA_PAUSE
key 66    TV_MEDIA_STOP

Use the IR

The following figure shows the waveform generated by pressing the infrared remote control button, which is mainly composed of four parts: head, control, information, and signed free. For details, please refer to RC6 Protocol. _images/ir.png