Skip to content

Commit

Permalink
add boards filtered by idf target (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 authored Dec 19, 2023
1 parent a910f68 commit 00198dc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
20 changes: 16 additions & 4 deletions src/espIdf/openOcd/boardConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ export function getOpenOcdScripts(workspace: Uri): string {
return openOcdScriptsPath;
}

export async function getBoards(openOcdScriptsPath: string = "") {
export async function getBoards(
idfTarget: string = "",
openOcdScriptsPath: string = ""
) {
if (!openOcdScriptsPath) {
return defaultBoards;
const filteredDefaultBoards = defaultBoards.filter((b) => {
return b.target === idfTarget;
});
return idfTarget ? filteredDefaultBoards : defaultBoards;
}
const openOcdEspConfig = join(openOcdScriptsPath, "esp-config.json");
try {
Expand Down Expand Up @@ -131,9 +137,15 @@ export async function getBoards(openOcdScriptsPath: string = "") {
configFiles: ["interface/ftdi/esp32_devkitj_v1.cfg", "target/esp32.cfg"],
} as IdfBoard;
espBoards.push(emptyBoard);
return espBoards;
const filteredEspBoards = espBoards.filter((b) => {
return b.target === idfTarget;
});
return idfTarget ? filteredEspBoards : espBoards;
} catch (error) {
Logger.error(error.message, error);
return defaultBoards;
const filteredDefaultBoards = defaultBoards.filter((b) => {
return b.target === idfTarget;
});
return idfTarget ? filteredDefaultBoards : defaultBoards;
}
}
10 changes: 3 additions & 7 deletions src/espIdf/setTarget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export async function setIdfTarget(placeHolderMsg: string) {
},
async (progress: Progress<{ message: string; increment: number }>) => {
try {
const openOcdScriptsPath = getOpenOcdScripts(workspaceFolder.uri);
const boards = await getBoards(openOcdScriptsPath);
const targetsFromIdf = await getTargetsFromEspIdf(workspaceFolder.uri);
const selectedTarget = await window.showQuickPick(targetsFromIdf);
if (!selectedTarget) {
Expand Down Expand Up @@ -87,11 +85,9 @@ export async function setIdfTarget(placeHolderMsg: string) {
configurationTarget,
workspaceFolder.uri
);

const boardsForTarget = boards.filter(
(b) => b.target === selectedTarget.target
);
const choices = boardsForTarget.map((b) => {
const openOcdScriptsPath = getOpenOcdScripts(workspaceFolder.uri);
const boards = await getBoards(selectedTarget.target, openOcdScriptsPath);
const choices = boards.map((b) => {
return {
description: `${b.description} (${b.configFiles})`,
label: b.name,
Expand Down
12 changes: 11 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,17 @@ export async function activate(context: vscode.ExtensionContext) {
registerIDFCommand("espIdf.selectOpenOcdConfigFiles", async () => {
try {
const openOcdScriptsPath = getOpenOcdScripts(workspaceRoot);
const boards = await getBoards(openOcdScriptsPath);
let idfTarget = idfConf.readParameter(
"idf.adapterTargetName",
workspaceRoot
) as string;
if (idfTarget === "custom") {
idfTarget = idfConf.readParameter(
"idf.customAdapterTargetName",
workspaceRoot
) as string;
}
const boards = await getBoards(idfTarget, openOcdScriptsPath);
const choices = boards.map((b) => {
return {
description: `${b.description} (${b.configFiles})`,
Expand Down
2 changes: 1 addition & 1 deletion src/test/oocdBoards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ suite("OpenOCD Board tests", () => {
});

test("OpenOCD Boards method", async () => {
const boards = await getBoards(openOcdScriptsPath);
const boards = await getBoards(boardJsonObj.boards[0].target, openOcdScriptsPath);
assert.equal(boards[0].name, boardJsonObj.boards[0].name);
assert.equal(boards[0].description, boardJsonObj.boards[0].description);
assert.equal(boards[0].target, boardJsonObj.boards[0].target);
Expand Down

0 comments on commit 00198dc

Please sign in to comment.