-
Notifications
You must be signed in to change notification settings - Fork 5.2k
add gpio-key overlay #2329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add gpio-key overlay #2329
Conversation
ok fixed now. let me know if I have made any obvious errors! |
I've been playing with this for an hour or so, and apart from a minor syntax error (a missing semicolon in the parameter declarations) there are a some more serious problems:
A trivial change that would allow us to remove the need for Another simple change would be to keep the use of I've added another commit that brings the PR up to date with as far as I've got, not relying on new firmware features. Give it a try - although the overlay looks like it applies OK I haven't tested that it works. For example, it is conceivable that gpio-keys doesn't like multiple instantiations. This has turned into a bit of a brain dump - sorry - but this needs more time and I didn't want to leave you hanging. |
i have just tested this with the buttons on our media center HAT and PaPiRus HAT and it works perfectly with both distinct buttons and a joystick. FYI - i tested PaPiRus with no pull ups set (as it has on board ones) and used media center hat with raspi pull ups set (it doesnt have on board ones) |
That's great. Does it work if you load the overlays at runtime instead? Comment out the config.txt entries and run something like:
It's not a train smash if they don't, but if we have a mechanism that works in both cases then I'm more likely to merge it as is. |
i tried those at runtime on the command line. this is exactly how i did it:
it didn't seem to respond at all to that. it didn't give an error message but the buttons did not respond when pressed. is there a way I can check if it is loaded correctly? |
@pelwell actually, i just tested it again and it works perfectly at runtime. don't know what i was doing wrong before. think possibly the HAT PCB wasn't properly connected or something. |
It's quite cool being able to add and change keys like this on the fly. I'm happy to merge if you are. |
sorry, "level" should have been "label"! and yes - i had gpio_pull=0 because my board has hardware pullups on it so no need to use the RPi ones :-) yeah - very nice indeed and super useful! will be making use of this a lot. happy to merge also. couple further questions i have for you though...for our media-center-overlay - is it preferred to add keymappings directly to that overlay for the joystick/buttons? or to use a separate overlay to set them up? if the latter, is there a way we can add multiple device tree overlays to a device tree blob for the eeprom on the product? just trying to work out the most user-friendly way to have the buttons set up. |
HATs are expected to have a single overlay associated with them. This can either be built into or, recently, just named. In order to make use of the generic gpio-key overlay directly in your application you would need to be able to pass parameters to the multiple invocations - you would really need to embed a config.txt fragment, and this is even less likely to be supported in the future. What is needed is a tool to combine a few overlays, with optional parameters, and generate a standalone overlay. We would then check the output (in source format) into the kernel tree - I wouldn't want require the use of this tool to build the kernel and its DTBs - but build into it enough information to be able to rerun the merge in the event that something changes. A checker script could then verify whether or not an update is required. The |
kernel: Add additional overrides to rotary-encoder overlay See: raspberrypi/linux#2334 kernel: An overlay that allows a Linux key to be bound to a GPIO See: raspberrypi/linux#2329 firmware: dtoverlay app: Keep overlay symbols private firmware: dtoverlay app: Report unknown parameters in help firmware: IL ISP: Remove DPCM10_8 compressed input firmware: mmal_il: Add missing mappings for 8 bit Bayer encodings firmware: IMX219 tuning: enable motion detection firmware: IL camera: increase minimum resolution to 32x32 firmware: audioplus: hdmi: Remove spamming logging message firmware: tidy: Platform cull
kernel: Add additional overrides to rotary-encoder overlay See: raspberrypi/linux#2334 kernel: An overlay that allows a Linux key to be bound to a GPIO See: raspberrypi/linux#2329 firmware: dtoverlay app: Keep overlay symbols private firmware: dtoverlay app: Report unknown parameters in help firmware: IL ISP: Remove DPCM10_8 compressed input firmware: mmal_il: Add missing mappings for 8 bit Bayer encodings firmware: IMX219 tuning: enable motion detection firmware: IL camera: increase minimum resolution to 32x32 firmware: audioplus: hdmi: Remove spamming logging message firmware: tidy: Platform cull
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
@pelwell so if the overlays are in RasPi kernel, in the device EEPROM you can just name the overlay? Do you have an example of how that works? Is there a benefit to using the full overlay in the EEPROM instead of this way? Thanks for the info on the rest of the stuff too :-) |
To embed the name, create a file containing the name of the overlay and pass that to eepmake, just as you would pass the .dtbo. Alternatively, include the blob in the settings file:
I don't see any real advantage to embedding the overlay, provided the overlay is part of the standard firmware. |
Guess the only benefit would be for an out-of-date kernel from a downstream application - OSMC or other distro - or perhaps a distro that is not derived from the official RPi one? |
Since most overlay PRs usually include config changes they tend to be tied to new kernels. |
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
@shawaj That fun project for combining overlays I mentioned earlier is now entering the beta phase. It can be used to:
There is minimal usage information in the file. It is written in Perl (sorry), but I've tried to keep it readable (just don't look at the regexp in the tokeniser...) You can find the current version here. Feedback is welcome. My plan is to make this tool generally availabe once it's ready. |
An overlay that allows a Linux key to be bound to a GPIO.
looks great! had a quick play and seems to work really nicely but haven't had time to give it more than a "play" definitely will be useful for future though - near tool :-) by generally available - does that mean listed on the RasPi site / github as a tool? Just wondering whether to bookmark this page :-) |
An overlay that allows a Linux key to be bound to a GPIO.
An overlay that allows a Linux key to be bound to a GPIO.
The ovmerge script is now available as (the only) part of a new "utils" repo. |
Ok, so I don’t want to sound like a complete noob which I clearly am, but when I was playing around with the sudo dtoverlay gpio-key gpio=21 keycode=4 label="KEY_4" gpio_pull=0 Command from terminal it got stuck. I tried to kill the command, change the command, etc... nothing works. when I kill the command it appears to work but after about ten seconds it starts printing 3333333333333 again. When I try to change the command I get this error: Failed to apply overlay ‘1_gpio-key’ (kernel) any idea what I might be missing or messing up? |
Having no pull ( Where did you get your keycode from? They are defined in https://github.com/raspberrypi/linux/blob/rpi-5.10.y/include/uapi/linux/input-event-codes.h, which shows that the keycode for |
as discussed in #2312 this is my first attempt at a generic gpio-key overlay with overrides for all of the necessary changes.
The one thing I am unsure of (other than generally whether it will work or not!!) is the
key@0
part - have I done that right?Also - perhaps it is better to not have the active-low on by default and to configure it to something less unexpected than a shutdown? Since gpio-shutdown overlay already does that. Not sure it matters hugely, but could just map it to an up arrow or something and have active low off. Let me know what you think?
P.S. this is untested so far with any buttons. I will test tomorrow when I am close to some hardware.
P.P.S i just noticed that I have accidentally deleted some stuff from the last commit (the mcp3202 overlay stuff) - off to fix that now!