Skip to content

Commit ac6a004

Browse files
committed
Fix zephyr integration (part 6)
Signed-off-by: paulober <[email protected]>
1 parent e1ace0b commit ac6a004

File tree

14 files changed

+508
-471
lines changed

14 files changed

+508
-471
lines changed

package.json

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,13 @@
8181
"command": "raspberry-pi-pico.switchSDK",
8282
"title": "Switch Pico SDK",
8383
"category": "Raspberry Pi Pico",
84-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isPicoZephyrProject"
84+
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isZephyrProject"
8585
},
8686
{
8787
"command": "raspberry-pi-pico.switchBoard",
8888
"title": "Switch Board",
8989
"category": "Raspberry Pi Pico",
90-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
91-
},
92-
{
93-
"command": "raspberry-pi-pico.switchBoardZephyr",
94-
"title": "Switch Board for Zephyr",
95-
"category": "Raspberry Pi Pico",
96-
"enablement": "false"
90+
"enablement": "raspberry-pi-pico.isPicoProject"
9791
},
9892
{
9993
"command": "raspberry-pi-pico.launchTargetPath",
@@ -223,13 +217,13 @@
223217
"command": "raspberry-pi-pico.configureCmake",
224218
"title": "Configure CMake",
225219
"category": "Raspberry Pi Pico",
226-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isPicoZephyrProject"
220+
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
227221
},
228222
{
229223
"command": "raspberry-pi-pico.switchBuildType",
230224
"title": "Switch Build Type",
231225
"category": "Raspberry Pi Pico",
232-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isPicoZephyrProject"
226+
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isZephyrProject"
233227
},
234228
{
235229
"command": "raspberry-pi-pico.importProject",
@@ -261,13 +255,7 @@
261255
"command": "raspberry-pi-pico.cleanCmake",
262256
"title": "Clean CMake",
263257
"category": "Raspberry Pi Pico",
264-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isPicoZephyrProject"
265-
},
266-
{
267-
"command": "raspberry-pi-pico.getRTTDecoderPath",
268-
"title": "Get RTT Decoder module path",
269-
"category": "Raspberry Pi Pico",
270-
"enablement": "false"
258+
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
271259
},
272260
{
273261
"command": "raspberry-pi-pico.sbomTargetPathDebug",
@@ -280,16 +268,6 @@
280268
"title": "Get path of the project release SBOM (rust only)",
281269
"category": "Raspberry Pi Pico",
282270
"enablement": "false"
283-
},
284-
{
285-
"command": "raspberry-pi-pico.setupZephyr",
286-
"title": "Setup Zephyr Toolchain",
287-
"category": "Raspberry Pi Pico"
288-
},
289-
{
290-
"command": "raspberry-pi-pico.newZephyrProject",
291-
"title": "New Zephyr Project",
292-
"category": "Raspberry Pi Pico"
293271
}
294272
],
295273
"configuration": {

src/commands/configureCmake.mts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export default class ConfigureCmakeCommand extends Command {
4747
} else {
4848
void window.showWarningMessage(
4949
"CMake failed to configure your build. " +
50-
"See the developer console for details " +
51-
"(Help -> Toggle Developer Tools). " +
52-
"You can also use the CMake Tools Extension Integration " +
53-
"to get more information about the error."
50+
"See the developer console for details " +
51+
"(Help -> Toggle Developer Tools). " +
52+
"You can also use the CMake Tools Extension Integration " +
53+
"to get more information about the error."
5454
);
5555
}
5656
}
@@ -110,15 +110,15 @@ export class CleanCMakeCommand extends Command {
110110
} else {
111111
void window.showWarningMessage(
112112
"CMake could not be reconfigured. " +
113-
"See the developer console for details " +
114-
"(Help -> Toggle Developer Tools). " +
115-
"You can also use the CMake Tools Extension Integration " +
116-
"to get more information about the error."
113+
"See the developer console for details " +
114+
"(Help -> Toggle Developer Tools). " +
115+
"You can also use the CMake Tools Extension Integration " +
116+
"to get more information about the error."
117117
);
118118
}
119119

120120
const ws = workspaceFolder.uri.fsPath;
121-
const cMakeCachePath = join(ws, "build","CMakeCache.txt");
121+
const cMakeCachePath = join(ws, "build", "CMakeCache.txt");
122122
const newBuildType = cmakeGetPicoVar(cMakeCachePath, "CMAKE_BUILD_TYPE");
123123
this._ui.updateBuildType(newBuildType ?? "unknown");
124124
}
@@ -159,7 +159,7 @@ export class SwitchBuildTypeCommand extends Command {
159159
}
160160

161161
const ws = workspaceFolder.uri.fsPath;
162-
const cMakeCachePath = join(ws, "build","CMakeCache.txt");
162+
const cMakeCachePath = join(ws, "build", "CMakeCache.txt");
163163
const oldBuildType = cmakeGetPicoVar(cMakeCachePath, "CMAKE_BUILD_TYPE");
164164

165165
// QuickPick for the build type
@@ -173,10 +173,10 @@ export class SwitchBuildTypeCommand extends Command {
173173
} else {
174174
void window.showWarningMessage(
175175
"CMake failed to configure your build. " +
176-
"See the developer console for details " +
177-
"(Help -> Toggle Developer Tools). " +
178-
"You can also use the CMake Tools Extension Integration " +
179-
"to get more information about the error."
176+
"See the developer console for details " +
177+
"(Help -> Toggle Developer Tools). " +
178+
"You can also use the CMake Tools Extension Integration " +
179+
"to get more information about the error."
180180
);
181181
}
182182

src/commands/getPaths.mts

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ import { getSupportedToolchains } from "../utils/toolchainUtil.mjs";
2828
import Logger from "../logger.mjs";
2929
import { rustProjectGetSelectedChip } from "../utils/rustUtil.mjs";
3030
import { OPENOCD_VERSION } from "../utils/sharedConstants.mjs";
31+
import {
32+
getBoardFromZephyrProject,
33+
ZEPHYR_PICO,
34+
ZEPHYR_PICO2,
35+
ZEPHYR_PICO2_W,
36+
ZEPHYR_PICO_W,
37+
} from "./switchBoard.mjs";
3138

3239
export class GetPythonPathCommand extends CommandWithResult<string> {
3340
public static readonly id = "getPythonPath";
@@ -265,6 +272,37 @@ export class GetChipCommand extends CommandWithResult<string> {
265272

266273
const workspaceFolder = workspace.workspaceFolders?.[0];
267274
const isRustProject = State.getInstance().isRustProject;
275+
const isZephyrProject = State.getInstance().isZephyrProject;
276+
277+
if (isZephyrProject) {
278+
const board = await getBoardFromZephyrProject(
279+
join(workspaceFolder.uri.fsPath, ".vscode", "tasks.json")
280+
);
281+
282+
if (board === undefined) {
283+
this._logger.error("Failed to read Zephyr board from tasks.json");
284+
285+
return "";
286+
}
287+
288+
switch (board) {
289+
case ZEPHYR_PICO:
290+
case ZEPHYR_PICO_W:
291+
return "rp2040";
292+
case ZEPHYR_PICO2:
293+
case ZEPHYR_PICO2_W:
294+
return "rp2350";
295+
default:
296+
this._logger.error(`Unsupported Zephyr board: ${board}`);
297+
void window.showErrorMessage(
298+
`Unsupported Zephyr board: ${board}. ` +
299+
`Supported boards are: ${ZEPHYR_PICO}, ${ZEPHYR_PICO_W}, ` +
300+
`${ZEPHYR_PICO2}, ${ZEPHYR_PICO2_W}`
301+
);
302+
303+
return "rp2040";
304+
}
305+
}
268306

269307
if (isRustProject) {
270308
// read .pico-rs
@@ -350,7 +388,28 @@ export class GetTargetCommand extends CommandWithResult<string> {
350388

351389
const workspaceFolder = workspace.workspaceFolders?.[0];
352390
const isRustProject = State.getInstance().isRustProject;
391+
const isZephyrProject = State.getInstance().isZephyrProject;
392+
393+
if (isZephyrProject) {
394+
const board = await getBoardFromZephyrProject(
395+
join(workspaceFolder.uri.fsPath, ".vscode", "tasks.json")
396+
);
397+
398+
if (board === undefined) {
399+
return "rp2040";
400+
}
353401

402+
switch (board) {
403+
case ZEPHYR_PICO:
404+
case ZEPHYR_PICO_W:
405+
return "rp2040";
406+
case ZEPHYR_PICO2:
407+
case ZEPHYR_PICO2_W:
408+
return "rp2350";
409+
default:
410+
return "rp2040";
411+
}
412+
}
354413
if (isRustProject) {
355414
const chip = rustProjectGetSelectedChip(workspaceFolder.uri.fsPath);
356415

@@ -523,61 +582,39 @@ export class GetSVDPathCommand extends CommandWithResult<string | undefined> {
523582
}
524583

525584
export class GetWestPathCommand extends CommandWithResult<string | undefined> {
526-
private running: boolean = false;
527-
528585
public static readonly id = "getWestPath";
529586

530587
constructor() {
531588
super(GetWestPathCommand.id);
532589
}
533590

534591
execute(): string | undefined {
535-
if (this.running) {
536-
return undefined;
537-
}
538-
this.running = true;
539-
540592
const result = buildWestPath();
541593

542594
if (result === null || !result) {
543-
this.running = false;
544-
545595
return undefined;
546596
}
547597

548-
this.running = false;
549-
550598
return result;
551599
}
552600
}
553601

554602
export class GetZephyrWorkspacePathCommand extends CommandWithResult<
555603
string | undefined
556604
> {
557-
private running: boolean = false;
558-
559605
public static readonly id = "getZephyrWorkspacePath";
560606

561607
constructor() {
562608
super(GetZephyrWorkspacePathCommand.id);
563609
}
564610

565611
execute(): string | undefined {
566-
if (this.running) {
567-
return undefined;
568-
}
569-
this.running = true;
570-
571612
const result = buildZephyrWorkspacePath();
572613

573614
if (result === null || !result) {
574-
this.running = false;
575-
576615
return undefined;
577616
}
578617

579-
this.running = false;
580-
581618
return result;
582619
}
583620
}

0 commit comments

Comments
 (0)