Higher-level, application-facing modules built on top of System and Hardware. More...
|
Modules | |
| Human Interface Device (HID) | |
Typedefs | |
| typedef struct app_t | app_t |
| Opaque application instance passed to app callbacks. | |
| typedef void(* | app_callback_start_t) (app_t *app, void *userdata) |
| Called once, on the main worker, before the run loop starts dispatching events. More... | |
| typedef void(* | app_callback_event_t) (app_t *app, sys_event_t event, void *userdata) |
| Called on a worker for each event the run loop dispatches. More... | |
Enumerations | |
| enum | app_flag_t { app_flag_none = 0, app_flag_multicore = (1 << 0), app_flag_signal = (1 << 1), app_flag_user_button = (1 << 2), app_flag_temperature = (1 << 3), app_flag_stdio_rtt = (1 << 5), app_flag_led = (1 << 6), app_flag_watchdog = (1 << 7), app_flag_usb = (1 << 8) } |
| Feature flags controlling how app_main() runs. More... | |
Lifecycle | |
| int | app_main (int argc, char *argv[], app_flag_t flags, app_callback_start_t on_start, app_callback_event_t on_event, void *userdata) |
| Initialize the sys subsystem, run the event loop, then tear it down. More... | |
Properties | |
| hid_t * | app_hid (const app_t *app) |
| Get the HID instance initialized for this app. More... | |
| hw_led_t * | app_led (const app_t *app) |
| Get the on-board LED handle initialized for this app. More... | |
| hw_watchdog_t * | app_watchdog (const app_t *app) |
| Get the watchdog handle initialized for this app. More... | |
| hw_usb_t * | app_usb (const app_t *app) |
| Get the USB host handle initialized for this app. More... | |
Methods | |
| void | app_shutdown (int exit_code) |
| Request that the running app's event loop stop. More... | |
Higher-level, application-facing modules built on top of System and Hardware.
| typedef void(* app_callback_event_t) (app_t *app, sys_event_t event, void *userdata) |
Called on a worker for each event the run loop dispatches.
| app | Application instance. |
| event | Event to handle, as posted via sys_runloop_post() (see sys/runloop.h). |
| userdata | Opaque pointer, as passed to app_main(). |
| typedef void(* app_callback_start_t) (app_t *app, void *userdata) |
Called once, on the main worker, before the run loop starts dispatching events.
| app | Application instance. Valid for the duration of app_main(). |
| userdata | Opaque pointer, as passed to app_main(). |
Use this to complete setup that must run before events can be produced, such as registering HID devices or opening buses.
| enum app_flag_t |
Feature flags controlling how app_main() runs.
| Enumerator | |
|---|---|
| app_flag_none | Default behavior. |
| app_flag_multicore | Run the event loop across all cores. |
| app_flag_signal | Register environment signals (TERM, INT, QUIT) as HID events (see app_hid). Has no effect on a platform with no signal support. |
| app_flag_user_button | Register the board's user button (if any) as a HID event with keycode KEYCODE_BUTTON_USER (see app_hid). Not every board has a user button; has no effect when the board has none. |
| app_flag_temperature | Register the internal temperature-sensor channel as a polling HID metric source (see hid_register_temperature() and app_hid). Has no effect when the platform has no internal temperature sensor. |
| app_flag_stdio_rtt | Initialize standard I/O via SEGGER RTT (sys_stdio_rtt) instead of the platform default. |
| app_flag_led | Initialize the on-board LED if available (see app_led). Has no effect when the platform has no default on-board LED. |
| app_flag_watchdog | Enable the watchdog (see app_watchdog) - hw_poll(), called every run loop tick, feeds it from there. Has no effect when the platform has no watchdog backend. |
| app_flag_usb | Initialize the USB host subsystem and register it with HID (see app_usb and app_hid) - hotplug activity flows in as hid_event_type_usb events automatically. Call hw_usb_set_callback() directly on the returned handle to replace that with your own callback instead. Has no effect when the platform has no USB host backend. |
Definition at line 41 of file app.h.
Get the HID instance initialized for this app.
| app | Application instance. |
on_start (see app_main) - picofuse-app always links picofuse-hid. Get the on-board LED handle initialized for this app.
| app | Application instance. |
Call hw_led_set()/hw_led_blink() on it directly.
| int app_main | ( | int | argc, |
| char * | argv[], | ||
| app_flag_t | flags, | ||
| app_callback_start_t | on_start, | ||
| app_callback_event_t | on_event, | ||
| void * | userdata | ||
| ) |
Initialize the sys subsystem, run the event loop, then tear it down.
| argc | Argument count, as passed to main(). |
| argv | Argument vector, as passed to main(). |
| flags | Feature flags selecting optional behavior (see app_flag_t). |
| on_start | Called once, on the main worker, before the event loop starts. May be NULL. |
| on_event | Called for each event the loop dispatches. May be NULL if nothing ever posts events. |
| userdata | Opaque pointer passed through to on_start and on_event. |
main().Calls sys_init() (with sys_stdio_rtt if app_flag_stdio_rtt is set, otherwise the platform default), hw_init(), and hid_init() (see app_hid), initializes the on-board LED if app_flag_led is set and available (see app_led), registers environment signals as HID events if app_flag_signal is set, registers the board's user button as a HID event if app_flag_user_button is set, registers the internal temperature sensor as a HID metric source if app_flag_temperature is set, enables the watchdog if app_flag_watchdog is set and available (see app_watchdog), initializes the USB host subsystem and registers it with HID if app_flag_usb is set and available (see app_usb and hw_usb_register_hid()), then runs the event loop across every available core if app_flag_multicore is set, or on the calling thread alone otherwise. Every run loop tick calls hw_poll(), which feeds the watchdog when enabled (see hw_watchdog_enable()). Blocks until app_shutdown is called from within a callback (or from another thread), then tears down (hid_deinit(), hw_led_deinit(), hw_watchdog_deinit(), hw_usb_deinit(), hw_exit(), sys_exit()).
| void app_shutdown | ( | int | exit_code | ) |
Request that the running app's event loop stop.
| exit_code | Value app_main() returns once the loop has drained and stopped. |
Safe to call from any callback or thread. Equivalent to sys_runloop_shutdown(), exposed here so callers do not need to include sys/runloop.h directly.
Get the USB host handle initialized for this app.
| app | Application instance. |
Already registered with HID (see app_hid) via hw_usb_register_hid()
| hw_watchdog_t* app_watchdog | ( | const app_t * | app | ) |
Get the watchdog handle initialized for this app.
| app | Application instance. |
app_main() already calls hw_watchdog_enable() to start feeding this from hw_poll() (see its own doc) - call hw_watchdog_reset() on it directly to force an earlier reset, or hw_watchdog_enable() to stop feeding it.