Which API to use for a rotary encoder driver?


Guy Morand
 

Hi Zephyr developers,

I would like to write a driver for a rotary encoder. I need it to be "event driven" by using a callback when the encoder is rotated.

I looked for an existing API and only found this in the sensors:
* Channel: SENSOR_CHAN_ROTATION
* Trigger: SENSOR_TRIG_MOTION

I'm wondering if that is the right channel because instead of a "Angular rotation, in degrees" (as documented), I need a position in integer form. Moreover, we had internal discussion if that is really a sensor, if we should define a new API.

* Would this be the API I should use?
* Should I define a new API for rotary encoders or extend the existing sensor?
* Any suggestion for a better approach?

Thanks for your pointers,
Best regards,

Guy Morand

--
bytes at work
Technoparkstrasse 7
CH-8406 Winterthur
Switzerland


Benjamin Cabé
 

Hi Guy,

I will let others chime in regarding the best/suggested to do this today, but please note that there is good progress being made on adding a new input subsystem that would allow to address devices such as rotary encoders. See https://github.com/zephyrproject-rtos/zephyr/issues/54622. I would encourage you to have a look and provide feedback if you have any!

Cheers,
Benjamin.


Le mer. 1 mars 2023, 13:59, Guy Morand <guy.morand@...> a écrit :
Hi Zephyr developers,

I would like to write a driver for a rotary encoder. I need it to be
"event driven" by using a callback when the encoder is rotated.

I looked for an existing API and only found this in the sensors:
* Channel: SENSOR_CHAN_ROTATION
* Trigger: SENSOR_TRIG_MOTION

I'm wondering if that is the right channel because instead of a "Angular
rotation, in degrees" (as documented), I need a position in integer
form. Moreover, we had internal discussion if that is really a sensor,
if we should define a new API.

* Would this be the API I should use?
* Should I define a new API for rotary encoders or extend the existing
sensor?
* Any suggestion for a better approach?

Thanks for your pointers,
Best regards,

Guy Morand

--
bytes at work
Technoparkstrasse 7
CH-8406 Winterthur
Switzerland







Guy Morand
 

Benjamin,

Thanks for the interesting link, this would suit me need very well! Although it seems to be on the right track to be merged soon, I will have to wait a little until the API will be available in Zephyr...
https://github.com/zephyrproject-rtos/zephyr/pull/54908

Happy hacking!

Guy

On 3/1/23 22:17, Benjamin Cabé wrote:
Hi Guy,
I will let others chime in regarding the best/suggested to do this today, but please note that there is good progress being made on adding a new input subsystem that would allow to address devices such as rotary encoders. See https://github.com/zephyrproject-rtos/zephyr/issues/54622 <https://github.com/zephyrproject-rtos/zephyr/issues/54622>. I would encourage you to have a look and provide feedback if you have any!
Cheers,
Benjamin.
Le mer. 1 mars 2023, 13:59, Guy Morand <guy.morand@... <mailto:guy.morand@...>> a écrit :
Hi Zephyr developers,
I would like to write a driver for a rotary encoder. I need it to be
"event driven" by using a callback when the encoder is rotated.
I looked for an existing API and only found this in the sensors:
* Channel: SENSOR_CHAN_ROTATION
* Trigger: SENSOR_TRIG_MOTION
I'm wondering if that is the right channel because instead of a
"Angular
rotation, in degrees" (as documented), I need a position in integer
form. Moreover, we had internal discussion if that is really a sensor,
if we should define a new API.
* Would this be the API I should use?
* Should I define a new API for rotary encoders or extend the existing
sensor?
* Any suggestion for a better approach?
Thanks for your pointers,
Best regards,
Guy Morand
--
bytes at work
Technoparkstrasse 7
CH-8406 Winterthur
Switzerland
--
bytes at work
Technoparkstrasse 7
CH-8406 Winterthur
Switzerland

phone: +41 52 213 79 79