Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for looking into PICO_BOARD_HEADER_DIRS custom board header #123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 13 additions & 2 deletions src/commands/launchTargetPath.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CommandWithResult } from "./command.mjs";
import { commands, window, workspace } from "vscode";
import { join } from "path";
import Settings, { SettingsKey } from "../settings.mjs";
import { cmakeGetPicoVar } from "../utils/cmakeUtil.mjs";

export default class LaunchTargetPathCommand extends CommandWithResult<string> {
constructor() {
Expand All @@ -27,8 +28,8 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {

// Extract the project name from the matched result
if (match && match[1]) {
const projectName = match[1].trim();

let projectName = match[1].trim();
if (matchBg && matchPoll) {
// For examples with both background and poll, let user pick which to run
const quickPickItems = ["Threadsafe Background", "Poll"];
Expand All @@ -45,6 +46,16 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
case quickPickItems[1]:
return projectName + "_poll";
}
}else{
if(workspace.workspaceFolders !== undefined) {
let cmakeCacheFile = workspace.workspaceFolders[0].uri.fsPath;
cmakeCacheFile = join(cmakeCacheFile,"build","CMakeCache.txt");

const value = cmakeGetPicoVar(cmakeCacheFile,"CMAKE_PROJECT_NAME");
if(value !== null){
projectName = value;
}
}
}

return projectName;
Expand Down
50 changes: 42 additions & 8 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 { compareLtMajor } from "../utils/semverUtil.mjs";
Expand All @@ -32,16 +33,51 @@ 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 (!compareLtMajor(sdkVersion, "2.0.0")) {
quickPickItems.push("pico2");
}

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 sdkPath = buildSDKPath(sdkVersion);
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 @@ -54,11 +90,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