@typecad/cuttlefish 0.1.0-alpha.2 → 1.0.0-alpha.10

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 (222) hide show
  1. package/README.md +10 -10
  2. package/dist/api/board-types.d.ts +1 -1
  3. package/dist/api/config.d.ts +32 -0
  4. package/dist/api/index.d.ts +1 -1
  5. package/dist/api/schema/types.d.ts +15 -0
  6. package/dist/api/shared/async-runtime-static.d.ts +12 -1
  7. package/dist/api/shared/async-runtime-static.js +69 -24
  8. package/dist/api/shared/async-symbol-detector.d.ts +11 -0
  9. package/dist/api/shared/async-symbol-detector.js +140 -0
  10. package/dist/api/shared/async-types.d.ts +24 -0
  11. package/dist/api/shared/coop-scheduler.d.ts +60 -0
  12. package/dist/api/shared/coop-scheduler.js +149 -0
  13. package/dist/api/shared/display-adapter.d.ts +4 -3
  14. package/dist/api/shared/display-adapter.js +15 -118
  15. package/dist/api/shared/display-adapters/sdl.js +38 -31
  16. package/dist/api/shared/display-profile.d.ts +47 -25
  17. package/dist/api/shared/display-profile.js +31 -164
  18. package/dist/api/shared/framework-manifest-registry.d.ts +9 -0
  19. package/dist/api/shared/framework-manifest-registry.js +27 -0
  20. package/dist/api/shared/framework-manifest.d.ts +595 -0
  21. package/dist/api/shared/framework-manifest.js +193 -0
  22. package/dist/api/shared/glcdfont.d.ts +12 -0
  23. package/dist/api/shared/glcdfont.js +124 -0
  24. package/dist/api/shared/graphics-strategy.d.ts +37 -0
  25. package/dist/api/shared/hal-op-ir.d.ts +764 -1
  26. package/dist/api/shared/hal-op-ir.js +129 -1
  27. package/dist/api/shared/index.d.ts +20 -2
  28. package/dist/api/shared/index.js +25 -1
  29. package/dist/api/shared/ir-core.d.ts +4 -0
  30. package/dist/api/shared/ir-declarations.d.ts +6 -0
  31. package/dist/api/shared/native-display-op-resolver.d.ts +10 -0
  32. package/dist/api/shared/native-display-op-resolver.js +64 -0
  33. package/dist/api/shared/platform-strategy.d.ts +119 -2
  34. package/dist/api/shared/polyfill-helper-registry.js +18 -1
  35. package/dist/api/shared/promise-runtime.d.ts +1 -1
  36. package/dist/api/shared/promise-runtime.js +95 -13
  37. package/dist/api/shared/toolchain-types.d.ts +17 -0
  38. package/dist/api/shared/types.d.ts +8 -0
  39. package/dist/api/shared/validate-framework-manifest.d.ts +28 -0
  40. package/dist/api/shared/validate-framework-manifest.js +494 -0
  41. package/dist/api/shared/worker-runtime-polyfill.d.ts +22 -0
  42. package/dist/api/shared/worker-runtime-polyfill.js +34 -0
  43. package/dist/api/shared/worker-runtime.d.ts +69 -0
  44. package/dist/api/shared/worker-runtime.js +163 -0
  45. package/dist/cli-utils.d.ts +1 -0
  46. package/dist/cli-utils.js +3 -1
  47. package/dist/cli.js +249 -32
  48. package/dist/config-loader.d.ts +7 -2
  49. package/dist/config-loader.js +23 -3
  50. package/dist/config-schema.d.ts +112 -70
  51. package/dist/config-schema.js +14 -0
  52. package/dist/contract/board-generator.d.ts +17 -0
  53. package/dist/contract/board-generator.js +57 -0
  54. package/dist/contract/contract-parser.d.ts +217 -0
  55. package/dist/contract/contract-parser.js +224 -0
  56. package/dist/contract/index.d.ts +22 -0
  57. package/dist/contract/index.js +68 -0
  58. package/dist/create/board-codegen.js +4 -4
  59. package/dist/create/board-generators.js +4 -5
  60. package/dist/create/board-spec.d.ts +72 -75
  61. package/dist/create/board-spec.js +0 -1
  62. package/dist/create/framework-catalog.d.ts +64 -0
  63. package/dist/create/framework-catalog.js +136 -0
  64. package/dist/create/index.d.ts +5 -1
  65. package/dist/create/index.js +3 -1
  66. package/dist/create/init-scaffold.d.ts +12 -3
  67. package/dist/create/init-scaffold.js +49 -14
  68. package/dist/create/init-templates.d.ts +4 -0
  69. package/dist/create/init-templates.js +263 -17
  70. package/dist/create/init-wizard.js +41 -27
  71. package/dist/create/install-deps.d.ts +32 -0
  72. package/dist/create/install-deps.js +46 -0
  73. package/dist/debug/preprocessor.js +178 -39
  74. package/dist/debug/types.d.ts +23 -0
  75. package/dist/diagnostics/mermaid-builder.d.ts +1 -1
  76. package/dist/diagnostics/mermaid-builder.js +34 -24
  77. package/dist/emit/compliance/arxml-writer.d.ts +11 -0
  78. package/dist/emit/compliance/arxml-writer.js +34 -0
  79. package/dist/emit/compliance/compliance-context.d.ts +57 -0
  80. package/dist/emit/compliance/compliance-context.js +113 -0
  81. package/dist/emit/compliance/deviation-ledger.d.ts +27 -0
  82. package/dist/emit/compliance/deviation-ledger.js +47 -0
  83. package/dist/emit/compliance/deviation-writer.d.ts +30 -0
  84. package/dist/emit/compliance/deviation-writer.js +37 -0
  85. package/dist/emit/compliance/index.d.ts +7 -0
  86. package/dist/emit/compliance/index.js +6 -0
  87. package/dist/emit/compliance/rule-engine.d.ts +13 -0
  88. package/dist/emit/compliance/rule-engine.js +101 -0
  89. package/dist/emit/compliance/rules.d.ts +16 -0
  90. package/dist/emit/compliance/rules.js +191 -0
  91. package/dist/emit/compliance/types.d.ts +59 -0
  92. package/dist/emit/compliance/types.js +8 -0
  93. package/dist/emit/cpp-emitter.js +4 -3
  94. package/dist/emit/emitters/class-emitter.js +6 -1
  95. package/dist/emit/emitters/emitter-context.d.ts +28 -1
  96. package/dist/emit/emitters/function-emitter-impl.js +153 -53
  97. package/dist/emit/emitters/line-appender.js +19 -0
  98. package/dist/emit/emitters/line-marker.d.ts +38 -0
  99. package/dist/emit/emitters/line-marker.js +39 -0
  100. package/dist/emit/emitters/output-finalizer.d.ts +6 -0
  101. package/dist/emit/emitters/output-finalizer.js +101 -12
  102. package/dist/emit/emitters/setup.d.ts +17 -0
  103. package/dist/emit/emitters/setup.js +372 -30
  104. package/dist/emit/emitters/top-level-prep.js +8 -0
  105. package/dist/emit/emitters/type-decl-emitter.js +28 -3
  106. package/dist/emit/emitters/ui-emitter.js +33 -9
  107. package/dist/emit/expression-renderer.d.ts +1 -1
  108. package/dist/emit/expression-renderer.js +91 -6
  109. package/dist/emit/route-hal-op.js +18 -5
  110. package/dist/emit/snprintf-helpers.js +15 -4
  111. package/dist/emit/statement-renderer.d.ts +10 -0
  112. package/dist/emit/statement-renderer.js +34 -5
  113. package/dist/emit/utils/async-state-machine.js +221 -125
  114. package/dist/emit/utils/hal-op-cpp-type.d.ts +6 -0
  115. package/dist/emit/utils/hal-op-cpp-type.js +40 -0
  116. package/dist/framework-package.js +2 -0
  117. package/dist/framework-registry.d.ts +17 -0
  118. package/dist/install/framework-catalog.d.ts +53 -0
  119. package/dist/install/framework-catalog.js +107 -0
  120. package/dist/install/handle-install.d.ts +35 -0
  121. package/dist/install/handle-install.js +177 -0
  122. package/dist/install/index.d.ts +4 -0
  123. package/dist/install/index.js +3 -0
  124. package/dist/ir/adc-range-validation.js +40 -26
  125. package/dist/ir/build-ir-state.d.ts +1 -0
  126. package/dist/ir/build-ir-state.js +14 -0
  127. package/dist/ir/build-ir.js +9 -5
  128. package/dist/ir/call-graph.js +16 -0
  129. package/dist/ir/expression-to-ir.js +207 -6
  130. package/dist/ir/feature-registry.js +7 -25
  131. package/dist/ir/function-builder.js +22 -0
  132. package/dist/ir/hal/hal-emitter.d.ts +5 -2
  133. package/dist/ir/hal/hal-emitter.js +50 -18
  134. package/dist/ir/hal/hal-parser.d.ts +6 -0
  135. package/dist/ir/hal/hal-parser.js +81 -0
  136. package/dist/ir/hal/hal-plugins.js +733 -1
  137. package/dist/ir/identifier-collector.js +35 -0
  138. package/dist/ir/interrupt-analysis.d.ts +5 -1
  139. package/dist/ir/interrupt-analysis.js +16 -19
  140. package/dist/ir/memory-budget-validation.js +1 -0
  141. package/dist/ir/network-validation.d.ts +4 -0
  142. package/dist/ir/network-validation.js +184 -0
  143. package/dist/ir/ownership-analysis.js +39 -1
  144. package/dist/ir/peripheral-ownership.js +5 -0
  145. package/dist/ir/peripheral-validation.d.ts +1 -1
  146. package/dist/ir/peripheral-validation.js +6 -3
  147. package/dist/ir/pin-alias-conflict.d.ts +1 -1
  148. package/dist/ir/pin-alias-conflict.js +2 -1
  149. package/dist/ir/pin-capability-validation.js +71 -32
  150. package/dist/ir/pin-mode-validation.d.ts +2 -2
  151. package/dist/ir/pin-mode-validation.js +54 -18
  152. package/dist/ir/pin-safety.d.ts +1 -1
  153. package/dist/ir/pin-safety.js +2 -1
  154. package/dist/ir/program-analysis.d.ts +81 -0
  155. package/dist/ir/program-analysis.js +429 -0
  156. package/dist/ir/pulldown-validation.d.ts +1 -1
  157. package/dist/ir/pulldown-validation.js +2 -1
  158. package/dist/ir/pwm-timer-sharing.d.ts +1 -1
  159. package/dist/ir/pwm-timer-sharing.js +2 -1
  160. package/dist/ir/render-expr.js +11 -0
  161. package/dist/ir/resource-analysis.js +2 -0
  162. package/dist/ir/timer0-pwm-timing-conflict.d.ts +1 -1
  163. package/dist/ir/timer0-pwm-timing-conflict.js +2 -1
  164. package/dist/ir/timing-validation.d.ts +6 -1
  165. package/dist/ir/timing-validation.js +61 -13
  166. package/dist/ir/transformers/call-statement.js +105 -0
  167. package/dist/ir/transformers/expressions.js +62 -0
  168. package/dist/ir/transformers/hal-call-resolver.js +21 -0
  169. package/dist/ir/transformers/hal-emit-helpers.js +1 -1
  170. package/dist/ir/transformers/namespace-methods.js +17 -12
  171. package/dist/ir/transformers/ui-reactive.js +2 -2
  172. package/dist/ir/transformers/variables.js +137 -19
  173. package/dist/ir/try-catch-validation.js +2 -0
  174. package/dist/ir/type-resolution.js +20 -2
  175. package/dist/ir/ui-element-auto-wire.js +7 -5
  176. package/dist/ir/unit-suspicion-validation.js +9 -7
  177. package/dist/ir/utils/map-statements.d.ts +4 -0
  178. package/dist/ir/utils/map-statements.js +79 -0
  179. package/dist/ir/validation-orchestrator.js +15 -8
  180. package/dist/ir/worker-analysis.d.ts +10 -0
  181. package/dist/ir/worker-analysis.js +261 -0
  182. package/dist/libdef/c-to-decl.d.ts +27 -0
  183. package/dist/libdef/c-to-decl.js +397 -0
  184. package/dist/libdef/component-decls.d.ts +2 -0
  185. package/dist/libdef/component-decls.js +6 -0
  186. package/dist/libdef/component-discovery.d.ts +43 -0
  187. package/dist/libdef/component-discovery.js +83 -0
  188. package/dist/libdef/cpp-to-decl.d.ts +9 -0
  189. package/dist/libdef/cpp-to-decl.js +72 -0
  190. package/dist/libdef/registry.js +5 -2
  191. package/dist/lint-cache.d.ts +59 -0
  192. package/dist/lint-cache.js +257 -0
  193. package/dist/orchestrator/graph-builder.js +14 -9
  194. package/dist/platform/coop-scheduler-runtime.d.ts +19 -0
  195. package/dist/platform/coop-scheduler-runtime.js +41 -0
  196. package/dist/platform/generic-strategy.d.ts +15 -3
  197. package/dist/platform/generic-strategy.js +49 -4
  198. package/dist/safety/safety-bridge.d.ts +11 -0
  199. package/dist/safety/safety-bridge.js +48 -0
  200. package/dist/safety/sidecar-bridge.d.ts +5 -0
  201. package/dist/safety/sidecar-bridge.js +22 -0
  202. package/dist/safety-hook.d.ts +79 -0
  203. package/dist/safety-hook.js +35 -0
  204. package/dist/testing.d.ts +8 -2
  205. package/dist/testing.js +9 -2
  206. package/dist/transpile.d.ts +3 -0
  207. package/dist/transpile.js +191 -49
  208. package/dist/types.d.ts +22 -3
  209. package/dist/ui-hook.d.ts +17 -3
  210. package/dist/utils/cli.js +122 -2
  211. package/dist/utils/fs.d.ts +13 -0
  212. package/dist/utils/fs.js +50 -0
  213. package/dist/utils/ui.js +3 -1
  214. package/package.json +23 -3
  215. package/dist/api/shared/display-adapters/eink-mono.d.ts +0 -2
  216. package/dist/api/shared/display-adapters/eink-mono.js +0 -53
  217. package/dist/api/shared/display-adapters/ssd1309.d.ts +0 -2
  218. package/dist/api/shared/display-adapters/ssd1309.js +0 -136
  219. package/dist/api/shared/display-adapters/st7796.d.ts +0 -2
  220. package/dist/api/shared/display-adapters/st7796.js +0 -132
  221. package/dist/ir/heap-array-validation.d.ts +0 -24
  222. package/dist/ir/heap-array-validation.js +0 -29
@@ -297,6 +297,9 @@ export function parseConfigFile(configPath) {
297
297
  const framework = flat.get("framework");
298
298
  if (typeof framework === "string")
299
299
  resolved.framework = framework;
300
+ const psram = flat.get("psram");
301
+ if (psram === "opi" || psram === "quad")
302
+ resolved.psram = psram;
300
303
  const outputFramework = flat.get("output.framework");
301
304
  if (typeof outputFramework === "string")
302
305
  resolved.outputFramework = outputFramework;
@@ -323,8 +326,20 @@ export function parseConfigFile(configPath) {
323
326
  if (outputDefines)
324
327
  resolved.outputDefines = outputDefines;
325
328
  const nativeSection = extractFrameworkSection(configObject, "native");
326
- if (nativeSection)
329
+ if (nativeSection) {
327
330
  resolved.frameworkConfig = nativeSection;
331
+ }
332
+ // Parse zephyr-specific config section.
333
+ const zephyrKconfig = extractStringRecord(configObject, ["zephyr", "kconfig"]);
334
+ const zephyrCmakeArgs = extractStringArray(configObject, ["zephyr", "cmakeArgs"]);
335
+ const zephyrRunner = flat.get("zephyr.runner");
336
+ if (zephyrKconfig || zephyrCmakeArgs || typeof zephyrRunner === "string") {
337
+ resolved.zephyrConfig = {
338
+ ...(zephyrKconfig ? { kconfig: zephyrKconfig } : {}),
339
+ ...(zephyrCmakeArgs ? { cmakeArgs: zephyrCmakeArgs } : {}),
340
+ ...(typeof zephyrRunner === "string" ? { runner: zephyrRunner } : {}),
341
+ };
342
+ }
328
343
  // Parse display profile config (nested object with profile name, wiring, touch)
329
344
  const displaySection = extractFrameworkSection(configObject, "display");
330
345
  if (displaySection)
@@ -344,6 +359,8 @@ export function parseConfigFile(configPath) {
344
359
  structuredForValidation.entry = resolved.entry;
345
360
  if (resolved.framework)
346
361
  structuredForValidation.framework = resolved.framework;
362
+ if (resolved.psram)
363
+ structuredForValidation.psram = resolved.psram;
347
364
  if (resolved.outputFramework || resolved.outputOptimize || resolved.outputOutDir || resolved.outputExtraFlags || resolved.outputDefines) {
348
365
  structuredForValidation.output = {
349
366
  ...(resolved.outputFramework ? { framework: resolved.outputFramework } : {}),
@@ -355,6 +372,8 @@ export function parseConfigFile(configPath) {
355
372
  }
356
373
  if (resolved.console)
357
374
  structuredForValidation.console = resolved.console;
375
+ if (resolved.zephyrConfig)
376
+ structuredForValidation.zephyr = resolved.zephyrConfig;
358
377
  if (resolved.buildTarget) {
359
378
  structuredForValidation.frameworkData = { buildTarget: resolved.buildTarget };
360
379
  }
@@ -478,8 +497,9 @@ export function generateVirtualTypeDeclaration(config, platformDeclarations) {
478
497
  // `declare module` in cuttlefish-env.d.ts is treated as module augmentation
479
498
  // (because that file has `export {}`), which can't define a new module.
480
499
  //
481
- // For contract-based configs, board.ts is generated by the board-codegen
482
- // system, so don't overwrite it here.
500
+ // For contract-based configs, the narrowed board.ts is generated by the
501
+ // contract reader (`contract/board-generator.ts`, invoked from cli.ts before
502
+ // this function runs), so don't overwrite it with the generic re-export here.
483
503
  if (!config.contract && (config.board || config.mcu)) {
484
504
  const reExportSource = config.board ?? config.mcu;
485
505
  const boardTsPath = path.join(cuttlefishDir, "board.ts");
@@ -11,6 +11,11 @@ export declare const CuttlefishConfigSchema: z.ZodEffects<z.ZodObject<{
11
11
  board: z.ZodOptional<z.ZodString>;
12
12
  contract: z.ZodOptional<z.ZodString>;
13
13
  framework: z.ZodOptional<z.ZodString>;
14
+ /** ESP32 PSRAM type. When set, the framework emits the PSRAM-enabling
15
+ * Kconfig/define so canvas allocations prefer external RAM (large scroll
16
+ * viewports/lists stop failing on PSRAM targets). No effect on boards
17
+ * without PSRAM (the runtime falls back to SRAM then the band renderer). */
18
+ psram: z.ZodOptional<z.ZodEnum<["opi", "quad"]>>;
14
19
  output: z.ZodOptional<z.ZodObject<{
15
20
  framework: z.ZodOptional<z.ZodString>;
16
21
  optimize: z.ZodOptional<z.ZodEnum<["none", "size", "speed", "balanced"]>>;
@@ -19,14 +24,14 @@ export declare const CuttlefishConfigSchema: z.ZodEffects<z.ZodObject<{
19
24
  extraFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
20
25
  }, "strict", z.ZodTypeAny, {
21
26
  framework?: string | undefined;
27
+ optimize?: "none" | "size" | "speed" | "balanced" | undefined;
22
28
  outDir?: string | undefined;
23
- optimize?: "size" | "none" | "speed" | "balanced" | undefined;
24
29
  defines?: Record<string, string> | undefined;
25
30
  extraFlags?: string[] | undefined;
26
31
  }, {
27
32
  framework?: string | undefined;
33
+ optimize?: "none" | "size" | "speed" | "balanced" | undefined;
28
34
  outDir?: string | undefined;
29
- optimize?: "size" | "none" | "speed" | "balanced" | undefined;
30
35
  defines?: Record<string, string> | undefined;
31
36
  extraFlags?: string[] | undefined;
32
37
  }>>;
@@ -41,19 +46,19 @@ export declare const CuttlefishConfigSchema: z.ZodEffects<z.ZodObject<{
41
46
  buildTarget: z.ZodOptional<z.ZodString>;
42
47
  board: z.ZodOptional<z.ZodString>;
43
48
  }, "strict", z.ZodTypeAny, {
44
- buildTarget?: string | undefined;
45
- port?: string | undefined;
46
49
  board?: string | undefined;
47
- baudRate?: number | undefined;
48
50
  include?: string[] | undefined;
51
+ port?: string | undefined;
52
+ baudRate?: number | undefined;
49
53
  timeout?: number | undefined;
50
- }, {
51
54
  buildTarget?: string | undefined;
52
- port?: string | undefined;
55
+ }, {
53
56
  board?: string | undefined;
54
- baudRate?: number | undefined;
55
57
  include?: string[] | undefined;
58
+ port?: string | undefined;
59
+ baudRate?: number | undefined;
56
60
  timeout?: number | undefined;
61
+ buildTarget?: string | undefined;
57
62
  }>>;
58
63
  toolchain: z.ZodOptional<z.ZodObject<{
59
64
  type: z.ZodOptional<z.ZodString>;
@@ -76,141 +81,178 @@ export declare const CuttlefishConfigSchema: z.ZodEffects<z.ZodObject<{
76
81
  baudRate?: number | undefined;
77
82
  }>>;
78
83
  native: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
84
+ zephyr: z.ZodOptional<z.ZodObject<{
85
+ kconfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
86
+ cmakeArgs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
87
+ runner: z.ZodOptional<z.ZodString>;
88
+ }, "strict", z.ZodTypeAny, {
89
+ kconfig?: Record<string, string> | undefined;
90
+ cmakeArgs?: string[] | undefined;
91
+ runner?: string | undefined;
92
+ }, {
93
+ kconfig?: Record<string, string> | undefined;
94
+ cmakeArgs?: string[] | undefined;
95
+ runner?: string | undefined;
96
+ }>>;
79
97
  }, "strict", z.ZodTypeAny, {
80
- console?: {
81
- port?: string | undefined;
82
- baudRate?: number | undefined;
83
- } | undefined;
84
- frameworkData?: Record<string, unknown> | undefined;
98
+ entry?: string | undefined;
85
99
  target?: string | undefined;
100
+ mcu?: string | undefined;
101
+ board?: string | undefined;
102
+ contract?: string | undefined;
86
103
  framework?: string | undefined;
87
- native?: Record<string, unknown> | undefined;
104
+ psram?: "opi" | "quad" | undefined;
88
105
  output?: {
89
106
  framework?: string | undefined;
107
+ optimize?: "none" | "size" | "speed" | "balanced" | undefined;
90
108
  outDir?: string | undefined;
91
- optimize?: "size" | "none" | "speed" | "balanced" | undefined;
92
109
  defines?: Record<string, string> | undefined;
93
110
  extraFlags?: string[] | undefined;
94
111
  } | undefined;
95
- board?: string | undefined;
96
- mcu?: string | undefined;
112
+ frameworkData?: Record<string, unknown> | undefined;
97
113
  include?: string[] | undefined;
98
- entry?: string | undefined;
99
- toolchain?: {
100
- type?: string | undefined;
101
- frameworkOptions?: Record<string, unknown> | undefined;
102
- } | undefined;
103
- contract?: string | undefined;
104
114
  exclude?: string[] | undefined;
105
115
  test?: {
106
- buildTarget?: string | undefined;
107
- port?: string | undefined;
108
116
  board?: string | undefined;
109
- baudRate?: number | undefined;
110
117
  include?: string[] | undefined;
118
+ port?: string | undefined;
119
+ baudRate?: number | undefined;
111
120
  timeout?: number | undefined;
121
+ buildTarget?: string | undefined;
122
+ } | undefined;
123
+ toolchain?: {
124
+ type?: string | undefined;
125
+ frameworkOptions?: Record<string, unknown> | undefined;
112
126
  } | undefined;
113
- }, {
114
127
  console?: {
115
128
  port?: string | undefined;
116
129
  baudRate?: number | undefined;
117
130
  } | undefined;
118
- frameworkData?: Record<string, unknown> | undefined;
131
+ native?: Record<string, unknown> | undefined;
132
+ zephyr?: {
133
+ kconfig?: Record<string, string> | undefined;
134
+ cmakeArgs?: string[] | undefined;
135
+ runner?: string | undefined;
136
+ } | undefined;
137
+ }, {
138
+ entry?: string | undefined;
119
139
  target?: string | undefined;
140
+ mcu?: string | undefined;
141
+ board?: string | undefined;
142
+ contract?: string | undefined;
120
143
  framework?: string | undefined;
121
- native?: Record<string, unknown> | undefined;
144
+ psram?: "opi" | "quad" | undefined;
122
145
  output?: {
123
146
  framework?: string | undefined;
147
+ optimize?: "none" | "size" | "speed" | "balanced" | undefined;
124
148
  outDir?: string | undefined;
125
- optimize?: "size" | "none" | "speed" | "balanced" | undefined;
126
149
  defines?: Record<string, string> | undefined;
127
150
  extraFlags?: string[] | undefined;
128
151
  } | undefined;
129
- board?: string | undefined;
130
- mcu?: string | undefined;
152
+ frameworkData?: Record<string, unknown> | undefined;
131
153
  include?: string[] | undefined;
132
- entry?: string | undefined;
133
- toolchain?: {
134
- type?: string | undefined;
135
- frameworkOptions?: Record<string, unknown> | undefined;
136
- } | undefined;
137
- contract?: string | undefined;
138
154
  exclude?: string[] | undefined;
139
155
  test?: {
140
- buildTarget?: string | undefined;
141
- port?: string | undefined;
142
156
  board?: string | undefined;
143
- baudRate?: number | undefined;
144
157
  include?: string[] | undefined;
158
+ port?: string | undefined;
159
+ baudRate?: number | undefined;
145
160
  timeout?: number | undefined;
161
+ buildTarget?: string | undefined;
162
+ } | undefined;
163
+ toolchain?: {
164
+ type?: string | undefined;
165
+ frameworkOptions?: Record<string, unknown> | undefined;
146
166
  } | undefined;
147
- }>, {
148
167
  console?: {
149
168
  port?: string | undefined;
150
169
  baudRate?: number | undefined;
151
170
  } | undefined;
152
- frameworkData?: Record<string, unknown> | undefined;
171
+ native?: Record<string, unknown> | undefined;
172
+ zephyr?: {
173
+ kconfig?: Record<string, string> | undefined;
174
+ cmakeArgs?: string[] | undefined;
175
+ runner?: string | undefined;
176
+ } | undefined;
177
+ }>, {
178
+ entry?: string | undefined;
153
179
  target?: string | undefined;
180
+ mcu?: string | undefined;
181
+ board?: string | undefined;
182
+ contract?: string | undefined;
154
183
  framework?: string | undefined;
155
- native?: Record<string, unknown> | undefined;
184
+ psram?: "opi" | "quad" | undefined;
156
185
  output?: {
157
186
  framework?: string | undefined;
187
+ optimize?: "none" | "size" | "speed" | "balanced" | undefined;
158
188
  outDir?: string | undefined;
159
- optimize?: "size" | "none" | "speed" | "balanced" | undefined;
160
189
  defines?: Record<string, string> | undefined;
161
190
  extraFlags?: string[] | undefined;
162
191
  } | undefined;
163
- board?: string | undefined;
164
- mcu?: string | undefined;
192
+ frameworkData?: Record<string, unknown> | undefined;
165
193
  include?: string[] | undefined;
166
- entry?: string | undefined;
167
- toolchain?: {
168
- type?: string | undefined;
169
- frameworkOptions?: Record<string, unknown> | undefined;
170
- } | undefined;
171
- contract?: string | undefined;
172
194
  exclude?: string[] | undefined;
173
195
  test?: {
174
- buildTarget?: string | undefined;
175
- port?: string | undefined;
176
196
  board?: string | undefined;
177
- baudRate?: number | undefined;
178
197
  include?: string[] | undefined;
198
+ port?: string | undefined;
199
+ baudRate?: number | undefined;
179
200
  timeout?: number | undefined;
201
+ buildTarget?: string | undefined;
202
+ } | undefined;
203
+ toolchain?: {
204
+ type?: string | undefined;
205
+ frameworkOptions?: Record<string, unknown> | undefined;
180
206
  } | undefined;
181
- }, {
182
207
  console?: {
183
208
  port?: string | undefined;
184
209
  baudRate?: number | undefined;
185
210
  } | undefined;
186
- frameworkData?: Record<string, unknown> | undefined;
211
+ native?: Record<string, unknown> | undefined;
212
+ zephyr?: {
213
+ kconfig?: Record<string, string> | undefined;
214
+ cmakeArgs?: string[] | undefined;
215
+ runner?: string | undefined;
216
+ } | undefined;
217
+ }, {
218
+ entry?: string | undefined;
187
219
  target?: string | undefined;
220
+ mcu?: string | undefined;
221
+ board?: string | undefined;
222
+ contract?: string | undefined;
188
223
  framework?: string | undefined;
189
- native?: Record<string, unknown> | undefined;
224
+ psram?: "opi" | "quad" | undefined;
190
225
  output?: {
191
226
  framework?: string | undefined;
227
+ optimize?: "none" | "size" | "speed" | "balanced" | undefined;
192
228
  outDir?: string | undefined;
193
- optimize?: "size" | "none" | "speed" | "balanced" | undefined;
194
229
  defines?: Record<string, string> | undefined;
195
230
  extraFlags?: string[] | undefined;
196
231
  } | undefined;
197
- board?: string | undefined;
198
- mcu?: string | undefined;
232
+ frameworkData?: Record<string, unknown> | undefined;
199
233
  include?: string[] | undefined;
200
- entry?: string | undefined;
234
+ exclude?: string[] | undefined;
235
+ test?: {
236
+ board?: string | undefined;
237
+ include?: string[] | undefined;
238
+ port?: string | undefined;
239
+ baudRate?: number | undefined;
240
+ timeout?: number | undefined;
241
+ buildTarget?: string | undefined;
242
+ } | undefined;
201
243
  toolchain?: {
202
244
  type?: string | undefined;
203
245
  frameworkOptions?: Record<string, unknown> | undefined;
204
246
  } | undefined;
205
- contract?: string | undefined;
206
- exclude?: string[] | undefined;
207
- test?: {
208
- buildTarget?: string | undefined;
247
+ console?: {
209
248
  port?: string | undefined;
210
- board?: string | undefined;
211
249
  baudRate?: number | undefined;
212
- include?: string[] | undefined;
213
- timeout?: number | undefined;
250
+ } | undefined;
251
+ native?: Record<string, unknown> | undefined;
252
+ zephyr?: {
253
+ kconfig?: Record<string, string> | undefined;
254
+ cmakeArgs?: string[] | undefined;
255
+ runner?: string | undefined;
214
256
  } | undefined;
215
257
  }>;
216
258
  /** Inferred TypeScript type from the Zod schema. */
@@ -8,6 +8,8 @@
8
8
  import { z } from 'zod';
9
9
  /** Optimization levels accepted by the output.optimize field. */
10
10
  const OptimizationLevel = z.enum(['none', 'size', 'speed', 'balanced']);
11
+ /** PSRAM types accepted by the top-level `psram` field (ESP32 PSRAM variants). */
12
+ const PsramType = z.enum(['opi', 'quad']);
11
13
  /** Schema for the `output` section. */
12
14
  const OutputConfig = z.object({
13
15
  framework: z.string().min(1).optional(),
@@ -35,6 +37,12 @@ const ToolchainConfig = z.object({
35
37
  type: z.string().optional(),
36
38
  frameworkOptions: z.record(z.string(), z.unknown()).optional(),
37
39
  }).strict();
40
+ /** Schema for the `zephyr` section. */
41
+ const ZephyrConfig = z.object({
42
+ kconfig: z.record(z.string(), z.string()).optional(),
43
+ cmakeArgs: z.array(z.string()).optional(),
44
+ runner: z.string().optional(),
45
+ }).strict();
38
46
  /**
39
47
  * Schema for the full CuttlefishConfig shape.
40
48
  *
@@ -47,6 +55,11 @@ export const CuttlefishConfigSchema = z.object({
47
55
  board: z.string().optional(),
48
56
  contract: z.string().optional(),
49
57
  framework: z.string().optional(),
58
+ /** ESP32 PSRAM type. When set, the framework emits the PSRAM-enabling
59
+ * Kconfig/define so canvas allocations prefer external RAM (large scroll
60
+ * viewports/lists stop failing on PSRAM targets). No effect on boards
61
+ * without PSRAM (the runtime falls back to SRAM then the band renderer). */
62
+ psram: PsramType.optional(),
50
63
  output: OutputConfig.optional(),
51
64
  frameworkData: z.record(z.string(), z.unknown()).optional(),
52
65
  include: z.array(z.string()).optional(),
@@ -55,6 +68,7 @@ export const CuttlefishConfigSchema = z.object({
55
68
  toolchain: ToolchainConfig.optional(),
56
69
  console: ConsoleConfig.optional(),
57
70
  native: z.record(z.string(), z.unknown()).optional(),
71
+ zephyr: ZephyrConfig.optional(),
58
72
  }).strict().refine(data => !(data.board && data.contract), {
59
73
  message: "Specifying both 'board' and 'contract' is not allowed. Choose one.",
60
74
  path: ['board'],
@@ -0,0 +1,17 @@
1
+ /** The directory (relative to the project root) where board.ts is generated. */
2
+ export declare const CUTTLEFISH_DIR = ".cuttlefish";
3
+ export interface GenerateBoardOptions {
4
+ /** Absolute project root dir (where .cuttlefish/ lives). */
5
+ projectDir: string;
6
+ /** MCU package specifier, e.g. '@typecad/mcu-atmega328p'. */
7
+ mcuPackage: string;
8
+ /** Matched MCU pin names to re-export (e.g. ['PB5','PC4']). */
9
+ connectedPins: string[];
10
+ /** Selected peripheral instance names to re-export (e.g. ['I2C0']). */
11
+ peripherals: string[];
12
+ }
13
+ /**
14
+ * Writes the narrowed `.cuttlefish/board.ts`.
15
+ * @returns the absolute path to the generated file.
16
+ */
17
+ export declare function generateBoardFile(opts: GenerateBoardOptions): string;
@@ -0,0 +1,57 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Board generator — emits the narrowed `.cuttlefish/board.ts` for a contract
3
+ //
4
+ // Given the MCU package name plus the matched pin and peripheral names, writes
5
+ // a board.ts that:
6
+ // - re-exports the full HAL surface from @typecad/hal (constants, functions,
7
+ // timing, math, GPIO/Pin helpers, buses) so firmware has the complete
8
+ // runtime vocabulary; and
9
+ // - re-exports ONLY the connected pins and selected peripherals from the MCU
10
+ // package, so any pin the PCB did not wire is absent from `@typecad/board`
11
+ // and using it becomes a compile error.
12
+ //
13
+ // The emitted file is consumed via cuttlefish-env.d.ts, which emits
14
+ // `declare module '@typecad/board' { export * from './board.js'; ... }`
15
+ // for contract-based configs (see config-loader.ts). The './board.js' relative
16
+ // specifier resolves to this file in the same `.cuttlefish/` directory.
17
+ // ---------------------------------------------------------------------------
18
+ import fs from 'node:fs';
19
+ import path from 'node:path';
20
+ /** The directory (relative to the project root) where board.ts is generated. */
21
+ export const CUTTLEFISH_DIR = '.cuttlefish';
22
+ /**
23
+ * Writes the narrowed `.cuttlefish/board.ts`.
24
+ * @returns the absolute path to the generated file.
25
+ */
26
+ export function generateBoardFile(opts) {
27
+ const { projectDir, mcuPackage, connectedPins, peripherals } = opts;
28
+ const cuttlefishDir = path.join(projectDir, CUTTLEFISH_DIR);
29
+ if (!fs.existsSync(cuttlefishDir)) {
30
+ fs.mkdirSync(cuttlefishDir, { recursive: true });
31
+ }
32
+ const lines = [
33
+ '// Auto-generated by the cuttlefish transpiler from a TypeCAD contract.',
34
+ '// Do not edit manually — regenerate by re-running cuttlefish.',
35
+ '//',
36
+ '// This board exposes only the pins and peripherals that the source contract',
37
+ `// (${mcuPackage}) declares as connected on the PCB. Pins the board did not wire`,
38
+ '// are intentionally absent: using one is a compile error.',
39
+ '',
40
+ '// Full HAL runtime surface (constants, timing, math, GPIO/bus helpers).',
41
+ "export * from '@typecad/hal';",
42
+ '',
43
+ '// Narrowed pin set — only pins the contract declares connected.',
44
+ ];
45
+ if (connectedPins.length > 0) {
46
+ lines.push(`export { ${connectedPins.join(', ')} } from '${mcuPackage}';`);
47
+ }
48
+ if (peripherals.length > 0) {
49
+ lines.push('');
50
+ lines.push('// Narrowed peripheral set — only buses whose pins are wired on the PCB.');
51
+ lines.push(`export { ${peripherals.join(', ')} } from '${mcuPackage}';`);
52
+ }
53
+ lines.push(''); // trailing newline
54
+ const outPath = path.join(cuttlefishDir, 'board.ts');
55
+ fs.writeFileSync(outPath, lines.join('\n'), 'utf-8');
56
+ return outPath;
57
+ }