@@ -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";
2628import Logger from "../logger.mjs" ;
2729import { rustProjectGetSelectedChip } from "../utils/rustUtil.mjs" ;
2830import { 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
3039export 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
4960export 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
6881export 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
159174export 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
198215export 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
309359export 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
322374export 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