Skip to content

subsys/input: add the input subsystem - #2365

Merged
gmarull merged 5 commits into
coredevices:mainfrom
teslabs:input-subsys
Oct 12, 2026
Merged

gmarull merged 5 commits into
coredevices:mainfrom
teslabs:input-subsys

Conversation

@gmarull

@gmarull gmarull commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Adds subsys/input, a Zephyr-style input subsystem. Drivers report events with pbl_input_report() and know nothing about who consumes them. Listeners are defined with PBL_INPUT_CALLBACK_DEFINE() next to the code that uses them and are collected at link time, the same way shell commands are.

  • Events: KEY (buttons, BTN_TOUCH), ABS (touch X/Y) and GES (tap, double tap, palm). Events are grouped into reports, and the last event of a report carries sync.
  • Delivery is synchronous: listeners run in the context of the report. That is the debounce ISR for buttons, the system task for touch, and the calling thread for injected input. The subsystem has no queue or thread of its own, because the kernel event queue already moves work out of ISRs. Listeners must not block, and they check pbl_in_isr() before calling APIs that are not ISR-safe.
  • Buttons: the four drivers (SF32LB, nRF5, QEMU, SDL) report key events. Each board's ButtonConfig sets the key code its button reports, so the codes are independent of ButtonId. A listener in fw/kernel maps the codes back to ButtonId and turns them into PEBBLE_BUTTON_DOWN/UP_EVENT, so click recognition and everything above it is unchanged. The SELECT+BACK hard reset stays in the drivers on purpose: it has to work when every thread is wedged.
  • Touch: CST816, QEMU and SDL report samples and gestures. The touch service collects each report and passes it on to touch_handle_update() / touch_handle_gesture().
  • Injection:
    • button click/hold/multi, the remote input endpoint and button raw all go through the subsystem. button raw was duplicated in three drivers; it now exists once and works on every board.
    • New input dump on|off and input report <key|abs|ges> <code> <value> [sync] shell commands.

Design notes are in docs/architecture/input.md.

Future work, not part of this PR: a generic gpio_keys driver that owns debouncing, the hold timer and combos, once the device model can describe keys per board.

Testing

  • pbl test: 375/375 pass, including the new test_input and test_remote_input, which now runs through the subsystem and the button listener.
  • Builds: qemu_emery, obelix@pvt (normal and PRF), asterix and native_emery on SDK 0.1.11. qemu_emery also builds at every commit.
  • QEMU (qemu_emery), with input dump on:
    • QEMU sendkey and pbl touch produce the expected key, BTN_TOUCH and ABS reports.
    • In the launcher, button raw 3 1/0, button click 3 and input report key 3 1/0 each move the selection down one row.
  • obelix (pvt), with input dump on:
    • BACK, UP, SELECT and DOWN report key codes 0–3 on press and release through the SF32LB debounce path.
    • The CST816 reports touch samples (BTN_TOUCH, ABS_X, ABS_Y) and the tap, double-tap and palm gestures.
    • button raw, button click and input report key report the expected events.
    • Buttons, touch scrolling and gestures drive the UI as before.
  • Not tested on hardware: the nRF5 debounce path (asterix) is only build-tested.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the pending:hw-validation Changes require hardware validation label Oct 8, 2026
@gmarull
gmarull marked this pull request as ready for review October 9, 2026 20:07
@gmarull
gmarull requested a review from jplexer as a code owner October 9, 2026 20:07
@gmarull gmarull removed the pending:hw-validation Changes require hardware validation label Oct 9, 2026
@github-actions github-actions Bot added the pending:hw-validation Changes require hardware validation label Oct 9, 2026
@gmarull gmarull removed the pending:hw-validation Changes require hardware validation label Oct 9, 2026
gmarull and others added 5 commits October 9, 2026 22:31
Drivers report input events (keys, absolute axes, gestures) with
pbl_input_report() and listeners defined with PBL_INPUT_CALLBACK_DEFINE()
consume them, collected at link time like the shell commands. Modelled on
the Zephyr input subsystem.

Delivery is synchronous, in the context of the report: the kernel event
queue already defers work out of ISRs, so a queue and thread of its own
would only add latency, stack and a task watchdog channel. Listeners must
not block and check pbl_in_isr() before using APIs that are not ISR-safe.

The input shell command dumps events and reports arbitrary ones.

Nothing selects INPUT yet; the button and touch drivers move over next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Each ButtonConfig carries the input subsystem key code its button
reports, so that the key codes do not need to share values with
ButtonId.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
The button drivers report key events instead of putting PebbleEvents on
the kernel queue, and a listener in fw/kernel turns them back into
PEBBLE_BUTTON_DOWN/UP_EVENT, so the click recognizers and everything above
them are unchanged. Drivers report the key code set in the board configuration,
and the listener maps it back to its ButtonId. The listener runs in the debounce ISR, like the
event_put_isr() calls it replaces.

The SELECT+BACK hard reset stays in the drivers: it has to work with every
thread wedged, and the debounce timer is what times the hold.

`button raw`, duplicated in the SF32LB, nRF5 and QEMU drivers, moves next
to the other button commands and reports through the subsystem, so it is
now available on every board.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
The touch drivers report samples (BTN_TOUCH, ABS_X, ABS_Y) and gestures
(ABS_X, ABS_Y, GES) instead of calling into the touch service, which now
collects each report in an input listener and passes it on to
touch_handle_update() and touch_handle_gesture(). The reports come from
the system task, as the calls they replace did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Injected button presses (button click/hold/multi and the remote input
endpoint) take the same path as the hardware buttons. The test links the
subsystem and the button listener, and checks the PebbleEvents at the end
of it as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
@github-actions github-actions Bot added the pending:hw-validation Changes require hardware validation label Oct 9, 2026
@gmarull gmarull removed the pending:hw-validation Changes require hardware validation label Oct 9, 2026
@gmarull
gmarull merged commit 07809a6 into coredevices:main Oct 12, 2026
72 of 73 checks passed
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

Successfully merging this pull request may close these issues.

2 participants