GPIO hardware buttons control with gpio-keys

You can build the kernelpackage from osmc github with the drivers activated and test if it works. If so, supply a pullrequest.

Or tell us what kernel drivers to activate.
And maybe @sam_nazarko can integrate them in the next kernel update.

Hi,

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.

Regards,

Rob.

Hi,

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.

Regards,

Rob.

You have to alter the kernel config patch for rbp2 and / or rpb1 to activate the build of the module.

I’m not used to build kernels so I need more info.
This is what I did:
1 - git clone https://github.com/osmc/osmc.git
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.

Good. After it finished, install the resulting ketbel deb manually with dpki -i and reboot.
Let us know if it worked.

Hi,

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.

Regards,

Rob.

Add it to Makefile and Kconfig and select it in your kernel config if it isn’t enabled

Hi,

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 https://github.com/osmc/osmc.git
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.

Regards,

Rob.

make menuconfig should survive the next build.
Changes to the patch file might not as it is applied on every build.

Hi,

I started from scratch.
The commands:
git clone https://github.com/osmc/osmc.git
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.

Regards,

Rob.

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.

Hi,

This is more building the osmc kernel for dummies. Me being the dummy!
Again I started from scratch.
git clone https://github.com/osmc/osmc.git
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 @@

— /dev/null 2016-10-16 16:16:51.870941319 +0100
+++ b/.config 2016-10-22 17:52:20.956169632 +0100
@@ -0,0 +1,4888 @@
1805c1805
< +CONFIG_INPUT_POLLDEV=y


+CONFIG_INPUT_POLLDEV=m
1807c1807
< +CONFIG_INPUT_MATRIXKMAP=y


+# 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 https://github.com/osmc/osmc.git
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.

Regards,

Rob.

1 Like

Use diff -u
And diff against null not the patch

Hi,

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.

Regards,

Rob.

Device Tree is handled by OSMC’s build scripts automatically

Sam

Hi,

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.

Regards,

Rob.

Hi

We used to package Device Tree with some patches necessary for building for Raspberry Pi, but this is no longer necessary, and we are able to use the device tree compiler in the kernel tarball that we download.

OSMC doesn’t use ‘dtc’ from apt-get when building for Pi. It builds the in tree device tree compiler and adjusts PATH to prefer that one. If you are using the official OSMC build scripts it will all be handled for you.

I think something is wrong if you are having issues building DTBs. OSMC should build everything you need automatically and you should only need to adjust the patch which creates .config, and add a patch to add your driver.

Sam

Hi,

I’ll install a "“normal” osmc and try to compile the dts-file below without installing the device_tree package.

Regards,

Rob.

/dts-v1/;
/plugin/;
/ {
compatible = “brcm,bcm2835”, “brcm,bcm2708”, “brcm,bcm2709”;
fragment@0 {
target-path = “/”;
overlay {
keypad: comics_keys {
compatible = “gpio-keys”;
#address-cells = <1>;
#size-cells = <0>;
// autorepeat;
// key up = 1-1
button@13 {
label = “comics up”;
linux,code = <103>;
gpios = <&gpio 13 1>;
};
};
};
};
};

I’m not sure DT changes are necessary, but if they are, patch the DTS as a patches/ patch and OSMC will take care of it for you.

We build all overlays in the kernel build process.