Solved Adafruit PiGRRL2 keyboard not recognized
#1
Hi guys

I bought and built an Adafruit PiGRRL2. This emulator enclosure runs a retropie 4.0 beta2 over a raspbian Jessie. I actually took retropie latest image.

Code:
pi@retropie ~ $ uname -a
Linux retropie 4.4.15-v7+ #897 SMP Tue Jul 12 18:42:55 BST 2016 armv7l GNU/Linux

Everything works fine from a game emulation point of view.

Then, I installed kodi 16.1 with retropie built in installer. I had some issue to setup the small 2.8" lcd display but I finally succeeded.

Unfortunately I am now stuck with the keyboard. Of course I'd like to use the builtin "joypad" (which is actually a virtual keyboard) but it seems it is not recognized by Kodi.

This joypad offers 16 keys (up, down, left, right, start, select, A, B, X, Y and a few others). It is connected to the Rpi2 via GPIO. To be usable someone at Adafruit wrote a C program to make it recognized as a virtual keyboard using uevent. Basically this utility maps gpio connected buttons to keyboard event.

Interesting part of retrogame.c:
Code:
ioStandard[] = {
        // This pin/key table is used when the PiTFT isn't found
        // (using HDMI or composite instead), as with our original
        // retro gaming guide.
        // Input   Output (from /usr/include/linux/input.h)
        { 4,  KEY_LEFT     }, // Joystick (4 pins)
        { 19, KEY_RIGHT    },
        { 16, KEY_UP       },
        { 26, KEY_DOWN     },
        { 15, KEY_LEFTCTRL }, // A/Fire/jump/primary/RED
        { 14, KEY_LEFTALT  }, // B/Bomb/secondary/YELLOW
        { 20, KEY_LEFTSHIFT}, // X/BLUE
        { 18, KEY_W        }, // Y/GREEN
        {  5, KEY_RIGHTCTRL}, // Select
        {  6, KEY_ENTER    }, // Start
        { 12, KEY_A        }, // L Shoulder
        { 13, KEY_S        }, // R Shoulder
        { 17, KEY_ESC      }, // Exit ROM PiTFT Button 1
        { 22, KEY_KP5      }, // PiTFT Button 2
        { 23, KEY_KPMINUS  }, // PiTFT Button 3
        { 27, KEY_F12      }, // PiTFT Button 4
        // For credit/start/etc., use USB keyboard or add more buttons.
        {  -1,     -1           } }; // END OF LIST, DO NOT CHANGE

Here is what I get when I do a "cat /proc/bus/input/devices":
Code:
I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="stmpe-ts"
P: Phys=stmpe-ts/input0
S: Sysfs=/devices/platform/soc/3f204000.spi/spi_master/spi0/spi0.1/stmpe-ts/input/input0
U: Uniq=
H: Handlers=mouse0 event0
B: PROP=0
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=1000003

I: Bus=0003 Vendor=04d9 Product=2519 Version=0110
N: Name="2.4G Wireless Touchpad Keyboard"
P: Phys=usb-3f980000.usb-1.4/input0
S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:04D9:2519.0001/input/input2
U: Uniq=
H: Handlers=sysrq kbd leds event2
B: PROP=0
B: EV=120013
B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7

I: Bus=0003 Vendor=04d9 Product=2519 Version=0110
N: Name="2.4G Wireless Touchpad Keyboard"
P: Phys=usb-3f980000.usb-1.4/input1
S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.1/0003:04D9:2519.0002/input/input3
U: Uniq=
H: Handlers=kbd mouse1 event3
B: PROP=0
B: EV=1f
B: KEY=3f 3007f 0 0 0 0 483ffff 17aff32d bf544446 0 0 1f0001 130f93 8b17c000 677bfa d941dfed 9ed680 4400 0 10000002
B: REL=1c3
B: ABS=1 0
B: MSC=10

I: Bus=0003 Vendor=0001 Product=0001 Version=0001
N: Name="retrogame"
P: Phys=
S: Sysfs=/devices/virtual/input/input5
U: Uniq=
H: Handlers=kbd event1
B: PROP=0
B: EV=3
B: KEY=1682 1001400 1000400 f0020002

Bloc #1 is the not-used touch screen.
Bloc #2 and #3 are a wireless usb keyboard and mouse
Bloc #4 is the device joypad which is causing trouble

Listing my /dev/input:
Code:
pi@retropie ~/ $ ll /dev/input/
total 0
drwxr-xr-x 2 root root     100 Jul 20 02:17 by-id
drwxr-xr-x 2 root root     120 Jul 20 02:17 by-path
crw-rw---- 1 root input 13, 64 Jul 20 02:11 event0
crw-rw---- 1 root input 13, 65 Jul 20 02:29 event1
crw-rw---- 1 root input 13, 66 Jul 20 02:17 event2
crw-rw---- 1 root input 13, 67 Jul 20 02:17 event3
crw-rw---- 1 root input 13, 63 Jul 20 02:11 mice
crw-rw---- 1 root input 13, 32 Jul 20 02:11 mouse0
crw-rw---- 1 root input 13, 33 Jul 20 02:17 mouse1

and after a "dmesg":
Code:
[ 1127.158690] input: retrogame as /devices/virtual/input/input5

Kernel modules:
Code:
Module                  Size  Used by
cfg80211              427855  0
rfkill                 16037  1 cfg80211
evdev                  11396  8
joydev                  9024  0
stmpe_ts                3929  0
snd_bcm2835            20511  0
snd_pcm                75698  1 snd_bcm2835
snd_timer              19160  1 snd_pcm
snd                    51844  3 snd_bcm2835,snd_timer,snd_pcm
bcm2835_wdt             3225  0
gpio_backlight          2427  0
bcm2835_gpiomem         3040  0
spi_bcm2835             6678  0
uio_pdrv_genirq         3164  0
uio                     8000  1 uio_pdrv_genirq
fb_ili9340              3204  1
fbtft                  26084  1 fb_ili9340
syscopyarea             2945  1 fbtft
sysfillrect             3443  1 fbtft
sysimgblt               2069  1 fbtft
fb_sys_fops             1309  1 fbtft
i2c_dev                 5859  0
uinput                  7454  1
fuse                   83461  1
ipv6                  347530  36
+

I then went to Kodi wiki to try to figure out how to make my joypad seen by Kodi. I read a lot about keymaps, keyboard.xml and so on... without success.

Anyway, one of the first thing I checked was kodi.log in debug mode.
Kodi startup:
http://pastebin.com/jg0vzt8y

With my wireless keyboard plugged in, I was able to see keycodes received by Kodi. Nothing with the joypad:
Code:
03:30:08 4752.533203 T:1944715840  NOTICE: Log level changed to "LOG_LEVEL_DEBUG_FREEMEM"
03:30:08 4752.533691 T:1944715840  NOTICE: Enabled debug logging due to GUI setting. Level 2.
03:30:08 4752.535645 T:1944715840   DEBUG: ------ Window Init () ------
03:30:11 4755.973633 T:1944715840   DEBUG: Keyboard: scancode: 0x6a, sym: 0x0113, unicode: 0x0000, modifier: 0x0
03:30:11 4755.974121 T:1944715840   DEBUG: OnKey: right (0xf083) pressed, action is Right
03:30:12 4756.935547 T:1944715840   DEBUG: Keyboard: scancode: 0x67, sym: 0x0111, unicode: 0x0000, modifier: 0x0
03:30:12 4756.935547 T:1944715840   DEBUG: OnKey: up (0xf080) pressed, action is Up
03:30:13 4757.434082 T:1944715840   DEBUG: Keyboard: scancode: 0x6c, sym: 0x0112, unicode: 0x0000, modifier: 0x0
03:30:13 4757.434570 T:1944715840   DEBUG: OnKey: down (0xf081) pressed, action is Down
03:30:13 4757.879395 T:1944715840   DEBUG: Keyboard: scancode: 0x69, sym: 0x0114, unicode: 0x0000, modifier: 0x0
03:30:13 4757.880371 T:1944715840   DEBUG: OnKey: left (0xf082) pressed, action is Left

Then, I went to a more basic layer: checking system in console via "showkey":

Wireless keyboard:
Code:
pi@retropie ~/ $ showkey -a
^[[D     24 0033 0x1b
         91 0133 0x5b
         58 0104 0x44
q       113 0161 0x71

PiGRRL2 joypad using retrogame.c:
Code:
pi@retropie ~/ $ showkey -a
^[[D     24 0033 0x1b
         91 0133 0x5b
         58 0104 0x44
q       113 0161 0x71

I forgot to mention that I set a French azerty keyboard layout in both system and Kodi. I use to choose this layout which works fine so far on other systems.

I'm a bit dry now. I hope my (first) post is clear enough and that it would be helpfull. I'd really appreciate. Don't blame me too much if I missed something. Thank you for reading.
Reply
#2
I don't fully understand your system. Does kodi run on top of retropie, or do you have to reboot to get into kodi?
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#3
Sorry for not having been clear enough. Kodi runs on top of Retropie.

Edit:
This actually gave me an idea. I set Kodi to start at boot before EmulationStation (Retropie frontend). No change, still unable to use joypad as input device.
Reply
#4
OK forget about Retropie. To simplify, here is the heart of the problem:
  • I'm using a bunch of tactile switches connected to a Rapsberry Pi 2 through GPIO.
  • To map these switches to legacy keyboard keys I'm using a C program: retrogame.c from Adafruit.
  • This tool, which runs in background, creates a Linux virtual keyboard
  • This virtual keyboard works as expected in a console but not with Kodi
Reply
#5
I don't know a lot about the kodi input subsystem, but:
https://github.com/xbmc/xbmc/blob/master....cpp#L1234

Looks like you need a /dev/input/event* node for an input device to be detected.
If you don't have one of those I don't see it being detected.

So you either need a kernel module that reports your input device as a /dev/input/event* device,
or you need to modify kodi to search for other types of device node.
Reply
#6
Thanx for replying Popcornmix.
I have a /dev/input/event node:
Code:
cat /proc/bus/input/devices
I: Bus=0003 Vendor=0001 Product=0001 Version=0001
N: Name="retrogame"
P: Phys=
S: Sysfs=/devices/virtual/input/input4
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=3
B: KEY=1682 1001400 1000400 f0020002

ls -l /dev/input
total 0
crw-rw---- 1 root input 13, 64 Jul 22 03:04 event0
crw-rw---- 1 root input 13, 63 Jul 22 03:00 mice

and it seems to be detected by Kodi:
Code:
04:15:56 4516.163574 T:1944932928  NOTICE: Found a non joystick : use it as standard kodi input device - /dev/input/event0
...
04:15:56 4516.420410 T:1944932928    INFO: Found input device /dev/input/event0
04:15:56 4516.420410 T:1944932928    INFO: opened device 'retrogame' (file name /dev/input/event0), m_bSkipNonKeyEvents 0
04:15:56 4516.420898 T:1676145584   DEBUG: Thread CLinuxInputDevicesCheckHotplugged start, auto delete: false
So I guess it should work. I likely miss something obvious...
Reply
#7
Open a terminal, hit the buttons, do they show up.
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#8
Yes they do.
Reply
#9
And what characters show up? Do they match what you'd expect for using a keyboard with kodi?
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#10
Yes. For instance if I set the Up key on up arrow, I scroll up in my commands history in a console. If I set the "A" key on a button and I hit this button in a console I get a "A" on the prompt. As far as I can see, it works as expected in a console.
unfortunately, when I do the same in Kodi nothing happens, neither in Kodi gui nor in kodi.log.
Reply
#11
OK I finally resolved my issue.

In retrogame.c, I changed this (line 396):
Code:
// ----------------------------------------------------------------
        // Set up uinput

#if 1
        // Retrogame normally uses /dev/uinput for generating key events.
        // Cupcade requires this and it's the default.  SDL2 (used by
        // some newer emulators) doesn't like it, wants /dev/input/event0
        // instead.  Enable that code by changing to "#if 0" above.

by this:
Code:
// ----------------------------------------------------------------
        // Set up uinput

#if 0
        // Retrogame normally uses /dev/uinput for generating key events.
        // Cupcade requires this and it's the default.  SDL2 (used by
        // some newer emulators) doesn't like it, wants /dev/input/event0
        // instead.  Enable that code by changing to "#if 0" above.
Blush
Thanks for helping.
Reply

Logout Mark Read Team Forum Stats Members Help
Adafruit PiGRRL2 keyboard not recognized0