@typecad/framework-zephyr 1.0.0-alpha.13 → 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.
- package/README.md +22 -35
- package/dist/as-built.d.ts +33 -0
- package/dist/as-built.js +188 -0
- package/dist/async/timer-polyfill.js +1 -1
- package/dist/boardgen.d.ts +128 -0
- package/dist/boardgen.js +1366 -0
- package/dist/chips/board-overrides.d.ts +7 -0
- package/dist/chips/board-overrides.js +11 -0
- package/dist/chips/controllers.d.ts +28 -8
- package/dist/chips/controllers.js +49 -12
- package/dist/chips/esp32s3.js +49 -0
- package/dist/chips/index.d.ts +6 -12
- package/dist/chips/index.js +18 -34
- package/dist/chips/resolve.d.ts +16 -2
- package/dist/chips/resolve.js +298 -15
- package/dist/chips/soc/.d.ts +2 -0
- package/dist/chips/soc/.js +129 -0
- package/dist/chips/soc/esp32.d.ts +2 -0
- package/dist/chips/soc/esp32.js +120 -0
- package/dist/chips/soc/esp32c3.d.ts +2 -0
- package/dist/chips/soc/esp32c3.js +90 -0
- package/dist/chips/soc/esp32c6.d.ts +2 -0
- package/dist/chips/soc/esp32c6.js +109 -0
- package/dist/chips/soc/esp32s3.d.ts +2 -0
- package/dist/chips/soc/esp32s3.js +189 -0
- package/dist/chips/soc/index.d.ts +2 -0
- package/dist/chips/soc/index.js +23 -0
- package/dist/chips/soc/nrf52840.d.ts +2 -0
- package/dist/chips/soc/nrf52840.js +130 -0
- package/dist/chips/soc/rp2040.d.ts +2 -0
- package/dist/chips/soc/rp2040.js +141 -0
- package/dist/chips/soc/rp2350a.d.ts +2 -0
- package/dist/chips/soc/rp2350a.js +145 -0
- package/dist/chips/soc/samd21g18a.d.ts +2 -0
- package/dist/chips/soc/samd21g18a.js +143 -0
- package/dist/chips/soc/stm32f411xe.d.ts +2 -0
- package/dist/chips/soc/stm32f411xe.js +251 -0
- package/dist/chips/types.d.ts +382 -12
- package/dist/chips/xiao-ble.js +33 -0
- package/dist/display/profiles.js +1 -1
- package/dist/doctor.js +38 -4
- package/dist/dt-config/custom-board.d.ts +23 -0
- package/dist/dt-config/custom-board.js +227 -0
- package/dist/dt-config/kconfig.d.ts +83 -1
- package/dist/dt-config/kconfig.js +116 -27
- package/dist/dt-config/overlay.js +623 -18
- package/dist/framework.manifest.d.ts +20 -30
- package/dist/framework.manifest.js +124 -178
- package/dist/index.d.ts +4 -1
- package/dist/index.js +8 -2
- package/dist/lowering/adc.d.ts +26 -5
- package/dist/lowering/adc.js +137 -31
- package/dist/lowering/ble.js +31 -28
- package/dist/lowering/dac.js +9 -9
- package/dist/lowering/fs.js +18 -10
- package/dist/lowering/gpio.d.ts +2 -0
- package/dist/lowering/gpio.js +90 -10
- package/dist/lowering/http.js +39 -14
- package/dist/lowering/hwtimer.d.ts +4 -0
- package/dist/lowering/hwtimer.js +35 -10
- package/dist/lowering/i2c.js +46 -54
- package/dist/lowering/index.d.ts +5 -5
- package/dist/lowering/index.js +15 -16
- package/dist/lowering/interrupts.d.ts +22 -5
- package/dist/lowering/interrupts.js +104 -22
- package/dist/lowering/mqtt.js +12 -6
- package/dist/lowering/power.js +0 -4
- package/dist/lowering/preferences.js +49 -77
- package/dist/lowering/pulse.js +5 -36
- package/dist/lowering/pwm.d.ts +32 -3
- package/dist/lowering/pwm.js +105 -17
- package/dist/lowering/random.js +3 -3
- package/dist/lowering/sensor.d.ts +37 -0
- package/dist/lowering/sensor.js +119 -0
- package/dist/lowering/spi.d.ts +12 -0
- package/dist/lowering/spi.js +65 -40
- package/dist/lowering/thread.d.ts +14 -0
- package/dist/lowering/thread.js +55 -0
- package/dist/lowering/timing.js +20 -46
- package/dist/lowering/tone.js +18 -5
- package/dist/lowering/uart.d.ts +13 -0
- package/dist/lowering/uart.js +72 -51
- package/dist/lowering/usb.d.ts +34 -0
- package/dist/lowering/usb.js +206 -0
- package/dist/lowering/wdt.d.ts +1 -1
- package/dist/lowering/wdt.js +17 -7
- package/dist/lowering/wifi.d.ts +3 -2
- package/dist/lowering/wifi.js +120 -111
- package/dist/sdk/board-catalog-sync.d.ts +16 -0
- package/dist/sdk/board-catalog-sync.js +41 -0
- package/dist/sdk/board-data.generated.d.ts +2 -0
- package/dist/sdk/board-data.generated.js +4 -0
- package/dist/sdk/catalog-walker.d.ts +90 -0
- package/dist/sdk/catalog-walker.js +682 -0
- package/dist/sdk/dts-reader.d.ts +83 -0
- package/dist/sdk/dts-reader.js +596 -0
- package/dist/strategy.d.ts +136 -17
- package/dist/strategy.js +881 -212
- package/dist/toolchain/bossac-touch.d.ts +18 -0
- package/dist/toolchain/bossac-touch.js +88 -0
- package/dist/toolchain/compat.d.ts +2 -2
- package/dist/toolchain/compat.js +8 -3
- package/dist/toolchain/debug-config.d.ts +21 -26
- package/dist/toolchain/debug-config.js +212 -72
- package/dist/toolchain/env-check.d.ts +4 -4
- package/dist/toolchain/env-check.js +5 -5
- package/dist/toolchain/index.d.ts +66 -1
- package/dist/toolchain/index.js +713 -58
- package/dist/toolchain/scaffold.d.ts +9 -0
- package/dist/toolchain/scaffold.js +84 -7
- package/dist/toolchain/west-discover.d.ts +8 -1
- package/dist/toolchain/west-discover.js +19 -6
- package/dist/toolchain/west-spawn.js +17 -5
- package/installer/CHANGELOG.md +473 -0
- package/installer/README.md +328 -0
- package/installer/environment.yml +46 -0
- package/installer/etc/conda/activate.d/zephyr.bat +7 -0
- package/installer/etc/conda/activate.d/zephyr.ps1 +12 -0
- package/installer/etc/conda/activate.d/zephyr.sh +20 -0
- package/installer/etc/conda/deactivate.d/zephyr.bat +6 -0
- package/installer/etc/conda/deactivate.d/zephyr.ps1 +6 -0
- package/installer/etc/conda/deactivate.d/zephyr.sh +4 -0
- package/installer/install.mjs +580 -0
- package/installer/install.ps1 +619 -0
- package/installer/install.sh +310 -0
- package/installer/lib/detect-platform.sh +62 -0
- package/installer/lib/fetch-sdk.sh +304 -0
- package/installer/lib/init-workspace.sh +153 -0
- package/installer/lib/write-activation.sh +76 -0
- package/installer/patches/tfm-c-include-separators.patch +19 -0
- package/installer/patches/zephyr-tfm-nordic-zephyr-include.patch +24 -0
- package/installer/templates/project/.typecad/activate-zephyr.ps1 +31 -0
- package/installer/templates/project/.typecad/activate-zephyr.sh +31 -0
- package/installer/templates/project/.vscode/settings.json +30 -0
- package/installer/templates/project/README.md +58 -0
- package/installer/versions.env +110 -0
- package/package.json +16 -16
- package/src/as-built.ts +206 -0
- package/src/boardgen.ts +1428 -0
- package/src/chips/controllers.ts +61 -12
- package/src/chips/index.ts +35 -54
- package/src/chips/resolve.ts +316 -14
- package/src/chips/types.ts +388 -13
- package/src/display/profiles.ts +1 -1
- package/src/doctor.ts +110 -77
- package/src/dt-config/custom-board.ts +325 -0
- package/src/dt-config/kconfig.ts +177 -19
- package/src/dt-config/overlay.ts +1058 -450
- package/src/framework.manifest.ts +125 -178
- package/src/index.ts +57 -41
- package/src/lowering/adc.ts +222 -102
- package/src/lowering/ble.ts +32 -28
- package/src/lowering/dac.ts +82 -82
- package/src/lowering/fs.ts +18 -10
- package/src/lowering/gpio.ts +242 -152
- package/src/lowering/http.ts +512 -488
- package/src/lowering/hwtimer.ts +139 -101
- package/src/lowering/i2c.ts +116 -126
- package/src/lowering/index.ts +91 -93
- package/src/lowering/interrupts.ts +113 -21
- package/src/lowering/mqtt.ts +12 -6
- package/src/lowering/preferences.ts +327 -354
- package/src/lowering/pwm.ts +167 -74
- package/src/lowering/random.ts +3 -3
- package/src/lowering/sensor.ts +155 -0
- package/src/lowering/spi.ts +164 -124
- package/src/lowering/thread.ts +63 -0
- package/src/lowering/timing.ts +46 -72
- package/src/lowering/uart.ts +73 -51
- package/src/lowering/usb.ts +221 -0
- package/src/lowering/wdt.ts +95 -84
- package/src/lowering/wifi.ts +120 -111
- package/src/sdk/board-catalog-sync.ts +62 -0
- package/src/strategy.ts +888 -229
- package/src/toolchain/bossac-touch.ts +112 -0
- package/src/toolchain/compat.ts +8 -3
- package/src/toolchain/debug-config.ts +666 -522
- package/src/toolchain/env-check.ts +9 -9
- package/src/toolchain/index.ts +765 -44
- package/src/toolchain/scaffold.ts +81 -7
- package/src/toolchain/west-discover.ts +334 -316
- package/src/toolchain/west-spawn.ts +17 -5
- package/src/async/timer-polyfill.ts +0 -107
- package/src/chips/esp32.ts +0 -74
- package/src/chips/esp32s3.ts +0 -57
- package/src/chips/xiao-ble.ts +0 -70
- package/src/lowering/power.ts +0 -70
- package/src/lowering/pulse.ts +0 -93
- package/src/lowering/tone.ts +0 -60
- package/src/lowering/worker-backing.ts +0 -94
- package/src/lowering/worker.ts +0 -17
package/src/as-built.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// as-built.ts — harvest pin routes from a build's resolved zephyr.dts
|
|
3
|
+
//
|
|
4
|
+
// The third fact source: after any successful `west build`, the fully
|
|
5
|
+
// merged devicetree at <build>/zephyr/zephyr.dts contains the board's
|
|
6
|
+
// pinctrl nodes with LABELS verbatim — the stable name grammar
|
|
7
|
+
// (`adc1_in1_pa1`, `tim4_ch1_pb6`, `iomuxc_<pad>_adc1_in1`) — with the
|
|
8
|
+
// vendor macro values already expanded away. Parsing names only needs ONE
|
|
9
|
+
// grammar per shape, immune to vendor macro churn, and corrects a broken
|
|
10
|
+
// catalog harvest per-pin before the next build (the walker's macro-value
|
|
11
|
+
// grammars are the fragile half; this is the robust half).
|
|
12
|
+
//
|
|
13
|
+
// Scope is honest: only node-name families appear (STM32-style dtsi nodes
|
|
14
|
+
// and the i.MX RT label grammar with its in-band pad join). Header-matrix
|
|
15
|
+
// families (Kinetis/LPC/GD32 macro routing, ESP32/RP2 matrices) never
|
|
16
|
+
// exist as DT nodes — the walker + family tables remain their source.
|
|
17
|
+
// ----------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
export interface AsBuiltRoute {
|
|
20
|
+
source: string;
|
|
21
|
+
channel: number;
|
|
22
|
+
port: string;
|
|
23
|
+
bit: number;
|
|
24
|
+
pinctrl: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AsBuiltFacts {
|
|
28
|
+
adc: AsBuiltRoute[];
|
|
29
|
+
pwm: AsBuiltRoute[];
|
|
30
|
+
dac: AsBuiltRoute[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The .cuttlefish/as-built.json shape (machine-authored facts file). */
|
|
34
|
+
export interface AsBuiltFile {
|
|
35
|
+
version: 1;
|
|
36
|
+
board: string;
|
|
37
|
+
generatedAt: string;
|
|
38
|
+
routes: {
|
|
39
|
+
adcPins: AsBuiltRoute[];
|
|
40
|
+
pwmPins: AsBuiltRoute[];
|
|
41
|
+
dacPins: AsBuiltRoute[];
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// STM32-style pinctrl dtsi labels (all spellings the walker knows):
|
|
46
|
+
// adc1_in1_pa1 / adc_in0_pa0 / adc1_inp16_pa0, tim4_ch1_pb6,
|
|
47
|
+
// dac1_out1_pa4. Labels appear verbatim in zephyr.dts
|
|
48
|
+
// (`adc1_in0_pa0: adc1_in0_pa0 {`). The `inn` negative inputs stay out —
|
|
49
|
+
// the thin HAL is single-ended. The F1 (AFIO) family uses `tim1_ch1_pwm_out_pa8`
|
|
50
|
+
// and `dac_out1_pa4` — separate grammars.
|
|
51
|
+
const ST_ADC = /^([a-z]*adc\d*_(?:in|inp)\d+_p([a-z])(\d+))$/;
|
|
52
|
+
const ST_PWM = /^(tim(\d+)_ch(\d+)_p([a-z])(\d+))$/;
|
|
53
|
+
const ST_PWM_F1 = /^(tim(\d+)_ch(\d+)_pwm_out_p([a-z])(\d+))$/;
|
|
54
|
+
const ST_DAC = /^(dac(\d+)_out(\d+)_p([a-z])(\d+))$/;
|
|
55
|
+
const ST_DAC_F1 = /^(dac_out(\d+)_p([a-z])(\d+))$/;
|
|
56
|
+
// i.MX RT labels: iomuxc_<pad>_adc1_in1 / iomuxc_<pad>_flexpwm2_pwma3,
|
|
57
|
+
// with the pad→GPIO join as sibling iomuxc_<pad>_gpio1_io12 labels. The NEW
|
|
58
|
+
// RT parts (rt11xx/rt116x/rt118x) use `…_flexpwm1_pwm0_a` (pwm<K>_<a|b> →
|
|
59
|
+
// A=0/B=1). Their ADC is the LPADC (`lpadc<N>`) and stays out — see
|
|
60
|
+
// dts-reader.ts.
|
|
61
|
+
const IMX_GPIO = /^iomuxc_([a-z0-9_]+)_gpio(\d+)_io(\d+)$/;
|
|
62
|
+
const IMX_ADC = /^iomuxc_([a-z0-9_]+)_adc(\d+)_in(\d+)$/;
|
|
63
|
+
const IMX_PWM = /^iomuxc_([a-z0-9_]+)_flexpwm(\d+)_pwm([ab])(\d+)$/;
|
|
64
|
+
const IMX_PWM2 = /^iomuxc_([a-z0-9_]+)_flexpwm(\d+)_pwm(\d+)_([ab])$/;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Parse a resolved zephyr.dts into raw pin routes. Labels are matched as
|
|
68
|
+
* whole tokens (`label:` or `label {`) — in dtc output every node carries
|
|
69
|
+
* its labels inline before the node name.
|
|
70
|
+
*/
|
|
71
|
+
export function parseZephyrDts(text: string): AsBuiltFacts {
|
|
72
|
+
const facts: AsBuiltFacts = { adc: [], pwm: [], dac: [] };
|
|
73
|
+
const imxPadToGpio = new Map<string, { port: string; bit: number }>();
|
|
74
|
+
const seen = new Set<string>();
|
|
75
|
+
// Every label occurrence: `label:` (label before node) — zephyr.dts
|
|
76
|
+
// renders `label: nodename {`, INDENTED with tabs. Whole-token labels.
|
|
77
|
+
for (const m of text.matchAll(/^\s*([a-z][a-z0-9_]*):\s/gm)) {
|
|
78
|
+
const label = m[1]!;
|
|
79
|
+
if (seen.has(label)) continue;
|
|
80
|
+
let g: RegExpMatchArray | null;
|
|
81
|
+
if ((g = label.match(ST_ADC))) {
|
|
82
|
+
seen.add(label);
|
|
83
|
+
// Source: the unit prefix from the name — `adc1_in1…` → adc1, the
|
|
84
|
+
// single-unit spelling `adc_in0…` → adc.
|
|
85
|
+
const unit = label.match(/^([a-z]+?\d*)_in/);
|
|
86
|
+
facts.adc.push({
|
|
87
|
+
source: unit ? unit[1]! : 'adc',
|
|
88
|
+
channel: Number(label.match(/_(?:in|inp)(\d+)_/)![1]),
|
|
89
|
+
port: g[2]!.toUpperCase(),
|
|
90
|
+
bit: Number(g[3]),
|
|
91
|
+
pinctrl: label,
|
|
92
|
+
});
|
|
93
|
+
} else if ((g = label.match(ST_PWM))) {
|
|
94
|
+
seen.add(label);
|
|
95
|
+
facts.pwm.push({
|
|
96
|
+
source: `tim${g[2]}`,
|
|
97
|
+
channel: Number(g[3]),
|
|
98
|
+
port: g[4]!.toUpperCase(),
|
|
99
|
+
bit: Number(g[5]),
|
|
100
|
+
pinctrl: label,
|
|
101
|
+
});
|
|
102
|
+
} else if ((g = label.match(ST_PWM_F1))) {
|
|
103
|
+
seen.add(label);
|
|
104
|
+
facts.pwm.push({
|
|
105
|
+
source: `tim${g[2]}`,
|
|
106
|
+
channel: Number(g[3]),
|
|
107
|
+
port: g[4]!.toUpperCase(),
|
|
108
|
+
bit: Number(g[5]),
|
|
109
|
+
pinctrl: label,
|
|
110
|
+
});
|
|
111
|
+
} else if ((g = label.match(ST_DAC))) {
|
|
112
|
+
seen.add(label);
|
|
113
|
+
facts.dac.push({
|
|
114
|
+
source: `dac${g[2]}`,
|
|
115
|
+
channel: Number(g[3]),
|
|
116
|
+
port: g[4]!.toUpperCase(),
|
|
117
|
+
bit: Number(g[5]),
|
|
118
|
+
pinctrl: label,
|
|
119
|
+
});
|
|
120
|
+
} else if ((g = label.match(ST_DAC_F1))) {
|
|
121
|
+
seen.add(label);
|
|
122
|
+
facts.dac.push({
|
|
123
|
+
source: 'dac1',
|
|
124
|
+
channel: Number(g[2]),
|
|
125
|
+
port: g[3]!.toUpperCase(),
|
|
126
|
+
bit: Number(g[4]),
|
|
127
|
+
pinctrl: label,
|
|
128
|
+
});
|
|
129
|
+
} else if ((g = label.match(IMX_GPIO))) {
|
|
130
|
+
seen.add(label);
|
|
131
|
+
if (!imxPadToGpio.has(g[1]!)) imxPadToGpio.set(g[1]!, { port: g[2]!, bit: Number(g[3]) });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// i.MX routes resolve after the join map is complete.
|
|
135
|
+
for (const m of text.matchAll(/^\s*([a-z][a-z0-9_]*):\s/gm)) {
|
|
136
|
+
const label = m[1]!;
|
|
137
|
+
let g: RegExpMatchArray | null;
|
|
138
|
+
if ((g = label.match(IMX_ADC))) {
|
|
139
|
+
const gpio = imxPadToGpio.get(g[1]!);
|
|
140
|
+
if (!gpio || seen.has(label)) continue;
|
|
141
|
+
seen.add(label);
|
|
142
|
+
facts.adc.push({
|
|
143
|
+
source: `adc${g[2]}`,
|
|
144
|
+
channel: Number(g[3]),
|
|
145
|
+
port: gpio.port,
|
|
146
|
+
bit: gpio.bit,
|
|
147
|
+
pinctrl: label,
|
|
148
|
+
});
|
|
149
|
+
} else if ((g = label.match(IMX_PWM))) {
|
|
150
|
+
const gpio = imxPadToGpio.get(g[1]!);
|
|
151
|
+
if (!gpio || seen.has(label)) continue;
|
|
152
|
+
seen.add(label);
|
|
153
|
+
facts.pwm.push({
|
|
154
|
+
source: `flexpwm${g[2]}_pwm${g[4]}`,
|
|
155
|
+
channel: g[3] === 'b' ? 1 : 0,
|
|
156
|
+
port: gpio.port,
|
|
157
|
+
bit: gpio.bit,
|
|
158
|
+
pinctrl: label,
|
|
159
|
+
});
|
|
160
|
+
} else if ((g = label.match(IMX_PWM2))) {
|
|
161
|
+
const gpio = imxPadToGpio.get(g[1]!);
|
|
162
|
+
if (!gpio || seen.has(label)) continue;
|
|
163
|
+
seen.add(label);
|
|
164
|
+
facts.pwm.push({
|
|
165
|
+
source: `flexpwm${g[2]}_pwm${g[3]}`,
|
|
166
|
+
channel: g[4] === 'b' ? 1 : 0,
|
|
167
|
+
port: gpio.port,
|
|
168
|
+
bit: gpio.bit,
|
|
169
|
+
pinctrl: label,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return facts;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Parse + shape-validate .cuttlefish/as-built.json; errors name the file. */
|
|
177
|
+
export function parseAsBuiltJson(text: string, source = '.cuttlefish/as-built.json'): AsBuiltFile {
|
|
178
|
+
let parsed: unknown;
|
|
179
|
+
try {
|
|
180
|
+
parsed = JSON.parse(text);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
throw new Error(`${source} is not valid JSON: ${(err as Error).message}`);
|
|
183
|
+
}
|
|
184
|
+
const file = parsed as AsBuiltFile;
|
|
185
|
+
if (!file || typeof file !== 'object' || file.version !== 1 || typeof file.board !== 'string'
|
|
186
|
+
|| !file.routes || !Array.isArray(file.routes.adcPins) || !Array.isArray(file.routes.pwmPins)) {
|
|
187
|
+
throw new Error(`${source} must carry version 1, a board target, and routes.{adcPins,pwmPins}.`);
|
|
188
|
+
}
|
|
189
|
+
return file;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Serialize the as-built snapshot (deterministic field order). */
|
|
193
|
+
export function asBuiltJson(board: string, facts: AsBuiltFacts): string {
|
|
194
|
+
const byPin = (a: AsBuiltRoute, b: AsBuiltRoute) =>
|
|
195
|
+
a.port.localeCompare(b.port) || a.bit - b.bit || a.channel - b.channel;
|
|
196
|
+
return JSON.stringify({
|
|
197
|
+
version: 1,
|
|
198
|
+
board,
|
|
199
|
+
generatedAt: new Date().toISOString(),
|
|
200
|
+
routes: {
|
|
201
|
+
adcPins: [...facts.adc].sort(byPin),
|
|
202
|
+
pwmPins: [...facts.pwm].sort(byPin),
|
|
203
|
+
dacPins: [...facts.dac].sort(byPin),
|
|
204
|
+
},
|
|
205
|
+
}, null, 1);
|
|
206
|
+
}
|