Add support for a new IR remote controller

May I add my question to this forum topic, if it is not allowed please move it to separate topic.

How to find out which remote protocol does IR remote controller supports?

I got Khadas VIM Pro yesterday and i updated it to Android 7.1.1 . Here I have an unused QNAP IR (RM-IR002) which I would like to use. I see when looking trough Smartphone camera that remote is working (i see light when pressing buttons). But on Khadas VIM nothing is moving.

2 Likes

Are you a developer ?
If you are a developer, I will release the docs about how to add the support for a new IR.

No i am not developer. I don’t even know if this QNAP IR do speak NEC protocol. But maybe I can compile own ROM, but need to prepare ENV.

1 Like

You can follow this to build your rom and I will release the docs about how to add the support for a new IR tomorrow

Please follow below steps to add support for a new IR

###Steps

###1. Add the debug informations

Modify the file ‘PROJECT/common/drivers/amlogic/input/remote/remote_meson.c’

@@ -147,6 +147,7 @@ static u32 getkeycode(struct remote_dev *dev, u32 scancode)
                pr_err("cur_custom is nulll\n");
                return KEY_RESERVED;
        }
+       printk("%s,scancode=0x%04x\n",__func__, scancode);
        index = ir_lookup_by_scancode(&ct->tab, scancode);
        if (index < 0) {
                remote_printk(2, "scancode %d undefined\n", scancode);
@@ -163,6 +164,7 @@ static bool is_valid_custom(struct remote_dev *dev)
                return true;
        custom_code = chip->ir_contr[chip->ir_work].get_custom_code(chip);
        chip->cur_tab = seek_map_tab(chip, custom_code);
+       printk("%s,custom_code=0x%04x\n",__func__, custom_code);
        if (chip->cur_tab) {
                dev->keyup_delay = chip->cur_tab->tab.release_delay;
                return true;

after do that, you need to rebuild the kernel and reflash the image

###2. Get the custom code from printing log
The list of custom code in system:
<1> 0xfb04
<2> 0xfe01
<3> 0xbd02
<4> 0xff00

  1. If your custom code isn’t included , the printing log only one line when you click your IR
eg:  
is_valid_custom,custom_code=0xfc02

You need to add the custom code to the file ‘PROJECT/common/arch/arm64/boot/dts/amlogic/mesongxl.dtsi’

        custom_maps:custom_maps {
-               mapnum = <4>;
+               mapnum = <5>;
                map0 = <&map_0>;
                map1 = <&map_1>;
                map2 = <&map_2>;
                map3 = <&map_3>;
+               map4 = <&map_4>;
                map_0: map_0{
                        mapname = "amlogic-remote-1";
                        customcode = <0xfb04>;
@@ -852,6 +853,13 @@
                                REMOTE_KEY(0x01,158)
                                REMOTE_KEY(0x48,102)>;
                };
+               map_4: map_4{
+                       mapname = "amlogic-remote-5";
+                       customcode = <0xfc02>;
+                       release_delay = <80>;
+                       size  = <0>;
+                       keymap = <>;
+               }
        };

After do that, you need to rebuild the kernel and reflash the image
Now the printing log has two lines when you click your IR
eg:
is_valid_custom,custom_code=0xfc02
getkeycode,scancode=0x0009

Record the scancode of each key when you click your IR.

  1. If your custom code is included , the printing log has two lines when you click your IR
    eg:
    is_valid_custom,custom_code=0xff00
    getkeycode,scancode=0x0009

Record the scancode of each key when you click your IR.

###3. The list of Android Map Key

key 399   GRAVE
key 1     BACK
key 2     1
key 3     2
key 4     3
key 5     4
key 6     5
key 7     6
key 8     7
key 9     8
key 10    9
key 11    0
key 15    BACK
key 158   BACK
key 58    SOFT_RIGHT
key 107   ENDCALL
key 62    ENDCALL
key 139    MENU
key 125    MENU
key 60    NOTIFICATION
key 127   SEARCH
key 217   SEARCH
key 228   POUND
key 227   STAR
key 231   CALL
key 61    CALL
key 97    DPAD_CENTER
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 104   VOLUME_UP
key 109   VOLUME_DOWN
key 212   CAMERA

key 16    Q
key 17    W
key 18    E
key 19    R
key 20    T
key 21    Y
key 22    U
key 23    I
key 24    O
key 25    P
key 26    LEFT_BRACKET
key 27    RIGHT_BRACKET
key 43    BACKSLASH

key 30    A
key 31    S
key 32    D
key 33    F
key 34    G
key 35    H
key 36    J
key 37    K
key 38    L
key 39    SEMICOLON
key 40    APOSTROPHE
key 14    DEL

key 44    Z
key 45    X
key 46    C
key 47    V
key 48    B
key 49    N
key 50    M
key 51    COMMA
key 52    PERIOD
key 53    SLASH
key 28    ENTER

key 75		F3
key 76		F4
key 77		F5
key 64		F6
key 65		F7
key 66		F8
key 67		F9
key 68		F10
key 69		F11

key 56    ALT_LEFT
key 100   ALT_RIGHT
key 42    SHIFT_LEFT
key 54    SHIFT_RIGHT
#key 15    TAB
key 57    SPACE
key 70    EXPLORER
key 155   ENVELOPE

key 12    MINUS
key 13    EQUALS
key 215   AT
key 119   MEDIA_PLAY_PAUSE
key 122   MEDIA_PREVIOUS
key 123   MEDIA_NEXT
key 120   MEDIA_FAST_FORWARD
key 121   MEDIA_REWIND
key 116   POWER
#key 116   POWER	WAKE
key 113   VOLUME_MUTE
key 128   MEDIA_STOP
key 130   ZOOM_IN
key 131   ZOOM_OUT
#key 133   NETFLIX
key 140   F10
#key 132   TV_REPEAT
#key 134   TV_SHORTCUTKEY_DISPAYMODE
#key 135   TV_SUBTITLE
#key 136   TV_SHORTCUTKEY_VOICEMODE
#key 137   TV_SWITCH

###4. Map the IR key of your

If you need to map one key of your IR as VOLUME_UP(the Map Key is 115, you can verify the list of Android Map Key)
Modify the file ‘PROJECT/common/arch/arm64/boot/dts/amlogic/mesongxl.dtsi’

@@ -857,8 +857,8 @@
                        mapname = "amlogic-remote-5";
                        customcode = <0xfc02>;
                        release_delay = <80>;
-                       size  = <0>;
-                       keymap = <>;
+                       size  = <1>;
+                       keymap = <REMOTE_KEY(0x09,115)>;
                }
        };

About REMOTE_KEY(0x09,115):
The 0x09 is the scancode of key
The 115 is the map key of Android

####Notice:

  • It is only for Nougat.
  • The PROJECT is the path of your project.
  • I’m very sorry for my bad english
1 Like

Thanks Terry,

After ordering my Khadas VIM yesterday I was wondering about IR.

Now it will be fine.

@Terry thank you for the steps how this can be achieved.

But will this be also included in official Rom?

I don’t know the IR scancode of user , It need the user to build the rom by himself
It isn’t included in official Rom.
Thanks.

But can at least the new ROM have option from steps 1) and 2), so an user can provide you scancode for each key and then provided to you so you can include it in next build?

  1. and 2)
    where the record of scancode can be captured? Is it written in log file (which)?

The type of IR is different for each of user , It is too hard to support the all IR .
I’m sorry for it, please understanding.

You need to type below command on Terminal

$ adb connect  IP
$ adb shell 
$ dmesg 

Notice:

  1. The IP is the ip addr of Vim
  2. Before type the ‘dmesg’ , You need to click your IR

Thanks!

But the debug code have nothing to do with remote, if you include these debug code in the official ROM then everyone can contribute his scancode. Right now even ti get scancode one need ti compile his own ROM and flash.

@Terry and all:
I git clone kernel source code form khadas github , and modify this file: arch/arm64/boot/dts/amlogic/mesongxl.dtsi, my question is how can I compile for this modify???

I have try :1. make clean ARCH=arm64 && make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- , but it cannot compiled mesongxl.dtsi(I add some error in this file)
2. run this command: make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- kvim.dtb , it can generate arch/arm64/boot/dts/amlogic/kvim.dtb, but I have no idea about how to package it to kernel image(Image)

What kind of system do you want to test? Ubuntu or Andoird7.1?
You can download the kvim.dtb to your device Load Images with U-Boot via TFTP

Hi @Terry:
It works!
I try it with ubuntu mate
But I wondering if there have any method to package it to kernel image? because this is only for debug mode, thanks!

It hasn’t the method to pack dtb to kernel image because the dtb and kernel is two different partitions. But you can pack the dtb and kernel into final update image.

Hi @Terry:
beacuse dts file is in kernel path, I used to think it would be package into kernel image.
But how can I do this? and I have no ubuntu source code for khadas vim.

About How to build and pack Ubuntu image,you can refer to the post

@Terry help me add wake up key in uboot .
My remote : factory_code = 0xef10 , and scancode power key = 0x5d

define CONFIG_IR_REMOTE_POWER_UP_KEY_VAL1 0XEB14FF00

here will change this value 0xeb5def10 ? , how to make it work?

Firstly, You need to know the 16bit scancode and not 8bit.
What’s the version of your system? Nougat or Mmallow?

  • On Nougat:
    You need to remove your Remote configs in mesongxm.dts(VIM2) or mesongxl.dts(VIM)file.
  • On Mmallow
    You need to remove your Remote configs in remote.conf file

Now, you can see the kernel log when you click your Remote power key.

kvim2:/ $ [  379.901297@1] meson-remote c8100580.rc: invalid custom:0xeb14ff00

Example:

khadas IR power key: factory_code = 0xFF00, scancode = 0xEB14
#define CONFIG_IR_REMOTE_POWER_UP_KEY_VAL1 0XEB14FF00

2 Likes

Hey I know this is not really related but your post was the best I found to fix my problem. I have a dtb file that I decompiled so I can add my remote and then recompile but I need to know the result of the macro REMOTE_KEY because it doesnt let me compile when I have “keymap = <REMOTE_KEY(0x18,116)>;” I think I need the actual hex value. Can you help me?