CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
host_api.h
Go to the documentation of this file.
1
12
13#ifndef CDC_BADGE_HOST_API_H
14#define CDC_BADGE_HOST_API_H
15
16#include <stdint.h>
17#include <stddef.h>
18#include <stdbool.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/* ------------------------------------------------------------------------- */
25/* API Level */
26/* ------------------------------------------------------------------------- */
27
28#define HOST_API_LEVEL_MAJOR 0
29#define HOST_API_LEVEL_MINOR 8
30#define HOST_API_LEVEL_STR "0.8"
31#define HOST_API_LEVEL_PACKED (((uint32_t)HOST_API_LEVEL_MAJOR << 16) | HOST_API_LEVEL_MINOR)
32
33/* ------------------------------------------------------------------------- */
34/* Return Codes */
35/* ------------------------------------------------------------------------- */
36
37#define HOST_OK 0
38#define HOST_ERR_GENERIC -1
39#define HOST_ERR_INVALID_ARG -2
40#define HOST_ERR_NO_CAPABILITY -3
41#define HOST_ERR_NOT_FOUND -4
42#define HOST_ERR_TIMEOUT -5
43#define HOST_ERR_NO_MEMORY -6
44#define HOST_ERR_BUSY -7
45#define HOST_ERR_NOT_SUPPORTED -8
46#define HOST_ERR_RMEM_FULL -9
47
57
58#define LOG_LEVEL_ERROR 0
59#define LOG_LEVEL_WARN 1
60#define LOG_LEVEL_INFO 2
61#define LOG_LEVEL_DEBUG 3
62#define LOG_LEVEL_VERBOSE 4
63
65void host_log (uint8_t level, const char* tag, const char* msg);
66
68void host_log_hex(const char* tag, const char* label, const uint8_t* data, size_t len);
69
71
81
82struct host_tm {
83 uint16_t year; /* 1900-3000 */
84 uint8_t month; /* 1-12 */
85 uint8_t day; /* 1-31 */
86 uint8_t hour; /* 0-23 */
87 uint8_t minute; /* 0-59 */
88 uint8_t second; /* 0-59 */
89 uint8_t weekday; /* 0=Sunday */
90};
91
93uint64_t host_uptime_ms (void);
94
96int64_t host_unix_time (void);
97
99int host_local_time (struct host_tm* out);
100
102int32_t host_timezone_offset (void);
103
105bool host_is_time_set (void);
106
108
114
115#define POWER_SRC_UNKNOWN 0
116#define POWER_SRC_BATTERY 1
117#define POWER_SRC_USB 2
118
119#define CHARGE_NOT_CHARGING 0
120#define CHARGE_PRE_CHARGE 1
121#define CHARGE_FAST 2
122#define CHARGE_DONE 3
123#define CHARGE_FAULT 4
124
126uint16_t host_battery_mv (void);
127
129uint8_t host_battery_pct (void);
130
132bool host_is_usb_connected (void);
133
135uint8_t host_power_source (void);
136
138uint8_t host_charge_status (void);
139
141bool host_is_battery_low (void);
142
144bool host_is_battery_critical(void);
145
151void host_set_sleep_inhibit (uint32_t on);
152
154
163
165int host_random (uint8_t* buf, size_t len);
166
168int host_random_strict (uint8_t* buf, size_t len);
169
171int host_sha256 (const uint8_t* data, size_t len, uint8_t out[32]);
172
174int host_hmac_sha256 (const uint8_t* key, size_t klen,
175 const uint8_t* data, size_t dlen, uint8_t out[32]);
176
186int host_aes_gcm_encrypt(const uint8_t* key, const uint8_t* iv,
187 const uint8_t* aad, size_t aad_len,
188 const uint8_t* pt, size_t pt_len,
189 uint8_t* ct, uint8_t tag[16]);
190
200int host_aes_gcm_decrypt(const uint8_t* key, const uint8_t* iv,
201 const uint8_t* aad, size_t aad_len,
202 const uint8_t* ct, size_t ct_len,
203 const uint8_t tag[16], uint8_t* pt);
204
206int host_base32_encode(const uint8_t* in, size_t in_len, char* out, size_t out_size);
207
209int host_base32_decode(const char* in, size_t in_len, uint8_t* out, size_t out_size);
210
212int host_base64_encode(const uint8_t* in, size_t in_len, char* out, size_t out_size);
213
215int host_base64_decode(const char* in, size_t in_len, uint8_t* out, size_t out_size);
216
218int host_hex_encode (const uint8_t* in, size_t in_len, char* out, size_t out_size);
219
221int host_hex_decode (const char* in, size_t in_len, uint8_t* out, size_t out_size);
222
224
235
236#define ECC_CURVE_P256 0
237#define ECC_CURVE_ED25519 1
238
239/*
240 * Retained memory (rmem) is allocated by name from a shared plugin pool.
241 * Slots persist across reboot, plugin uninstall, and plugin reinstall as
242 * long as the name remains declared in some installed plugin's
243 * `capabilities.rmem`. Plugins declaring the same name share the same
244 * physical slot (intentional, common scope).
245 *
246 * Name length: max 15 bytes excluding the trailing NUL.
247 */
248
249#define HOST_RMEM_NAME_MAX 15
250
257int host_rmem_read_named (const char* name, uint8_t* buf, size_t* len);
258
260int host_rmem_write_named (const char* name, const uint8_t* buf, size_t len);
261
263int host_rmem_erase_named (const char* name);
264
266bool host_rmem_name_used (const char* name);
267
269uint16_t host_rmem_slot_size (void);
270
271/*
272 * ECC keys are addressed by name, not by physical slot. The host maps each
273 * declared name (manifest `capabilities.ecc`) to a slot in a reserved plugin
274 * ECC pool and persists the mapping in NVS, so a key keeps its slot across
275 * reboot and reinstall. The pool is small (ECC slots are scarce and reserved
276 * for firmware features such as attestation and WebAuthn); growing it is a
277 * firmware change.
278 *
279 * Name length: max HOST_ECC_NAME_MAX bytes excluding the trailing NUL.
280 */
281#define HOST_ECC_NAME_MAX 15
282
284int host_ecc_generate (const char* name, uint8_t curve);
285
287int host_ecc_import (const char* name, const uint8_t* priv, uint8_t curve);
288
290int host_ecc_pubkey (const char* name, uint8_t* pub, uint8_t curve);
291
293int host_ecc_delete (const char* name);
294
296bool host_ecc_exists (const char* name);
297
299int host_ecdsa_sign (const char* name, const uint8_t* msg, size_t len, uint8_t sig[64]);
300
302int host_eddsa_sign (const char* name, const uint8_t* msg, size_t len, uint8_t sig[64]);
303
309int host_se_chip_id (uint8_t* serial, size_t* len);
310
312int host_se_fw_version(uint8_t* riscv, uint8_t* spect);
313
315
325
326#define HTTP_GET 0
327#define HTTP_POST 1
328#define HTTP_PUT 2
329#define HTTP_DELETE 3
330
338int host_http_open (uint8_t method, const char* url, uint32_t timeout_ms);
339
341int host_http_set_header (int handle, const char* key, const char* value);
342
344int host_http_set_body (int handle, const uint8_t* body, size_t len);
345
347int host_http_perform (int handle);
348
350int host_http_status (int handle);
351
356int host_http_read_chunk (int handle, uint8_t* buf, size_t buf_size, size_t* out_len);
357
359size_t host_http_content_length(int handle);
360
362int host_http_close (int handle);
363
365
378
380#define HOST_SOCK_TCP 0
381#define HOST_SOCK_UDP 1
382
391int host_socket_open(uint8_t proto, const char* host, uint16_t port, uint32_t timeout_ms);
392
397int host_socket_write(int handle, const uint8_t* data, size_t len, uint32_t timeout_ms);
398
403int host_socket_read(int handle, uint8_t* out, size_t cap, uint32_t timeout_ms);
404
406int host_socket_close(int handle);
407
409
426
430int host_net_listen(uint16_t port, uint32_t action_id);
431
435int host_net_accept(void);
436
440int host_net_close(uint16_t port);
441
443
456
461
463
473
474typedef struct {
475 char ssid[33];
476 uint8_t bssid[6];
477 int8_t rssi;
478 uint8_t channel;
479 uint8_t auth_mode;
481
483int host_wifi_request (uint32_t timeout_ms);
484
486int host_wifi_release (void);
487
489bool host_wifi_is_connected(void);
490
492int host_wifi_ssid (char* out, size_t out_size);
493
495int host_wifi_ip (char* out, size_t out_size);
496
498int8_t host_wifi_rssi (void);
499
501int host_wifi_mac (uint8_t out[6]);
502
504int host_wifi_start_scan (void);
505
507bool host_wifi_scan_done (void);
508
513int host_wifi_scan_results(wifi_scan_result_t* out, size_t* count);
514
516
525
526/* GATT characteristic property flags (BLE Core Spec Vol 3, Part G, 3.3.1.1). */
527#define BLE_PROP_READ 0x02
528#define BLE_PROP_WRITE_NO_RSP 0x04
529#define BLE_PROP_WRITE 0x08
530#define BLE_PROP_NOTIFY 0x10
531#define BLE_PROP_INDICATE 0x20
532
534typedef struct {
535 uint8_t uuid[16];
536 uint8_t properties;
537 uint8_t reserved[3];
539 uint32_t char_handle;
541
543typedef struct {
544 uint8_t uuid[16];
545 uint8_t num_chars;
546 uint8_t reserved[3];
547 uint32_t service_handle;
549
551typedef struct {
552 uint8_t addr[6];
553 uint8_t addr_type;
554 int8_t rssi;
555 char name[32];
557
559typedef struct {
560 uint8_t uuid[16];
561 uint16_t value_handle;
562 uint8_t properties;
563 uint8_t reserved;
565
566/* --- State (read-only) --- */
567
569bool host_ble_is_enabled (void);
570
572int host_ble_mac (uint8_t out[6]);
573
575int host_ble_device_name (char* out, size_t out_size);
576
578int8_t host_ble_rssi (void);
579
580/* --- Peripheral (GATT server) --- */
581
592 ble_char_def_t* chars, uint32_t num_chars);
593
595int host_ble_unregister_service(uint32_t service_handle);
596
598int host_ble_send_notification(uint32_t char_handle, const uint8_t* data, size_t len);
599
601int host_ble_send_indication (uint32_t char_handle, const uint8_t* data, size_t len);
602
611int host_ble_consume_write (uint32_t char_handle, uint8_t* buf, size_t buf_size);
612
613/* --- Central (GATT client) --- */
614
616int host_ble_scan_start (uint32_t duration_ms);
617
619bool host_ble_scan_done (void);
620
625int host_ble_scan_results (ble_scan_result_t* out, size_t* count);
626
631int host_ble_connect (const uint8_t addr[6], uint8_t addr_type);
632
634uint32_t host_ble_conn_handle (void);
635
637int host_ble_disconnect (uint32_t conn);
638
643int host_ble_discover (uint32_t conn, const uint8_t uuid[16], uint32_t action_id);
644
649int host_ble_consume_discovery(ble_remote_char_t* out, size_t* count);
650
655int host_ble_read_char (uint32_t conn, uint16_t value_handle, uint32_t action_id);
656
661int host_ble_consume_read (uint8_t* buf, size_t buf_size);
662
664int host_ble_write_char (uint32_t conn, uint16_t value_handle,
665 const uint8_t* data, size_t len, uint8_t with_response);
666
674int host_ble_subscribe (uint32_t conn, uint16_t cccd_handle, uint32_t action_id);
675
685int host_ble_subscribe_char (uint32_t conn, uint16_t value_handle, uint32_t action_id);
686
692int host_ble_consume_notification(uint16_t* value_handle_out, uint8_t* buf, size_t buf_size);
693
700uint16_t host_ble_get_mtu (uint32_t conn);
701
710int host_ble_on_write_complete(uint32_t action_id);
711
713
722
727int host_nvs_get_blob (const char* key, uint8_t* buf, size_t* len);
728
730int host_nvs_set_blob (const char* key, const uint8_t* buf, size_t len);
731
733int host_nvs_get_u32 (const char* key, uint32_t* out);
734
736int host_nvs_set_u32 (const char* key, uint32_t value);
737
739int host_nvs_get_str (const char* key, char* buf, size_t buf_size);
740
742int host_nvs_set_str (const char* key, const char* value);
743
745int host_nvs_erase (const char* key);
746
748int host_nvs_erase_all(void);
749
754int host_nvs_list_keys(char* out, size_t* out_len);
755
757
768
770int host_fs_write (const char* name, const uint8_t* data, size_t len);
771
777int host_fs_read (const char* name, uint8_t* buf, size_t* len);
778
780int host_fs_remove(const char* name);
781
783int host_fs_size (const char* name, size_t* out);
784
789int host_fs_list (char* out, size_t* out_len);
790
796int host_fs_view (const char* name);
797
802int host_fs_view_image (const char* name);
803
808int host_fs_view_markdown (const char* name);
809
811
822
823typedef struct {
824 const char* label;
825 uint8_t icon;
827 uint32_t item_id;
828} ui_item_t;
829
830/* CP437 glyph codes routed straight to Adafruit-GFX. cdc_log + plugin SDKs
831 * mirror these. UI_ICON_NONE renders a default bullet point. */
832#define UI_ICON_NONE 0
833#define UI_ICON_SUCCESS 2
834#define UI_ICON_ERROR 1
835#define UI_ICON_HEART 3 /* favorite */
836#define UI_ICON_DIAMOND 4
837#define UI_ICON_CLUB 5
838#define UI_ICON_SPADE 6
839#define UI_ICON_BULLET 7
840#define UI_ICON_INVERSE_BULLET 8 /* remove / delete */
841#define UI_ICON_CIRCLE 9 /* info / hollow circle */
842#define UI_ICON_INVERSE_CIRCLE 0x0A
843#define UI_ICON_MALE 0x0B
844#define UI_ICON_FEMALE 0x0C
845#define UI_ICON_MUSIC 0x0D
846#define UI_ICON_NOTES 0x0E /* scene / playlist */
847#define UI_ICON_SUN 0x0F /* brightness / light */
848#define UI_ICON_PLAY 0x10 /* action / switch / submenu */
849#define UI_ICON_REVERSE_PLAY 0x11 /* back */
850#define UI_ICON_UPDOWN 0x12 /* cover / vertical adjust */
851#define UI_ICON_ALERT 0x13 /* double exclamation */
852#define UI_ICON_PARAGRAPH 0x14
853#define UI_ICON_SECTION 0x15
854#define UI_ICON_BAR 0x16 /* sensor / list / count */
855#define UI_ICON_UPDOWN_BAR 0x17
856#define UI_ICON_ARROW_UP 0x18
857#define UI_ICON_ARROW_DOWN 0x19
858#define UI_ICON_ARROW_RIGHT 0x1A
859#define UI_ICON_ARROW_LEFT 0x1B
860#define UI_ICON_ANGLE 0x1C
861#define UI_ICON_LEFTRIGHT 0x1D
862#define UI_ICON_TRIANGLE_UP 0x1E
863#define UI_ICON_TRIANGLE_DOWN 0x1F
864
865/* Semantic aliases. Plugins are free to use either the CP437 name or
866 * a semantic one - they map to the same byte. */
867#define UI_ICON_INFO UI_ICON_CIRCLE
868#define UI_ICON_TASK UI_ICON_PLAY
869#define UI_ICON_REMOVE UI_ICON_INVERSE_BULLET
870#define UI_ICON_LIGHT UI_ICON_SUN
871#define UI_ICON_COVER UI_ICON_UPDOWN
872#define UI_ICON_SENSOR UI_ICON_BAR
873#define UI_ICON_SWITCH UI_ICON_PLAY
874#define UI_ICON_SCENE UI_ICON_NOTES
875#define UI_ICON_BACK UI_ICON_REVERSE_PLAY
876
878int host_ui_push_toast (const char* text, uint8_t icon, uint16_t duration_ms);
879
881int host_ui_push_message (const char* text, uint8_t icon, uint32_t duration_ms);
882
887int host_ui_push_confirm (const char* text, uint8_t icon, uint32_t action_id);
888
890int host_ui_push_info (const char* title, const char* body);
891
898int host_ui_view_image (const uint8_t* data, uint32_t len);
899
906int host_ui_view_markdown (const uint8_t* data, uint32_t len);
907
914int host_browser_open (const char* url);
915
924int host_ui_push_context_menu(const char* title, const ui_item_t* items, uint16_t count,
925 uint32_t select_action_id);
926
935int host_ui_push_t9_input (const char* title, const char* initial,
936 uint16_t max_len, uint32_t action_id);
937
944int host_ui_push_password (const char* title, const char* initial,
945 uint16_t max_len, uint32_t action_id);
946
953int host_ui_push_pin_entry (const char* title, uint8_t max_len, uint8_t max_attempts,
954 uint32_t action_id);
955
956/* On confirm fires action_id with user_data = 1 (read the value via
957 * host_ui_consume_input_int); on cancel fires with user_data = 0 and no value
958 * pending. The view pops itself before the action fires. */
960int host_ui_push_slider (const char* title, int32_t min, int32_t max, int32_t init,
961 int32_t step, const char* unit, uint32_t action_id);
962
963/* RGB color picker. On Y the host fires action_id with idx = packed RGB
964 * (0xRRGGBB) and user_data = 1; on N it fires with user_data = 0 and no value
965 * pending. The view pops itself first. Read the packed value via
966 * host_ui_consume_input_int(). */
968int host_ui_push_color_picker(uint8_t initial_r, uint8_t initial_g, uint8_t initial_b,
969 uint32_t action_id);
970
971/* On confirm fires action_id with user_data = 1 (read via
972 * host_ui_consume_input_int); on cancel fires with user_data = 0. Pops first. */
974int host_ui_push_date (const char* title, uint8_t d, uint8_t m, uint16_t y,
975 uint32_t action_id);
976
977/* On confirm fires action_id with user_data = 1 (read via
978 * host_ui_consume_input_int); on cancel fires with user_data = 0. Pops first. */
980int host_ui_push_time (const char* title, uint8_t h, uint8_t m, uint32_t action_id);
981
989int host_ui_push_list (const char* title, const ui_item_t* items, uint16_t count,
990 uint32_t select_action_id, uint32_t menu_action_id);
991
992/* Replace the plugin's currently-top list view with a fresh one. Falls back
993 * to a plain push when the plugin has no list on top (e.g. on first call).
994 * Use this for "refresh after toggle" patterns so the view stack does not
995 * grow on every action. */
997int host_ui_replace_list (const char* title, const ui_item_t* items, uint16_t count,
998 uint32_t select_action_id, uint32_t menu_action_id);
999
1000/* Override the footer hint for the plugin's current top view (list, confirm,
1001 * T9, pin, slider, date or time). Pass NULL or an empty string to fall back
1002 * to the view's default hint. The text is copied internally so the caller
1003 * can free it after the call returns. Returns HOST_ERR_NOT_FOUND if the top
1004 * view is not owned by the plugin runtime. */
1006int host_ui_set_view_footer (const char* hint);
1007
1009int host_ui_set_view_empty (const char* text);
1010
1011/* Wire hide/show callbacks on the plugin's current top view. `hide_action_id`
1012 * fires via plugin_on_action(hide_action_id, 0, 0) when the view is covered by
1013 * another view or modal; `show_action_id` fires when it becomes visible again.
1014 * Pass 0 for either id to leave that event unhooked. Returns HOST_ERR_NOT_FOUND
1015 * if the top view is not owned by the plugin runtime. */
1017int host_ui_set_view_lifecycle(uint32_t hide_action_id, uint32_t show_action_id);
1018
1019/* Redraw a single row of the plugin's current top list view in place, without
1020 * re-pushing or fully re-rendering the list. The label, icon and item_id of
1021 * the given index are replaced from `item`; the new label is copied
1022 * internally. Only repaints when the plugin's list is the active top view and
1023 * the row is on screen (partial refresh). Returns HOST_ERR_NOT_FOUND if the
1024 * top view is not the plugin's list, HOST_ERR_INVALID_ARG on a bad index. */
1026int host_ui_update_list_item(uint16_t index, const ui_item_t* item);
1027
1028/* Insert a new row into the plugin's current top list at `index` (later rows
1029 * shift down), then partial-repaint. The label is copied internally. `index`
1030 * is clamped to the current item count (append). Returns HOST_ERR_NOT_FOUND if
1031 * the top view is not the plugin's list. */
1033int host_ui_insert_list_item(uint16_t index, const ui_item_t* item);
1034
1035/* Remove the row at `index` from the plugin's current top list (later rows
1036 * shift up), then partial-repaint. Returns HOST_ERR_NOT_FOUND if the top view
1037 * is not the plugin's list, HOST_ERR_INVALID_ARG on a bad index. */
1039int host_ui_remove_list_item(uint16_t index);
1040
1042int host_ui_pop (void);
1043
1051int host_ui_pop_to_plugin (void);
1052
1054int host_ui_repaint (void);
1055
1057int host_ui_consume_input_text (char* out, size_t out_size);
1058
1060int host_ui_consume_input_int (int32_t* out);
1061
1063int host_ui_acquire_exclusive (void);
1064
1066int host_ui_release_exclusive (void);
1067
1072int host_ui_set_inactivity (uint32_t timeout_ms, uint32_t action_id);
1073
1074/*
1075 * Blink the badge backlight as a visual "look at me" signal. Count is clamped
1076 * to 1..10, period_ms (each off- and on-phase) to 50..1000. Use 0 for either
1077 * argument to take the default (2 cycles, 150 ms). Blocks the calling task
1078 * for `2 * count * period_ms` milliseconds; the underlying LEDC PWM is
1079 * thread-safe so no framebuffer ordering is involved.
1080 */
1086int host_ui_wink (uint8_t count, uint16_t period_ms);
1087
1089
1098
1099/* Canvas widget event subtypes used as the user_data on the widget callback. */
1100#define CANVAS_WIDGET_CHANGED 1
1101#define CANVAS_WIDGET_COMMITTED 2
1102#define CANVAS_WIDGET_CANCELLED 3
1103
1111int host_view_canvas_push (const char* title, uint32_t key_action_id,
1112 uint32_t widget_action_id);
1113
1115int host_view_canvas_get_body_size (uint16_t* w, uint16_t* h);
1116
1118int host_view_canvas_set_footer (const char* hint);
1119
1121int host_view_canvas_clear (void);
1122
1123/* Flags for host_view_canvas_clear_ex(). */
1124#define HOST_CANVAS_CLEAR_KEEP_SPRITES 0x01
1125
1140int host_view_canvas_clear_ex (uint32_t flags);
1141
1143int host_view_canvas_set_text_size (uint8_t size);
1144
1145#define HOST_FONT_BUILTIN 0
1146#define HOST_FONT_BOLD_9PT 1
1147#define HOST_FONT_BOLD_12PT 2
1148#define HOST_FONT_BOLD_18PT 3
1149#define HOST_FONT_BOLD_24PT 4
1150#define HOST_FONT_COUNT 5
1151
1163int host_view_canvas_set_font (uint8_t font_id);
1164
1181int host_text_pick_font_that_fits (const char* text, int16_t max_width_px,
1182 const uint8_t* candidates, uint32_t count,
1183 uint8_t* out_font_id);
1184
1186int host_view_canvas_set_text_color(bool inverted);
1187
1197int host_view_canvas_set_shade (uint8_t shade);
1198
1200int host_view_canvas_draw_text (int16_t x, int16_t y, const char* text);
1201
1206int host_view_canvas_draw_text_aligned(int16_t x, int16_t y, int16_t w,
1207 const char* text, uint8_t align);
1208
1210int host_view_canvas_draw_rect (int16_t x, int16_t y, int16_t w, int16_t h, bool filled);
1211
1213int host_view_canvas_draw_pixel (int16_t x, int16_t y);
1214
1216int host_view_canvas_draw_line (int16_t x0, int16_t y0, int16_t x1, int16_t y1);
1217
1219int host_view_canvas_draw_circle (int16_t x, int16_t y, int16_t r, bool filled);
1220
1222int host_view_canvas_draw_triangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1,
1223 int16_t x2, int16_t y2, bool filled);
1224
1226int host_view_canvas_draw_round_rect(int16_t x, int16_t y, int16_t w, int16_t h,
1227 int16_t r, bool filled);
1228
1238int host_view_canvas_draw_bitmap (int16_t x, int16_t y, int16_t w, int16_t h,
1239 const uint8_t* data, uint32_t len);
1240
1242int host_view_canvas_hline (int16_t x, int16_t y, int16_t w);
1243
1245int host_view_canvas_vline (int16_t x, int16_t y, int16_t h);
1246
1251int host_view_canvas_commit (bool full_refresh);
1252
1269int host_view_canvas_elem_begin (uint32_t elem_id);
1270
1277int host_view_canvas_elem_end (void);
1278
1287int host_view_canvas_elem_set_offset(uint32_t elem_id, int16_t ox, int16_t oy);
1288
1293int host_view_canvas_elem_move (uint32_t elem_id, int16_t dx, int16_t dy);
1294
1302int host_view_canvas_elem_show (uint32_t elem_id, bool visible);
1303
1312int host_view_canvas_elem_remove (uint32_t elem_id);
1313
1322int host_view_canvas_elem_clear (uint32_t elem_id);
1323
1333int host_view_canvas_elem_set_z (uint32_t elem_id, int8_t z);
1334
1336int host_view_canvas_elem_get_offset(uint32_t elem_id, int16_t* ox, int16_t* oy);
1337
1344int host_view_canvas_elem_get_bounds(uint32_t elem_id, int16_t* x, int16_t* y,
1345 uint16_t* w, uint16_t* h);
1346
1347/* Animation refresh policies for host_view_canvas_set_anim_policy(). */
1348#define HOST_CANVAS_ANIM_REFRESH_AUTO 0 /* flash-free while running, one FAST
1349 cleanup ~1 s after going idle */
1350#define HOST_CANVAS_ANIM_REFRESH_LIGHT 1 /* never clean up automatically;
1351 plugin manages ghosting itself */
1352
1368int host_view_canvas_set_anim_policy(uint8_t refresh_policy, uint8_t max_fps);
1369
1380int host_view_canvas_draw_sprite (int16_t x, int16_t y, uint32_t sprite);
1381
1392int host_view_canvas_set_ink (bool white);
1393
1408int host_view_canvas_marquee (int16_t x, int16_t y, int16_t window_w,
1409 const char* text, uint16_t step_px,
1410 uint16_t frame_ms);
1411
1413int host_view_canvas_add_slider (uint32_t widget_id, int32_t min, int32_t max,
1414 int32_t initial, int32_t step);
1415
1417int host_view_canvas_add_text (uint32_t widget_id, uint16_t max_len, const char* initial);
1418
1420int host_view_canvas_add_button (uint32_t widget_id);
1421
1423int host_view_canvas_remove_widget (uint32_t widget_id);
1424
1426int host_view_canvas_set_value (uint32_t widget_id, int32_t value);
1427
1429int host_view_canvas_get_value (uint32_t widget_id, int32_t* out);
1430
1432int host_view_canvas_set_text (uint32_t widget_id, const char* text);
1433
1435int host_view_canvas_get_text (uint32_t widget_id, char* out, size_t cap);
1436
1438int host_view_canvas_set_focus (uint32_t widget_id);
1439
1441int host_view_canvas_get_focus (uint32_t* out);
1442
1448int host_view_canvas_set_key_repeat(uint16_t initial_ms, uint16_t repeat_ms);
1449
1459int host_view_canvas_set_long_press_action(uint32_t action_id);
1460
1462
1478#define HOST_ANIM_MAX 16
1480#define HOST_ANIM_REPEAT_FOREVER 0xFFFF
1482/* Easing curves (fixed-point Penner subset). */
1483#define HOST_EASE_LINEAR 0
1484#define HOST_EASE_QUAD_IN 1
1485#define HOST_EASE_QUAD_OUT 2
1486#define HOST_EASE_QUAD_IN_OUT 3
1487#define HOST_EASE_CUBIC_IN 4
1488#define HOST_EASE_CUBIC_OUT 5
1489#define HOST_EASE_CUBIC_IN_OUT 6
1490#define HOST_EASE_OVERSHOOT 7 /* back-out: overshoots, then settles */
1491#define HOST_EASE_BOUNCE 8 /* bounce-out: ball-drop rebound */
1492#define HOST_EASE_STEP 9 /* holds the start, jumps at the end */
1493#define HOST_EASE_ELASTIC 10 /* elastic-out: springy overshoot wobble */
1495/* Tween flags. */
1496#define HOST_ANIM_FLAG_FROM_CURRENT 0x01 /* ignore from_x/y, start at the
1497 element's live offset */
1498#define HOST_ANIM_FLAG_YOYO 0x02 /* each repeat alternates direction */
1499#define HOST_ANIM_FLAG_HIDE_DONE 0x04 /* hide the element on completion */
1500#define HOST_ANIM_FLAG_SHOW_START 0x08 /* show the element when the delay
1501 elapses */
1504typedef struct {
1505 uint32_t elem_id;
1506 int16_t from_x;
1507 int16_t from_y;
1508 int16_t to_x;
1509 int16_t to_y;
1510 uint16_t duration_ms;
1511 uint16_t delay_ms;
1512 uint16_t repeat;
1514 uint8_t easing;
1515 uint8_t flags;
1516 uint32_t done_action_id;
1518 uint32_t start_after;
1521} host_anim_t;
1522
1528int host_anim_start(const host_anim_t* cfg);
1529
1536int host_anim_cancel(uint32_t handle);
1537
1539int host_anim_pause(uint32_t handle, bool paused);
1541/* Tween states returned by host_anim_state(). */
1542#define HOST_ANIM_STATE_DELAYED 0
1543#define HOST_ANIM_STATE_RUNNING 1
1544#define HOST_ANIM_STATE_PAUSED 2
1545
1551int host_anim_state(uint32_t handle);
1552
1554int host_anim_active_count(void);
1555
1565int host_anim_blink(uint32_t elem_id, uint16_t period_ms, uint16_t count,
1566 uint32_t done_action_id);
1567
1569
1578
1580uint16_t host_display_width (void);
1581
1583uint16_t host_display_height (void);
1584
1586int host_display_clear (void);
1587
1589int host_display_draw_pixel(int16_t x, int16_t y, uint16_t color);
1590
1592int host_display_draw_line (int16_t x0, int16_t y0, int16_t x1, int16_t y1,
1593 uint16_t color);
1594
1596int host_display_draw_rect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
1597
1599int host_display_fill_rect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
1600
1602int host_display_draw_text (int16_t x, int16_t y, const char* text, uint8_t size,
1603 uint16_t color);
1604
1609int host_display_flush (uint8_t refresh_mode);
1610
1612bool host_display_is_busy (void);
1613
1617int host_display_set_backlight(uint16_t level);
1618
1620uint16_t host_display_get_backlight(void);
1621
1623
1633
1634#define HOST_LANG_EN 0
1635#define HOST_LANG_DE 1
1636
1641int host_i18n_tr_key (const char* key, char* out, uint32_t out_cap);
1642
1644int host_i18n_tr_meta (const char* field, char* out, uint32_t out_cap);
1645
1647int host_i18n_tr_core (const char* key, char* out, uint32_t out_cap);
1648
1650uint8_t host_i18n_current_language(void);
1651
1653
1669#define EVENT_KEY_PRESSED (1u << 0)
1670#define EVENT_KEY_RELEASED (1u << 1)
1671#define EVENT_KEY_LONG_PRESS (1u << 2)
1672#define EVENT_POWER_USB_CONN (1u << 3)
1673#define EVENT_POWER_USB_DISCONN (1u << 4)
1674#define EVENT_POWER_CHARGING (1u << 5)
1675#define EVENT_POWER_BATT_LOW (1u << 6)
1676#define EVENT_POWER_BATT_CRIT (1u << 7)
1677#define EVENT_SYSTEM_UNLOCK (1u << 8)
1678#define EVENT_SYSTEM_LOCK (1u << 9)
1679#define EVENT_SYSTEM_SLEEP (1u << 10)
1680#define EVENT_SYSTEM_WAKE (1u << 11)
1681#define EVENT_BLE_CONNECTED (1u << 12)
1682#define EVENT_BLE_DISCONNECTED (1u << 13)
1683#define EVENT_TIMER_TICK (1u << 14)
1684#define EVENT_MODULE_EVENT (1u << 15)
1688#define EVENT_DISPLAY_REFRESH (1u << 16)
1689
1696int host_event_subscribe (uint32_t event_mask, uint32_t action_id);
1697
1699int host_event_unsubscribe(uint32_t subscription_id);
1700
1702int host_event_publish (uint32_t module_event_subtype, uint32_t value);
1703
1705
1712#define KEY_0 0
1713#define KEY_1 1
1714#define KEY_2 2
1715#define KEY_3 3
1716#define KEY_4 4
1717#define KEY_5 5
1718#define KEY_6 6
1719#define KEY_7 7
1720#define KEY_8 8
1721#define KEY_9 9
1722#define KEY_Y 10
1723#define KEY_N 11
1724
1726bool host_key_pressed (uint8_t key);
1727
1733int host_key_consume_next(uint8_t* out_key);
1734
1736
1742
1744int host_usb_cdc_write(const uint8_t* data, size_t len);
1745
1747
1753
1755bool host_feature_enabled (uint16_t feature_id);
1756
1758int host_get_firmware_version (char* out, size_t out_size);
1759
1761int host_get_build_profile (char* out, size_t out_size);
1762
1767uint8_t host_cpu_load (void);
1768
1770
1781
1786int host_cmd_consume (char* out, size_t out_size);
1787
1789
1814#define HOST_MSG_PAYLOAD_MAX 4096
1816#define HOST_MSG_MIME_MAX 64
1817
1827#define HOST_MSG_FLAG_PERSIST 0x01
1828
1841int host_msg_register_handler(const char* mime_type, uint32_t action_id);
1842
1848int host_msg_unregister_handler(const char* mime_type);
1849
1861int host_msg_consume(uint8_t* buf, size_t buf_size, char* mime_out, size_t mime_size);
1862
1876int host_msg_send_interactive(const char* mime_type, const uint8_t* data, size_t len,
1877 uint32_t flags);
1878
1892int host_msg_send(const uint8_t addr[6], uint8_t addr_type, const char* mime_type,
1893 const uint8_t* data, size_t len, uint32_t flags);
1894
1896
1923#define HOST_EXT_FEATURE_NAME_MAX 33
1925#define HOST_EXT_FEATURE_PAYLOAD_MAX 32768
1927#define HOST_EXT_FEATURE_STATUS_DONE 0
1929#define HOST_EXT_FEATURE_STATUS_ERROR 1
1930
1937int host_ext_feature_available(const char* feature);
1938
1957int host_ext_feature_use(const char* feature, const uint8_t* data, size_t len,
1958 uint32_t status_action_id);
1959
1973int host_ext_feature_register_handler(const char* feature, uint32_t action_id);
1974
1985int host_ext_feature_consume(uint8_t* buf, size_t buf_size,
1986 char* feature_out, size_t feature_size);
1987
1997int host_ext_feature_result(int32_t status_code);
1998
2000
2012
2014#define HOST_VCARD_MAX_LEN 768
2015
2023int host_vcard_get_own(char* out, size_t out_size);
2024
2030
2039int host_vcard_received_get(uint16_t index, char* out, size_t out_size);
2040
2047int host_vcard_received_display(uint16_t index, char* out, size_t out_size);
2048
2056int host_vcard_set_own(const char* vcard, size_t len);
2057
2066int host_vcard_received_add(const char* vcard, size_t len);
2067
2073int host_vcard_received_update(uint16_t index, const char* vcard, size_t len);
2074
2079int host_vcard_received_delete(uint16_t index);
2080
2082
2092
2101int host_qr_measure(const char* data, uint8_t max_version, uint8_t ecc,
2102 uint16_t* out_modules);
2103
2121int host_qr_render_bitmap(const char* data, uint8_t max_version, uint8_t ecc,
2122 uint8_t scale, uint8_t quiet_modules,
2123 uint8_t* out, size_t out_size,
2124 uint16_t* out_stride_bytes, uint16_t* out_height_px);
2125
2127
2137
2147int host_image_info(const uint8_t* data, size_t len, uint16_t* out_w, uint16_t* out_h);
2148
2161int host_image_render(const uint8_t* data, size_t len, uint16_t target_w,
2162 uint8_t* out, size_t out_size,
2163 uint16_t* out_stride_bytes, uint16_t* out_height_px);
2164
2166
2185#define HOST_SURFACE_MAX_PER_PLUGIN 2
2187#define HOST_SURFACE_MAX_BYTES 65536
2188
2196int host_surface_create(uint16_t w, uint16_t h);
2197
2199int host_surface_destroy(uint32_t surface);
2200
2202int host_surface_clear(uint32_t surface);
2203
2205int host_surface_set_font(uint32_t surface, uint8_t font_id);
2206
2208int host_surface_set_text_size(uint32_t surface, uint8_t size);
2209
2211int host_surface_set_text_color(uint32_t surface, uint8_t inverted);
2212
2214int host_surface_set_shade(uint32_t surface, uint8_t shade);
2215
2217int host_surface_draw_text(uint32_t surface, int16_t x, int16_t y, const char* text);
2218
2223int host_surface_draw_text_aligned(uint32_t surface, int16_t x, int16_t y, int16_t w,
2224 const char* text, uint8_t align);
2225
2231int host_surface_measure_text(uint32_t surface, const char* text,
2232 uint16_t* out_w, uint16_t* out_h);
2233
2235int host_surface_draw_pixel(uint32_t surface, int16_t x, int16_t y);
2236
2238int host_surface_draw_line(uint32_t surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1);
2239
2241int host_surface_draw_rect(uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h,
2242 uint8_t filled);
2243
2245int host_surface_draw_circle(uint32_t surface, int16_t x, int16_t y, int16_t r,
2246 uint8_t filled);
2247
2249int host_surface_draw_triangle(uint32_t surface, int16_t x0, int16_t y0,
2250 int16_t x1, int16_t y1, int16_t x2, int16_t y2,
2251 uint8_t filled);
2252
2254int host_surface_draw_round_rect(uint32_t surface, int16_t x, int16_t y,
2255 int16_t w, int16_t h, int16_t r, uint8_t filled);
2256
2258int host_surface_hline(uint32_t surface, int16_t x, int16_t y, int16_t w);
2259
2261int host_surface_vline(uint32_t surface, int16_t x, int16_t y, int16_t h);
2262
2267int host_surface_draw_bitmap(uint32_t surface, int16_t x, int16_t y,
2268 int16_t w, int16_t h, const uint8_t* data, uint32_t len);
2269
2276int host_surface_export(uint32_t surface, uint8_t* out, size_t out_size,
2277 uint16_t* out_stride_bytes);
2278
2287int host_surface_export_jpg(uint32_t surface, uint8_t quality,
2288 uint8_t* out, size_t out_size, uint32_t* out_len);
2289
2298int host_surface_draw_sprite(uint32_t surface, int16_t x, int16_t y, uint32_t sprite);
2299
2301
2328#define HOST_SPRITE_MAX_PER_CANVAS 8
2330#define HOST_SPRITE_MAX_FRAMES 32
2332#define HOST_SPRITE_ARENA_BYTES 65536
2334/* Playback modes. */
2335#define HOST_SPRITE_ONCE 0 /* play to the last frame and hold it */
2336#define HOST_SPRITE_LOOP 1 /* wrap around; finite runs hold the last */
2337#define HOST_SPRITE_PING_PONG 2 /* forward then backward per cycle */
2339/* Sprite flags. */
2340#define HOST_SPRITE_FLAG_OPAQUE 0x01 /* unset data bits paint white */
2341#define HOST_SPRITE_FLAG_FLIP_H 0x02 /* mirror horizontally when drawn */
2342#define HOST_SPRITE_FLAG_FLIP_V 0x04 /* mirror vertically when drawn */
2343#define HOST_SPRITE_FLAG_ROT_90 0x08 /* rotate 90 deg clockwise (before the
2344 flips; combine for 180/270). The
2345 drawn box becomes h x w. */
2346
2359int host_sprite_create(uint16_t frame_w, uint16_t frame_h, uint16_t frame_count,
2360 const uint8_t* frames, uint32_t len);
2361
2372int host_sprite_create_from_surface(uint32_t surface, uint16_t frame_w,
2373 uint16_t frame_h, uint16_t frame_count);
2374
2382int host_sprite_set_mask(uint32_t sprite, const uint8_t* mask, uint32_t len);
2383
2394int host_sprite_create_from_image(const uint8_t* data, uint32_t len,
2395 uint16_t target_w, uint16_t frame_h);
2396
2398int host_sprite_set_flags(uint32_t sprite, uint8_t flags);
2399
2405int host_sprite_set_scale(uint32_t sprite, uint8_t scale);
2406
2408int host_sprite_set_frame(uint32_t sprite, uint16_t frame);
2409
2411int host_sprite_get_frame(uint32_t sprite, uint16_t* out);
2412
2420int host_sprite_set_frame_durations(uint32_t sprite, const uint16_t* ms,
2421 uint16_t count);
2422
2437int host_sprite_play(uint32_t sprite, uint8_t mode, uint16_t frame_ms,
2438 uint16_t repeat, uint32_t done_action_id);
2439
2441int host_sprite_stop(uint32_t sprite);
2442
2447int host_sprite_destroy(uint32_t sprite);
2448
2450
2465
2467#define HOST_STR_TARGET_CP437 0 /* GFX builtin glcdfont (default after splash) */
2468#define HOST_STR_TARGET_LATIN1 1 /* FreeMonoBold*pt8b fonts (Latin-1 indexed) */
2469
2482int host_str_to_display(const char* in, char* out, size_t out_size, uint32_t target);
2483
2492int host_str_to_utf8(const char* in, char* out, size_t out_size);
2493
2495
2505#define GPIO_DIR_IN 0
2506#define GPIO_DIR_OUT 1
2507#define GPIO_DIR_OUT_OD 2
2508
2509#define GPIO_PULL_NONE 0
2510#define GPIO_PULL_UP 1
2511#define GPIO_PULL_DOWN 2
2512
2514int host_gpio_set_direction(uint8_t pin, uint8_t direction);
2515
2517int host_gpio_set_pull (uint8_t pin, uint8_t pull);
2518
2520int host_gpio_write (uint8_t pin, bool level);
2521
2523int host_gpio_read (uint8_t pin, bool* level);
2524
2526int host_gpio_release (uint8_t pin);
2527
2532int host_gpio_pwm_start (uint8_t pin, uint32_t freq_hz, uint16_t duty_per_mille);
2533
2535int host_gpio_pwm_set_duty (uint8_t pin, uint16_t duty_per_mille);
2536
2538int host_gpio_pwm_stop (uint8_t pin);
2539
2545int host_adc_read (uint8_t pin, uint16_t* raw, uint16_t* millivolt);
2546
2548int host_i2c_write (uint8_t bus, uint8_t addr, const uint8_t* data, size_t len);
2549
2551int host_i2c_read (uint8_t bus, uint8_t addr, uint8_t* data, size_t len);
2552
2554int host_i2c_write_read (uint8_t bus, uint8_t addr,
2555 const uint8_t* wr, size_t wr_len,
2556 uint8_t* rd, size_t rd_len);
2557
2562int host_i2c_scan (uint8_t bus, uint8_t* found_addrs, size_t* count);
2563
2565int host_sao_eeprom_read (uint16_t offset, uint8_t* buf, size_t len);
2566
2568int host_sao_eeprom_write (uint16_t offset, const uint8_t* buf, size_t len);
2569
2571
2582
2583#define PIXEL_FORMAT_GRB 0 /* WS2812/WS2813/SK6812 */
2584#define PIXEL_FORMAT_RGB 1
2585#define PIXEL_FORMAT_GRBW 2 /* SK6812 RGBW (white byte = 0 for plugin-side use) */
2586#define PIXEL_FORMAT_RGBW 3
2587
2589int host_pixel_strip_init (uint8_t gpio_pin, uint16_t num_pixels, uint8_t format);
2590
2592int host_pixel_strip_deinit (void);
2593
2595int host_pixel_strip_set (uint16_t index, uint8_t r, uint8_t g, uint8_t b);
2596
2598int host_pixel_strip_fill (uint8_t r, uint8_t g, uint8_t b);
2599
2601int host_pixel_strip_clear (void);
2602
2604int host_pixel_strip_refresh (void);
2605
2607uint16_t host_pixel_strip_length (void);
2608
2610bool host_pixel_strip_ready (void);
2611
2613
2624
2626int host_lockscreen_register_action (const char* label_key, uint32_t action_id);
2627
2630
2646int host_lockscreen_alert (const char* text, uint8_t icon, uint32_t action_id);
2647
2649
2650#ifdef __cplusplus
2651}
2652#endif
2653
2654#endif /* CDC_BADGE_HOST_API_H */
char name[cdc::hal::ISecureElement::RMEM_NAME_LEN]
uint8_t flags
uint8_t curve
bool resident
int host_ble_consume_write(uint32_t char_handle, uint8_t *buf, size_t buf_size)
Pull the next queued inbound write for char_handle.
int host_ble_scan_start(uint32_t duration_ms)
Start a central scan for duration_ms milliseconds.
int host_ble_connect(const uint8_t addr[6], uint8_t addr_type)
Connect to a peer. Completion arrives as a BLE_CONNECTED event; read the resulting handle with host_b...
int host_ble_subscribe(uint32_t conn, uint16_t cccd_handle, uint32_t action_id)
Subscribe to notifications on a peer characteristic (by CCCD handle). Each notification fires action_...
int host_ble_send_notification(uint32_t char_handle, const uint8_t *data, size_t len)
Notify subscribers of a value on one of the plugin's characteristics.
int host_ble_discover(uint32_t conn, const uint8_t uuid[16], uint32_t action_id)
Discover the characteristics of one service on a connected peer. Completion fires action_id; read ent...
bool host_ble_scan_done(void)
True when the scan started by host_ble_scan_start() has finished.
int host_ble_read_char(uint32_t conn, uint16_t value_handle, uint32_t action_id)
Start reading a peer characteristic by value handle. Completion fires action_id; read the value with ...
int host_ble_disconnect(uint32_t conn)
Disconnect a connection.
uint16_t host_ble_get_mtu(uint32_t conn)
Usable ATT payload of the current connection (negotiated MTU - 3).
int host_ble_device_name(char *out, size_t out_size)
Copy the local BLE device name into out.
int8_t host_ble_rssi(void)
Signal strength of the active BLE link in dBm, or 0 when idle.
int host_ble_unregister_service(uint32_t service_handle)
Tear down the plugin's registered GATT service.
int host_ble_scan_results(ble_scan_result_t *out, size_t *count)
Read results from the last central scan.
int host_ble_on_write_complete(uint32_t action_id)
Register an action fired on every completed central write.
int host_ble_send_indication(uint32_t char_handle, const uint8_t *data, size_t len)
Indicate (acknowledged notify) a value on a plugin characteristic.
bool host_ble_is_enabled(void)
True when the BLE stack is initialised and advertising or connectable.
int host_ble_consume_notification(uint16_t *value_handle_out, uint8_t *buf, size_t buf_size)
Pull the next queued inbound notification.
int host_ble_subscribe_char(uint32_t conn, uint16_t value_handle, uint32_t action_id)
Subscribe to notifications on a peer characteristic by VALUE handle.
int host_ble_register_service(ble_service_def_t *def, ble_char_def_t *chars, uint32_t num_chars)
Register the plugin's GATT service and its characteristics.
int host_ble_write_char(uint32_t conn, uint16_t value_handle, const uint8_t *data, size_t len, uint8_t with_response)
Write a value to a peer characteristic by value handle.
int host_ble_consume_discovery(ble_remote_char_t *out, size_t *count)
Pull discovered characteristics after a discovery action fires.
int host_ble_mac(uint8_t out[6])
Read the local BLE MAC address.
int host_ble_consume_read(uint8_t *buf, size_t buf_size)
Pull the value delivered by the last read action.
uint32_t host_ble_conn_handle(void)
Current connection handle (central or peripheral), or 0 when idle.
int host_anim_pause(uint32_t handle, bool paused)
Pause (paused != 0) or resume a tween; delay time freezes too.
int host_anim_blink(uint32_t elem_id, uint16_t period_ms, uint16_t count, uint32_t done_action_id)
Convenience: blink an element.
int host_anim_active_count(void)
Number of live tweens plus playing sprites (>= 0).
int host_anim_start(const host_anim_t *cfg)
Start (or queue, when start_after != 0) a tween on an element.
int host_anim_cancel(uint32_t handle)
Cancel a tween and its chained successors; handle 0 cancels all of the canvas's tweens....
int host_anim_state(uint32_t handle)
Query a tween's state.
int host_cmd_consume(char *out, size_t out_size)
Copy the pending command string into out, clearing it.
int host_hex_encode(const uint8_t *in, size_t in_len, char *out, size_t out_size)
Lowercase-hex-encode in into NUL-terminated out.
int host_random_strict(uint8_t *buf, size_t len)
Fill buf with hardware-RNG bytes only; fails without TRNG.
int host_base64_decode(const char *in, size_t in_len, uint8_t *out, size_t out_size)
Base64-decode in into raw bytes in out.
int host_base32_encode(const uint8_t *in, size_t in_len, char *out, size_t out_size)
Base32-encode in into NUL-terminated out.
int host_random(uint8_t *buf, size_t len)
Fill buf with hardware-RNG bytes; may fall back to PRNG.
int host_aes_gcm_decrypt(const uint8_t *key, const uint8_t *iv, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, const uint8_t tag[16], uint8_t *pt)
AES-256-GCM decrypt and verify.
int host_base64_encode(const uint8_t *in, size_t in_len, char *out, size_t out_size)
Base64-encode in into NUL-terminated out.
int host_aes_gcm_encrypt(const uint8_t *key, const uint8_t *iv, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, uint8_t tag[16])
AES-256-GCM encrypt.
int host_sha256(const uint8_t *data, size_t len, uint8_t out[32])
SHA-256 hash of data into the 32-byte out.
int host_hmac_sha256(const uint8_t *key, size_t klen, const uint8_t *data, size_t dlen, uint8_t out[32])
HMAC-SHA-256 of data under key into the 32-byte out.
int host_base32_decode(const char *in, size_t in_len, uint8_t *out, size_t out_size)
Base32-decode in into raw bytes in out.
int host_hex_decode(const char *in, size_t in_len, uint8_t *out, size_t out_size)
Hex-decode in (case-insensitive) into raw bytes in out.
int host_event_publish(uint32_t module_event_subtype, uint32_t value)
Publish an EVENT_MODULE_EVENT carrying subtype and value.
int host_event_unsubscribe(uint32_t subscription_id)
Cancel a subscription returned by host_event_subscribe.
int host_event_subscribe(uint32_t event_mask, uint32_t action_id)
Subscribe to one or more events.
int host_ext_feature_register_handler(const char *feature, uint32_t action_id)
Register this plugin as the live handler for a feature it provides.
int host_ext_feature_result(int32_t status_code)
Report the outcome of the job this provider is currently handling.
int host_ext_feature_use(const char *feature, const uint8_t *data, size_t len, uint32_t status_action_id)
Invoke feature with a payload; the provider runs in the foreground.
int host_ext_feature_consume(uint8_t *buf, size_t buf_size, char *feature_out, size_t feature_size)
Pull the payload of the job that fired the current handler action.
int host_ext_feature_available(const char *feature)
Check whether an installed plugin provides feature.
int host_i2c_write(uint8_t bus, uint8_t addr, const uint8_t *data, size_t len)
I2C write transaction.
int host_adc_read(uint8_t pin, uint16_t *raw, uint16_t *millivolt)
Single-shot ADC read.
int host_i2c_scan(uint8_t bus, uint8_t *found_addrs, size_t *count)
Scan the I2C bus for responding addresses.
int host_gpio_write(uint8_t pin, bool level)
Drive a digital output high/low.
int host_gpio_set_direction(uint8_t pin, uint8_t direction)
Configure pin direction (one of GPIO_DIR_*).
int host_gpio_set_pull(uint8_t pin, uint8_t pull)
Configure internal pull resistor (one of GPIO_PULL_*).
int host_sao_eeprom_write(uint16_t offset, const uint8_t *buf, size_t len)
Write to the SAO addon EEPROM at byte offset.
int host_gpio_pwm_start(uint8_t pin, uint32_t freq_hz, uint16_t duty_per_mille)
Start LEDC PWM on pin.
int host_gpio_read(uint8_t pin, bool *level)
Sample a digital input.
int host_i2c_write_read(uint8_t bus, uint8_t addr, const uint8_t *wr, size_t wr_len, uint8_t *rd, size_t rd_len)
I2C write-then-read transaction with repeated start.
int host_gpio_pwm_set_duty(uint8_t pin, uint16_t duty_per_mille)
Update PWM duty without restarting the timer.
int host_gpio_release(uint8_t pin)
Release the pin claim so other plugins can use it.
int host_gpio_pwm_stop(uint8_t pin)
Stop PWM and release the LEDC channel.
int host_sao_eeprom_read(uint16_t offset, uint8_t *buf, size_t len)
Read from the SAO addon EEPROM at byte offset.
int host_i2c_read(uint8_t bus, uint8_t addr, uint8_t *data, size_t len)
I2C read transaction.
int host_http_close(int handle)
Release a request handle.
int host_http_read_chunk(int handle, uint8_t *buf, size_t buf_size, size_t *out_len)
Stream one response chunk into buf.
int host_http_set_body(int handle, const uint8_t *body, size_t len)
Stage a request body before perform().
int host_http_status(int handle)
HTTP response status code, or negative on error.
int host_http_perform(int handle)
Send the request and read response headers.
size_t host_http_content_length(int handle)
Response Content-Length, or 0 when unknown / chunked.
int host_http_set_header(int handle, const char *key, const char *value)
Add a request header before perform().
int host_http_open(uint8_t method, const char *url, uint32_t timeout_ms)
Open an HTTP request.
uint8_t host_i18n_current_language(void)
Active language code (HOST_LANG_*).
int host_i18n_tr_core(const char *key, char *out, uint32_t out_cap)
Translate a core.* key from the firmware string table.
int host_i18n_tr_meta(const char *field, char *out, uint32_t out_cap)
Read a metadata field (name, description, ...) from the plugin manifest.
int host_i18n_tr_key(const char *key, char *out, uint32_t out_cap)
Translate a plugin-local key into the current language.
int host_image_info(const uint8_t *data, size_t len, uint16_t *out_w, uint16_t *out_h)
Decode only the image header to get its dimensions.
int host_image_render(const uint8_t *data, size_t len, uint16_t target_w, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes, uint16_t *out_height_px)
Decode, scale to target_w (aspect preserved) and dither to 1-bpp.
int host_key_consume_next(uint8_t *out_key)
Pop the next queued key press, if any.
bool host_key_pressed(uint8_t key)
True while key is currently held down.
int host_set_resident(bool resident)
Request (true) or drop (false) background residency. Needs the background or autoload capability to h...
int host_lockscreen_alert(const char *text, uint8_t icon, uint32_t action_id)
Raise a persistent Y/N alert over whatever is on screen, lock screen included, that stays until the u...
int host_lockscreen_register_action(const char *label_key, uint32_t action_id)
Publish (or replace) the plugin's lockscreen quick-action.
int host_lockscreen_unregister_action(void)
Remove the plugin's lockscreen quick-action.
void host_log_hex(const char *tag, const char *label, const uint8_t *data, size_t len)
Write a labelled hex dump of a binary buffer at debug level.
void host_log(uint8_t level, const char *tag, const char *msg)
Write a single log line at the given level.
int host_msg_send(const uint8_t addr[6], uint8_t addr_type, const char *mime_type, const uint8_t *data, size_t len, uint32_t flags)
Send a typed payload directly to a known peer address (no picker).
int host_msg_unregister_handler(const char *mime_type)
Drop a previously registered handler.
int host_msg_send_interactive(const char *mime_type, const uint8_t *data, size_t len, uint32_t flags)
Send a typed payload via the firmware-owned interactive peer picker.
int host_msg_consume(uint8_t *buf, size_t buf_size, char *mime_out, size_t mime_size)
Pull the payload delivered by the most recent inbound message action.
int host_msg_register_handler(const char *mime_type, uint32_t action_id)
Register that this plugin handles an incoming MIME type.
int host_net_accept(void)
Take the next accepted connection as a socket handle for host_socket_read/write/close.
int host_net_listen(uint16_t port, uint32_t action_id)
Start a TCP listener on port; fires action_id while clients wait.
int host_net_close(uint16_t port)
Stop the listener (pass 0 or the listening port). Closes pending un-accepted connections.
int host_nvs_list_keys(char *out, size_t *out_len)
Enumerate the keys in the plugin's namespace.
int host_nvs_erase(const char *key)
Delete a single key.
int host_nvs_set_u32(const char *key, uint32_t value)
Write a uint32 value.
int host_nvs_get_blob(const char *key, uint8_t *buf, size_t *len)
Read a binary blob from NVS.
int host_nvs_get_str(const char *key, char *buf, size_t buf_size)
Read a NUL-terminated string.
int host_nvs_get_u32(const char *key, uint32_t *out)
Read a uint32 value.
int host_nvs_erase_all(void)
Erase every key in the plugin's namespace.
int host_nvs_set_blob(const char *key, const uint8_t *buf, size_t len)
Write a binary blob to NVS.
int host_nvs_set_str(const char *key, const char *value)
Write a NUL-terminated string.
int host_pixel_strip_refresh(void)
Push the strip buffer out over the RMT bus.
int host_pixel_strip_clear(void)
Clear every pixel to off (0, 0, 0).
uint16_t host_pixel_strip_length(void)
Number of pixels the strip was initialised with.
int host_pixel_strip_fill(uint8_t r, uint8_t g, uint8_t b)
Fill every pixel with the same RGB colour.
int host_pixel_strip_set(uint16_t index, uint8_t r, uint8_t g, uint8_t b)
Set one pixel's RGB colour in the strip buffer.
int host_pixel_strip_init(uint8_t gpio_pin, uint16_t num_pixels, uint8_t format)
Initialise or reconfigure the global pixel strip.
int host_pixel_strip_deinit(void)
Tear down the global pixel strip.
bool host_pixel_strip_ready(void)
True when the strip has been successfully initialised.
uint8_t host_charge_status(void)
Charger state machine value - one of CHARGE_*.
uint8_t host_power_source(void)
Active power source - one of POWER_SRC_*.
bool host_is_battery_low(void)
True when battery has crossed the low-warning threshold.
bool host_is_battery_critical(void)
True when battery has crossed the critical-shutdown threshold.
void host_set_sleep_inhibit(uint32_t on)
Hold or release a light-sleep inhibitor for the calling plugin. While any inhibitor is held the badge...
bool host_is_usb_connected(void)
True when USB VBUS is detected.
uint16_t host_battery_mv(void)
Battery voltage in millivolts.
uint8_t host_battery_pct(void)
Battery state of charge as 0..100 percent.
int host_qr_render_bitmap(const char *data, uint8_t max_version, uint8_t ecc, uint8_t scale, uint8_t quiet_modules, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes, uint16_t *out_height_px)
Encode data into a packed 1-bpp QR raster.
int host_qr_measure(const char *data, uint8_t max_version, uint8_t ecc, uint16_t *out_modules)
Measure the QR module count for data without rendering.
int host_ecc_delete(const char *name)
Erase the named ECC key and free its pool slot.
int host_se_fw_version(uint8_t *riscv, uint8_t *spect)
Read TROPIC01 firmware versions for the RISC-V CPU and SPECT core.
int host_se_chip_id(uint8_t *serial, size_t *len)
Read the TROPIC01 chip serial / identity blob.
int host_rmem_read_named(const char *name, uint8_t *buf, size_t *len)
Read a named retained-memory slot.
int host_rmem_write_named(const char *name, const uint8_t *buf, size_t len)
Write up to host_rmem_slot_size() bytes into a named rmem slot.
uint16_t host_rmem_slot_size(void)
Maximum payload bytes per rmem slot.
int host_ecc_pubkey(const char *name, uint8_t *pub, uint8_t curve)
Export the public key for the named slot.
int host_ecdsa_sign(const char *name, const uint8_t *msg, size_t len, uint8_t sig[64])
ECDSA-sign msg with the P-256 named key; writes 64-byte raw sig.
bool host_rmem_name_used(const char *name)
True if the named rmem slot currently holds data.
int host_eddsa_sign(const char *name, const uint8_t *msg, size_t len, uint8_t sig[64])
Ed25519-sign msg with the named key; writes 64-byte signature.
int host_rmem_erase_named(const char *name)
Erase the contents of a named rmem slot.
int host_ecc_generate(const char *name, uint8_t curve)
Generate a fresh ECC key for the named slot.
int host_ecc_import(const char *name, const uint8_t *priv, uint8_t curve)
Import an externally-generated private key for the named slot.
bool host_ecc_exists(const char *name)
True when the named ECC key currently holds a key.
int host_socket_read(int handle, uint8_t *out, size_t cap, uint32_t timeout_ms)
Read bytes from the stream / receive a datagram from the connected peer.
int host_socket_close(int handle)
Close a socket handle.
int host_socket_write(int handle, const uint8_t *data, size_t len, uint32_t timeout_ms)
Write bytes to the stream / send a datagram to the connected peer.
int host_socket_open(uint8_t proto, const char *host, uint16_t port, uint32_t timeout_ms)
Open an outbound connection to a single remote endpoint.
int host_sprite_create(uint16_t frame_w, uint16_t frame_h, uint16_t frame_count, const uint8_t *frames, uint32_t len)
Create a sprite from a packed 1-bpp frame sheet in plugin memory.
int host_sprite_set_frame(uint32_t sprite, uint16_t frame)
Jump to a frame. A running playback continues from it.
int host_sprite_play(uint32_t sprite, uint8_t mode, uint16_t frame_ms, uint16_t repeat, uint32_t done_action_id)
Start host-driven playback from frame 0.
int host_sprite_create_from_image(const uint8_t *data, uint32_t len, uint16_t target_w, uint16_t frame_h)
Create a sprite straight from an encoded PNG/JPEG.
int host_sprite_destroy(uint32_t sprite)
Destroy a sprite and reclaim its arena bytes. Recorded draw-sprite commands referencing it are skippe...
int host_sprite_set_frame_durations(uint32_t sprite, const uint16_t *ms, uint16_t count)
Optional per-frame durations in milliseconds.
int host_sprite_set_scale(uint32_t sprite, uint8_t scale)
Integer upscale factor applied whenever the sprite is drawn.
int host_sprite_set_flags(uint32_t sprite, uint8_t flags)
Replace the sprite's flag set (HOST_SPRITE_FLAG_*).
int host_sprite_stop(uint32_t sprite)
Stop playback, keeping the current frame on screen.
int host_sprite_set_mask(uint32_t sprite, const uint8_t *mask, uint32_t len)
Attach a transparency mask plane (same sheet layout and size as the frame data). Mask bit set = pixel...
int host_sprite_create_from_surface(uint32_t surface, uint16_t frame_w, uint16_t frame_h, uint16_t frame_count)
Create a sprite by slicing a surface into a row-major grid of frame_w x frame_h cells.
int host_sprite_get_frame(uint32_t sprite, uint16_t *out)
Read the currently displayed frame index.
int host_str_to_utf8(const char *in, char *out, size_t out_size)
Convert CP437 display bytes in in to a UTF-8 string in out.
int host_str_to_display(const char *in, char *out, size_t out_size, uint32_t target)
Decode HTML entities + UTF-8 in in into single-byte display characters in out.
int host_surface_set_font(uint32_t surface, uint8_t font_id)
Select the font for subsequent text calls (HOST_FONT_* id).
int host_surface_draw_text(uint32_t surface, int16_t x, int16_t y, const char *text)
Draw UTF-8 text with the current font/size at (x, y) baseline-top.
int host_surface_draw_bitmap(uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *data, uint32_t len)
Blit a packed 1-bpp bitmap (MSB-first, set bit = black) at (x, y).
int host_surface_vline(uint32_t surface, int16_t x, int16_t y, int16_t h)
Draw a vertical line of height h.
int host_surface_draw_pixel(uint32_t surface, int16_t x, int16_t y)
Draw a pixel (current shade decides ink: shade > 0 draws black).
int host_surface_draw_sprite(uint32_t surface, int16_t x, int16_t y, uint32_t sprite)
Stamp a sprite's current frame onto a surface at (x, y).
int host_surface_measure_text(uint32_t surface, const char *text, uint16_t *out_w, uint16_t *out_h)
Measure UTF-8 text with the surface's current font/size.
int host_surface_destroy(uint32_t surface)
Destroy a surface and free its memory.
int host_surface_draw_line(uint32_t surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1)
Draw a line.
int host_surface_draw_text_aligned(uint32_t surface, int16_t x, int16_t y, int16_t w, const char *text, uint8_t align)
Draw UTF-8 text aligned within a w-wide box starting at x.
int host_surface_draw_rect(uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t filled)
Draw a rectangle; filled ones use the current shade.
int host_surface_draw_circle(uint32_t surface, int16_t x, int16_t y, int16_t r, uint8_t filled)
Draw a circle centered at (x, y); filled ones use the current shade.
int host_surface_set_text_color(uint32_t surface, uint8_t inverted)
Draw text white-on-black (inverted != 0) or black-on-white.
int host_surface_draw_triangle(uint32_t surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t filled)
Draw a triangle; filled ones use the current shade.
int host_surface_export(uint32_t surface, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes)
Copy the surface's packed pixel rows into out.
int host_surface_set_shade(uint32_t surface, uint8_t shade)
Set the fill shade for filled shapes: 0 white .. 255 solid black.
int host_surface_clear(uint32_t surface)
Clear a surface to white.
int host_surface_create(uint16_t w, uint16_t h)
Create a w x h surface, cleared to white.
int host_surface_set_text_size(uint32_t surface, uint8_t size)
Set the integer text scale (1..4) for subsequent text calls.
int host_surface_hline(uint32_t surface, int16_t x, int16_t y, int16_t w)
Draw a horizontal line of width w.
int host_surface_draw_round_rect(uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint8_t filled)
Draw a rounded rectangle with corner radius r.
int host_surface_export_jpg(uint32_t surface, uint8_t quality, uint8_t *out, size_t out_size, uint32_t *out_len)
Encode the surface as a grayscale JPEG.
int host_get_build_profile(char *out, size_t out_size)
Copy the build profile name (e.g. "release", "debug") into out.
uint8_t host_cpu_load(void)
Aggregate CPU load across all cores as 0..100 percent. Sampled on demand from FreeRTOS run-time stats...
bool host_feature_enabled(uint16_t feature_id)
True when the firmware was built with the given feature id enabled.
int host_get_firmware_version(char *out, size_t out_size)
Copy the firmware semver string into out.
int host_local_time(struct host_tm *out)
Fill out with the current local time broken into fields.
bool host_is_time_set(void)
True when the RTC has been synchronised at least once.
uint64_t host_uptime_ms(void)
Monotonic milliseconds since boot.
int64_t host_unix_time(void)
Current Unix timestamp in seconds, or 0 if RTC not set.
int32_t host_timezone_offset(void)
Configured timezone offset from UTC in seconds.
int host_view_canvas_clear_ex(uint32_t flags)
Clear with options: like host_view_canvas_clear, but HOST_CANVAS_CLEAR_KEEP_SPRITES keeps the sprite ...
int host_view_canvas_get_value(uint32_t widget_id, int32_t *out)
Read the integer value of a slider widget.
int host_view_canvas_elem_show(uint32_t elem_id, bool visible)
Show or hide an element (hidden elements are skipped on replay).
int host_view_canvas_draw_round_rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, bool filled)
Draw a rounded rectangle outline or filled, corner radius r.
int host_view_canvas_elem_set_offset(uint32_t elem_id, int16_t ox, int16_t oy)
Set an element's replay offset relative to its recorded coordinates.
int host_view_canvas_elem_remove(uint32_t elem_id)
Remove an element and all draw commands recorded under it.
int host_view_canvas_push(const char *title, uint32_t key_action_id, uint32_t widget_action_id)
Push a new canvas view.
int host_view_canvas_get_focus(uint32_t *out)
Read the currently focused widget id, 0 if none.
int host_view_canvas_hline(int16_t x, int16_t y, int16_t w)
Draw a horizontal line.
int host_view_canvas_vline(int16_t x, int16_t y, int16_t h)
Draw a vertical line.
int host_view_canvas_clear(void)
Clear all draw state and widgets. Equals host_view_canvas_clear_ex(0).
int host_view_canvas_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, bool filled)
Draw a rectangle outline or filled rectangle.
int host_view_canvas_set_ink(bool white)
Draw subsequent shapes in white instead of black.
int host_view_canvas_elem_move(uint32_t elem_id, int16_t dx, int16_t dy)
Shift an element's replay offset by a delta.
int host_view_canvas_elem_begin(uint32_t elem_id)
Start recording draw calls under element elem_id.
int host_view_canvas_set_text_color(bool inverted)
Switch between normal and inverted (white on black) text.
int host_view_canvas_set_font(uint8_t font_id)
Switch the canvas font to one of the canonical HOST_FONT_* ids.
int host_view_canvas_draw_bitmap(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *data, uint32_t len)
Draw a 1-bpp bitmap; set bits render black, unset bits are transparent.
int host_view_canvas_add_button(uint32_t widget_id)
Add a focusable button widget bound to widget_id.
int host_view_canvas_draw_pixel(int16_t x, int16_t y)
Draw a single pixel.
int host_view_canvas_draw_circle(int16_t x, int16_t y, int16_t r, bool filled)
Draw a circle outline or filled circle of radius r centred at (x, y).
int host_view_canvas_marquee(int16_t x, int16_t y, int16_t window_w, const char *text, uint16_t step_px, uint16_t frame_ms)
Record a host-driven text marquee (ticker).
int host_view_canvas_set_focus(uint32_t widget_id)
Move keyboard focus to the given widget.
int host_view_canvas_get_text(uint32_t widget_id, char *out, size_t cap)
Read the text of a text-input widget.
int host_view_canvas_set_text_size(uint8_t size)
Set text size multiplier (Adafruit-GFX semantics).
int host_view_canvas_elem_get_offset(uint32_t elem_id, int16_t *ox, int16_t *oy)
Read an element's current replay offset.
int host_view_canvas_set_key_repeat(uint16_t initial_ms, uint16_t repeat_ms)
Configure key auto-repeat timing for the canvas.
int host_view_canvas_elem_get_bounds(uint32_t elem_id, int16_t *x, int16_t *y, uint16_t *w, uint16_t *h)
Bounding box of an element's recorded commands, offset applied.
int host_view_canvas_elem_end(void)
Stop recording draw calls into an element.
int host_view_canvas_draw_text_aligned(int16_t x, int16_t y, int16_t w, const char *text, uint8_t align)
Draw text within a horizontal box.
int host_view_canvas_set_footer(const char *hint)
Override the footer hint of the canvas.
int host_view_canvas_draw_text(int16_t x, int16_t y, const char *text)
Draw text at (x, y) using the current text size/colour.
int host_view_canvas_set_shade(uint8_t shade)
Set the fill ink for subsequent filled shapes (rect, circle, triangle).
int host_view_canvas_remove_widget(uint32_t widget_id)
Remove a widget previously added to the canvas.
int host_text_pick_font_that_fits(const char *text, int16_t max_width_px, const uint8_t *candidates, uint32_t count, uint8_t *out_font_id)
Pick the largest HOST_FONT_* whose rendered text fits within max_width_px. Candidates are evaluated i...
int host_view_canvas_add_text(uint32_t widget_id, uint16_t max_len, const char *initial)
Add a T9 text input widget bound to widget_id.
int host_view_canvas_set_text(uint32_t widget_id, const char *text)
Set the text of a text-input widget.
int host_view_canvas_elem_set_z(uint32_t elem_id, int8_t z)
Set an element's replay layer (z-order).
int host_view_canvas_draw_triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, bool filled)
Draw a triangle outline or filled triangle through three points.
int host_view_canvas_set_anim_policy(uint8_t refresh_policy, uint8_t max_fps)
Configure host-driven animation pacing for the current canvas.
int host_view_canvas_set_long_press_action(uint32_t action_id)
Set the action id fired on a canvas long-press.
int host_view_canvas_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
Draw a line between two points.
int host_view_canvas_set_value(uint32_t widget_id, int32_t value)
Set the integer value of a slider widget.
int host_view_canvas_get_body_size(uint16_t *w, uint16_t *h)
Read the drawable body region (excluding header/footer).
int host_view_canvas_commit(bool full_refresh)
Flush draw state to the panel.
int host_view_canvas_add_slider(uint32_t widget_id, int32_t min, int32_t max, int32_t initial, int32_t step)
Add an integer slider widget bound to widget_id.
int host_view_canvas_elem_clear(uint32_t elem_id)
Drop only an element's recorded draw commands, keeping the element.
int host_view_canvas_draw_sprite(int16_t x, int16_t y, uint32_t sprite)
Record a draw of a sprite's current frame at (x, y).
int host_display_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a rectangle outline.
bool host_display_is_busy(void)
True while the panel is processing a previous refresh.
int host_display_draw_pixel(int16_t x, int16_t y, uint16_t color)
Set a single pixel.
uint16_t host_display_get_backlight(void)
Current backlight level (0 when no display is available).
int host_display_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draw a line between two points.
uint16_t host_display_width(void)
Display width in pixels.
int host_display_set_backlight(uint16_t level)
Set the display backlight level (0 = off .. panel maximum, e.g. 1023). Applied live; NOT persisted to...
int host_display_flush(uint8_t refresh_mode)
Push the framebuffer to the panel using the given refresh mode.
int host_display_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle.
int host_display_draw_text(int16_t x, int16_t y, const char *text, uint8_t size, uint16_t color)
Draw text using the default GFX font.
uint16_t host_display_height(void)
Display height in pixels.
int host_display_clear(void)
Clear the framebuffer to background.
int host_ui_set_inactivity(uint32_t timeout_ms, uint32_t action_id)
Arm an inactivity timer for the plugin's current view.
int host_ui_pop(void)
Pop the topmost view.
int host_ui_set_view_lifecycle(uint32_t hide_action_id, uint32_t show_action_id)
Register hide/show callbacks for the plugin's current top view.
int host_ui_remove_list_item(uint16_t index)
Remove the list row at index (partial redraw).
int host_ui_acquire_exclusive(void)
Claim exclusive UI ownership (block other plugins from pushing views).
int host_ui_push_time(const char *title, uint8_t h, uint8_t m, uint32_t action_id)
Show a time-of-day picker.
int host_ui_repaint(void)
Force a repaint of the current view.
int host_ui_set_view_empty(const char *text)
Override the empty-state text shown by an empty list view.
int host_ui_push_message(const char *text, uint8_t icon, uint32_t duration_ms)
Show a blocking message view that auto-dismisses after duration_ms.
int host_ui_view_markdown(const uint8_t *data, uint32_t len)
Render and show Markdown from an in-memory (UTF-8) buffer. No capability required; the buffer is boun...
int host_ui_push_t9_input(const char *title, const char *initial, uint16_t max_len, uint32_t action_id)
Show a T9-style text entry.
int host_ui_push_date(const char *title, uint8_t d, uint8_t m, uint16_t y, uint32_t action_id)
Show a date picker.
int host_ui_push_info(const char *title, const char *body)
Show a scrollable info screen with title and body.
int host_ui_release_exclusive(void)
Release a previously acquired exclusive UI lock.
int host_ui_consume_input_text(char *out, size_t out_size)
Read text input committed by the most recent input view.
int host_ui_consume_input_int(int32_t *out)
Read integer input committed by the most recent input view.
int host_ui_push_context_menu(const char *title, const ui_item_t *items, uint16_t count, uint32_t select_action_id)
Show a context menu. At most 8 items (ContextMenuView::MAX_ITEMS); the menu is scrollable and shows 4...
int host_ui_push_confirm(const char *text, uint8_t icon, uint32_t action_id)
Show a Y/N confirmation.
int host_ui_push_slider(const char *title, int32_t min, int32_t max, int32_t init, int32_t step, const char *unit, uint32_t action_id)
Show an integer slider.
int host_ui_push_color_picker(uint8_t initial_r, uint8_t initial_g, uint8_t initial_b, uint32_t action_id)
Show an RGB color picker.
int host_ui_push_toast(const char *text, uint8_t icon, uint16_t duration_ms)
Show a transient toast overlay.
int host_ui_insert_list_item(uint16_t index, const ui_item_t *item)
Insert a list row at index (partial redraw).
int host_ui_push_pin_entry(const char *title, uint8_t max_len, uint8_t max_attempts, uint32_t action_id)
Show a numeric PIN entry.
int host_ui_pop_to_plugin(void)
Pop back to the plugin's first view.
int host_ui_push_list(const char *title, const ui_item_t *items, uint16_t count, uint32_t select_action_id, uint32_t menu_action_id)
Show a list view.
int host_ui_push_password(const char *title, const char *initial, uint16_t max_len, uint32_t action_id)
Show a password entry (masked T9).
int host_ui_update_list_item(uint16_t index, const ui_item_t *item)
Update one list row in place (partial redraw).
int host_ui_view_image(const uint8_t *data, uint32_t len)
Decode and show an image (PNG/JPEG) from an in-memory buffer, dithered. No capability required; the b...
int host_ui_wink(uint8_t count, uint16_t period_ms)
Blink the backlight as a visual identification signal.
int host_ui_replace_list(const char *title, const ui_item_t *items, uint16_t count, uint32_t select_action_id, uint32_t menu_action_id)
Replace the plugin's top list view in place; falls back to push when none.
int host_ui_set_view_footer(const char *hint)
Override the footer hint of the plugin's current top view.
int host_browser_open(const char *url)
Open a URL in the badge browser (enters the browser and loads it). No capability required.
int host_usb_cdc_write(const uint8_t *data, size_t len)
Write raw bytes to the USB-CDC TX stream.
int host_vcard_received_count(void)
Number of received vCards in the store.
int host_vcard_received_add(const char *vcard, size_t len)
Store a new received vCard.
int host_vcard_received_display(uint16_t index, char *out, size_t out_size)
Copy the display name of the received vCard at sorted position index into out (for list rows).
int host_vcard_set_own(const char *vcard, size_t len)
Set / replace the badge's own vCard.
int host_vcard_received_update(uint16_t index, const char *vcard, size_t len)
Overwrite the received vCard at sorted position index.
int host_vcard_get_own(char *out, size_t out_size)
Copy the badge's own vCard text into out.
int host_vcard_received_delete(uint16_t index)
Delete the received vCard at sorted position index.
int host_vcard_received_get(uint16_t index, char *out, size_t out_size)
Copy the received vCard at sorted position index into out.
int host_fs_view_markdown(const char *name)
Render and show one of the plugin's own Markdown files in the scrollable text viewer.
int host_fs_view_image(const char *name)
Decode and show one of the plugin's own image files (PNG/JPEG) on the e-paper, dithered and scaled to...
int host_fs_view(const char *name)
Open one of the plugin's own files in a scrollable on-screen text viewer (same as opening the file in...
int host_fs_size(const char *name, size_t *out)
Write the byte size of name to *out.
int host_fs_read(const char *name, uint8_t *buf, size_t *len)
Read name into buf.
int host_fs_remove(const char *name)
Delete name.
int host_fs_write(const char *name, const uint8_t *data, size_t len)
Create or overwrite name with len bytes.
int host_fs_list(char *out, size_t *out_len)
Enumerate the plugin's own files.
bool host_wifi_scan_done(void)
True when the scan started by host_wifi_start_scan has finished.
int host_wifi_scan_results(wifi_scan_result_t *out, size_t *count)
Read results from the last completed scan.
int host_wifi_mac(uint8_t out[6])
Read the station MAC address.
int host_wifi_request(uint32_t timeout_ms)
Request the shared WiFi radio and wait up to timeout_ms for join.
int host_wifi_ip(char *out, size_t out_size)
Copy the current IPv4 address as dotted decimal into out.
bool host_wifi_is_connected(void)
True when WiFi STA is associated and has an IP.
int host_wifi_release(void)
Release the WiFi radio held by this plugin.
int8_t host_wifi_rssi(void)
Current AP signal strength in dBm.
int host_wifi_start_scan(void)
Start an asynchronous WiFi scan.
int host_wifi_ssid(char *out, size_t out_size)
Copy the currently joined SSID into out.
One characteristic of a plugin GATT service (peripheral role).
Definition host_api.h:534
uint32_t write_action_id
Definition host_api.h:538
uint8_t uuid[16]
Definition host_api.h:535
uint32_t char_handle
Definition host_api.h:539
uint8_t properties
Definition host_api.h:536
uint8_t reserved[3]
Definition host_api.h:537
One characteristic discovered on a connected peer (central role).
Definition host_api.h:559
uint16_t value_handle
Definition host_api.h:561
uint8_t uuid[16]
Definition host_api.h:560
uint8_t properties
Definition host_api.h:562
One device from a central scan.
Definition host_api.h:551
uint8_t addr_type
Definition host_api.h:553
uint8_t addr[6]
Definition host_api.h:552
A plugin GATT service definition (peripheral role). Always primary.
Definition host_api.h:543
uint8_t uuid[16]
Definition host_api.h:544
uint32_t service_handle
Definition host_api.h:547
uint8_t reserved[3]
Definition host_api.h:546
uint8_t num_chars
Definition host_api.h:545
Tween description for host_anim_start(); zero-init unused fields.
Definition host_api.h:1500
int16_t to_y
Definition host_api.h:1505
uint16_t delay_ms
Definition host_api.h:1507
int16_t from_x
Definition host_api.h:1502
uint32_t start_after
Definition host_api.h:1514
uint32_t done_action_id
Definition host_api.h:1512
uint8_t easing
Definition host_api.h:1510
int16_t from_y
Definition host_api.h:1503
uint8_t flags
Definition host_api.h:1511
uint16_t duration_ms
Definition host_api.h:1506
uint16_t repeat
Definition host_api.h:1508
uint32_t elem_id
Definition host_api.h:1501
int16_t to_x
Definition host_api.h:1504
uint8_t weekday
Definition host_api.h:89
uint8_t minute
Definition host_api.h:87
uint16_t year
Definition host_api.h:83
uint8_t hour
Definition host_api.h:86
uint8_t month
Definition host_api.h:84
uint8_t day
Definition host_api.h:85
uint8_t second
Definition host_api.h:88
uint8_t icon
Definition host_api.h:825
uint32_t item_id
Definition host_api.h:827
bool icon_disabled
Definition host_api.h:826
const char * label
Definition host_api.h:824
uint8_t bssid[6]
Definition host_api.h:476