Skip to content

Commit 9908fa6

Browse files
authored
Merge pull request #214 from raspberrypi/zephyr-support
Add Zephyr support
2 parents d15b421 + c00b3d4 commit 9908fa6

26 files changed

+5479
-244
lines changed

package.json

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"activationEvents": [
6767
"workspaceContains:./pico_sdk_import.cmake",
6868
"workspaceContains:./.pico-rs",
69+
"workspaceContains:./prj.conf",
6970
"onWebviewPanel:newPicoProject",
7071
"onWebviewPanel:newPicoMicroPythonProject"
7172
],
@@ -80,13 +81,13 @@
8081
"command": "raspberry-pi-pico.switchSDK",
8182
"title": "Switch Pico SDK",
8283
"category": "Raspberry Pi Pico",
83-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
84+
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isZephyrProject"
8485
},
8586
{
8687
"command": "raspberry-pi-pico.switchBoard",
8788
"title": "Switch Board",
8889
"category": "Raspberry Pi Pico",
89-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
90+
"enablement": "raspberry-pi-pico.isPicoProject"
9091
},
9192
{
9293
"command": "raspberry-pi-pico.launchTargetPath",
@@ -159,13 +160,25 @@
159160
"title": "Get OpenOCD root",
160161
"category": "Raspberry Pi Pico",
161162
"enablement": "false"
162-
},
163+
},
163164
{
164165
"command": "raspberry-pi-pico.getSVDPath",
165166
"title": "Get SVD Path (rust only)",
166167
"category": "Raspberry Pi Pico",
167168
"enablement": "false"
168169
},
170+
{
171+
"command": "raspberry-pi-pico.getWestPath",
172+
"title": "Get West path",
173+
"category": "Raspberry Pi Pico",
174+
"enablement": "false"
175+
},
176+
{
177+
"command": "raspberry-pi-pico.getZephyrWorkspacePath",
178+
"title": "Get Zephyr workspace path",
179+
"category": "Raspberry Pi Pico",
180+
"enablement": "false"
181+
},
169182
{
170183
"command": "raspberry-pi-pico.compileProject",
171184
"title": "Compile Pico Project",
@@ -210,7 +223,7 @@
210223
"command": "raspberry-pi-pico.switchBuildType",
211224
"title": "Switch Build Type",
212225
"category": "Raspberry Pi Pico",
213-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
226+
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject && !raspberry-pi-pico.isZephyrProject"
214227
},
215228
{
216229
"command": "raspberry-pi-pico.importProject",
@@ -244,12 +257,6 @@
244257
"category": "Raspberry Pi Pico",
245258
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
246259
},
247-
{
248-
"command": "raspberry-pi-pico.getRTTDecoderPath",
249-
"title": "Get RTT Decoder module path",
250-
"category": "Raspberry Pi Pico",
251-
"enablement": "false"
252-
},
253260
{
254261
"command": "raspberry-pi-pico.sbomTargetPathDebug",
255262
"title": "Get path of the project debug SBOM (rust only)",

scripts/pico_project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ def generateProjectFiles(
11591159
]
11601160
}
11611161

1162+
# TODO: use get picotool path command!
11621163
tasks = f"""{{
11631164
"version": "2.0.0",
11641165
"tasks": [

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: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
buildPicotoolPath,
1414
buildSDKPath,
1515
buildToolchainPath,
16+
buildWestPath,
17+
buildZephyrWorkspacePath,
1618
downloadAndInstallOpenOCD,
1719
downloadAndInstallPicotool,
1820
} from "../utils/download.mjs";
@@ -26,10 +28,19 @@ import { getSupportedToolchains } from "../utils/toolchainUtil.mjs";
2628
import Logger from "../logger.mjs";
2729
import { rustProjectGetSelectedChip } from "../utils/rustUtil.mjs";
2830
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";
2938

3039
export class GetPythonPathCommand extends CommandWithResult<string> {
40+
public static readonly id = "getPythonPath";
41+
3142
constructor() {
32-
super("getPythonPath");
43+
super(GetPythonPathCommand.id);
3344
}
3445

3546
async execute(): Promise<string> {
@@ -47,8 +58,10 @@ export class GetPythonPathCommand extends CommandWithResult<string> {
4758
}
4859

4960
export class GetEnvPathCommand extends CommandWithResult<string> {
61+
public static readonly id = "getEnvPath";
62+
5063
constructor() {
51-
super("getEnvPath");
64+
super(GetEnvPathCommand.id);
5265
}
5366

5467
async execute(): Promise<string> {
@@ -66,8 +79,10 @@ export class GetEnvPathCommand extends CommandWithResult<string> {
6679
}
6780

6881
export class GetGDBPathCommand extends CommandWithResult<string> {
82+
public static readonly id = "getGDBPath";
83+
6984
constructor(private readonly _extensionUri: Uri) {
70-
super("getGDBPath");
85+
super(GetGDBPathCommand.id);
7186
}
7287

7388
async execute(): Promise<string> {
@@ -157,8 +172,10 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
157172
}
158173

159174
export class GetCompilerPathCommand extends CommandWithResult<string> {
175+
public static readonly id = "getCompilerPath";
176+
160177
constructor() {
161-
super("getCompilerPath");
178+
super(GetCompilerPathCommand.id);
162179
}
163180

164181
async execute(): Promise<string> {
@@ -196,8 +213,10 @@ export class GetCompilerPathCommand extends CommandWithResult<string> {
196213
}
197214

198215
export class GetCxxCompilerPathCommand extends CommandWithResult<string> {
216+
public static readonly id = "getCxxCompilerPath";
217+
199218
constructor() {
200-
super("getCxxCompilerPath");
219+
super(GetCxxCompilerPathCommand.id);
201220
}
202221

203222
async execute(): Promise<string> {
@@ -253,6 +272,37 @@ export class GetChipCommand extends CommandWithResult<string> {
253272

254273
const workspaceFolder = workspace.workspaceFolders?.[0];
255274
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+
}
256306

257307
if (isRustProject) {
258308
// read .pico-rs
@@ -307,8 +357,10 @@ export class GetChipCommand extends CommandWithResult<string> {
307357
}
308358

309359
export class GetChipUppercaseCommand extends CommandWithResult<string> {
360+
public static readonly id = "getChipUppercase";
361+
310362
constructor() {
311-
super("getChipUppercase");
363+
super(GetChipUppercaseCommand.id);
312364
}
313365

314366
async execute(): Promise<string> {
@@ -320,8 +372,10 @@ export class GetChipUppercaseCommand extends CommandWithResult<string> {
320372
}
321373

322374
export class GetTargetCommand extends CommandWithResult<string> {
375+
public static readonly id = "getTarget";
376+
323377
constructor() {
324-
super("getTarget");
378+
super(GetTargetCommand.id);
325379
}
326380

327381
async execute(): Promise<string> {
@@ -334,7 +388,28 @@ export class GetTargetCommand extends CommandWithResult<string> {
334388

335389
const workspaceFolder = workspace.workspaceFolders?.[0];
336390
const isRustProject = State.getInstance().isRustProject;
391+
const isZephyrProject = State.getInstance().isZephyrProject;
337392

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+
}
401+
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+
}
338413
if (isRustProject) {
339414
const chip = rustProjectGetSelectedChip(workspaceFolder.uri.fsPath);
340415

@@ -505,3 +580,41 @@ export class GetSVDPathCommand extends CommandWithResult<string | undefined> {
505580
);
506581
}
507582
}
583+
584+
export class GetWestPathCommand extends CommandWithResult<string | undefined> {
585+
public static readonly id = "getWestPath";
586+
587+
constructor() {
588+
super(GetWestPathCommand.id);
589+
}
590+
591+
execute(): string | undefined {
592+
const result = buildWestPath();
593+
594+
if (result === null || !result) {
595+
return undefined;
596+
}
597+
598+
return result;
599+
}
600+
}
601+
602+
export class GetZephyrWorkspacePathCommand extends CommandWithResult<
603+
string | undefined
604+
> {
605+
public static readonly id = "getZephyrWorkspacePath";
606+
607+
constructor() {
608+
super(GetZephyrWorkspacePathCommand.id);
609+
}
610+
611+
execute(): string | undefined {
612+
const result = buildZephyrWorkspacePath();
613+
614+
if (result === null || !result) {
615+
return undefined;
616+
}
617+
618+
return result;
619+
}
620+
}

0 commit comments

Comments
 (0)