@typecad/framework-zephyr 1.0.0-alpha.12 → 1.0.0-alpha.14
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 +13 -1
- package/dist/chips/controllers.d.ts +28 -8
- package/dist/chips/controllers.js +49 -12
- package/dist/chips/resolve.js +32 -6
- package/dist/chips/types.d.ts +63 -12
- package/dist/chips/xiao-ble.js +12 -0
- package/dist/display/index.d.ts +1 -1
- package/dist/display/index.js +1 -1
- package/dist/display/profiles.d.ts +8 -0
- package/dist/display/profiles.js +19 -0
- package/dist/display/ui-adapter.d.ts +4 -0
- package/dist/display/ui-adapter.js +46 -0
- package/dist/dt-config/kconfig.d.ts +11 -0
- package/dist/dt-config/kconfig.js +1 -1
- package/dist/dt-config/overlay.d.ts +8 -1
- package/dist/dt-config/overlay.js +104 -1
- package/dist/framework.manifest.d.ts +20 -30
- package/dist/framework.manifest.js +12 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/lowering/adc.d.ts +7 -4
- package/dist/lowering/adc.js +25 -11
- package/dist/lowering/gpio.js +15 -8
- package/dist/lowering/mqtt.js +9 -1
- package/dist/lowering/pulse.js +7 -7
- package/dist/lowering/pwm.d.ts +21 -3
- package/dist/lowering/pwm.js +28 -4
- package/dist/lowering/spi.js +2 -2
- package/dist/lowering/tone.js +3 -2
- package/dist/lowering/wifi.js +28 -5
- package/dist/strategy.d.ts +20 -0
- package/dist/strategy.js +295 -119
- package/dist/toolchain/debug-config.d.ts +43 -2
- package/dist/toolchain/debug-config.js +129 -17
- package/dist/toolchain/index.d.ts +14 -1
- package/dist/toolchain/index.js +146 -20
- package/dist/toolchain/scaffold.d.ts +9 -0
- package/dist/toolchain/scaffold.js +84 -19
- package/dist/toolchain/west-discover.d.ts +4 -1
- package/dist/toolchain/west-discover.js +2 -0
- package/dist/toolchain/west-spawn.js +17 -5
- package/package.json +5 -5
- package/src/chips/controllers.ts +61 -12
- package/src/chips/resolve.ts +32 -5
- package/src/chips/types.ts +63 -12
- package/src/chips/xiao-ble.ts +82 -70
- package/src/display/index.ts +1 -1
- package/src/display/profiles.ts +23 -0
- package/src/display/ui-adapter.ts +51 -0
- package/src/dt-config/kconfig.ts +12 -1
- package/src/dt-config/overlay.ts +123 -0
- package/src/framework.manifest.ts +12 -3
- package/src/index.ts +6 -0
- package/src/lowering/adc.ts +28 -12
- package/src/lowering/gpio.ts +15 -8
- package/src/lowering/mqtt.ts +9 -1
- package/src/lowering/pulse.ts +7 -7
- package/src/lowering/pwm.ts +29 -4
- package/src/lowering/spi.ts +2 -2
- package/src/lowering/tone.ts +3 -3
- package/src/lowering/wifi.ts +29 -5
- package/src/strategy.ts +320 -123
- package/src/toolchain/debug-config.ts +137 -14
- package/src/toolchain/index.ts +645 -513
- package/src/toolchain/scaffold.ts +81 -17
- package/src/toolchain/west-discover.ts +321 -316
- package/src/toolchain/west-spawn.ts +17 -5
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'node:fs';
|
|
19
19
|
import { join, resolve, dirname, relative } from 'node:path';
|
|
20
|
+
import { ZephyrStrategy } from '../strategy.js';
|
|
20
21
|
|
|
21
22
|
export interface DebugConfigOptions {
|
|
22
23
|
/** Absolute path to the Zephyr project root (contains CMakeLists.txt + src/). */
|
|
@@ -34,8 +35,10 @@ export interface DebugConfigOptions {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
|
-
* Resolve the GDB binary path for the target from the build cache
|
|
38
|
-
*
|
|
38
|
+
* Resolve the GDB binary path for the target from the build cache, falling
|
|
39
|
+
* back to a filesystem scan of known Zephyr SDK locations when no build
|
|
40
|
+
* exists yet (the create-time starter artifacts path). Zephyr records
|
|
41
|
+
* ZEPHYR_SDK_INSTALL_DIR in CMakeCache.txt at configure time, and the
|
|
39
42
|
* xtensa GDB lives at <sdk>/xtensa-espressif_esp32s3_zephyr-elf/bin/... (note
|
|
40
43
|
* the Zephyr-SDK naming, distinct from the ESP-IDF xtensa-esp32s3-elf-gdb).
|
|
41
44
|
*
|
|
@@ -43,24 +46,94 @@ export interface DebugConfigOptions {
|
|
|
43
46
|
* omits gdbPath and relies on Cortex-Debug's default resolution).
|
|
44
47
|
*/
|
|
45
48
|
export function resolveGdbPath(buildDir: string, target: string): string | undefined {
|
|
49
|
+
void target; // toolchain dir is esp32s3-specific today; see gdbPathFromSdkRoot
|
|
46
50
|
const cachePath = join(buildDir, 'CMakeCache.txt');
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
if (existsSync(cachePath)) {
|
|
52
|
+
try {
|
|
53
|
+
const cache = readFileSync(cachePath, 'utf-8');
|
|
54
|
+
const m = cache.match(/^ZEPHYR_SDK_INSTALL_DIR:PATH=(.+)$/m);
|
|
55
|
+
if (m) {
|
|
56
|
+
const fromCache = gdbPathFromSdkRoot(m[1].trim());
|
|
57
|
+
if (fromCache) return fromCache;
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
// unreadable cache — fall through to the SDK scan
|
|
61
|
+
}
|
|
55
62
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
// No build dir yet (project just created): probe known SDK locations.
|
|
64
|
+
for (const sdkRoot of discoverZephyrSdkRoots()) {
|
|
65
|
+
const p = gdbPathFromSdkRoot(sdkRoot);
|
|
66
|
+
if (p) return p;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The esp32s3 xtensa GDB location inside a Zephyr SDK root (verified against
|
|
72
|
+
* zephyr-sdk-0.17.4). Returns a forward-slash absolute path or undefined. */
|
|
73
|
+
export function gdbPathFromSdkRoot(sdkRoot: string): string | undefined {
|
|
59
74
|
const gdbName = 'xtensa-espressif_esp32s3_zephyr-elf-gdb.exe';
|
|
60
|
-
const gdbPath = join(
|
|
75
|
+
const gdbPath = join(sdkRoot, 'xtensa-espressif_esp32s3_zephyr-elf', 'bin', gdbName);
|
|
61
76
|
return existsSync(gdbPath) ? gdbPath.replace(/\\/g, '/') : undefined;
|
|
62
77
|
}
|
|
63
78
|
|
|
79
|
+
/** Compare two dotted version strings numerically (0.17.10 > 0.17.4). */
|
|
80
|
+
function compareSdkVersions(a: string, b: string): number {
|
|
81
|
+
const segsOf = (v: string): number[] => v.split('.').map((s) => parseInt(s, 10) || 0);
|
|
82
|
+
const aa = segsOf(a);
|
|
83
|
+
const bb = segsOf(b);
|
|
84
|
+
for (let i = 0; i < Math.max(aa.length, bb.length); i++) {
|
|
85
|
+
const d = (aa[i] ?? 0) - (bb[i] ?? 0);
|
|
86
|
+
if (d !== 0) return d;
|
|
87
|
+
}
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Probe the well-known Zephyr SDK install locations, newest version first:
|
|
93
|
+
* 1. $ZEPHYR_SDK_INSTALL_DIR (the var board.cmake reads)
|
|
94
|
+
* 2. <MAMBA_ROOT_PREFIX | ~/micromamba>/zephyr-sdk/zephyr-sdk-<ver> — the
|
|
95
|
+
* @typecad/zephyr-installer layout
|
|
96
|
+
* 3. ~/zephyr-sdk-<ver> — the standalone download layout
|
|
97
|
+
*
|
|
98
|
+
* Only roots that actually contain the esp32s3 GDB are useful to callers;
|
|
99
|
+
* this returns candidate roots (gdbPathFromSdkRoot does the existence check)
|
|
100
|
+
* so tests can inject home/env overrides.
|
|
101
|
+
*/
|
|
102
|
+
export function discoverZephyrSdkRoots(opts?: {
|
|
103
|
+
home?: string;
|
|
104
|
+
env?: Record<string, string | undefined>;
|
|
105
|
+
}): string[] {
|
|
106
|
+
const env = opts?.env ?? process.env;
|
|
107
|
+
const home = opts?.home ?? (env.USERPROFILE || env.HOME || '');
|
|
108
|
+
const scanned: string[] = [];
|
|
109
|
+
|
|
110
|
+
const versionedDirs = (base: string): string[] => {
|
|
111
|
+
try {
|
|
112
|
+
return readdirSync(base)
|
|
113
|
+
.filter((d) => existsSync(join(base, d)) && d.startsWith('zephyr-sdk-'))
|
|
114
|
+
.map((d) => join(base, d));
|
|
115
|
+
} catch {
|
|
116
|
+
return []; // dir absent
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const mambaRoot = env.MAMBA_ROOT_PREFIX || (home ? join(home, 'micromamba') : '');
|
|
120
|
+
if (mambaRoot) scanned.push(...versionedDirs(join(mambaRoot, 'zephyr-sdk')));
|
|
121
|
+
if (home) scanned.push(...versionedDirs(home));
|
|
122
|
+
|
|
123
|
+
// Scanned roots newest version first; the env var stays pinned first
|
|
124
|
+
// (explicit user intent outranks any discovered location).
|
|
125
|
+
scanned.sort((a, b) => {
|
|
126
|
+
const va = a.match(/zephyr-sdk-([\d.]+)/)?.[1] ?? '';
|
|
127
|
+
const vb = b.match(/zephyr-sdk-([\d.]+)/)?.[1] ?? '';
|
|
128
|
+
return compareSdkVersions(vb, va);
|
|
129
|
+
});
|
|
130
|
+
const roots = env.ZEPHYR_SDK_INSTALL_DIR
|
|
131
|
+
? [env.ZEPHYR_SDK_INSTALL_DIR, ...scanned]
|
|
132
|
+
: scanned;
|
|
133
|
+
// De-duplicate (an env var may repeat a scan hit) preserving order.
|
|
134
|
+
return roots.filter((r, i) => roots.indexOf(r) === i);
|
|
135
|
+
}
|
|
136
|
+
|
|
64
137
|
/**
|
|
65
138
|
* Resolve the Espressif OpenOCD binary path. The esp32s3 needs the Espressif
|
|
66
139
|
* OpenOCD fork (openocd-esp32) — not the Zephyr SDK's openocd and not a
|
|
@@ -397,3 +470,53 @@ export function writeDebugConfig(o: DebugConfigOptions): void {
|
|
|
397
470
|
const task = buildTask(o);
|
|
398
471
|
mergeJsonArrayEntry(join(vscodeDir, 'tasks.json'), 'tasks', 'label', task);
|
|
399
472
|
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* The Zephyr app dir a `cuttlefish create` scaffold produces, relative to the
|
|
476
|
+
* project root: the scaffold fixes entry `./src/main.ts` + outDir `./out`, and
|
|
477
|
+
* the CLI resolves output.outDir against the ENTRY's directory (cli.ts), so
|
|
478
|
+
* the emitted app root — and therefore the ELF, build dir, and .cuttlefish/
|
|
479
|
+
* debug artifacts — always lands at `src/out`. Keep in sync with
|
|
480
|
+
* generateProjectConfig in @typecad/cuttlefish create/templates.ts.
|
|
481
|
+
*/
|
|
482
|
+
const STARTER_SKETCH_REL = 'src/out';
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Create-time starter debug artifacts. Called by the cuttlefish `create` flow
|
|
486
|
+
* (via the package's `writeProjectDebugArtifacts` export) so a fresh project
|
|
487
|
+
* has a working F5 before any build exists:
|
|
488
|
+
*
|
|
489
|
+
* The launch.json's preLaunchTask runs `cuttlefish build --compile --upload
|
|
490
|
+
* --debug`, which builds + flashes AND rewrites this same launch entry (merged
|
|
491
|
+
* by name) with the CMakeCache-resolved gdbPath — so the starter files upgrade
|
|
492
|
+
* themselves on the first debug build.
|
|
493
|
+
*
|
|
494
|
+
* No-ops (returns []) for targets without native GDB support (debugMode() !==
|
|
495
|
+
* 'gdb'); the gdb frame-filter script is skipped (no source map exists yet).
|
|
496
|
+
*
|
|
497
|
+
* Returns the workspace-relative paths written, for CLI reporting.
|
|
498
|
+
*/
|
|
499
|
+
export function writeProjectDebugArtifacts(o: {
|
|
500
|
+
/** Absolute path to the cuttlefish project root (contains cuttlefish.config.ts). */
|
|
501
|
+
workspaceRoot: string;
|
|
502
|
+
/** The Zephyr board id from the project config (frameworkData.buildTarget). */
|
|
503
|
+
buildTarget?: string;
|
|
504
|
+
}): string[] {
|
|
505
|
+
if (new ZephyrStrategy().debugMode(o.buildTarget) !== 'gdb') return [];
|
|
506
|
+
const workspaceRoot = resolve(o.workspaceRoot);
|
|
507
|
+
const projectRoot = join(workspaceRoot, STARTER_SKETCH_REL);
|
|
508
|
+
writeDebugConfig({
|
|
509
|
+
projectRoot,
|
|
510
|
+
workspaceRoot,
|
|
511
|
+
sketchRel: STARTER_SKETCH_REL,
|
|
512
|
+
target: o.buildTarget ?? '',
|
|
513
|
+
// No build dir exists yet — resolveGdbPath falls back to probing known
|
|
514
|
+
// Zephyr SDK locations so gdbPath is still filled in when possible.
|
|
515
|
+
buildDir: join(projectRoot, 'build'),
|
|
516
|
+
});
|
|
517
|
+
return [
|
|
518
|
+
'.vscode/launch.json',
|
|
519
|
+
'.vscode/tasks.json',
|
|
520
|
+
`${STARTER_SKETCH_REL}/.cuttlefish/openocd.cfg`,
|
|
521
|
+
];
|
|
522
|
+
}
|