@typecad/framework-zephyr 1.0.0-alpha.13 → 1.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +22 -35
  2. package/dist/as-built.d.ts +33 -0
  3. package/dist/as-built.js +188 -0
  4. package/dist/async/timer-polyfill.js +1 -1
  5. package/dist/boardgen.d.ts +128 -0
  6. package/dist/boardgen.js +1366 -0
  7. package/dist/chips/board-overrides.d.ts +7 -0
  8. package/dist/chips/board-overrides.js +11 -0
  9. package/dist/chips/controllers.d.ts +28 -8
  10. package/dist/chips/controllers.js +49 -12
  11. package/dist/chips/esp32s3.js +49 -0
  12. package/dist/chips/index.d.ts +6 -12
  13. package/dist/chips/index.js +18 -34
  14. package/dist/chips/resolve.d.ts +16 -2
  15. package/dist/chips/resolve.js +298 -15
  16. package/dist/chips/soc/.d.ts +2 -0
  17. package/dist/chips/soc/.js +129 -0
  18. package/dist/chips/soc/esp32.d.ts +2 -0
  19. package/dist/chips/soc/esp32.js +120 -0
  20. package/dist/chips/soc/esp32c3.d.ts +2 -0
  21. package/dist/chips/soc/esp32c3.js +90 -0
  22. package/dist/chips/soc/esp32c6.d.ts +2 -0
  23. package/dist/chips/soc/esp32c6.js +109 -0
  24. package/dist/chips/soc/esp32s3.d.ts +2 -0
  25. package/dist/chips/soc/esp32s3.js +189 -0
  26. package/dist/chips/soc/index.d.ts +2 -0
  27. package/dist/chips/soc/index.js +23 -0
  28. package/dist/chips/soc/nrf52840.d.ts +2 -0
  29. package/dist/chips/soc/nrf52840.js +130 -0
  30. package/dist/chips/soc/rp2040.d.ts +2 -0
  31. package/dist/chips/soc/rp2040.js +141 -0
  32. package/dist/chips/soc/rp2350a.d.ts +2 -0
  33. package/dist/chips/soc/rp2350a.js +145 -0
  34. package/dist/chips/soc/samd21g18a.d.ts +2 -0
  35. package/dist/chips/soc/samd21g18a.js +143 -0
  36. package/dist/chips/soc/stm32f411xe.d.ts +2 -0
  37. package/dist/chips/soc/stm32f411xe.js +251 -0
  38. package/dist/chips/types.d.ts +382 -12
  39. package/dist/chips/xiao-ble.js +33 -0
  40. package/dist/display/profiles.js +1 -1
  41. package/dist/doctor.js +38 -4
  42. package/dist/dt-config/custom-board.d.ts +23 -0
  43. package/dist/dt-config/custom-board.js +227 -0
  44. package/dist/dt-config/kconfig.d.ts +83 -1
  45. package/dist/dt-config/kconfig.js +116 -27
  46. package/dist/dt-config/overlay.js +623 -18
  47. package/dist/framework.manifest.d.ts +20 -30
  48. package/dist/framework.manifest.js +124 -178
  49. package/dist/index.d.ts +4 -1
  50. package/dist/index.js +8 -2
  51. package/dist/lowering/adc.d.ts +26 -5
  52. package/dist/lowering/adc.js +137 -31
  53. package/dist/lowering/ble.js +31 -28
  54. package/dist/lowering/dac.js +9 -9
  55. package/dist/lowering/fs.js +18 -10
  56. package/dist/lowering/gpio.d.ts +2 -0
  57. package/dist/lowering/gpio.js +90 -10
  58. package/dist/lowering/http.js +39 -14
  59. package/dist/lowering/hwtimer.d.ts +4 -0
  60. package/dist/lowering/hwtimer.js +35 -10
  61. package/dist/lowering/i2c.js +46 -54
  62. package/dist/lowering/index.d.ts +5 -5
  63. package/dist/lowering/index.js +15 -16
  64. package/dist/lowering/interrupts.d.ts +22 -5
  65. package/dist/lowering/interrupts.js +104 -22
  66. package/dist/lowering/mqtt.js +12 -6
  67. package/dist/lowering/power.js +0 -4
  68. package/dist/lowering/preferences.js +49 -77
  69. package/dist/lowering/pulse.js +5 -36
  70. package/dist/lowering/pwm.d.ts +32 -3
  71. package/dist/lowering/pwm.js +105 -17
  72. package/dist/lowering/random.js +3 -3
  73. package/dist/lowering/sensor.d.ts +37 -0
  74. package/dist/lowering/sensor.js +119 -0
  75. package/dist/lowering/spi.d.ts +12 -0
  76. package/dist/lowering/spi.js +65 -40
  77. package/dist/lowering/thread.d.ts +14 -0
  78. package/dist/lowering/thread.js +55 -0
  79. package/dist/lowering/timing.js +20 -46
  80. package/dist/lowering/tone.js +18 -5
  81. package/dist/lowering/uart.d.ts +13 -0
  82. package/dist/lowering/uart.js +72 -51
  83. package/dist/lowering/usb.d.ts +34 -0
  84. package/dist/lowering/usb.js +206 -0
  85. package/dist/lowering/wdt.d.ts +1 -1
  86. package/dist/lowering/wdt.js +17 -7
  87. package/dist/lowering/wifi.d.ts +3 -2
  88. package/dist/lowering/wifi.js +120 -111
  89. package/dist/sdk/board-catalog-sync.d.ts +16 -0
  90. package/dist/sdk/board-catalog-sync.js +41 -0
  91. package/dist/sdk/board-data.generated.d.ts +2 -0
  92. package/dist/sdk/board-data.generated.js +4 -0
  93. package/dist/sdk/catalog-walker.d.ts +90 -0
  94. package/dist/sdk/catalog-walker.js +682 -0
  95. package/dist/sdk/dts-reader.d.ts +83 -0
  96. package/dist/sdk/dts-reader.js +596 -0
  97. package/dist/strategy.d.ts +136 -17
  98. package/dist/strategy.js +881 -212
  99. package/dist/toolchain/bossac-touch.d.ts +18 -0
  100. package/dist/toolchain/bossac-touch.js +88 -0
  101. package/dist/toolchain/compat.d.ts +2 -2
  102. package/dist/toolchain/compat.js +8 -3
  103. package/dist/toolchain/debug-config.d.ts +21 -26
  104. package/dist/toolchain/debug-config.js +212 -72
  105. package/dist/toolchain/env-check.d.ts +4 -4
  106. package/dist/toolchain/env-check.js +5 -5
  107. package/dist/toolchain/index.d.ts +66 -1
  108. package/dist/toolchain/index.js +713 -58
  109. package/dist/toolchain/scaffold.d.ts +9 -0
  110. package/dist/toolchain/scaffold.js +84 -7
  111. package/dist/toolchain/west-discover.d.ts +8 -1
  112. package/dist/toolchain/west-discover.js +19 -6
  113. package/dist/toolchain/west-spawn.js +17 -5
  114. package/installer/CHANGELOG.md +473 -0
  115. package/installer/README.md +328 -0
  116. package/installer/environment.yml +46 -0
  117. package/installer/etc/conda/activate.d/zephyr.bat +7 -0
  118. package/installer/etc/conda/activate.d/zephyr.ps1 +12 -0
  119. package/installer/etc/conda/activate.d/zephyr.sh +20 -0
  120. package/installer/etc/conda/deactivate.d/zephyr.bat +6 -0
  121. package/installer/etc/conda/deactivate.d/zephyr.ps1 +6 -0
  122. package/installer/etc/conda/deactivate.d/zephyr.sh +4 -0
  123. package/installer/install.mjs +580 -0
  124. package/installer/install.ps1 +619 -0
  125. package/installer/install.sh +310 -0
  126. package/installer/lib/detect-platform.sh +62 -0
  127. package/installer/lib/fetch-sdk.sh +304 -0
  128. package/installer/lib/init-workspace.sh +153 -0
  129. package/installer/lib/write-activation.sh +76 -0
  130. package/installer/patches/tfm-c-include-separators.patch +19 -0
  131. package/installer/patches/zephyr-tfm-nordic-zephyr-include.patch +24 -0
  132. package/installer/templates/project/.typecad/activate-zephyr.ps1 +31 -0
  133. package/installer/templates/project/.typecad/activate-zephyr.sh +31 -0
  134. package/installer/templates/project/.vscode/settings.json +30 -0
  135. package/installer/templates/project/README.md +58 -0
  136. package/installer/versions.env +110 -0
  137. package/package.json +16 -16
  138. package/src/as-built.ts +206 -0
  139. package/src/boardgen.ts +1428 -0
  140. package/src/chips/controllers.ts +61 -12
  141. package/src/chips/index.ts +35 -54
  142. package/src/chips/resolve.ts +316 -14
  143. package/src/chips/types.ts +388 -13
  144. package/src/display/profiles.ts +1 -1
  145. package/src/doctor.ts +110 -77
  146. package/src/dt-config/custom-board.ts +325 -0
  147. package/src/dt-config/kconfig.ts +177 -19
  148. package/src/dt-config/overlay.ts +1058 -450
  149. package/src/framework.manifest.ts +125 -178
  150. package/src/index.ts +57 -41
  151. package/src/lowering/adc.ts +222 -102
  152. package/src/lowering/ble.ts +32 -28
  153. package/src/lowering/dac.ts +82 -82
  154. package/src/lowering/fs.ts +18 -10
  155. package/src/lowering/gpio.ts +242 -152
  156. package/src/lowering/http.ts +512 -488
  157. package/src/lowering/hwtimer.ts +139 -101
  158. package/src/lowering/i2c.ts +116 -126
  159. package/src/lowering/index.ts +91 -93
  160. package/src/lowering/interrupts.ts +113 -21
  161. package/src/lowering/mqtt.ts +12 -6
  162. package/src/lowering/preferences.ts +327 -354
  163. package/src/lowering/pwm.ts +167 -74
  164. package/src/lowering/random.ts +3 -3
  165. package/src/lowering/sensor.ts +155 -0
  166. package/src/lowering/spi.ts +164 -124
  167. package/src/lowering/thread.ts +63 -0
  168. package/src/lowering/timing.ts +46 -72
  169. package/src/lowering/uart.ts +73 -51
  170. package/src/lowering/usb.ts +221 -0
  171. package/src/lowering/wdt.ts +95 -84
  172. package/src/lowering/wifi.ts +120 -111
  173. package/src/sdk/board-catalog-sync.ts +62 -0
  174. package/src/strategy.ts +888 -229
  175. package/src/toolchain/bossac-touch.ts +112 -0
  176. package/src/toolchain/compat.ts +8 -3
  177. package/src/toolchain/debug-config.ts +666 -522
  178. package/src/toolchain/env-check.ts +9 -9
  179. package/src/toolchain/index.ts +765 -44
  180. package/src/toolchain/scaffold.ts +81 -7
  181. package/src/toolchain/west-discover.ts +334 -316
  182. package/src/toolchain/west-spawn.ts +17 -5
  183. package/src/async/timer-polyfill.ts +0 -107
  184. package/src/chips/esp32.ts +0 -74
  185. package/src/chips/esp32s3.ts +0 -57
  186. package/src/chips/xiao-ble.ts +0 -70
  187. package/src/lowering/power.ts +0 -70
  188. package/src/lowering/pulse.ts +0 -93
  189. package/src/lowering/tone.ts +0 -60
  190. package/src/lowering/worker-backing.ts +0 -94
  191. package/src/lowering/worker.ts +0 -17
@@ -1,7 +1,7 @@
1
1
  // ---------------------------------------------------------------------------
2
- // WiFi lowering — net_mgmt (connect/scan/radio) + conn_mgr monitor (L4 events)
2
+ // WiFi lowering — net_mgmt (join/scan/radio) + conn_mgr monitor (L4 events)
3
3
  //
4
- // Hybrid: the WiFi connect/disconnect/scan/radio-query requests go directly
4
+ // Hybrid: the WiFi join/disconnect/scan/radio-query requests go directly
5
5
  // through net_mgmt + wifi_mgmt.h (NET_REQUEST_WIFI_CONNECT/DISCONNECT/SCAN/...),
6
6
  // taking the iface admin-up with net_if_up first. IP-level connectivity is
7
7
  // still signaled by conn_mgr's monitoring layer (conn_mgr_monitor.c raises
@@ -23,8 +23,9 @@ function s(v) {
23
23
  *
24
24
  * State is driven by two net_mgmt event handlers:
25
25
  * - L4 connectivity (NET_EVENT_L4_CONNECTED/DISCONNECTED) → connected flag.
26
- * This reflects IP connectivity (post-DHCP), not just the WiFi link — the
27
- * events are raised by conn_mgr's monitoring layer (conn_mgr_monitor.c).
26
+ * This reflects IP connectivity (post-DHCP, or right after static IPv4
27
+ * facts are applied) — the events are raised by conn_mgr's monitoring
28
+ * layer (conn_mgr_monitor.c).
28
29
  * - WiFi scan (NET_EVENT_WIFI_SCAN_RESULT/SCAN_DONE) → scan_results pool.
29
30
  */
30
31
  export function wifiInitLines() {
@@ -35,12 +36,12 @@ export function wifiInitLines() {
35
36
  `// ── core (always needed when wifi.* is used) ────────────────────────────`,
36
37
  `// CUTTLEFISH_WIFI_CORE_BEGIN`,
37
38
  `// WiFi event callback signature (wifi.on_event). One slot per supported`,
38
- `// event — a second registration overwrites the first (matches framework-esp32).`,
39
+ `// event — a second registration overwrites the first.`,
39
40
  `typedef void (*__tc_wifi_cb_t)(void);`,
40
41
  ``,
41
42
  `// WiFi state. connected reflects IP connectivity (L4), not just link —`,
42
- `// connect takes the iface admin-up (net_if_up) and conn_mgr_monitor raises`,
43
- `// the L4 event once DHCP completes. is_connected polls this flag.`,
43
+ `// join takes the iface admin-up (net_if_up) and conn_mgr_monitor raises`,
44
+ `// the L4 event once DHCP completes (or the static-IPv4 facts are applied).`,
44
45
  `static struct {`,
45
46
  ` bool inited; // net_mgmt handlers registered + iface resolved`,
46
47
  ` bool connected; // set by NET_EVENT_L4_CONNECTED/DISCONNECTED`,
@@ -71,15 +72,15 @@ export function wifiInitLines() {
71
72
  ` __tc_wifi.connected = true;`,
72
73
  ` } else if (mgmt_event == NET_EVENT_L4_DISCONNECTED) {`,
73
74
  ` __tc_wifi.connected = false;`,
74
- ` // Defer on_disconnect via k_work_submit so the user callback (which`,
75
- ` // typically calls connectAsync) runs outside the net_mgmt event`,
76
- ` // chain. Calling NET_REQUEST_WIFI_CONNECT from within the disconnect`,
75
+ ` // Defer on_drop via k_work_submit so the user callback (which`,
76
+ ` // typically re-joins) runs outside the net_mgmt event chain.`,
77
+ ` // Calling NET_REQUEST_WIFI_CONNECT from within the disconnect`,
77
78
  ` // callback causes re-entrancy that prevents re-association.`,
78
79
  ` if (__tc_wifi.on_disconnect != nullptr) {`,
79
80
  ` (void)k_work_submit(&__tc_wifi.disconnect_work);`,
80
81
  ` }`,
81
82
  ` } else if (mgmt_event == NET_EVENT_IPV4_ADDR_ADD) {`,
82
- ` // DHCP assigned an IPv4 address — the true "got IP" signal. Fires`,
83
+ ` // An IPv4 address was assigned — the true "got IP" signal. Fires`,
83
84
  ` // after NET_EVENT_L4_CONNECTED on a successful DHCP join.`,
84
85
  ` if (__tc_wifi.on_connect != nullptr) __tc_wifi.on_connect();`,
85
86
  ` } else if (mgmt_event == NET_EVENT_WIFI_SCAN_RESULT) {`,
@@ -122,19 +123,45 @@ export function wifiInitLines() {
122
123
  ` }`,
123
124
  ` __tc_wifi.inited = true;`,
124
125
  `}`,
126
+ ``,
127
+ `// ── blocking-wait pump ───────────────────────────────────────────────────`,
128
+ `// Blocking wifi waits hold the main thread, which suspends the loop()-driven`,
129
+ `// ui_tick — a 15s association would freeze the display for its whole`,
130
+ `// duration. Each wait slice sleeps 20ms and, in the entry TU of a UI build`,
131
+ `// (the only TU carrying the ui_tick definition), pumps one frame so`,
132
+ `// animations and touch stay live during the wait. Constraint: do NOT call`,
133
+ `// join() from inside UI event handlers — that re-enters ui_tick mid-tick;`,
134
+ `// use joinStart() + linked() there.`,
135
+ `#ifdef CUTTLEFISH_ENTRY_UI_TU`,
136
+ `static void ui_tick(uint16_t deltaMs); // defined by the UI runtime header`,
137
+ `#endif`,
138
+ `static void __tc_wifi_wait_slice(uint32_t slice_ms) {`,
139
+ ` k_msleep(slice_ms);`,
140
+ `#ifdef CUTTLEFISH_ENTRY_UI_TU`,
141
+ ` static uint32_t last_ms = 0U;`,
142
+ ` uint32_t now_ms = k_uptime_get_32();`,
143
+ ` uint32_t delta = (last_ms != 0U) ? (now_ms - last_ms) : 0U;`,
144
+ ` if (delta > 250U) delta = 250U; // same clamp as the loop() tick injection`,
145
+ ` last_ms = now_ms;`,
146
+ ` ui_tick(static_cast<uint16_t>(delta));`,
147
+ `#endif`,
148
+ `}`,
125
149
  `// CUTTLEFISH_WIFI_CORE_END`,
126
150
  ``,
127
- `// ── connect / disconnect (net_mgmt — conn_mgr monitor supplies L4 events) ─`,
151
+ `// ── join / leave (net_mgmt — conn_mgr monitor supplies L4 events) ────────`,
128
152
  `// CUTTLEFISH_WIFI_CONNECT_BEGIN`,
129
153
  `// SSID/PSK are staged into static buffers (wifi_connect_req_params.ssid/psk`,
130
154
  `// are const uint8_t* — they point at caller-owned storage that must outlive`,
131
155
  `// the request), then net_if_up takes the iface admin-up and NET_REQUEST_WIFI_CONNECT`,
132
- `// is issued. conn_mgr_monitor raises the L4 event once DHCP completes.`,
156
+ `// is issued with the station's construction facts (security/band/channel).`,
157
+ `// conn_mgr_monitor raises the L4 event once DHCP completes.`,
133
158
  `static struct wifi_connect_req_params __tc_wifi_conn_params;`,
134
159
  `static uint8_t __tc_wifi_ssid_buf[33]; // SSID ≤32 + slack`,
135
160
  `static uint8_t __tc_wifi_psk_buf[64]; // PSK ≤63 + slack`,
136
161
  ``,
137
- `static void __tc_wifi_stage_creds(const char* ssid, const char* password) {`,
162
+ `static void __tc_wifi_stage_creds(const char* ssid, const char* password,`,
163
+ ` enum wifi_security_type security, int32_t channel,`,
164
+ ` enum wifi_frequency_bands band) {`,
138
165
  ` __tc_wifi_ensure_init();`,
139
166
  ` if (__tc_wifi.iface == nullptr) return;`,
140
167
  ` uint32_t ssid_len = strlen(ssid);`,
@@ -151,15 +178,16 @@ export function wifiInitLines() {
151
178
  ` } else {`,
152
179
  ` __tc_wifi_conn_params.psk_length = 0U;`,
153
180
  ` }`,
154
- ` __tc_wifi_conn_params.security = WIFI_SECURITY_TYPE_PSK;`,
155
- ` __tc_wifi_conn_params.channel = WIFI_CHANNEL_ANY;`,
156
- ` __tc_wifi_conn_params.band = WIFI_FREQ_BAND_2_4_GHZ;`,
157
- ` // Stage the connection request (wifi_connect). The L4 handler sets`,
158
- ` // \`connected\` once DHCP completes.`,
181
+ ` __tc_wifi_conn_params.security = security;`,
182
+ ` __tc_wifi_conn_params.channel = (channel > 0) ? static_cast<uint8_t>(channel) : WIFI_CHANNEL_ANY;`,
183
+ ` __tc_wifi_conn_params.band = band;`,
159
184
  ` (void)net_mgmt(NET_REQUEST_WIFI_CONNECT, __tc_wifi.iface,`,
160
185
  ` &__tc_wifi_conn_params, sizeof(__tc_wifi_conn_params));`,
161
186
  `}`,
162
187
  ``,
188
+ `// joinStart(): stage the association without waiting — poll linked() or`,
189
+ `// await join() in an async function (the async machinery splits it into`,
190
+ `// this + the is_connected poll).`,
163
191
  `static void __tc_wifi_connect_start(const char* ssid, const char* password) {`,
164
192
  ` __tc_wifi_ensure_init();`,
165
193
  ` if (__tc_wifi.iface == nullptr) {`,
@@ -167,20 +195,58 @@ export function wifiInitLines() {
167
195
  ` return;`,
168
196
  ` }`,
169
197
  ` net_if_up(__tc_wifi.iface);`,
170
- ` __tc_wifi_stage_creds(ssid, password);`,
198
+ ` __tc_wifi_stage_creds(ssid, password, WIFI_SECURITY_TYPE_PSK, 0, WIFI_FREQ_BAND_2_4_GHZ);`,
171
199
  ` __tc_wifi.connected = false;`,
172
200
  ` printk("tc-wifi: connecting to %s\\n", ssid);`,
173
201
  `}`,
174
202
  ``,
175
- `// CUTTLEFISH_WIFI_CONNECT_BLOCKING_BEGIN`,
176
- `static void __tc_wifi_connect(const char* ssid, const char* password, int32_t timeout_ms) {`,
177
- ` __tc_wifi_connect_start(ssid, password);`,
178
- ` // Block until the L4 handler signals connectivity or the deadline passes.`,
203
+ `// join(): the thin station verb — associate from the construction facts,`,
204
+ `// apply the optional static-IPv4 / power-save facts, then bounded-wait for`,
205
+ `// IP connectivity. Returns whether the link came up (boolean, no exceptions).`,
206
+ `static bool __tc_wifi_join(const char* ssid, const char* psk,`,
207
+ ` enum wifi_security_type security, int32_t channel,`,
208
+ ` enum wifi_frequency_bands band, int32_t timeout_ms,`,
209
+ ` bool ps_off, const char* ip_addr, const char* gateway,`,
210
+ ` const char* netmask) {`,
211
+ ` __tc_wifi_ensure_init();`,
212
+ ` if (__tc_wifi.iface == nullptr) {`,
213
+ ` printk("tc-wifi: no WiFi iface found\\n");`,
214
+ ` return false;`,
215
+ ` }`,
216
+ ` net_if_up(__tc_wifi.iface);`,
217
+ ` __tc_wifi_stage_creds(ssid, psk, security, channel, band);`,
218
+ ` __tc_wifi.connected = false;`,
219
+ ` if (ip_addr != nullptr && gateway != nullptr && netmask != nullptr) {`,
220
+ ` // Static IPv4 facts: stop DHCP, configure the address manually. The`,
221
+ ` // addr-add raises the events conn_mgr_monitor listens for, so`,
222
+ ` // \`connected\` flips without a lease.`,
223
+ ` net_dhcpv4_stop(__tc_wifi.iface);`,
224
+ ` struct in_addr addr = { 0 }, gw = { 0 }, mask = { 0 };`,
225
+ ` if (net_addr_pton(AF_INET, ip_addr, &addr) == 0`,
226
+ ` && net_addr_pton(AF_INET, netmask, &mask) == 0`,
227
+ ` && net_addr_pton(AF_INET, gateway, &gw) == 0) {`,
228
+ ` (void)net_if_ipv4_addr_add(__tc_wifi.iface, &addr, NET_ADDR_MANUAL, 0);`,
229
+ ` // set_netmask() is __deprecated on Zephyr >= 4.3 — the`,
230
+ ` // by-addr form carries the prefix it belongs to.`,
231
+ ` (void)net_if_ipv4_set_netmask_by_addr(__tc_wifi.iface, &addr, &mask);`,
232
+ ` (void)net_if_ipv4_set_gw(__tc_wifi.iface, &gw);`,
233
+ ` } else {`,
234
+ ` printk("tc-wifi: bad static ipv4 facts, falling back to DHCP\\n");`,
235
+ ` net_dhcpv4_start(__tc_wifi.iface);`,
236
+ ` }`,
237
+ ` }`,
238
+ ` if (ps_off) {`,
239
+ ` // WiFi.PS_OFF — disable the radio's modem sleep (wifi_ps_params).`,
240
+ ` struct wifi_ps_params ps = {}; // value-init: first member is an enum`,
241
+ ` ps.enabled = WIFI_PS_DISABLED;`,
242
+ ` (void)net_mgmt(NET_REQUEST_WIFI_PS_CONFIG, __tc_wifi.iface, &ps, sizeof(ps));`,
243
+ ` }`,
244
+ ` printk("tc-wifi: joining %s\\n", ssid);`,
179
245
  ` int32_t waited = 0;`,
180
- ` while (!__tc_wifi.connected && waited < timeout_ms) { k_msleep(100); waited += 100; }`,
181
- ` printk("tc-wifi: connect %s after %dms\\n", __tc_wifi.connected ? "ok" : "timeout", waited);`,
246
+ ` while (!__tc_wifi.connected && waited < timeout_ms) { __tc_wifi_wait_slice(20); waited += 20; }`,
247
+ ` printk("tc-wifi: join %s after %dms\\n", __tc_wifi.connected ? "ok" : "timeout", waited);`,
248
+ ` return __tc_wifi.connected;`,
182
249
  `}`,
183
- `// CUTTLEFISH_WIFI_CONNECT_BLOCKING_END`,
184
250
  ``,
185
251
  `static void __tc_wifi_disconnect(void) {`,
186
252
  ` __tc_wifi_ensure_init();`,
@@ -193,10 +259,6 @@ export function wifiInitLines() {
193
259
  ``,
194
260
  `// ── status / radio queries ───────────────────────────────────────────────`,
195
261
  `// CUTTLEFISH_WIFI_QUERY_BEGIN`,
196
- `static int32_t __tc_wifi_status(void) {`,
197
- ` return __tc_wifi.connected ? 3 : 0; // 3=Connected in the HAL status enum`,
198
- `}`,
199
- ``,
200
262
  `static const char* __tc_wifi_local_ip(void) {`,
201
263
  ` __tc_wifi_ensure_init();`,
202
264
  ` if (__tc_wifi.iface == nullptr || !__tc_wifi.connected) return "0.0.0.0";`,
@@ -223,7 +285,7 @@ export function wifiInitLines() {
223
285
  ` struct wifi_iface_status status = { 0 };`,
224
286
  ` (void)net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, __tc_wifi.iface,`,
225
287
  ` &status, sizeof(status));`,
226
- ` // Pack the 6 MAC bytes (status.bssid) into a uint64 (HAL returns a number).`,
288
+ ` // Pack the 6 MAC bytes (status.bssid) into a uint64 (the HAL returns a number).`,
227
289
  ` uint64_t m = 0;`,
228
290
  ` for (int32_t b = 0; b < 6; b++) { m = (m << 8) | static_cast<uint64_t>(status.bssid[b]); }`,
229
291
  ` return m;`,
@@ -241,7 +303,7 @@ export function wifiInitLines() {
241
303
  ``,
242
304
  `static void __tc_wifi_scan_blocking(void) {`,
243
305
  ` __tc_wifi_scan_start();`,
244
- ` while (__tc_wifi.scanning) { k_msleep(100); }`,
306
+ ` while (__tc_wifi.scanning) { __tc_wifi_wait_slice(20); }`,
245
307
  `}`,
246
308
  ``,
247
309
  `static const char* __tc_wifi_scan_ssid(int32_t i) {`,
@@ -267,62 +329,12 @@ export function wifiInitLines() {
267
329
  `}`,
268
330
  `// CUTTLEFISH_WIFI_SCAN_END`,
269
331
  ``,
270
- `// ── config ───────────────────────────────────────────────────────────────`,
271
- `// CUTTLEFISH_WIFI_CONFIG_BEGIN`,
272
- `// NOTE: wifi.set_tx_power is intentionally NOT lowered here. The Zephyr esp32`,
273
- `// WiFi driver owns esp_wifi_start/esp_wifi_connect, and calling`,
274
- `// esp_wifi_set_max_tx_power from this shim fights the driver for control of`,
275
- `// the radio (brownout). The compile-time PHY ceiling (ESP_PHY_MAX_WIFI_TX_POWER`,
276
- `// in ESP-IDF's components/esp_phy/Kconfig) is NOT sourced into Zephyr's Kconfig`,
277
- `// tree, so it cannot be lowered via prj.conf either (zephyr#45580). TX power`,
278
- `// stays at its default until a Zephyr-native surface exists.`,
279
- `static void __tc_wifi_set_hostname(const char* name) {`,
280
- ` // Best-effort: Zephyr has no net_if_set_hostname; the system hostname`,
281
- ` // comes from the hostname subsystem (net_hostname.h) + CONFIG_NET_HOSTNAME.`,
282
- ` // The interface name is set via net_if_set_name, which is not the same as`,
283
- ` // a DHCP hostname. No-op until the hostname subsystem is wired.`,
284
- ` (void)name;`,
285
- ` (void)__tc_wifi;`,
286
- `}`,
287
- ``,
288
- `// ── power save (NET_REQUEST_WIFI_PS_CONFIG) ─────────────────────────────`,
289
- `// wifi.set_power_save: HAL modes are "default" (enabled) / "none" (disabled).`,
290
- `// The Zephyr esp32 driver implements esp32_wifi_set_power_save, so this is a`,
291
- `// real net_mgmt request — not a no-op like set_hostname above.`,
292
- `static void __tc_wifi_set_power_save(const char* mode) {`,
293
- ` __tc_wifi_ensure_init();`,
294
- ` if (__tc_wifi.iface == nullptr) return;`,
295
- ` struct wifi_ps_params ps = { 0 };`,
296
- ` ps.type = WIFI_PS_PARAM_TYPE_ENABLED;`,
297
- ` // HAL mode "default" → power save on; "none" → off. (The full HAL surface`,
298
- ` // only exposes those two; deeper ps_mode/wakeup tuning isn't exposed.)`,
299
- ` bool on = (mode != nullptr && strcmp(mode, "none") != 0);`,
300
- ` ps.enabled = on ? WIFI_PS_ENABLED : WIFI_PS_DISABLED;`,
301
- ` (void)net_mgmt(NET_REQUEST_WIFI_PS_CONFIG, __tc_wifi.iface,`,
302
- ` &ps, sizeof(ps));`,
303
- `}`,
304
- ``,
305
- `// ── waits (block on the L4 connectivity flag) ───────────────────────────`,
306
- `// wifi.wait_connected / wait_disconnected: poll __tc_wifi.connected (set by`,
307
- `// the L4 net_mgmt handler) with a deadline. Same blocking pattern as`,
308
- `// __tc_wifi_connect.`,
309
- `static void __tc_wifi_wait_connected(int32_t timeout_ms) {`,
310
- ` __tc_wifi_ensure_init();`,
311
- ` int32_t waited = 0;`,
312
- ` while (!__tc_wifi.connected && waited < timeout_ms) { k_msleep(100); waited += 100; }`,
313
- `}`,
314
- ``,
315
- `static void __tc_wifi_wait_disconnected(void) {`,
316
- ` __tc_wifi_ensure_init();`,
317
- ` // No timeout in the HAL surface — block until the L4 handler clears the flag.`,
318
- ` while (__tc_wifi.connected) { k_msleep(100); }`,
319
- `}`,
320
- ``,
321
332
  `// ── AP mode (NET_REQUEST_WIFI_AP_ENABLE / DISABLE) ──────────────────────`,
322
- `// wifi.ap_start / ap_stop: bring the iface up as an AP. The esp32 driver's`,
323
- `// ap_enable takes the same struct as connect (ssid/psk/channel/security).`,
324
- `// hidden/maxClients/channel-after-start have no driver hook (see manifest) —`,
325
- `// only ssid/password/channel at start are honored.`,
333
+ `// CUTTLEFISH_WIFI_CONFIG_BEGIN`,
334
+ `// WiFiAP.start()/stop(): bring the iface up as an AP. The esp32 driver's`,
335
+ `// ap_enable takes the same struct as join (ssid/psk/channel/security).`,
336
+ `// hidden/maxClients have no driver hook — the thin WiFiAP facts carry only`,
337
+ `// what the driver honors.`,
326
338
  `static struct wifi_connect_req_params __tc_wifi_ap_params;`,
327
339
  `static uint8_t __tc_wifi_ap_ssid_buf[33];`,
328
340
  `static uint8_t __tc_wifi_ap_psk_buf[64];`,
@@ -373,15 +385,21 @@ export function wifiInitLines() {
373
385
  export function lowerWifi(op) {
374
386
  const o = op;
375
387
  switch (op.operation) {
376
- // ── Connection ──
377
- case 'wifi.connect':
378
- return { code: `__tc_wifi_connect(${s(o.ssid)}, ${s(o.password ?? 'nullptr')}, ${s(o.timeoutMs ?? 15000)});` };
388
+ // ── Station ──
389
+ case 'wifi.join': {
390
+ // Token Zephyr enum mapping (WiFi.OPEN/WPA2/WPA3/WPA2_WPA3).
391
+ const sec = Number(o.security ?? 1);
392
+ const secEnum = sec === 0 ? 'WIFI_SECURITY_TYPE_NONE'
393
+ : sec === 2 ? 'WIFI_SECURITY_TYPE_SAE'
394
+ : sec === 3 ? 'WIFI_SECURITY_TYPE_PSK_SAE'
395
+ : 'WIFI_SECURITY_TYPE_PSK';
396
+ const bandEnum = Number(o.band ?? 0) === 1 ? 'WIFI_FREQ_BAND_5_GHZ' : 'WIFI_FREQ_BAND_2_4_GHZ';
397
+ return { expression: `__tc_wifi_join(${s(o.ssid)}, ${o.psk != null ? s(o.psk) : 'nullptr'}, ${secEnum}, ${s(o.channel ?? 0)}, ${bandEnum}, ${s(o.timeoutMs ?? 15000)}, ${Number(o.ps ?? 0) !== 0 ? 'true' : 'false'}, ${o.ipAddr != null ? s(o.ipAddr) : 'nullptr'}, ${o.gateway != null ? s(o.gateway) : 'nullptr'}, ${o.netmask != null ? s(o.netmask) : 'nullptr'})` };
398
+ }
379
399
  case 'wifi.connect_start':
380
- return { code: `__tc_wifi_connect_start(${s(o.ssid)}, ${s(o.password ?? 'nullptr')});` };
400
+ return { code: `__tc_wifi_connect_start(${s(o.ssid)}, ${o.password != null ? s(o.password) : 'nullptr'});` };
381
401
  case 'wifi.disconnect':
382
402
  return { code: `__tc_wifi_disconnect();` };
383
- case 'wifi.status':
384
- return { expression: `__tc_wifi_status()` };
385
403
  case 'wifi.is_connected':
386
404
  return { expression: `(__tc_wifi.connected)` };
387
405
  case 'wifi.local_ip':
@@ -393,6 +411,8 @@ export function lowerWifi(op) {
393
411
  // ── Scan ──
394
412
  case 'wifi.scan':
395
413
  return { code: `__tc_wifi_scan_blocking();` };
414
+ // Async split of wifi.scan (synthesized by the async tier's netWaitInfo —
415
+ // no TS-facing method maps here). Kick without waiting; poll scan_done.
396
416
  case 'wifi.scan_start':
397
417
  return { code: `__tc_wifi_scan_start();` };
398
418
  case 'wifi.scan_done':
@@ -409,14 +429,9 @@ export function lowerWifi(op) {
409
429
  : '__tc_wifi_scan_channel';
410
430
  return { expression: `${helper}(${s(o.index ?? 0)})` };
411
431
  }
412
- // ── Config ──
413
- case 'wifi.set_hostname':
414
- return { code: `__tc_wifi_set_hostname(${s(o.name)});` };
415
- case 'wifi.set_power_save':
416
- // HAL modes are "default" (on) / "none" (off) — see the shim's note.
417
- return { code: `__tc_wifi_set_power_save(${s(o.mode)});` };
432
+ // ── Events ──
418
433
  case 'wifi.on_event': {
419
- // Event callbacks (wifi.on_event). 'disconnect' and 'connect' are supported.
434
+ // 'disconnect' and 'connect' are the supported events.
420
435
  if (o.event === 'disconnect') {
421
436
  return { code: `__tc_wifi.on_disconnect = ${s(o.handler)};` };
422
437
  }
@@ -425,11 +440,6 @@ export function lowerWifi(op) {
425
440
  }
426
441
  return undefined;
427
442
  }
428
- // ── Waits (block on the L4 connectivity flag) ──
429
- case 'wifi.wait_connected':
430
- return { code: `__tc_wifi_wait_connected(${s(o.timeoutMs ?? 15000)});` };
431
- case 'wifi.wait_disconnected':
432
- return { code: `__tc_wifi_wait_disconnected();` };
433
443
  // ── AP mode (esp32 driver: ap_enable/ap_disable wired; only ssid/psk/channel
434
444
  // honored — hidden/maxClients have no driver hook). ──
435
445
  case 'wifi.ap_start':
@@ -437,11 +447,10 @@ export function lowerWifi(op) {
437
447
  case 'wifi.ap_stop':
438
448
  return { code: `__tc_wifi_ap_stop();` };
439
449
  default:
440
- // Out of scope (genuinely not lowered): ap_client_count/ap_ip/ap_set_*,
441
- // credentials (save/connect_saved/clear), set_static_ip, set_auto_reconnect,
442
- // set_tx_power. Each has no driver/Kconfig hook on Zephyr — see the manifest's
443
- // per-op reasons. Return undefined so the resolver falls back and the
444
- // 'unsupported' declaration is honest (the validator probes these).
450
+ // Out of scope (genuinely not lowered): each remaining wifi.* kind has no
451
+ // driver/Kconfig hook on Zephyr — see the manifest's per-op reasons.
452
+ // Return undefined so the resolver falls back and the 'unsupported'
453
+ // declaration is honest (the validator probes these).
445
454
  return undefined;
446
455
  }
447
456
  }
@@ -0,0 +1,16 @@
1
+ import * as catalog from '@typecad/cuttlefish/board-catalog';
2
+ export type BoardCatalogSyncReport = catalog.BoardCatalogSyncReport;
3
+ export type BoardCatalogEnsureResult = catalog.BoardCatalogEnsureResult;
4
+ export type BoardCatalogOverlay = catalog.BoardCatalogOverlay;
5
+ export declare const GENERATOR_REV: number, isZephyrBase: typeof catalog.isZephyrBase, locateZephyrBaseCheap: typeof catalog.locateZephyrBaseCheap, overlayPathFor: typeof catalog.overlayPathFor, readBoardCatalogOverlayFile: typeof catalog.readBoardCatalogOverlayFile, loadBoardCatalogOverlay: typeof catalog.loadBoardCatalogOverlay, resetBoardCatalogOverlayCache: typeof catalog.resetBoardCatalogOverlayCache, isOverlayStale: typeof catalog.isOverlayStale, diffBoardCatalogs: typeof catalog.diffBoardCatalogs, boardRecordFingerprint: typeof catalog.boardRecordFingerprint, findBoardInCatalog: typeof catalog.findBoardInCatalog, activeBoardCatalog: typeof catalog.activeBoardCatalog, resetActiveBoardCatalog: typeof catalog.resetActiveBoardCatalog;
6
+ /** Sync with the full west discovery cascade behind it (the CLI's path):
7
+ * falls back through spawn-based discovery when the cheap fs probes find
8
+ * nothing. */
9
+ export declare function syncBoardCatalog(opts?: {
10
+ zephyrBase?: string;
11
+ }): catalog.BoardCatalogSyncReport;
12
+ /** The build-path pre-step: refresh a stale overlay before a regen
13
+ * (fs-only discovery — no spawns during builds). */
14
+ export declare function ensureFreshBoardCatalog(): catalog.BoardCatalogEnsureResult;
15
+ /** Locate a Zephyr tree by any means (spawn cascade included). */
16
+ export declare function locateZephyrBaseFull(): string | undefined;
@@ -0,0 +1,41 @@
1
+ // ---------------------------------------------------------------------------
2
+ // sdk/board-catalog-sync.ts — framework-side catalog orchestration.
3
+ //
4
+ // The catalog tooling (walker, overlay store, fs-only discovery) lives in
5
+ // @typecad/cuttlefish/board-catalog — the create flow needs it before any
6
+ // framework is installed. This module adds the one thing the framework owns
7
+ // — the full spawn-based west discovery cascade for an explicit
8
+ // `cuttlefish board sync` — and re-exports the store for the strategy's
9
+ // import surface.
10
+ // ----------------------------------------------------------------------------
11
+ import path from 'node:path';
12
+ import * as catalog from '@typecad/cuttlefish/board-catalog';
13
+ import { discoverWest } from '../toolchain/west-discover.js';
14
+ export const { GENERATOR_REV, isZephyrBase, locateZephyrBaseCheap, overlayPathFor, readBoardCatalogOverlayFile, loadBoardCatalogOverlay, resetBoardCatalogOverlayCache, isOverlayStale, diffBoardCatalogs, boardRecordFingerprint, findBoardInCatalog, activeBoardCatalog, resetActiveBoardCatalog, } = catalog;
15
+ /** Sync with the full west discovery cascade behind it (the CLI's path):
16
+ * falls back through spawn-based discovery when the cheap fs probes find
17
+ * nothing. */
18
+ export function syncBoardCatalog(opts = {}) {
19
+ if (opts.zephyrBase)
20
+ return catalog.syncBoardCatalog(opts);
21
+ const cheap = catalog.locateZephyrBaseCheap();
22
+ if (cheap)
23
+ return catalog.syncBoardCatalog({ zephyrBase: cheap });
24
+ const install = discoverWest();
25
+ const base = install?.zephyrBase && catalog.isZephyrBase(install.zephyrBase)
26
+ ? path.resolve(install.zephyrBase)
27
+ : undefined;
28
+ return catalog.syncBoardCatalog(base ? { zephyrBase: base } : {});
29
+ }
30
+ /** The build-path pre-step: refresh a stale overlay before a regen
31
+ * (fs-only discovery — no spawns during builds). */
32
+ export function ensureFreshBoardCatalog() {
33
+ return catalog.ensureFreshBoardCatalog();
34
+ }
35
+ /** Locate a Zephyr tree by any means (spawn cascade included). */
36
+ export function locateZephyrBaseFull() {
37
+ const install = discoverWest();
38
+ return install?.zephyrBase && catalog.isZephyrBase(install.zephyrBase)
39
+ ? path.resolve(install.zephyrBase)
40
+ : undefined;
41
+ }
@@ -0,0 +1,2 @@
1
+ export { BOARD_DATA } from '@typecad/cuttlefish/api/shared';
2
+ export type { BoardDataEntry } from '@typecad/cuttlefish/api/shared';
@@ -0,0 +1,4 @@
1
+ // The board data pack lives in cuttlefish (src/create/) so the scaffolder
2
+ // and the framework share one catalog. Re-exported here for boardgen + the
3
+ // existing sdk imports.
4
+ export { BOARD_DATA } from '@typecad/cuttlefish/api/shared';
@@ -0,0 +1,90 @@
1
+ import type { BoardDataEntry } from '@typecad/cuttlefish/api/shared';
2
+ /** Provenance of a walked catalog — pins it to the exact tree it describes. */
3
+ export interface BoardCatalogProvenance {
4
+ /** The Zephyr base directory the walk read (resolved). */
5
+ readonly zephyrBase: string;
6
+ /** VERSION file contents rendered 'MAJOR.MINOR.PATCH' (best-effort). */
7
+ readonly version: string;
8
+ /** Git HEAD of the tree when readable (best-effort; tarballs carry none). */
9
+ readonly gitHead?: string;
10
+ /** Boards-dir mtime (epoch ms) — the fallback change signal for git-less trees. */
11
+ readonly boardsMtimeMs: number;
12
+ /** ISO timestamp of the walk. */
13
+ readonly generatedAt: string;
14
+ /** Variant count, carried for quick display without loading `boards`. */
15
+ readonly variants: number;
16
+ }
17
+ /** A completed walk: records in boards/ directory order + provenance. */
18
+ export interface BoardCatalogWalkResult {
19
+ readonly boards: Readonly<Record<string, BoardDataEntry>>;
20
+ readonly provenance: BoardCatalogProvenance;
21
+ readonly stats: {
22
+ readonly variants: number;
23
+ readonly withFacts: number;
24
+ readonly failures: number;
25
+ };
26
+ }
27
+ /** board.yml soc lookup, both formats Zephyr ships:
28
+ * - legacy single-board (`board:` / top-level `socs:`): every soc listed
29
+ * under the socs: block → `uniqueSocs`;
30
+ * - multi-board directories (top-level `boards:` list — lyra_24_dvk,
31
+ * lyra_dvk, …): each entry carries its own socs; single-soc entries map
32
+ * board name → soc in `byName`. Multi-soc entries stay unmapped (their
33
+ * variant yamls carry qualified identifiers).
34
+ * `boardNames` lists every declared board name (the `boards:` entries and
35
+ * the legacy `board:` name) — the CONFIG_BOARD_<X> stem a variant's
36
+ * board.cmake guards its runner args with. */
37
+ export interface BoardYmlSocIndex {
38
+ readonly byName: ReadonlyMap<string, string>;
39
+ readonly uniqueSocs: readonly string[];
40
+ readonly boardNames: readonly string[];
41
+ }
42
+ /** Read board.yml's board→soc index (see BoardYmlSocIndex). */
43
+ export declare function boardYmlSocIndex(dir: string): BoardYmlSocIndex;
44
+ /** How the caller pins runner args to ONE variant of a shared board dir. */
45
+ export interface VariantPin {
46
+ /** CONFIG_BOARD stems to try in order: the board.yml entry name this
47
+ * target belongs to, then the full underscored target name. */
48
+ readonly boardConfigs?: readonly string[];
49
+ /** The target's soc segment ('nrf5340'). */
50
+ readonly soc?: string;
51
+ /** Qualifier segments after the soc ('cpunet', ['a53','smp']). */
52
+ readonly quals?: readonly string[];
53
+ }
54
+ export declare function boardProbeMethods(dir: string, variant?: VariantPin): BoardDataEntry['probeMethods'];
55
+ /** VERSION file → 'MAJOR.MINOR.PATCH' ('' when unreadable). */
56
+ export declare function zephyrVersionOf(zephyrBase: string): string;
57
+ /**
58
+ * Git HEAD of the tree, read straight off the filesystem (no git spawn —
59
+ * sync runs where git may be absent). Handles the plain clone (.git dir,
60
+ * HEAD → ref → loose ref or packed-refs) and the worktree/submodule form
61
+ * (.git file pointing at a gitdir). Best-effort: undefined when unreadable.
62
+ */
63
+ export declare function gitHeadOf(zephyrBase: string): string | undefined;
64
+ /** Every build target a board.yml declares, with the naming facts the
65
+ * synthesizer needs (board.yml-driven dirs ship NO per-variant yamls —
66
+ * nucleo_n657x0_q's sb target exists only as a board.yml entry). */
67
+ export interface BoardYmlTarget {
68
+ readonly identifier: string;
69
+ /** The board entry name the target belongs to (CONFIG_BOARD stem). */
70
+ readonly boardName: string;
71
+ readonly soc?: string;
72
+ /** Variant chain segments after the soc ('sb', ['a53','smp']). */
73
+ readonly chain: readonly string[];
74
+ readonly fullName?: string;
75
+ readonly vendor?: string;
76
+ }
77
+ /**
78
+ * Parse board.yml into its declared build targets, both shapes:
79
+ * multi-board (`boards:` list) and legacy (`board:` block), with socs and
80
+ * (nested) variants. Variant chains accumulate through nesting levels
81
+ * (board/soc/v1/v2).
82
+ */
83
+ export declare function boardYmlTargets(dir: string): BoardYmlTarget[];
84
+ /**
85
+ * Walk `<zephyrBase>/boards` and extract one record per board variant.
86
+ * Reader failures degrade to the base record (identifier/name/vendor/dts +
87
+ * probe methods) — a board whose DTS defeats the reader still resolves, it
88
+ * just carries no pin facts.
89
+ */
90
+ export declare function walkBoardCatalog(zephyrBase: string): BoardCatalogWalkResult;