ROC-RK3328-CC Buy Specs

Firefly first ultra-small open-source main board, unique USB3.0 and DDR4 to make its performance faster and more stable. The ultra-affordable ROC-RK3328-CC is your first choice for exploring the programming world.

IR

Update time:2018-04-13 Views:3176

IR Configuration

The ROC-RK3328-CC 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::

kernel/arch/arm64/boot/dts/rk3328-roc-cc-port.dtsi
    drivers/input/remotectl/rockchip_pwm_remotectl.c

Define Data Structure

Do as follows:

Add a array as follow:

&pwm3 {
	status = "okay";
	compatible = "rockchip,remotectl-pwm";
	remote_pwm_id = <3>;
	handle_cpu_id = <1>;
	remote_support_psci = <1> ;
        ir_key{    
                rockchip,usercode = <0xff00>;
                rockchip,key_table =
                            <0xeb   KEY_POWER>,
                            <0xec   KEY_MENU>,
                            <0xfe   KEY_BACK>,
                            <0xb7   KEY_HOME>,
                            <0xa3   KEY_WWW>,
                            <0xf4   KEY_VOLUMEUP>,
                            <0xa7   KEY_VOLUMEDOWN>,
                            <0xf8   KEY_REPLY>,
                            <0xfc   KEY_UP>,
                            <0xfd   KEY_DOWN>,
                            <0xf1   KEY_LEFT>,
                            <0xe5   KEY_RIGHT>;
         };
  };

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

   case RMC_USERCODE: {
                    if ((RK_PWM_TIME_BIT1_MIN < ddata->period) &&(ddata->period < RK_PWM_TIME_BIT1_MAX))
                            ddata->scandata |= (0x01 << ddata->count);
                        ddata->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;
                            }
                        }
                    }

The following command can be used to make the DBG_CODE print:

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:

config ROCKCHIP_REMOTECTL_PWM
    bool "rockchip remoctrl pwm capture"
default n

(2) 、Edit drivers/input/remotectl/Makefile. Add object file as following:

obj-$(CONFIG_ROCKCHIP_REMOTECTL_PWM)   += rockchip_pwm_remotectl.o

(3)、Use make menuconfig, and select in the IR support:

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

After saving, compiling and writing the kernel IMG file.

Android Key Remapping

/system/usr/keylayout/ff680030_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

IR use

As shown below, the waveform generated by the button of infrared remote control is mainly composed of four parts, head, Control, information and signed free, which can refer to RC6 Protocol.

Rk3399 ir 1.png