Refactored events (#621)

Event handling:

- Added unified event handling for application, system, and Wi‑Fi events.
- Updated all apps to reflect event handling changes

Wi-Fi:

- Refactored event handling from listener interface to task & event group.
- Added direct Wi‑Fi radio controls and improved event subscriptions.
- Wi‑Fi screens now refresh asynchronously and handle unavailable devices more gracefully.
- Enabled Wi‑Fi by default on in dts files, but radio on/off is still done by code. The main reason was reliable event subscription and consistent devicetree states.
- Improved Wi‑Fi shutdown cleanup and radio-state handling.

Other:
- Renamed the Kernel Display app to Display.
This commit is contained in:
Ken Van Hoeylandt
2026-08-25 17:44:20 +02:00
committed by GitHub
parent db48dfe812
commit ab75d2022d
121 changed files with 2416 additions and 1381 deletions
+55 -21
View File
@@ -6,15 +6,14 @@
#include <stddef.h>
#include <stdint.h>
#include <tactility/concurrent/task_event_group.h>
#include <tactility/error.h>
#include <tactility/freertos/freertos.h>
#include <tactility/freertos/task.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Identifies the kind of app-lifecycle event delivered through app_event_await(). */
/** Identifies the kind of app-lifecycle event delivered through app_event_poll(). */
enum AppEventType {
APP_EVENT_RESULT, // struct AppResultEventData
APP_EVENT_CLOSE, // no data - terminate now, permanently
@@ -51,30 +50,62 @@ struct AppEvent {
* Caller-owned subscription node. Unlike TactilityKernel's system_event poll subscription
* (which coalesces to the latest value), this queues events by value (FIFO) since dropping an
* APP_EVENT_RESULT would be unacceptable.
* @warning Fields other than `app_instance_id` are for internal use only; do not read or write
* them directly.
* @warning Fields other than `bit` are for internal use only; do not read or write them
* directly.
*/
struct AppEventSubscription {
/** The app instance this subscription receives events for; set by the caller before app_event_subscribe(). */
AppInstanceId app_instance_id;
/** Set by app_event_subscribe()/app_event_subscribe_with_app_id(). Read-only for the
* caller: OR it into a task_event_group_wait() mask (alongside other subscriptions sharing
* the same `event_group`) to block on this subscription and other event sources with one
* call. */
uint32_t bit;
TaskHandle_t task;
struct {
/** The app instance this subscription receives events for; set by
* app_event_subscribe()/app_event_subscribe_with_app_id(). */
AppInstanceId app_instance_id;
struct AppEvent queue[APP_EVENT_QUEUE_CAPACITY];
uint8_t head;
uint8_t count;
/** Caller-owned, borrowed; set by app_event_subscribe(). */
struct TaskEventGroup* event_group;
struct AppEventSubscription* next;
struct AppEvent queue[APP_EVENT_QUEUE_CAPACITY];
uint8_t head;
uint8_t count;
struct AppEventSubscription* next;
} internal;
};
/**
* Register a subscription for events addressed to @a sub->app_instance_id.
* @warning Does not work in ISR context.
* @param[in,out] sub subscription to register; caller sets @a sub->app_instance_id beforehand,
* owns the storage, and must keep it alive (and stationary) until unsubscribed
* @return ERROR_NONE on success
* Register a subscription for events addressed to the calling app's own instance (identified via
* app_scheduler_current_app_id()).
* @warning Does not work in ISR context. Must be called from the app's own task.
* @param[in,out] sub subscription to register; owns the storage, must stay alive (and
* stationary) until unsubscribed
* @param[in] event_group caller-owned group to wait on; must outlive @a sub (i.e. be
* destructed only after app_event_unsubscribe()). To block for an event, call
* task_event_group_wait()/task_event_group_wait_any() on this group (OR sub->bit into the mask,
* or use _wait_any() to include every subscription sharing it), then drain with app_event_poll().
* @retval ERROR_NONE on success
* @retval ERROR_RESOURCE @a event_group has no free bits left to claim; @a sub was not registered
* @retval ERROR_INVALID_STATE @a sub is already registered
*/
error_t app_event_subscribe(struct AppEventSubscription* sub);
error_t app_event_subscribe(struct AppEventSubscription* sub, struct TaskEventGroup* event_group);
/**
* Same as app_event_subscribe(), but for a caller that isn't running on @a app_instance_id's own
* task (e.g. test code simulating multiple distinct app instances from one thread). Production
* app code should use app_event_subscribe() instead.
* @warning Does not work in ISR context.
* @param[in,out] sub subscription to register; owns the storage, must stay alive (and
* stationary) until unsubscribed
* @param[in] event_group caller-owned group to wait on; same contract as app_event_subscribe()
* @param[in] app_instance_id the app instance this subscription receives events for
* @retval ERROR_NONE on success
* @retval ERROR_RESOURCE @a event_group has no free bits left to claim; @a sub was not registered
* @retval ERROR_INVALID_STATE @a sub is already registered
*/
error_t app_event_subscribe_with_app_id(struct AppEventSubscription* sub, struct TaskEventGroup* event_group, AppInstanceId app_instance_id);
/**
* Remove a previously registered subscription.
@@ -94,11 +125,14 @@ error_t app_event_unsubscribe(struct AppEventSubscription* sub);
error_t app_event_emit(AppInstanceId app_instance_id, const struct AppEvent* event);
/**
* Pop the next event for @a sub, blocking up to @a timeout if the queue is currently empty.
* Non-blocking: pop the next event for @a sub if one is already queued.
* @warning Never blocks. To wait for an event, block in task_event_group_wait()/
* task_event_group_wait_any() on @a sub's event group first (see app_event_subscribe()), then
* drain with this in a loop.
* @retval ERROR_NONE @a out_event was filled
* @retval ERROR_TIMEOUT no event arrived before the timeout elapsed
* @retval ERROR_TIMEOUT nothing queued right now
*/
error_t app_event_await(struct AppEventSubscription* sub, struct AppEvent* out_event, TickType_t timeout);
error_t app_event_poll(struct AppEventSubscription* sub, struct AppEvent* out_event);
#ifdef __cplusplus
}
+3 -3
View File
@@ -21,13 +21,13 @@ extern "C" {
/**
* Entry point signature for an APP_LOCATION_MEMORY app: a function linked directly into this
* firmware binary. Called on the dedicated task app-module's scheduler spawns for this instance,
* blocking for the app's whole lifetime - same contract as an external app's main(), plus
* @a app_instance_id identifying this running instance (use it with
* blocking for the app's whole lifetime - same contract as an external app's main(). Use
* app_scheduler_current_app_id() to identify this running instance (e.g. with
* app_event_subscribe()/window_manager_create()/etc.). The instance closes when this function
* returns - no separate call is needed.
* AppManifest::location.location holds this cast to void*.
*/
typedef int32_t (*AppMainFn)(uint32_t app_instance_id, int argc, char* argv[]);
typedef int32_t (*AppMainFn)(int argc, char* argv[]);
typedef void* AppRuntime;