I would like to use hardware keys to control Kodi on OSMC. (up, down, right, left, enter and esc) On Raspbian I can use gpio-keys and an overlay file to create keyboard events. On OSMC the gpio-keys driver is not included in the kernel. I would like to add it. What’s the best way to do it?
Thanks for the fast reply. I have to explain more.
I need the keys to turn the pages when reading a book.
This is what I want:
“Raspbian now uses a device-tree based approach for system setup and a driver called gpio-keys is readily available in its standard kernel.”
I can use the keys in Raspbian using this method. I can’t use this method in OSMC because the gpio-keys driver is not included. I can write my own background program to read the keys and create keyboards events. But I agree with the writer of the blog that’s not the best approach.
“Linux already has drivers for almost all of the common low level peripheral interfaces like I2C, SPI, OneWire, hardware PWM and generic GPIO. It is usually the better approach to use them instead of constantly re-inventing the wheel.”
So I would like to add the gpio-keys driver to OSMC if that is possible. That will be an “easy” way of mapping gpio hardware to keyboard events. I also prefere if the added driver will survive updates of OSMC. The question is how to achieve this. Because it is a generic solution it’s usefull for everybody who wants to use hardware buttons. (I also prefere to change the driver because the Raspbian driver doesn’t use the internal pull-up resistor.)
I would love to do that but this is where I got stuck. I can get osmc from github but that doesn’t include the gpio-keys driver. This is the line in the dts file: compatible = “gpio-keys”; This works in Raspbian and fails in osmc. Can’t find it using google. Can’t find it using find on the raspbian os. Can find a reference https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt.
So now the questions are: Any idea where I can search for the driver and how can I include it in the osmc build?
(Edit: I found “linux / drivers / input / keyboard / gpio_keys.c”. Looks like that’s the code.)
It works perfectly on Raspbian. Got 7 buttons working without any coding and soldering. Would love to have this in osmc/kodi for navigating.
I downloaded the sources and build the osmc package. The gpio_keys sources are present but not included in the build. How can I include them? (Activate the driver?)
It is not possible to enable the internal resistors from gpio_keys. I use the gpio tool that comes with wiringpi to enable the pullup. This issue is solved.
I’m not used to build kernels so I need more info.
This is what I did:
1 - git clone GitHub - osmc/osmc: OSMC (Open Source Media Center) is a free and open source media center distribution
2 - cd osmc/package/kernel-osmc
3 - make rbp1
Now I want to add CONFIG_KEYBOARD_GPIO to the .config.
So after step 2, I edit the rbp1-000-add-kernel-config.patch?
Ignore +# Automatically generated file; DO NOT EDIT.
Insert CONFIG_KEYBOARD_GPIO in the +# Input Device Drivers paragraph.
(I used make menuconfig to create my own .config file and copy and paste the changes into the patch. Added + before each line.)
Got a warning but ignored it.
The .config is changed and the build is now running.
I switched to a rbp2 to increase the build speed.
I edited the rbp2 kernel patch but that didn’t result in a changed .config file. The gpio_keys.c is not compiled. I checked that in the log file. I have no idea why the patch isn’t working so I also have no idea where to look at in the log.
I feel stupid not understanding this. I use this as a guide: Compile Kernel on RPI2 from RBP2-sources-osmc
I use this command to get osmc: git clone GitHub - osmc/osmc: OSMC (Open Source Media Center) is a free and open source media center distribution
I go to this directory: cd ~/osmc/package/kernel-osmc
There I run: sudo make rbp2
This will give me a package to install.
Now I would like to make changes. (Include an extra driver in the kernel.) According to the “guide” I should modify this file: rbp2-000-add-kernel-config.patch
When I run sudo make rbp2 the latest sources are downloaded. Somewhere is the scripts the rbp2-000-add-kernel-config.patch creates the .config file. This file is used to configure the build of the kernel?
If I check this file after the build my changes aren’t there so there’s my misunderstanding. My problem with adding it to Makefile and kconfig is that I have no idea which of the files to change and how to change it. I can make changes to the .config file with sudo make menuconfig but I think those changes won’t survive the next sudo make rbp2 command.
I would love to continu but I have no idea what I’m doing.
I started from scratch.
The commands:
git clone GitHub - osmc/osmc: OSMC (Open Source Media Center) is a free and open source media center distribution
cd ~/osmc/package/kernel-osmc
sudo make rbp2
Stopped the script after the .config is build.
cd ~/osmc/package/kernel-osmc/src/linux-4.4.27
sudo make menuconfig
loaded the .config file
included the drivers
saved the .config file
cd ~/osmc/package/kernel-osmc
sudo make rbp2
After the build the .config file no longer has the changes I made. I don’t know what I did wrong. Changing it in the patch file also didn’t work. Happy to try other suggestions.
When you have a config file customised, run diff -u /dev/null .config > add-kconfig.patch. Edit the patch file and change /.config to b/.config (so p1 works), and replace the kernel config in patches/ with this new patch file. Then you won’t need to stop any builds.
For adding new drivers, you need to diff -u /dev/null (or against an empty git tree) so they can be added as patch files.
This is more building the osmc kernel for dummies. Me being the dummy!
Again I started from scratch.
git clone GitHub - osmc/osmc: OSMC (Open Source Media Center) is a free and open source media center distribution
cd ~/osmc/package/kernel-osmc
sudo make rbp2
ctrl-z stop build after .config is made
cd ~/osmc/package/kernel-osmc/src/linux-4.4.27/
=== Add the wanted drivers
sudo make menuconfig
sudo su
sudo diff -u /dev/null .config > add-kconfig.patch
=== Change .config to b/ .config
sudo nano add-kconfig.patch
=== Get out of superuser
exit
cd ~
sudo mv ~/osmc/package/kernel-osmc/src/linux-4.4.27/add-kconfig.patch add-kconfig.patch
cd ~/osmc/package/kernel-osmc/patches
sudo cp rbp2-000-add-kernel-config.patch ~
diff add-kconfig.patch rbp2-000-add-kernel-config.patch
1,3c1,3
< — /dev/null 1970-01-01 01:00:17.639999993 +0100
< +++ b/ .config 2017-02-26 09:14:27.630137404 +0100
< @@ -0,0 +1,4915 @@
+# CONFIG_INPUT_MATRIXKMAP is not set
1823,1848c1823
< +CONFIG_INPUT_KEYBOARD=y
< +# CONFIG_KEYBOARD_ADP5588 is not set
< +# CONFIG_KEYBOARD_ADP5589 is not set
< +CONFIG_KEYBOARD_ATKBD=y
< +# CONFIG_KEYBOARD_QT1070 is not set
< +# CONFIG_KEYBOARD_QT2160 is not set
< +# CONFIG_KEYBOARD_LKKBD is not set
< +CONFIG_KEYBOARD_GPIO=y
< +CONFIG_KEYBOARD_GPIO_POLLED=y
< +# CONFIG_KEYBOARD_TCA6416 is not set
< +# CONFIG_KEYBOARD_TCA8418 is not set
< +CONFIG_KEYBOARD_MATRIX=y
< +# CONFIG_KEYBOARD_LM8323 is not set
< +# CONFIG_KEYBOARD_LM8333 is not set
< +# CONFIG_KEYBOARD_MAX7359 is not set
< +# CONFIG_KEYBOARD_MCS is not set
< +# CONFIG_KEYBOARD_MPR121 is not set
< +# CONFIG_KEYBOARD_NEWTON is not set
< +# CONFIG_KEYBOARD_OPENCORES is not set
< +# CONFIG_KEYBOARD_SAMSUNG is not set
< +# CONFIG_KEYBOARD_STOWAWAY is not set
< +# CONFIG_KEYBOARD_SUNKBD is not set
< +# CONFIG_KEYBOARD_OMAP4 is not set
< +# CONFIG_KEYBOARD_XTKBD is not set
< +# CONFIG_KEYBOARD_CAP11XX is not set
< +# CONFIG_KEYBOARD_BCM is not set
+# CONFIG_INPUT_KEYBOARD is not set
1997d1971
< +# CONFIG_INPUT_SOC_BUTTON_ARRAY is not set
4799d4772
< +CONFIG_CRYPTO_TWOFISH_COMMON=m
This looks OK for me.
Removed the osmc directory.
git clone GitHub - osmc/osmc: OSMC (Open Source Media Center) is a free and open source media center distribution
cp ~/add-kconfig.patch ~/osmc/package/kernel-osmc/patches/rbp2-000-add-kernel-config.patch
cd ~/osmc/package/kernel-osmc
sudo make rbp2
Now I get a lot of questions about “new” features. I all answered them with the default option by just hitting the enter key. Build is running and I’m optimistic that you managed to remotely build the kernel.
You managed to create a kernel! My errors were editing the patch file manually and a typo.
The gpio_keys are now build-in. I’m struggling with the device tree compiler now. Have a lot to learn here to. Thanks for all the support.
The first problem here is that the device tree compiler (dtc) for Raspbian has a patch. (I think.)
Raspbian: dtc -v => Version: DTC 1.4.1-gbd1c3aca-dirty
OSMC: dtc -v => Version: DTC 1.4.0
My guess this one: http://lists.busybox.net/pipermail/buildroot/2015-January/117739.html
New version is needed because of the “plugin” tag. I don’t know what happens if I just remove it. When I remove it the syntac error is gone but I get errors because the &gpio is not recognised. That could be related to the tag or it could be another error. (Could not find any documentation other than the patch for the plugin tag.) I use a known good dts file for my tests. Don’t know how to build a patched dtc but I haven’t searched for it either.