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

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 (132) hide show
  1. package/LICENSE +202 -21
  2. package/README.md +49 -87
  3. package/dist/as-built.d.ts +2 -2
  4. package/dist/as-built.js +2 -2
  5. package/dist/boardgen.d.ts +1 -9
  6. package/dist/boardgen.js +228 -45
  7. package/dist/chips/types.d.ts +1 -1
  8. package/dist/debug-codegen.js +1 -1
  9. package/dist/display/touch-adapter.js +1 -1
  10. package/dist/display/ui-adapter.js +549 -549
  11. package/dist/doctor.js +4 -4
  12. package/dist/dt-config/custom-board.js +2 -2
  13. package/dist/dt-config/kconfig.js +18 -12
  14. package/dist/dt-config/overlay.d.ts +2 -2
  15. package/dist/dt-config/overlay.js +2 -2
  16. package/dist/framework.manifest.d.ts +3 -3
  17. package/dist/framework.manifest.js +10 -7
  18. package/dist/index.js +5 -5
  19. package/dist/licenses.d.ts +2 -2
  20. package/dist/licenses.js +8 -8
  21. package/dist/lowering/fs.js +1 -1
  22. package/dist/lowering/gpio.js +0 -32
  23. package/dist/lowering/http.js +264 -32
  24. package/dist/lowering/i2c.js +0 -8
  25. package/dist/lowering/interrupts.js +6 -0
  26. package/dist/lowering/mqtt.js +110 -8
  27. package/dist/lowering/usb.js +11 -11
  28. package/dist/lowering/wdt.js +2 -29
  29. package/dist/sdk/board-catalog-sync.d.ts +1 -3
  30. package/dist/sdk/board-catalog-sync.js +4 -10
  31. package/dist/strategy.d.ts +22 -44
  32. package/dist/strategy.js +152 -155
  33. package/dist/tmp-probe.d.ts +2 -0
  34. package/dist/tmp-probe.js +9 -0
  35. package/dist/toolchain/debug-config.d.ts +50 -90
  36. package/dist/toolchain/debug-config.js +241 -502
  37. package/dist/toolchain/env-check.d.ts +1 -3
  38. package/dist/toolchain/env-check.js +2 -7
  39. package/dist/toolchain/index.d.ts +65 -2
  40. package/dist/toolchain/index.js +432 -55
  41. package/dist/toolchain/runners.d.ts +16 -0
  42. package/dist/toolchain/runners.js +75 -0
  43. package/dist/toolchain/scaffold.d.ts +1 -1
  44. package/dist/toolchain/scaffold.js +12 -12
  45. package/dist/toolchain/west-discover.d.ts +6 -0
  46. package/dist/toolchain/west-discover.js +36 -13
  47. package/dist/toolchain/west-spawn.js +8 -2
  48. package/installer/README.md +328 -328
  49. package/installer/install.sh +2 -2
  50. package/installer/templates/project/.typecad/activate-zephyr.ps1 +1 -1
  51. package/installer/templates/project/.typecad/activate-zephyr.sh +1 -1
  52. package/installer/templates/project/.vscode/settings.json +1 -1
  53. package/installer/templates/project/README.md +2 -2
  54. package/package.json +5 -5
  55. package/src/as-built.ts +206 -206
  56. package/src/boardgen.ts +214 -48
  57. package/src/chips/types.ts +567 -567
  58. package/src/display/touch-adapter.ts +204 -204
  59. package/src/display/ui-adapter.ts +781 -781
  60. package/src/doctor.ts +4 -4
  61. package/src/dt-config/custom-board.ts +2 -2
  62. package/src/dt-config/kconfig.ts +18 -12
  63. package/src/dt-config/overlay.ts +1058 -1058
  64. package/src/framework.manifest.ts +538 -535
  65. package/src/index.ts +5 -5
  66. package/src/licenses.ts +425 -425
  67. package/src/lowering/fs.ts +135 -135
  68. package/src/lowering/gpio.ts +0 -33
  69. package/src/lowering/http.ts +264 -32
  70. package/src/lowering/i2c.ts +0 -9
  71. package/src/lowering/interrupts.ts +6 -0
  72. package/src/lowering/mqtt.ts +109 -8
  73. package/src/lowering/usb.ts +221 -221
  74. package/src/lowering/wdt.ts +2 -25
  75. package/src/sdk/board-catalog-sync.ts +4 -25
  76. package/src/strategy.ts +2265 -2309
  77. package/src/toolchain/debug-config.ts +264 -514
  78. package/src/toolchain/env-check.ts +279 -285
  79. package/src/toolchain/index.ts +1703 -1286
  80. package/src/toolchain/runners.ts +80 -0
  81. package/src/toolchain/scaffold.ts +296 -296
  82. package/src/toolchain/west-discover.ts +35 -13
  83. package/src/toolchain/west-spawn.ts +174 -168
  84. package/dist/async/timer-polyfill.d.ts +0 -10
  85. package/dist/async/timer-polyfill.js +0 -95
  86. package/dist/chips/board-overrides.d.ts +0 -7
  87. package/dist/chips/board-overrides.js +0 -11
  88. package/dist/chips/esp32.d.ts +0 -2
  89. package/dist/chips/esp32.js +0 -71
  90. package/dist/chips/esp32s3.d.ts +0 -2
  91. package/dist/chips/esp32s3.js +0 -103
  92. package/dist/chips/soc/.d.ts +0 -2
  93. package/dist/chips/soc/.js +0 -129
  94. package/dist/chips/soc/esp32.d.ts +0 -2
  95. package/dist/chips/soc/esp32.js +0 -120
  96. package/dist/chips/soc/esp32c3.d.ts +0 -2
  97. package/dist/chips/soc/esp32c3.js +0 -90
  98. package/dist/chips/soc/esp32c6.d.ts +0 -2
  99. package/dist/chips/soc/esp32c6.js +0 -109
  100. package/dist/chips/soc/esp32s3.d.ts +0 -2
  101. package/dist/chips/soc/esp32s3.js +0 -189
  102. package/dist/chips/soc/index.d.ts +0 -2
  103. package/dist/chips/soc/index.js +0 -23
  104. package/dist/chips/soc/nrf52840.d.ts +0 -2
  105. package/dist/chips/soc/nrf52840.js +0 -130
  106. package/dist/chips/soc/rp2040.d.ts +0 -2
  107. package/dist/chips/soc/rp2040.js +0 -141
  108. package/dist/chips/soc/rp2350a.d.ts +0 -2
  109. package/dist/chips/soc/rp2350a.js +0 -145
  110. package/dist/chips/soc/samd21g18a.d.ts +0 -2
  111. package/dist/chips/soc/samd21g18a.js +0 -143
  112. package/dist/chips/soc/stm32f411xe.d.ts +0 -2
  113. package/dist/chips/soc/stm32f411xe.js +0 -251
  114. package/dist/chips/xiao-ble.d.ts +0 -2
  115. package/dist/chips/xiao-ble.js +0 -100
  116. package/dist/lowering/power.d.ts +0 -9
  117. package/dist/lowering/power.js +0 -60
  118. package/dist/lowering/pulse.d.ts +0 -7
  119. package/dist/lowering/pulse.js +0 -51
  120. package/dist/lowering/tone.d.ts +0 -10
  121. package/dist/lowering/tone.js +0 -63
  122. package/dist/lowering/worker-backing.d.ts +0 -14
  123. package/dist/lowering/worker-backing.js +0 -79
  124. package/dist/lowering/worker.d.ts +0 -6
  125. package/dist/lowering/worker.js +0 -14
  126. package/dist/sdk/board-data.generated.d.ts +0 -2
  127. package/dist/sdk/board-data.generated.js +0 -4
  128. package/dist/sdk/catalog-walker.d.ts +0 -90
  129. package/dist/sdk/catalog-walker.js +0 -682
  130. package/dist/sdk/dts-reader.d.ts +0 -83
  131. package/dist/sdk/dts-reader.js +0 -596
  132. package/src/debug-codegen.ts +0 -207
@@ -1,63 +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
- import { findPwmSpec, pwmDtAliasToken } from './pwm.js';
15
- /**
16
- * The PWM spec a tone op drives: the op's own pin when it maps to a spec
17
- * (matrix chips — ESP32 LEDC — resolve any driven pad), else the board's
18
- * first spec (the aliased LED channel, e.g. pwm-led0 on the XIAO).
19
- */
20
- function toneSpec(chip, pin) {
21
- return (typeof pin === 'number' ? findPwmSpec(chip, pin) : undefined)
22
- ?? chip.pwm?.specs[0];
23
- }
24
- /**
25
- * Resolve a HAL tone.* op to Zephyr C++ via PWM.
26
- * Returns `{ code }` for statement ops, `{ expression }` for value-returning ops.
27
- */
28
- export function lowerTone(op, chip) {
29
- const o = op;
30
- switch (op.operation) {
31
- case 'tone.play': {
32
- // period_ns = 1e9 / freq; pulse_ns = period / 2 (50% duty).
33
- // Build a fake pwm.write would need the spec var directly; emit the
34
- // pwm_set_dt call against the same spec var the PWM lowering uses.
35
- const spec = toneSpec(chip, o.pin);
36
- if (!spec) {
37
- return { code: `/* tone.play(${o.frequency}): no PWM spec in chip descriptor */` };
38
- }
39
- const v = `__tc_pwm_${pwmDtAliasToken(spec)}`;
40
- const freq = o.frequency;
41
- const duration = o.duration;
42
- // Braced: two tone ops in one statement-scope (e.g. tone(440).for(50)
43
- // lowers tone.play + tone.play_for back-to-back) would otherwise
44
- // redeclare __period.
45
- const setTone = `{ uint32_t __period = (${freq} > 0) ? (1000000000ULL / static_cast<uint64_t>(${freq})) : 0; pwm_set_dt(&${v}, __period, __period / 2); }`;
46
- if (duration !== undefined) {
47
- // Blocking tone for the requested duration, then stop.
48
- return { code: `${setTone} k_msleep(${duration}); pwm_set_pulse_dt(&${v}, 0);` };
49
- }
50
- return { code: setTone };
51
- }
52
- case 'tone.stop': {
53
- const spec = toneSpec(chip, o.pin);
54
- if (!spec)
55
- return { code: `/* tone.stop: no PWM spec */` };
56
- const v = `__tc_pwm_${pwmDtAliasToken(spec)}`;
57
- return { code: `pwm_set_pulse_dt(&${v}, 0);` };
58
- }
59
- default:
60
- throw new Error(`framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
61
- `Open an issue or use rawCpp() to emit it manually.`);
62
- }
63
- }
@@ -1,14 +0,0 @@
1
- import type { WorkerBacking } from "@typecad/cuttlefish/api/shared";
2
- export interface ZephyrWorkerBackingOptions {
3
- /** Initial count of each per-slot semaphore. Default 0 (empty). */
4
- initialSemCount?: number;
5
- }
6
- /**
7
- * Build the Zephyr (k_work + k_sem) worker backing.
8
- *
9
- * Per slot: a `struct k_work _work_<i>` and a `struct k_sem _done_sem_<i>`.
10
- * submit resets the semaphore and submits the work to the system workqueue;
11
- * the work handler runs the trampoline; the trampoline signals completion via
12
- * k_sem_give; done polls via k_sem_take(K_NO_WAIT).
13
- */
14
- export declare function buildZephyrWorkerBacking(_options?: ZephyrWorkerBackingOptions): WorkerBacking;
@@ -1,79 +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
- * Build the Zephyr (k_work + k_sem) worker backing.
27
- *
28
- * Per slot: a `struct k_work _work_<i>` and a `struct k_sem _done_sem_<i>`.
29
- * submit resets the semaphore and submits the work to the system workqueue;
30
- * the work handler runs the trampoline; the trampoline signals completion via
31
- * k_sem_give; done polls via k_sem_take(K_NO_WAIT).
32
- */
33
- export function buildZephyrWorkerBacking(_options = {}) {
34
- return {
35
- requiredIncludes: ['<zephyr/kernel.h>', '<zephyr/work/work.h>'],
36
- declarations: [
37
- `// Zephyr worker backing: per-slot work item + completion semaphore.`,
38
- `// Declared inside the typecad_worker namespace alongside the slots.`,
39
- ],
40
- slotDeclarations: (handleId, trampolineName) => {
41
- // Per-slot completion semaphore (given from workqueue thread context).
42
- // Declared before the trampoline so the trampoline's signalDoneExpr can
43
- // reference it. The trampoline itself is forward-declared by the shared
44
- // runtime above this block.
45
- return [
46
- `// Per-slot completion semaphore.`,
47
- `K_SEM_DEFINE(_done_sem_${handleId}, 0, 1);`,
48
- ``,
49
- `// Per-slot work item + handler. The handler forwards to the shared-`,
50
- `// runtime trampoline (which runs the submitted fn + signals the sem).`,
51
- `static void ${trampolineName}_work_handler(struct k_work* work) {`,
52
- ` (void)work;`,
53
- ` ${trampolineName}(nullptr);`,
54
- `}`,
55
- `K_WORK_DEFINE(_work_${handleId}, ${trampolineName}_work_handler);`,
56
- ];
57
- },
58
- spawnLines: (handleId, trampolineName, _waiterExpr) => {
59
- // The waiter field is unused on Zephyr (the semaphore IS the signal).
60
- // Reset the completion semaphore, then submit the work item to the
61
- // system workqueue. The work handler (bound via K_WORK_DEFINE above)
62
- // runs the shared-runtime trampoline.
63
- return [
64
- `(void)0; // waiter unused: k_sem is the signal`,
65
- `k_sem_reset(&_done_sem_${handleId});`,
66
- `(void)k_work_submit(&_work_${handleId}); // ${trampolineName} on sys workqueue`,
67
- ];
68
- },
69
- signalDoneExpr: (handleId) =>
70
- // Given from workqueue thread context (k_sem_give is thread-safe here).
71
- // k_sem provides the kernel memory barrier making the worker's outputs
72
- // visible to the consumer once k_sem_take succeeds.
73
- `k_sem_give(&_done_sem_${handleId})`,
74
- isDoneExpr: (handleId) =>
75
- // Non-blocking take; its barrier makes the worker's outputs safe to read.
76
- // The shared runtime fast-paths on the volatile done flag first.
77
- `(k_sem_take(&_done_sem_${handleId}, K_NO_WAIT) == 0)`,
78
- };
79
- }
@@ -1,6 +0,0 @@
1
- import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
2
- /** Resolve a HAL worker.* op to C++ against the shared __tc_worker contract. */
3
- export declare function lowerWorker(op: HALOpIR): {
4
- code?: string;
5
- expression?: string;
6
- } | undefined;
@@ -1,14 +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
- import { lowerWorkerOp } from '@typecad/cuttlefish/api/shared';
11
- /** Resolve a HAL worker.* op to C++ against the shared __tc_worker contract. */
12
- export function lowerWorker(op) {
13
- return lowerWorkerOp(op);
14
- }
@@ -1,2 +0,0 @@
1
- export { BOARD_DATA } from '@typecad/cuttlefish/api/shared';
2
- export type { BoardDataEntry } from '@typecad/cuttlefish/api/shared';
@@ -1,4 +0,0 @@
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';
@@ -1,90 +0,0 @@
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;