Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 62 additions & 7 deletions src/commands/switchBoard.mts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge this change - just a couple of whitespace issues which I'll fixup

Copy link
Contributor Author

@shalxmva shalxmva Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added support to that variable as a path list,
If you add spaces at the end of the value, single quote characters are added at start and at the end.
This change will make this feature more robust.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import {
cmakeGetSelectedToolchainAndSDKVersions,
cmakeUpdateBoard,
cmakeUpdateSDK,
cmakeGetPicoVar,
} from "../utils/cmakeUtil.mjs";
import { join } from "path";
import { resolve } from "path";
import { normalize } from "path";
import { compareLt } from "../utils/semverUtil.mjs";
import type UI from "../ui.mjs";
import { updateVSCodeStaticConfigs } from "../utils/vscodeConfigUtil.mjs";
Expand All @@ -32,20 +35,74 @@ 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");
}

if (!compareLt(sdkVersion, "2.1.0")) {
quickPickItems.push("pico2_w");
}

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

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

let picoBoardHeaderDirs = cmakeGetPicoVar(
cMakeCachePath,
"PICO_BOARD_HEADER_DIRS");

if(picoBoardHeaderDirs){
if(picoBoardHeaderDirs.startsWith("'")){
const substrLen = picoBoardHeaderDirs.length-1;
picoBoardHeaderDirs = picoBoardHeaderDirs.substring(1,substrLen);
}

readdirSync(join(sdkPath, "src", "boards", "include", "boards")).forEach(
file => {
quickPickItems.push(file.split(".")[0]);
const picoBoardHeaderDirList = picoBoardHeaderDirs.split(";");
picoBoardHeaderDirList.forEach(
item => {
let boardPath = resolve(item);
const normalized = normalize(item);

//If path is not absolute, join workspace path
if(boardPath !== normalized){
boardPath = join(ws,normalized);
}

if(existsSync(boardPath)){
boardHeaderDirList.push(boardPath);
}
}
);
}
}

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 @@ -60,9 +117,7 @@ export default class SwitchBoardCommand extends Command {
}

// 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