@typecad/framework-zephyr 1.0.0-alpha.16 → 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 +239 -510
  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 +16 -2
  40. package/dist/toolchain/index.js +383 -35
  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 +262 -522
  78. package/src/toolchain/env-check.ts +279 -285
  79. package/src/toolchain/index.ts +1703 -1359
  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,207 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Zephyr debug code generator — printk-based debug output
3
- //
4
- // The Zephyr counterpart to framework-esp32/src/debug-codegen.ts. Zephyr's
5
- // minimal C++ config has no <iostream> (manifest: needsIostream=false,
6
- // stdlibSupport.hasIostream=false), so the GenericStrategy's std::cout fallback
7
- // used by the debug preprocessor would NOT compile. This module routes every
8
- // debug line through printk("...\n") — the always-available Zephyr console,
9
- // with no CONFIG_CONSOLE dependency — so `cuttlefish build --debug` produces
10
- // compiling output.
11
- //
12
- // The halt primitive is __tc_debug_wait_for_continue() (emitted in
13
- // ZephyrStrategy.shimLines when --debug is active): a k_console-input / busy
14
- // poll that yields to the scheduler so an unattended breakpoint does not trip
15
- // any watchdog. ENTER continues; 's' disables this breakpoint for the run.
16
- //
17
- // Used by ZephyrStrategy's generateDebug* overrides, dispatched by the
18
- // cuttlefish debug preprocessor (cuttlefish/src/debug/preprocessor.ts).
19
- // ---------------------------------------------------------------------------
20
-
21
- export interface CapturedVariable {
22
- name: string;
23
- isFunction?: boolean;
24
- /** Coarse C++ type category (inferred by the preprocessor without a checker). */
25
- cppType?: 'bool' | 'int' | 'long' | 'float' | 'string' | 'unknown';
26
- }
27
-
28
- export interface LogMessagePart {
29
- type: 'text' | 'variable';
30
- value: string;
31
- }
32
-
33
- /**
34
- * Generate the debug-mode banner. printk is always wired (Zephyr console), so
35
- * there is no init to perform — just confirm debug instrumentation is live.
36
- */
37
- export function generateZephyrInitCode(): string[] {
38
- return [
39
- `// === DEBUG: Zephyr console (printk) ===`,
40
- `printk("[TypeCAD] Debug Mode Active\\n");`,
41
- `// === END DEBUG INIT ===`,
42
- ``,
43
- ];
44
- }
45
-
46
- /**
47
- * Generate Zephyr code for a breakpoint.
48
- *
49
- * The halt is __tc_debug_wait_for_continue() (emitted in ZephyrStrategy.shimLines
50
- * under --debug): blocks until a byte arrives on the console, yielding to the
51
- * scheduler between polls. The user must have a console attached (`west serial`
52
- * or a terminal on the USB-CDC port); ENTER continues, 's' skips this breakpoint
53
- * for the rest of the run.
54
- *
55
- * When `breakpointId` is set, the whole halt block is wrapped in
56
- * `if (!__tc_bp_disabled_<id>)`, so a skipped breakpoint becomes a no-op until
57
- * reboot. The flag is `static` so it persists across loop() iterations.
58
- */
59
- export function generateZephyrBreakpointCode(
60
- fileName: string,
61
- lineNum: number,
62
- originalLine: string,
63
- variables: CapturedVariable[],
64
- normalizedCondition: string | undefined,
65
- breakpointId?: number,
66
- ): string[] {
67
- const lines: string[] = [];
68
- const hasDisableGuard = breakpointId !== undefined;
69
- // Each wrap level adds two spaces of indent: the disable guard (outermost)
70
- // then the condition (if any).
71
- const indent = ' ' + (hasDisableGuard ? ' ' : '') + (normalizedCondition ? ' ' : '');
72
-
73
- lines.push(` // === BREAKPOINT: ${fileName}:${lineNum} ===`);
74
-
75
- // Disable guard: a skipped breakpoint becomes a no-op until reboot. The
76
- // disable state lives in the framework's debug shim (a static registry keyed
77
- // by breakpointId) — NOT as a per-breakpoint declaration here, because the
78
- // transpiler mangles `static bool` declarations injected into the source.
79
- if (hasDisableGuard) {
80
- lines.push(` if (!__tc_bp_is_disabled(${breakpointId})) {`);
81
- }
82
-
83
- if (normalizedCondition) {
84
- lines.push(` ${hasDisableGuard ? ' ' : ''}if (${normalizedCondition}) {`);
85
- }
86
-
87
- lines.push(`${indent}printk("----------------------------------------\\n");`);
88
-
89
- const headerText = normalizedCondition
90
- ? `[BREAK] ${fileName}:${lineNum} (condition: ${escapeString(normalizedCondition)})`
91
- : `[BREAK] ${fileName}:${lineNum}`;
92
- lines.push(`${indent}printk("%s\\n", "${headerText}");`);
93
-
94
- lines.push(`${indent}printk(" %s\\n", "${escapeString(originalLine)}");`);
95
-
96
- if (variables.length > 0) {
97
- lines.push(`${indent}printk(" Variables:\\n");`);
98
- for (const v of variables) {
99
- if (v.isFunction) {
100
- lines.push(`${indent}printk(" - %s = [function]\\n", "${v.name}");`);
101
- } else {
102
- const { spec, arg } = formatSpecFor(v.name, v.cppType);
103
- lines.push(`${indent}printk(" - %s = ${spec}\\n", "${v.name}", ${arg});`);
104
- }
105
- }
106
- } else {
107
- lines.push(`${indent}printk(" (no variables in scope)\\n");`);
108
- }
109
-
110
- lines.push(`${indent}printk(" [ENTER: continue | s: skip this breakpoint]\\n");`);
111
- lines.push(`${indent}printk("----------------------------------------\\n");`);
112
-
113
- // Halt — block on console input, scheduler-yielding. 's' records this id as
114
- // disabled in the shim's registry. Pass -1 when no id (never disable).
115
- lines.push(`${indent}__tc_debug_wait_for_continue(${hasDisableGuard ? breakpointId : -1});`);
116
-
117
- if (normalizedCondition) {
118
- lines.push(` ${hasDisableGuard ? ' ' : ''}}`);
119
- }
120
-
121
- if (hasDisableGuard) {
122
- lines.push(` }`);
123
- }
124
-
125
- lines.push(` // === END BREAKPOINT ===`);
126
-
127
- return lines;
128
- }
129
-
130
- /**
131
- * Generate Zephyr code for a logpoint (logs a message without halting).
132
- */
133
- export function generateZephyrLogpointCode(
134
- fileName: string,
135
- lineNum: number,
136
- parts: LogMessagePart[],
137
- variables: CapturedVariable[],
138
- ): string[] {
139
- const lines: string[] = [];
140
-
141
- lines.push(` // === LOGPOINT: ${fileName}:${lineNum} ===`);
142
- lines.push(` printk("[LOG ${fileName}:${lineNum}] ");`);
143
-
144
- for (const part of parts) {
145
- if (part.type === 'text') {
146
- lines.push(` printk("${escapeString(part.value)}");`);
147
- } else {
148
- // variable part: only printable if it is a non-function value in scope.
149
- const match = variables.find((v) => v.name === part.value && !v.isFunction);
150
- if (match) {
151
- const { spec, arg } = formatSpecFor(match.name, match.cppType);
152
- lines.push(` printk("${spec}", ${arg});`);
153
- } else {
154
- lines.push(` printk("{${escapeString(part.value)}}"); // variable not in scope`);
155
- }
156
- }
157
- }
158
-
159
- lines.push(` printk("\\n");`);
160
- lines.push(` // === END LOGPOINT ===`);
161
-
162
- return lines;
163
- }
164
-
165
- /**
166
- * Escape a string for use inside printk("..."). Same rules as the ESP-IDF
167
- * generator: backslash, double-quote, newline, carriage return.
168
- */
169
- function escapeString(s: string): string {
170
- return s
171
- .replace(/\\/g, '\\\\')
172
- .replace(/"/g, '\\"')
173
- .replace(/\n/g, '\\n')
174
- .replace(/\r/g, '\\r');
175
- }
176
-
177
- /**
178
- * Pick a printk format specifier + argument expression for a debug variable.
179
- *
180
- * The debug preprocessor has no TypeChecker, so `cppType` is a coarse category
181
- * inferred from AST shape. For `unknown` we cast to `double` and use `%g` so
182
- * the generated printk always compiles for any numeric/bool variable. printk
183
- * supports the standard printf format specifiers.
184
- *
185
- * Returns `{ spec, arg }` where `spec` is the `%`-specifier substring to embed
186
- * in the format string and `arg` is the C++ argument expression.
187
- */
188
- function formatSpecFor(
189
- varName: string,
190
- cppType: CapturedVariable['cppType'],
191
- ): { spec: string; arg: string } {
192
- switch (cppType) {
193
- case 'bool':
194
- case 'int':
195
- return { spec: '%d', arg: varName };
196
- case 'long':
197
- return { spec: '%ld', arg: varName };
198
- case 'float':
199
- return { spec: '%g', arg: varName };
200
- case 'string':
201
- return { spec: '%s', arg: varName };
202
- case 'unknown':
203
- default:
204
- // Cast to double so printk compiles regardless of the real C++ type.
205
- return { spec: '%g', arg: `static_cast<double>(${varName})` };
206
- }
207
- }