@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,135 +1,135 @@
1
- // ---------------------------------------------------------------------------
2
- // Filesystem lowering — Zephyr FS API (littlefs on the storage partition)
3
- //
4
- // HAL `fs.*` (begin/read_text/write_text/exists/remove) maps onto Zephyr's
5
- // <zephyr/fs/fs.h>. A littlefs filesystem is mounted at "/lfs" on the board's
6
- // `storage_partition` fixed-partition (the same partition the ZMS settings
7
- // backend uses for preferences — a program should not use both surfaces at
8
- // once without dedicating separate partitions). The mount is lazy: it formats
9
- // + remounts on first use when the partition is unformatted.
10
- //
11
- // The HAL paths are treated as paths WITHIN the filesystem: the shim joins the
12
- // mount point, so fs.read_text("/data.txt") reads "/lfs/data.txt". This keeps
13
- // the mount point an implementation detail.
14
- //
15
- // Requires Kconfig CONFIG_FILE_SYSTEM + CONFIG_FILE_SYSTEM_LITTLEFS (+ FLASH /
16
- // FLASH_MAP) — emitted by the scaffold when the program uses fs.* — and the
17
- // storage_partition node (added by the overlay).
18
- // ---------------------------------------------------------------------------
19
-
20
- import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
21
-
22
- /**
23
- * Emit the littlefs mount + the typed helper API the lowering calls into.
24
- * Called from shimLines when the program uses the filesystem. The helpers are
25
- * `static` so multiple TUs that carry the shim (guarded by the include guard)
26
- * do not collide.
27
- */
28
- export function fsInitLines(): string[] {
29
- return [
30
- '// CUTTLEFISH_FS_BEGIN',
31
- 'static struct fs_mount_t __tc_fs_mp;',
32
- 'static bool __tc_fs_mounted = false;',
33
- '',
34
- 'FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(__tc_fs_data);',
35
- 'static struct fs_mount_t __tc_fs_mp_init = {',
36
- ' .type = FS_LITTLEFS,',
37
- ' .mnt_point = "/lfs",',
38
- ' .fs_data = &__tc_fs_data,',
39
- ' .storage_dev = (void *)FIXED_PARTITION_ID(storage_partition),',
40
- '};',
41
- '',
42
- 'static void __tc_fs_ensure_mount(void) {',
43
- ' if (__tc_fs_mounted) return;',
44
- ' __tc_fs_mp = __tc_fs_mp_init;',
45
- ' int rc = fs_mount(&__tc_fs_mp);',
46
- ' if (rc != 0) {',
47
- ' // Any mount failure with a valid config means the partition is',
48
- ' // unformatted or corrupt (littlefs reports -EIO on erased flash,',
49
- ' // not only -ENODATA/-EINVAL) — format it and remount once.',
50
- ' (void)fs_mkfs(FS_LITTLEFS, static_cast<uintptr_t>(FIXED_PARTITION_ID(storage_partition)), NULL, 0);',
51
- ' rc = fs_mount(&__tc_fs_mp);',
52
- ' }',
53
- ' if (rc == 0) {',
54
- ' __tc_fs_mounted = true;',
55
- ' } else {',
56
- ' char __tc_fs_err[48];',
57
- ' (void)snprintf(__tc_fs_err, sizeof(__tc_fs_err), "cuttlefish-fs: mount failed rc=%d", rc);',
58
- ' __tc_println(__tc_fs_err);',
59
- ' }',
60
- '}',
61
- '',
62
- '// Join the mount point with the user path (paths are within the FS).',
63
- 'static const char* __tc_fs_path(const char* p) {',
64
- ' static char buf[128];',
65
- ' if (!p) return "/lfs";',
66
- ' const char* s = (p[0] == \'/\') ? p + 1 : p;',
67
- ' (void)snprintf(buf, sizeof(buf), "/lfs/%s", s);',
68
- ' return buf;',
69
- '}',
70
- '',
71
- 'static bool __tc_fs_begin(void) { __tc_fs_ensure_mount(); return true; }',
72
- '',
73
- 'static const char* __tc_fs_read_text(const char* path) {',
74
- ' __tc_fs_ensure_mount();',
75
- ' static char buf[256];',
76
- ' buf[0] = 0;',
77
- ' struct fs_file_t f;',
78
- ' fs_file_t_init(&f);',
79
- ' if (fs_open(&f, __tc_fs_path(path), FS_O_READ) == 0) {',
80
- ' // Terminate at the READ length: the buffer is static and shared',
81
- ' // across reads, so bytes from a longer previous file survive a',
82
- ' // short read otherwise.',
83
- ' ssize_t n = fs_read(&f, buf, sizeof(buf) - 1);',
84
- ' buf[(n > 0) ? n : 0] = 0;',
85
- ' (void)fs_close(&f);',
86
- ' }',
87
- ' return buf;',
88
- '}',
89
- '',
90
- 'static void __tc_fs_write_text(const char* path, const char* content) {',
91
- ' __tc_fs_ensure_mount();',
92
- ' struct fs_file_t f;',
93
- ' fs_file_t_init(&f);',
94
- ' if (fs_open(&f, __tc_fs_path(path), FS_O_WRITE | FS_O_CREATE | FS_O_TRUNC) == 0) {',
95
- ' (void)fs_write(&f, content, (content ? strlen(content) : 0));',
96
- ' (void)fs_close(&f);',
97
- ' }',
98
- '}',
99
- '',
100
- 'static bool __tc_fs_exists(const char* path) {',
101
- ' __tc_fs_ensure_mount();',
102
- ' struct fs_dirent ent;',
103
- ' return fs_stat(__tc_fs_path(path), &ent) == 0;',
104
- '}',
105
- '',
106
- 'static bool __tc_fs_remove(const char* path) {',
107
- ' __tc_fs_ensure_mount();',
108
- ' return fs_unlink(__tc_fs_path(path)) == 0;',
109
- '}',
110
- '// CUTTLEFISH_FS_END',
111
- ];
112
- }
113
-
114
- /**
115
- * Resolve a HAL fs.* op to Zephyr C++.
116
- * Returns `{ code }` — each op's code is the body of the HAL FS class method.
117
- */
118
- export function lowerFs(op: HALOpIR): { code?: string; expression?: string } {
119
- const o = op as any;
120
- switch (op.operation) {
121
- case 'fs.read_text':
122
- return { code: `return __tc_fs_read_text(${o.path});` };
123
- case 'fs.write_text':
124
- return { code: `__tc_fs_write_text(${o.path}, ${o.content});` };
125
- case 'fs.exists':
126
- return { code: `return __tc_fs_exists(${o.path});` };
127
- case 'fs.remove':
128
- return { code: `return __tc_fs_remove(${o.path});` };
129
- default:
130
- throw new Error(
131
- `framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
132
- `Open an issue or use rawCpp() to emit it manually.`,
133
- );
134
- }
135
- }
1
+ // ---------------------------------------------------------------------------
2
+ // Filesystem lowering — Zephyr FS API (littlefs on the storage partition)
3
+ //
4
+ // HAL `fs.*` (begin/read_text/write_text/exists/remove) maps onto Zephyr's
5
+ // <zephyr/fs/fs.h>. A littlefs filesystem is mounted at "/lfs" on the board's
6
+ // `storage_partition` fixed-partition (the same partition the ZMS settings
7
+ // backend uses for preferences — a program should not use both surfaces at
8
+ // once without dedicating separate partitions). The mount is lazy: it formats
9
+ // + remounts on first use when the partition is unformatted.
10
+ //
11
+ // The HAL paths are treated as paths WITHIN the filesystem: the shim joins the
12
+ // mount point, so fs.read_text("/data.txt") reads "/lfs/data.txt". This keeps
13
+ // the mount point an implementation detail.
14
+ //
15
+ // Requires Kconfig CONFIG_FILE_SYSTEM + CONFIG_FILE_SYSTEM_LITTLEFS (+ FLASH /
16
+ // FLASH_MAP) — emitted by the scaffold when the program uses fs.* — and the
17
+ // storage_partition node (added by the overlay).
18
+ // ---------------------------------------------------------------------------
19
+
20
+ import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
21
+
22
+ /**
23
+ * Emit the littlefs mount + the typed helper API the lowering calls into.
24
+ * Called from shimLines when the program uses the filesystem. The helpers are
25
+ * `static` so multiple TUs that carry the shim (guarded by the include guard)
26
+ * do not collide.
27
+ */
28
+ export function fsInitLines(): string[] {
29
+ return [
30
+ '// CUTTLEFISH_FS_BEGIN',
31
+ 'static struct fs_mount_t __tc_fs_mp;',
32
+ 'static bool __tc_fs_mounted = false;',
33
+ '',
34
+ 'FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(__tc_fs_data);',
35
+ 'static struct fs_mount_t __tc_fs_mp_init = {',
36
+ ' .type = FS_LITTLEFS,',
37
+ ' .mnt_point = "/lfs",',
38
+ ' .fs_data = &__tc_fs_data,',
39
+ ' .storage_dev = (void *)FIXED_PARTITION_ID(storage_partition),',
40
+ '};',
41
+ '',
42
+ 'static void __tc_fs_ensure_mount(void) {',
43
+ ' if (__tc_fs_mounted) return;',
44
+ ' __tc_fs_mp = __tc_fs_mp_init;',
45
+ ' int rc = fs_mount(&__tc_fs_mp);',
46
+ ' if (rc != 0) {',
47
+ ' // Any mount failure with a valid config means the partition is',
48
+ ' // unformatted or corrupt (littlefs reports -EIO on erased flash,',
49
+ ' // not only -ENODATA/-EINVAL) — format it and remount once.',
50
+ ' (void)fs_mkfs(FS_LITTLEFS, static_cast<uintptr_t>(FIXED_PARTITION_ID(storage_partition)), NULL, 0);',
51
+ ' rc = fs_mount(&__tc_fs_mp);',
52
+ ' }',
53
+ ' if (rc == 0) {',
54
+ ' __tc_fs_mounted = true;',
55
+ ' } else {',
56
+ ' char __tc_fs_err[48];',
57
+ ' (void)snprintf(__tc_fs_err, sizeof(__tc_fs_err), "typecad-hal-fs: mount failed rc=%d", rc);',
58
+ ' __tc_println(__tc_fs_err);',
59
+ ' }',
60
+ '}',
61
+ '',
62
+ '// Join the mount point with the user path (paths are within the FS).',
63
+ 'static const char* __tc_fs_path(const char* p) {',
64
+ ' static char buf[128];',
65
+ ' if (!p) return "/lfs";',
66
+ ' const char* s = (p[0] == \'/\') ? p + 1 : p;',
67
+ ' (void)snprintf(buf, sizeof(buf), "/lfs/%s", s);',
68
+ ' return buf;',
69
+ '}',
70
+ '',
71
+ 'static bool __tc_fs_begin(void) { __tc_fs_ensure_mount(); return true; }',
72
+ '',
73
+ 'static const char* __tc_fs_read_text(const char* path) {',
74
+ ' __tc_fs_ensure_mount();',
75
+ ' static char buf[256];',
76
+ ' buf[0] = 0;',
77
+ ' struct fs_file_t f;',
78
+ ' fs_file_t_init(&f);',
79
+ ' if (fs_open(&f, __tc_fs_path(path), FS_O_READ) == 0) {',
80
+ ' // Terminate at the READ length: the buffer is static and shared',
81
+ ' // across reads, so bytes from a longer previous file survive a',
82
+ ' // short read otherwise.',
83
+ ' ssize_t n = fs_read(&f, buf, sizeof(buf) - 1);',
84
+ ' buf[(n > 0) ? n : 0] = 0;',
85
+ ' (void)fs_close(&f);',
86
+ ' }',
87
+ ' return buf;',
88
+ '}',
89
+ '',
90
+ 'static void __tc_fs_write_text(const char* path, const char* content) {',
91
+ ' __tc_fs_ensure_mount();',
92
+ ' struct fs_file_t f;',
93
+ ' fs_file_t_init(&f);',
94
+ ' if (fs_open(&f, __tc_fs_path(path), FS_O_WRITE | FS_O_CREATE | FS_O_TRUNC) == 0) {',
95
+ ' (void)fs_write(&f, content, (content ? strlen(content) : 0));',
96
+ ' (void)fs_close(&f);',
97
+ ' }',
98
+ '}',
99
+ '',
100
+ 'static bool __tc_fs_exists(const char* path) {',
101
+ ' __tc_fs_ensure_mount();',
102
+ ' struct fs_dirent ent;',
103
+ ' return fs_stat(__tc_fs_path(path), &ent) == 0;',
104
+ '}',
105
+ '',
106
+ 'static bool __tc_fs_remove(const char* path) {',
107
+ ' __tc_fs_ensure_mount();',
108
+ ' return fs_unlink(__tc_fs_path(path)) == 0;',
109
+ '}',
110
+ '// CUTTLEFISH_FS_END',
111
+ ];
112
+ }
113
+
114
+ /**
115
+ * Resolve a HAL fs.* op to Zephyr C++.
116
+ * Returns `{ code }` — each op's code is the body of the HAL FS class method.
117
+ */
118
+ export function lowerFs(op: HALOpIR): { code?: string; expression?: string } {
119
+ const o = op as any;
120
+ switch (op.operation) {
121
+ case 'fs.read_text':
122
+ return { code: `return __tc_fs_read_text(${o.path});` };
123
+ case 'fs.write_text':
124
+ return { code: `__tc_fs_write_text(${o.path}, ${o.content});` };
125
+ case 'fs.exists':
126
+ return { code: `return __tc_fs_exists(${o.path});` };
127
+ case 'fs.remove':
128
+ return { code: `return __tc_fs_remove(${o.path});` };
129
+ default:
130
+ throw new Error(
131
+ `framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
132
+ `Open an issue or use rawCpp() to emit it manually.`,
133
+ );
134
+ }
135
+ }
@@ -30,39 +30,6 @@ function findDtSpec(chip: ZephyrChipDescriptor, pin: number) {
30
30
  return chip.gpio.dtSpecs.find((s) => s.pin === pin);
31
31
  }
32
32
 
33
- // HAL passes UPPERCASE modes ("OUTPUT") while docs say lowercase ("output").
34
- // The *_pullup / *_pulldown modes map to GPIO_INPUT (Zephyr does not have
35
- // separate input+pull mode flags) and OR in a GPIO_PULL_UP / GPIO_PULL_DOWN
36
- // bit via `dtFlagsForMode` — without that bit the pin floats, so INPUT_PULLUP
37
- // was a silent no-op (bug B1). Mirrors the gpio_pullup_en/gpio_pulldown_en
38
- // extras framework-esp32 emits for the same modes.
39
- const MODE_MAP: Record<string, string> = {
40
- output: 'GPIO_OUTPUT',
41
- OUTPUT: 'GPIO_OUTPUT',
42
- input: 'GPIO_INPUT',
43
- INPUT: 'GPIO_INPUT',
44
- input_pullup: 'GPIO_INPUT',
45
- INPUT_PULLUP: 'GPIO_INPUT',
46
- input_pulldown: 'GPIO_INPUT',
47
- INPUT_PULLDOWN: 'GPIO_INPUT',
48
- };
49
-
50
- /** Additional DT flag bits for a HAL mode, OR'd into the configure flags.
51
- * Returns '' for modes with no extra bits so the join leaves the mode alone. */
52
- function dtFlagsForMode(mode: string): string {
53
- const m = (mode ?? '').toLowerCase();
54
- if (m === 'input_pullup') return ' | GPIO_PULL_UP';
55
- if (m === 'input_pulldown') return ' | GPIO_PULL_DOWN';
56
- return '';
57
- }
58
-
59
- /** Combined mode + pull flags for a HAL mode string, e.g.
60
- * 'INPUT_PULLUP' → 'GPIO_INPUT | GPIO_PULL_UP'. */
61
- function flagsForMode(mode: string): string {
62
- const base = MODE_MAP[mode] ?? 'GPIO_INPUT';
63
- return base + dtFlagsForMode(mode);
64
- }
65
-
66
33
  // ── Thin GPIO (hal/gpio-pin.ts) — flag tokens ─────────────────────────────
67
34
  //
68
35
  // "GPIO.OUTPUT | GPIO.PULL_UP" token text maps name-for-name onto the GPIO_*