I did a quick little test to see if I could get a rotary encoder running. Turns out it’s very easy - a small addition to the DTS file and three lines to enable the driver in the kernel configuration. I’ve added a branch to my fork of SDK V2 here:
Note this is connected to GPIO 18,19 on the Duo using 10k pullups.
Use the user-space ‘evtest’ utility to verify it’s working:
[root@milkv-duo]~# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: rotary@0
Select the device event number [0-0]: 0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "rotary@0"
Supported events:
Event type 0 (EV_SYN)
Event type 2 (EV_REL)
Event code 0 (REL_X)
Properties:
Testing ... (interrupt to exit)
Event: time 1412.421087, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 1412.421087, -------------- SYN_REPORT ------------
Event: time 1412.489055, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 1412.489055, -------------- SYN_REPORT ------------
Event: time 1412.813147, type 2 (EV_REL), code 0 (REL_X), value 1
Event: time 1412.813147, -------------- SYN_REPORT ------------
Event: time 1412.843591, type 2 (EV_REL), code 0 (REL_X), value 1
Easy-peasy!
[edit] - Added a gpio-key input driver for the encoder’s center pushbutton too. Uses GPIO 17 with a pullup and also accessible with evtest.