I’m working on a rotary encoder driver for FreeBSD 11.0 on the Raspberry Pi.
Why?
I’m tired of consuming CPU to poll GPIO pins for my rotary encoders for my garage door opener project, and as of yet there isn’t a mechanism to deal with GPIO interrupts from user space on FreeBSD. And even with the elegant kqueue mechanism, I don’t really need to push edge interrupts to user space. All I really want is rotary encoder state transitions.
There seems to be a quirk in the setup of GPIO interrupts on the BCM283[56] under FreeBSD. From a very quick scan of the data sheet, I should be able to have separate handlers for rising and falling edges. But FreeBSD doesn’t allow it. Specifically, gpio_alloc_intr_resource() fails for the second interrupt. I have worked around it for now, but I will hopefully find time to revisit this issue later.
I have the interrupt handling working, I tested it using a simple shell script to manipulate the pullup and pulldown resistors. I have two encoders configured since I need one for each of my garage doors.
gpiorotenc0:
gpiorotenc0: inputs on gpio0 pin 27, gpio0 pin 22
gpiorotenc1:
gpiorotenc1: inputs on gpio0 pin 23, gpio0 pin 24
...
Jul 4 06:54:48 rpi2 kernel: gpiorotenc0: channel A value 1
Jul 4 06:54:48 rpi2 kernel: gpiorotenc0: channel A value 0
Jul 4 06:54:48 rpi2 kernel: gpiorotenc0: channel B value 1
Jul 4 06:54:48 rpi2 kernel: gpiorotenc0: channel B value 0
Jul 4 06:54:48 rpi2 kernel: gpiorotenc1: channel A value 1
Jul 4 06:54:48 rpi2 kernel: gpiorotenc1: channel A value 0
Jul 4 06:54:48 rpi2 kernel: gpiorotenc1: channel B value 1
Jul 4 06:54:48 rpi2 kernel: gpiorotenc1: channel B value 0
