Skip to content

Commit 43c0463

Browse files
committed
Add support for looking into PICO_BOARD_HEADER_DIRS custom board header
files Add Use CMAKE_PROJECT_NAME from CMakeCache.txt when getting the project name
1 parent f9382f3 commit 43c0463

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

src/commands/switchBoard.mts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
cmakeGetSelectedToolchainAndSDKVersions,
1212
cmakeUpdateBoard,
1313
cmakeUpdateSDK,
14+
cmakeGetPicoVar,
1415
} from "../utils/cmakeUtil.mjs";
1516
import { join } from "path";
1617
import { compareLt } from "../utils/semverUtil.mjs";
@@ -32,6 +33,7 @@ export default class SwitchBoardCommand extends Command {
3233
public static async askBoard(sdkVersion: string):
3334
Promise<[string, boolean] | undefined> {
3435
const quickPickItems: string[] = ["pico", "pico_w"];
36+
const workspaceFolder = workspace.workspaceFolders?.[0];
3537

3638
if (!compareLt(sdkVersion, "2.0.0")) {
3739
quickPickItems.push("pico2");
@@ -42,10 +44,44 @@ export default class SwitchBoardCommand extends Command {
4244
}
4345

4446
const sdkPath = buildSDKPath(sdkVersion);
47+
const boardHeaderDirList = [];
48+
49+
if(workspaceFolder !== undefined) {
50+
const ws = workspaceFolder.uri.fsPath;
51+
const cMakeCachePath = join(ws, "build","CMakeCache.txt");
4552

46-
readdirSync(join(sdkPath, "src", "boards", "include", "boards")).forEach(
47-
file => {
48-
quickPickItems.push(file.split(".")[0]);
53+
const picoBoardHeaderDirs = cmakeGetPicoVar(
54+
cMakeCachePath,
55+
"PICO_BOARD_HEADER_DIRS");
56+
57+
if(picoBoardHeaderDirs){
58+
boardHeaderDirList.push(picoBoardHeaderDirs);
59+
}
60+
}
61+
62+
const systemBoardHeaderDir =
63+
join(sdkPath,"src", "boards", "include","boards");
64+
65+
boardHeaderDirList.push(systemBoardHeaderDir);
66+
67+
interface IBoardFile{
68+
[key: string]: string;
69+
};
70+
71+
const boardFiles:IBoardFile = {};
72+
73+
boardHeaderDirList.forEach(
74+
path =>{
75+
readdirSync(path).forEach(
76+
file => {
77+
const fullFilename = join(path, file);
78+
if(fullFilename.endsWith(".h")) {
79+
const boardName = file.split(".")[0];
80+
boardFiles[boardName] = fullFilename;
81+
quickPickItems.push(boardName);
82+
}
83+
}
84+
)
4985
}
5086
);
5187

@@ -58,11 +94,9 @@ export default class SwitchBoardCommand extends Command {
5894

5995
return board;
6096
}
61-
97+
6298
// Check that board doesn't have an RP2040 on it
63-
const data = readFileSync(
64-
join(sdkPath, "src", "boards", "include", "boards", `${board}.h`)
65-
)
99+
const data = readFileSync(boardFiles[board])
66100

67101
if (data.includes("rp2040")) {
68102

0 commit comments

Comments
 (0)