subsys/input/ carries input events from the drivers to the code that
consumes them. Its public API is include/pbl/input/input.h. Drivers report
events without knowing who consumes them, and listeners are defined next to the code they drive and
collected at link time.
An event is a type, a code and a value:
PBL_INPUT_EV_KEY: a key or button, with value 1 when pressed and 0 when
released. The codes PBL_INPUT_KEY_BACK, _UP, _SELECT and _DOWN
are the watch buttons, set per button in the board configuration;
PBL_INPUT_BTN_TOUCH is the touch contact.
PBL_INPUT_EV_ABS: an absolute axis, PBL_INPUT_ABS_X and _Y in pixels
for touch.
PBL_INPUT_EV_GES: a gesture recognized by the device (tap, double tap,
palm), located at the report’s ABS_X and ABS_Y.
Key and axis codes have the values of the Linux input event codes
(KEY_BACK is 158, ABS_X is 0, …), so a devicetree linux,code
property is a code as is.
Events are grouped in reports, the last one carrying sync. A touch sample
is BTN_TOUCH, ABS_X, ABS_Y (sync); a gesture is ABS_X, ABS_Y,
GES (sync); a button is a single KEY event with sync.
A touchscreen is a device of the touch class (include/pbl/drivers/touch.h).
Its driver reports through the class, with pbl_touch_report() and
pbl_touch_report_gesture(), which map the controller coordinates to the
display with the board’s touchscreen properties (touchscreen-size-x/y,
touchscreen-inverted-x/y, touchscreen-swapped-x-y) and report the
events above. The touchscreen is powered while it has users:
pbl_touch_enable() and pbl_touch_disable() count them, and the touch
service is one while it has subscribers. The touch shell command shows
the properties, the users and the last sample.
pbl_input_report() calls every listener before it returns, in the context
of the report: the debounce ISR for buttons, the background work queue for touch, the
calling thread for injected input. There is no queue or thread of its own;
the listeners that need to defer work already have the kernel event queue.
Listeners are registered with PBL_INPUT_CALLBACK_DEFINE() and must not
block. Those that use APIs that are not ISR-safe check pbl_in_isr().
static void prv_input_cb(const struct pbl_input_event *evt, void *user_data) {
if (evt->type == PBL_INPUT_EV_KEY && evt->code == PBL_INPUT_KEY_BACK && evt->value) {
...
}
}
PBL_INPUT_CALLBACK_DEFINE(prv_input_cb, NULL);
The firmware has three listeners:
pebble/kernel/input_buttons.c turns key events into
PEBBLE_BUTTON_DOWN_EVENT / PEBBLE_BUTTON_UP_EVENT, so the click
recognizers and everything above them are unchanged. It also tracks the
held buttons and swaps up and down while the watch is rotated.
The touch service (pebble/services/touch/touch.c) collects each report and
passes it to touch_handle_update() and touch_handle_gesture().
pebble/system/reset_keys.c hard resets the watch when BACK and SELECT are
held for 5 seconds, into PRF if UP is held too, except in MFG builds. It
has to work when every thread is wedged, so it times the hold with a
kernel timer, which expires in the tick interrupt.
Injected input goes through the same path as the hardware:
input report <key|abs|ges> <code> <value> [sync] reports any event, and
input dump on logs every event (CONFIG_INPUT_SHELL).
button raw <btn> <0|1> reports a button transition.
button click / hold / multi and the remote input endpoint
(pebble/kernel/remote_input.c) report their button presses.
Injected touch gestures (touch_handle_injected_update()) still go straight
to the touch service, which arbitrates between them and the physical sensor.
Generated from PebbleOS 7753e801d. This page is maintained in the pebbleos repository: docs/subsystems/input.md.