Skip to content

Commit

Permalink
Add support for looking into PICO_BOARD_HEADER_DIRS custom board header
Browse files Browse the repository at this point in the history
files

Add Use CMAKE_PROJECT_NAME from CMakeCache.txt when getting the project
name
  • Loading branch information
shalxmva committed Jan 6, 2025
1 parent 3e26da6 commit 9325bf0
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions src/commands/switchBoard.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
cmakeGetSelectedToolchainAndSDKVersions,
cmakeUpdateBoard,
cmakeUpdateSDK,
cmakeGetPicoVar,
} from "../utils/cmakeUtil.mjs";
import { join } from "path";
import { compareLt } from "../utils/semverUtil.mjs";
Expand All @@ -32,6 +33,7 @@ export default class SwitchBoardCommand extends Command {
public static async askBoard(sdkVersion: string):
Promise<[string, boolean] | undefined> {
const quickPickItems: string[] = ["pico", "pico_w"];
const workspaceFolder = workspace.workspaceFolders?.[0];

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

const sdkPath = buildSDKPath(sdkVersion);
const boardHeaderDirList = [];

if(workspaceFolder !== undefined) {
const ws = workspaceFolder.uri.fsPath;
const cMakeCachePath = join(ws, "build","CMakeCache.txt");

readdirSync(join(sdkPath, "src", "boards", "include", "boards")).forEach(
file => {
quickPickItems.push(file.split(".")[0]);
const picoBoardHeaderDirs = cmakeGetPicoVar(
cMakeCachePath,
"PICO_BOARD_HEADER_DIRS");

if(picoBoardHeaderDirs){
boardHeaderDirList.push(picoBoardHeaderDirs);
}
}

const systemBoardHeaderDir =
join(sdkPath,"src", "boards", "include","boards");

boardHeaderDirList.push(systemBoardHeaderDir);

interface IBoardFile{
[key: string]: string;
};

const boardFiles:IBoardFile = {};

boardHeaderDirList.forEach(
path =>{
readdirSync(path).forEach(
file => {
const fullFilename = join(path, file);
if(fullFilename.endsWith(".h")) {
const boardName = file.split(".")[0];
boardFiles[boardName] = fullFilename;
quickPickItems.push(boardName);
}
}
)
}
);

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

return board;
}

// Check that board doesn't have an RP2040 on it
const data = readFileSync(
join(sdkPath, "src", "boards", "include", "boards", `${board}.h`)
)
const data = readFileSync(boardFiles[board])

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

Expand Down

0 comments on commit 9325bf0

Please sign in to comment.