@typecad/framework-zephyr 1.0.0-alpha.14 → 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 (185) hide show
  1. package/README.md +22 -47
  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/esp32s3.js +49 -0
  10. package/dist/chips/index.d.ts +6 -12
  11. package/dist/chips/index.js +18 -34
  12. package/dist/chips/resolve.d.ts +16 -2
  13. package/dist/chips/resolve.js +267 -10
  14. package/dist/chips/soc/.d.ts +2 -0
  15. package/dist/chips/soc/.js +129 -0
  16. package/dist/chips/soc/esp32.d.ts +2 -0
  17. package/dist/chips/soc/esp32.js +120 -0
  18. package/dist/chips/soc/esp32c3.d.ts +2 -0
  19. package/dist/chips/soc/esp32c3.js +90 -0
  20. package/dist/chips/soc/esp32c6.d.ts +2 -0
  21. package/dist/chips/soc/esp32c6.js +109 -0
  22. package/dist/chips/soc/esp32s3.d.ts +2 -0
  23. package/dist/chips/soc/esp32s3.js +189 -0
  24. package/dist/chips/soc/index.d.ts +2 -0
  25. package/dist/chips/soc/index.js +23 -0
  26. package/dist/chips/soc/nrf52840.d.ts +2 -0
  27. package/dist/chips/soc/nrf52840.js +130 -0
  28. package/dist/chips/soc/rp2040.d.ts +2 -0
  29. package/dist/chips/soc/rp2040.js +141 -0
  30. package/dist/chips/soc/rp2350a.d.ts +2 -0
  31. package/dist/chips/soc/rp2350a.js +145 -0
  32. package/dist/chips/soc/samd21g18a.d.ts +2 -0
  33. package/dist/chips/soc/samd21g18a.js +143 -0
  34. package/dist/chips/soc/stm32f411xe.d.ts +2 -0
  35. package/dist/chips/soc/stm32f411xe.js +251 -0
  36. package/dist/chips/types.d.ts +319 -0
  37. package/dist/chips/xiao-ble.js +21 -0
  38. package/dist/display/profiles.js +1 -1
  39. package/dist/doctor.js +38 -4
  40. package/dist/dt-config/custom-board.d.ts +23 -0
  41. package/dist/dt-config/custom-board.js +227 -0
  42. package/dist/dt-config/kconfig.d.ts +72 -1
  43. package/dist/dt-config/kconfig.js +115 -26
  44. package/dist/dt-config/overlay.js +548 -28
  45. package/dist/framework.manifest.d.ts +3 -3
  46. package/dist/framework.manifest.js +122 -185
  47. package/dist/index.d.ts +4 -1
  48. package/dist/index.js +8 -2
  49. package/dist/lowering/adc.d.ts +20 -2
  50. package/dist/lowering/adc.js +121 -29
  51. package/dist/lowering/ble.js +31 -28
  52. package/dist/lowering/dac.js +9 -9
  53. package/dist/lowering/fs.js +18 -10
  54. package/dist/lowering/gpio.d.ts +2 -0
  55. package/dist/lowering/gpio.js +82 -5
  56. package/dist/lowering/http.js +39 -14
  57. package/dist/lowering/hwtimer.d.ts +4 -0
  58. package/dist/lowering/hwtimer.js +35 -10
  59. package/dist/lowering/i2c.js +46 -54
  60. package/dist/lowering/index.d.ts +5 -5
  61. package/dist/lowering/index.js +15 -16
  62. package/dist/lowering/interrupts.d.ts +22 -5
  63. package/dist/lowering/interrupts.js +104 -22
  64. package/dist/lowering/mqtt.js +3 -5
  65. package/dist/lowering/power.js +0 -4
  66. package/dist/lowering/preferences.js +49 -77
  67. package/dist/lowering/pulse.js +0 -31
  68. package/dist/lowering/pwm.d.ts +12 -1
  69. package/dist/lowering/pwm.js +78 -14
  70. package/dist/lowering/random.js +3 -3
  71. package/dist/lowering/sensor.d.ts +37 -0
  72. package/dist/lowering/sensor.js +119 -0
  73. package/dist/lowering/spi.d.ts +12 -0
  74. package/dist/lowering/spi.js +65 -40
  75. package/dist/lowering/thread.d.ts +14 -0
  76. package/dist/lowering/thread.js +55 -0
  77. package/dist/lowering/timing.js +20 -46
  78. package/dist/lowering/tone.js +16 -4
  79. package/dist/lowering/uart.d.ts +13 -0
  80. package/dist/lowering/uart.js +72 -51
  81. package/dist/lowering/usb.d.ts +34 -0
  82. package/dist/lowering/usb.js +206 -0
  83. package/dist/lowering/wdt.d.ts +1 -1
  84. package/dist/lowering/wdt.js +17 -7
  85. package/dist/lowering/wifi.d.ts +3 -2
  86. package/dist/lowering/wifi.js +97 -111
  87. package/dist/sdk/board-catalog-sync.d.ts +16 -0
  88. package/dist/sdk/board-catalog-sync.js +41 -0
  89. package/dist/sdk/board-data.generated.d.ts +2 -0
  90. package/dist/sdk/board-data.generated.js +4 -0
  91. package/dist/sdk/catalog-walker.d.ts +90 -0
  92. package/dist/sdk/catalog-walker.js +682 -0
  93. package/dist/sdk/dts-reader.d.ts +83 -0
  94. package/dist/sdk/dts-reader.js +596 -0
  95. package/dist/strategy.d.ts +136 -17
  96. package/dist/strategy.js +839 -222
  97. package/dist/toolchain/bossac-touch.d.ts +18 -0
  98. package/dist/toolchain/bossac-touch.js +88 -0
  99. package/dist/toolchain/compat.d.ts +2 -2
  100. package/dist/toolchain/compat.js +8 -3
  101. package/dist/toolchain/debug-config.d.ts +21 -26
  102. package/dist/toolchain/debug-config.js +211 -71
  103. package/dist/toolchain/env-check.d.ts +4 -4
  104. package/dist/toolchain/env-check.js +5 -5
  105. package/dist/toolchain/index.d.ts +66 -1
  106. package/dist/toolchain/index.js +650 -70
  107. package/dist/toolchain/scaffold.js +39 -7
  108. package/dist/toolchain/west-discover.d.ts +4 -0
  109. package/dist/toolchain/west-discover.js +17 -6
  110. package/installer/CHANGELOG.md +473 -0
  111. package/installer/README.md +328 -0
  112. package/installer/environment.yml +46 -0
  113. package/installer/etc/conda/activate.d/zephyr.bat +7 -0
  114. package/installer/etc/conda/activate.d/zephyr.ps1 +12 -0
  115. package/installer/etc/conda/activate.d/zephyr.sh +20 -0
  116. package/installer/etc/conda/deactivate.d/zephyr.bat +6 -0
  117. package/installer/etc/conda/deactivate.d/zephyr.ps1 +6 -0
  118. package/installer/etc/conda/deactivate.d/zephyr.sh +4 -0
  119. package/installer/install.mjs +580 -0
  120. package/installer/install.ps1 +619 -0
  121. package/installer/install.sh +310 -0
  122. package/installer/lib/detect-platform.sh +62 -0
  123. package/installer/lib/fetch-sdk.sh +304 -0
  124. package/installer/lib/init-workspace.sh +153 -0
  125. package/installer/lib/write-activation.sh +76 -0
  126. package/installer/patches/tfm-c-include-separators.patch +19 -0
  127. package/installer/patches/zephyr-tfm-nordic-zephyr-include.patch +24 -0
  128. package/installer/templates/project/.typecad/activate-zephyr.ps1 +31 -0
  129. package/installer/templates/project/.typecad/activate-zephyr.sh +31 -0
  130. package/installer/templates/project/.vscode/settings.json +30 -0
  131. package/installer/templates/project/README.md +58 -0
  132. package/installer/versions.env +110 -0
  133. package/package.json +15 -15
  134. package/src/as-built.ts +206 -0
  135. package/src/boardgen.ts +1428 -0
  136. package/src/chips/index.ts +35 -54
  137. package/src/chips/resolve.ts +285 -10
  138. package/src/chips/types.ts +325 -1
  139. package/src/display/profiles.ts +1 -1
  140. package/src/doctor.ts +110 -77
  141. package/src/dt-config/custom-board.ts +325 -0
  142. package/src/dt-config/kconfig.ts +165 -18
  143. package/src/dt-config/overlay.ts +537 -25
  144. package/src/framework.manifest.ts +123 -185
  145. package/src/index.ts +57 -41
  146. package/src/lowering/adc.ts +222 -118
  147. package/src/lowering/ble.ts +32 -28
  148. package/src/lowering/dac.ts +82 -82
  149. package/src/lowering/fs.ts +18 -10
  150. package/src/lowering/gpio.ts +242 -155
  151. package/src/lowering/http.ts +512 -488
  152. package/src/lowering/hwtimer.ts +139 -101
  153. package/src/lowering/i2c.ts +116 -126
  154. package/src/lowering/index.ts +91 -93
  155. package/src/lowering/interrupts.ts +113 -21
  156. package/src/lowering/mqtt.ts +3 -5
  157. package/src/lowering/preferences.ts +327 -354
  158. package/src/lowering/pwm.ts +167 -99
  159. package/src/lowering/random.ts +3 -3
  160. package/src/lowering/sensor.ts +155 -0
  161. package/src/lowering/spi.ts +164 -124
  162. package/src/lowering/thread.ts +63 -0
  163. package/src/lowering/timing.ts +46 -72
  164. package/src/lowering/uart.ts +73 -51
  165. package/src/lowering/usb.ts +221 -0
  166. package/src/lowering/wdt.ts +95 -84
  167. package/src/lowering/wifi.ts +97 -112
  168. package/src/sdk/board-catalog-sync.ts +62 -0
  169. package/src/strategy.ts +848 -237
  170. package/src/toolchain/bossac-touch.ts +112 -0
  171. package/src/toolchain/compat.ts +8 -3
  172. package/src/toolchain/debug-config.ts +666 -522
  173. package/src/toolchain/env-check.ts +9 -9
  174. package/src/toolchain/index.ts +1286 -645
  175. package/src/toolchain/scaffold.ts +38 -7
  176. package/src/toolchain/west-discover.ts +19 -6
  177. package/src/async/timer-polyfill.ts +0 -107
  178. package/src/chips/esp32.ts +0 -74
  179. package/src/chips/esp32s3.ts +0 -57
  180. package/src/chips/xiao-ble.ts +0 -82
  181. package/src/lowering/power.ts +0 -70
  182. package/src/lowering/pulse.ts +0 -93
  183. package/src/lowering/tone.ts +0 -60
  184. package/src/lowering/worker-backing.ts +0 -94
  185. package/src/lowering/worker.ts +0 -17
@@ -1,60 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Tone lowering — PWM-based square-wave generation
3
- //
4
- // tone is a convenience wrapper around PWM: a square wave at `frequency` Hz with
5
- // a 50% duty cycle. The lowering maps frequency → period (ns) and sets the PWM
6
- // channel to a 50% pulse. stop turns the output off (0% duty). The PWM spec is
7
- // resolved from the chip descriptor (pwm-led0 on the XIAO).
8
- //
9
- // An optional duration is honored by scheduling a stop via k_sleep in a detached
10
- // fashion — but the simple lowering is blocking (k_msleep(duration) then stop),
11
- // matching the synchronous Arduino tone() semantics. For non-blocking tone,
12
- // a workqueue would be needed (deferred).
13
- // ---------------------------------------------------------------------------
14
-
15
- import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
16
- import type { ZephyrChipDescriptor } from '../chips/types.js';
17
- import { lowerPwm, pwmDtAliasToken } from './pwm.js';
18
-
19
- /**
20
- * Resolve a HAL tone.* op to Zephyr C++ via PWM.
21
- * Returns `{ code }` for statement ops, `{ expression }` for value-returning ops.
22
- */
23
- export function lowerTone(
24
- op: HALOpIR,
25
- chip: ZephyrChipDescriptor,
26
- ): { code?: string; expression?: string } {
27
- const o = op as any;
28
-
29
- switch (op.operation) {
30
- case 'tone.play': {
31
- // period_ns = 1e9 / freq; pulse_ns = period / 2 (50% duty).
32
- // Build a fake pwm.write would need the spec var directly; emit the
33
- // pwm_set_dt call against the same spec var the PWM lowering uses.
34
- const spec = chip.pwm?.specs[0];
35
- if (!spec) {
36
- return { code: `/* tone.play(${o.frequency}): no PWM spec in chip descriptor */` };
37
- }
38
- const v = `__tc_pwm_${pwmDtAliasToken(spec)}`;
39
- const freq = o.frequency;
40
- const duration = o.duration;
41
- const setTone = `uint32_t __period = (${freq} > 0) ? (1000000000ULL / static_cast<uint64_t>(${freq})) : 0; pwm_set_dt(&${v}, __period, __period / 2);`;
42
- if (duration !== undefined) {
43
- // Blocking tone for the requested duration, then stop.
44
- return { code: `${setTone} k_msleep(${duration}); pwm_set_pulse_dt(&${v}, 0);` };
45
- }
46
- return { code: setTone };
47
- }
48
- case 'tone.stop': {
49
- const spec = chip.pwm?.specs[0];
50
- if (!spec) return { code: `/* tone.stop: no PWM spec */` };
51
- const v = `__tc_pwm_${pwmDtAliasToken(spec)}`;
52
- return { code: `pwm_set_pulse_dt(&${v}, 0);` };
53
- }
54
- default:
55
- throw new Error(
56
- `framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
57
- `Open an issue or use rawCpp() to emit it manually.`,
58
- );
59
- }
60
- }
@@ -1,94 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Zephyr worker-offload backing (system workqueue + counting semaphore)
3
- //
4
- // Supplies the spawn/signal/poll primitives that the shared worker_runtime
5
- // polyfill calls into, for Zephyr targets. This is the Zephyr-native analog of
6
- // the ESP32 FreeRTOS backing (framework-esp32/src/lowering/worker-backing.ts):
7
- //
8
- // ESP32 (FreeRTOS) Zephyr
9
- // ───────────────────────── ─────────────────────────────────────────
10
- // xTaskCreate + vTaskDelete k_work_submit to the system workqueue
11
- // xTaskNotifyGive (barrier) k_sem_give (kernel barrier)
12
- // ulTaskNotifyTake(0) k_sem_take(K_NO_WAIT)
13
- //
14
- // The worker runs on the system workqueue thread (a real kernel thread, not an
15
- // ISR), so it can execute a full function. Completion is signalled via a per-
16
- // slot counting semaphore given from workqueue thread context (k_sem_give is
17
- // safe from thread context — NOT k_sem_give from an ISR; workqueue handlers run
18
- // in thread context). k_sem provides the memory barrier the contract requires.
19
- //
20
- // IMPORTANT: the system workqueue has a fixed stack (CONFIG_SYSTEM_WORKQUEUE_
21
- // STACK_SIZE). The scaffold bumps it because heavy workers (TLS, sensor fusion)
22
- // overflow the default ~2 KB. Pin a large worker to a private workqueue if it
23
- // exceeds the system queue's stack.
24
- // ---------------------------------------------------------------------------
25
-
26
- import type { WorkerBacking } from "@typecad/cuttlefish/api/shared";
27
-
28
- export interface ZephyrWorkerBackingOptions {
29
- /** Initial count of each per-slot semaphore. Default 0 (empty). */
30
- initialSemCount?: number;
31
- }
32
-
33
- /**
34
- * Build the Zephyr (k_work + k_sem) worker backing.
35
- *
36
- * Per slot: a `struct k_work _work_<i>` and a `struct k_sem _done_sem_<i>`.
37
- * submit resets the semaphore and submits the work to the system workqueue;
38
- * the work handler runs the trampoline; the trampoline signals completion via
39
- * k_sem_give; done polls via k_sem_take(K_NO_WAIT).
40
- */
41
- export function buildZephyrWorkerBacking(
42
- _options: ZephyrWorkerBackingOptions = {},
43
- ): WorkerBacking {
44
- return {
45
- requiredIncludes: ['<zephyr/kernel.h>', '<zephyr/work/work.h>'],
46
-
47
- declarations: [
48
- `// Zephyr worker backing: per-slot work item + completion semaphore.`,
49
- `// Declared inside the typecad_worker namespace alongside the slots.`,
50
- ],
51
-
52
- slotDeclarations: (handleId, trampolineName) => {
53
- // Per-slot completion semaphore (given from workqueue thread context).
54
- // Declared before the trampoline so the trampoline's signalDoneExpr can
55
- // reference it. The trampoline itself is forward-declared by the shared
56
- // runtime above this block.
57
- return [
58
- `// Per-slot completion semaphore.`,
59
- `K_SEM_DEFINE(_done_sem_${handleId}, 0, 1);`,
60
- ``,
61
- `// Per-slot work item + handler. The handler forwards to the shared-`,
62
- `// runtime trampoline (which runs the submitted fn + signals the sem).`,
63
- `static void ${trampolineName}_work_handler(struct k_work* work) {`,
64
- ` (void)work;`,
65
- ` ${trampolineName}(nullptr);`,
66
- `}`,
67
- `K_WORK_DEFINE(_work_${handleId}, ${trampolineName}_work_handler);`,
68
- ];
69
- },
70
-
71
- spawnLines: (handleId, trampolineName, _waiterExpr) => {
72
- // The waiter field is unused on Zephyr (the semaphore IS the signal).
73
- // Reset the completion semaphore, then submit the work item to the
74
- // system workqueue. The work handler (bound via K_WORK_DEFINE above)
75
- // runs the shared-runtime trampoline.
76
- return [
77
- `(void)0; // waiter unused: k_sem is the signal`,
78
- `k_sem_reset(&_done_sem_${handleId});`,
79
- `(void)k_work_submit(&_work_${handleId}); // ${trampolineName} on sys workqueue`,
80
- ];
81
- },
82
-
83
- signalDoneExpr: (handleId) =>
84
- // Given from workqueue thread context (k_sem_give is thread-safe here).
85
- // k_sem provides the kernel memory barrier making the worker's outputs
86
- // visible to the consumer once k_sem_take succeeds.
87
- `k_sem_give(&_done_sem_${handleId})`,
88
-
89
- isDoneExpr: (handleId) =>
90
- // Non-blocking take; its barrier makes the worker's outputs safe to read.
91
- // The shared runtime fast-paths on the volatile done flag first.
92
- `(k_sem_take(&_done_sem_${handleId}, K_NO_WAIT) == 0)`,
93
- };
94
- }
@@ -1,17 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Zephyr worker-offload lowering
3
- //
4
- // Delegates the shared worker.* op contract to the cross-framework helper
5
- // lowerWorkerOp (worker-runtime.ts). The per-framework primitives are supplied
6
- // by the Zephyr worker backing (worker-backing.ts: k_work + k_sem), emitted via
7
- // the worker_runtime polyfill when the program uses worker.* ops. See the
8
- // Zephyr strategy's worker backing wiring + generateNativePolyfills.
9
- // ---------------------------------------------------------------------------
10
-
11
- import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
12
- import { lowerWorkerOp } from '@typecad/cuttlefish/api/shared';
13
-
14
- /** Resolve a HAL worker.* op to C++ against the shared __tc_worker contract. */
15
- export function lowerWorker(op: HALOpIR): { code?: string; expression?: string } | undefined {
16
- return lowerWorkerOp(op);
17
- }