-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Similar to esp-idf-lib/encoder#7, I would like to propose replacing the shared polling timer with per-button esp_timer instances.
The current design uses a single timer that iterates over a fixed-size global array of buttons, protected by a mutex. This introduces global state (buttons[], mutex, timer), and imposes an artificial limit on button count (CONFIG_BUTTON_MAX).
Proposal:
Give each button its own esp_timer. The timer callback receives the button handle directly, so no global array or mutex is needed.
The cost difference is negligible: esp_timer is a software timer system where all callbacks run on a single shared FreeRTOS task regardless of how many timers exist. Each additional timer handle costs only ~50-80 bytes of heap — no extra tasks or hardware resources are consumed.
This also enables adopting the standard ESP-IDF opaque handle pattern (_create/_delete with heap-allocated handles), making the struct definition private to the implementation.