Skip to content

rotary encoder overlay - add push button? #2312

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

Closed
shawaj opened this issue Dec 23, 2017 · 15 comments
Closed

rotary encoder overlay - add push button? #2312

shawaj opened this issue Dec 23, 2017 · 15 comments

Comments

@shawaj
Copy link

shawaj commented Dec 23, 2017

There is a rotary encoder overlay:

Name:   rotary-encoder
Info:   Overlay for GPIO connected rotary encoder.
Load:   dtoverlay=rotary-encoder,<param>=<val>
Params: rotary0_pin_a           GPIO connected to rotary encoder channel A
                                (default 4).
        rotary0_pin_b           GPIO connected to rotary encoder channel B
                                (default 17).

It would be nice to add a push button input to this for rotary encoders with a built in push button. Would this be feasible?

@pelwell
Copy link
Contributor

pelwell commented Dec 24, 2017

What effect would you want pushing the button to have - a key press? You can see an example of hooking a GPIO up to emulate a key in the gpio-shutdown overlay.

@shawaj
Copy link
Author

shawaj commented Dec 25, 2017

The specific thought I had in mind was the navigation of menus and changing of volume in audio and media center setups. But I guess this is context dependent, so perhaps isn't that useful for this generic overlay but should require a be underlay new overlay that's more specialised?

EDIT: edited for auto-correct faliure

@pelwell
Copy link
Contributor

pelwell commented Dec 27, 2017

A generic gpio-key overlay would be useful, with parameters to select the label, key code and GPIO. Appending @0 to the node name, adding a reg property and assigning the GPIO number to it will make it possible for multiple keys to be defined by multiple instances of the overlay.

If you want some examples, the gpio-key module is used by the gpio-shutdown and tinylcd35 overlays.

@shawaj
Copy link
Author

shawaj commented Dec 27, 2017

so you mean something like the gpio-shutdown one, but with parameters / overrides to choose other functions / key assignments from the gpio-keys bindings?

Might actually add this for easy config of buttons on our PaPiRus / Media Center HAT and other boards. Seems like a nice little way to do it :-)

@pelwell
Copy link
Contributor

pelwell commented Jan 2, 2018

so you mean something like the gpio-shutdown one, but with parameters / overrides to choose other functions / key assignments from the gpio-keys bindings?

Yes, in use it would look something like dtoverlay=gpio-key,gpio=24,keycode=59,label="KEY_F1".

@shawaj
Copy link
Author

shawaj commented Jan 2, 2018

@pelwell for the media-center HAT overlay, I am thinking to use a similar method to set up the joystick / buttons automatically to keys.

Is there a way to do this same method for multiple keys? Do you have an example overlay that does this for multiple keys?

@pelwell
Copy link
Contributor

pelwell commented Jan 2, 2018

Although I haven't tested it, I think we should be able to use the magic reg property support to allow multiple keys to be defined with multiple instances of the same overlay. I would prefer this than having a single overlay create multiple keys, because that would become ungainly quite quickly.

Basically, the created node would have to look something like this:

    key@4 {
        reg = < 4 >;
        linux,code = < 1 >;
        gpios = <&gpio 4 1>;
        label = "KEY_ESC";
    };

Modifying the reg parameter will also rename the node to match, so we can use the gpio parameter to create a unique "address" for each key.

@shawaj
Copy link
Author

shawaj commented Jan 2, 2018

@pelwell sorry if any of the following questions seem a bit stupid, but i am a little bit out of my depth at this point!

With the method you have said above - how would that then work to assign multiple keys to a board? is it some parameters after the dtoverlay call in config?

For reference, our board uses GPIO 13, 17, 22, 26, 27 (corresponding to Up SW1, left SW2, right SW4, down SW3, enter SW5 in image below)

gpio-sw1-5 1

The joystick uses the same pin mapping as the switches (it is just a 5 way switch)
gpio-joystick 1

@shawaj
Copy link
Author

shawaj commented Jan 2, 2018

P.S. i realise this is a bit off topic in regards to the rotary encoder, but talking about the same button mapping technique. Would it be better if I moved this to a new issue?

@pelwell
Copy link
Contributor

pelwell commented Jan 2, 2018

To map your switches to the first 5 function keys you would say:

dtoverlay=gpio-key,gpio=13,keycode=59,label="KEY_F1"
dtoverlay=gpio-key,gpio=17,keycode=60,label="KEY_F2"
dtoverlay=gpio-key,gpio=22,keycode=61,label="KEY_F3"
dtoverlay=gpio-key,gpio=26,keycode=62,label="KEY_F4"
dtoverlay=gpio-key,gpio=27,keycode=63,label="KEY_F5"

@pelwell
Copy link
Contributor

pelwell commented Jan 2, 2018

You can leave the discussion here or create a Pull Request as soon as you have any kind of work-in-progress.

@shawaj
Copy link
Author

shawaj commented Jan 2, 2018

aha - i see what you mean. so make an overlay called gpio-key-overlay.dts ?

@pelwell
Copy link
Contributor

pelwell commented Jan 2, 2018

Yes, that's the idea.

By the way, the label appears to be used by the GPIO framework to indicate the "owner" of the pin - it is information for users rather than something which has to be correct in order for the key to work.

@shawaj
Copy link
Author

shawaj commented Jan 3, 2018

ok, made an attempt here #2329

@shawaj
Copy link
Author

shawaj commented Jan 3, 2018

Closing this issue as gpio mappable button is now sorted in gpio-key-overlay.dts so can use this to set a button for a rotary encoder

#2329

@shawaj shawaj closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants