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 boards filtered by idf target #1079

Merged
merged 1 commit into from
Dec 19, 2023
Merged
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
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 @@ -1852,7 +1852,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
Loading