Denon RC-1146 remote with LibreELEC 9

In LibreELEC 9, the IR driver was changed from lircd to in-kernel decoding with ir-keytable.

I'm still using the GPIO IR receiver from this tutorial on my Raspberry Pi.

To activate it, I need to add a dtoverlay.

# mount -o remount,rw /flash
# echo dtoverlay=gpio-ir >> /flash/config.txt
# mount -o remount,ro /flash

I then proceeded along this tutorial.

# systemctl stop kodi
# systemctl stop eventlircd

I get from ir-keytable:

# ir-keytable
Found /sys/class/rc/rc0/ (/dev/input/event2) with:
 Name: gpio_ir_recv
 Driver: gpio_ir_recv, table: rc-rc6-mce
 lirc device: /dev/lirc0
 Supported protocols: other lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp
 Enabled protocols: lirc nec rc-6
 bus: 25, vendor/product: 0001:0001, version: 0x0100
 Repeat delay = 500 ms, repeat period = 125 ms

After some trial and error with different protocols, I finally found:

# ir-keytable --protocol sharp --test
Protocols changed to sharp
Testing events. Please, press CTRL-C to abort.
1009.423304: lirc protocol(sharp): scancode = 0x8ac
1009.423341: event type EV_MSC(0x04): scancode = 0x8ac
1009.423341: event type EV_SYN(0x00).

As with all things Linux, documentation is notoriously difficult to come by. According to ir-keytable --version, LibreELEC-9.0.1 uses v4l-utils-1.14.2. This is an important detail since v4l-utils have since changed their keytable format to toml!

I could not find any documentation for the old keytable format, so I had a look at the source code of keytable.c.

Apparently, a # in the first line can be followed by table and type keywords specifying the name of the table and what is otherwise known as the protocol, separated by various combinations of whitespace, equal signs, colons and commas. Otherwise, lines beginning with # are ignored. The remaining lines may start with an optional keyword "scancode", followed by whitespace, equals sign or colon. This is followed by the scancode (in a format understood by strtoul(3)) and terminated by whitespace, equals sign or colon. Finally, there should be a keycode terminated by whitespace, equals sign, colon or an open parenthesis(!). The keycodes can be ones listed by irrecord --list or, better yet, ones from the devinput section of /usr/share/kodi/system/Lircmap.xml to make sure they are assigned the desired function in Kodi, or in a format suitable for strtol(3). The rest of the line is ignored and can thus be used for comments.

Since Kodi is connected to the DVD input of my amp, I used the remote's default DVD profile. Eventually, I ended up with the following /storage/.config/rc_keymaps/denon1146dvd:

# table denon1146dvd, type: sharp
0x6c0 KEY_POWER
0x881 KEY_0
0x882 KEY_1
0x883 KEY_2
0x884 KEY_3
0x885 KEY_4
0x886 KEY_5
0x887 KEY_6
0x888 KEY_7
0x889 KEY_8
0x88a KEY_9
0x88c KEY_SUBTITLE 10+
0x891 KEY_INFO menu
0x892 KEY_BACK
0x898 KEY_NEXT
0x899 KEY_PREVIOUS
0x89a KEY_FASTFORWARD
0x89b KEY_REWIND
0x89d KEY_PAUSE
0x8a0 KEY_PLAY
0x8a1 KEY_STOP
0x8ac KEY_UP
0x8ad KEY_DOWN
0x8ae KEY_RIGHT
0x8af KEY_LEFT
0x8bb KEY_ENTER
0x8bc KEY_EPG search
0x8bd KEY_MENU top menu

The non-obvious assigments are: the key labelled »menu« on the remote sends a KEY_INFO code since that seems to be the most useful code in Kodi (file info or playing info, respectively). The »top menu« key sends KEY_MENU which takes you to Kodi's main menu and toggles the play menu. I assigned KEY_EPG to the »search« key since KEY_EPG invokes the context menu in the menu and the decoder info while playing. Finally, I cheekily remapped the »10+« key to KEY_SUBTITLE since the former seems to be unused and I use the latter a lot.

Last, I activated it like this:

# echo '* * denon1146dvd' >> /storage/.config/rc_maps.cfg