Skip to content
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
114 changes: 103 additions & 11 deletions src/espIdf/openOcd/boardConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
* limitations under the License.
*/
import { join } from "path";
import * as idfConf from "../../idfConfiguration";
import { readParameter, writeParameter } from "../../idfConfiguration";
import { readJSON } from "fs-extra";
import { Logger } from "../../logger/logger";
import { Uri } from "vscode";
import { commands, ConfigurationTarget, l10n, Uri, window } from "vscode";
import { defaultBoards } from "./defaultBoards";
import { IdfToolsManager } from "../../idfToolsManager";
import { getIdfTargetFromSdkconfig } from "../../workspaceConfig";

export interface IdfBoard {
name: string;
Expand All @@ -31,15 +32,11 @@ export interface IdfBoard {
}

export async function getOpenOcdScripts(workspace: Uri): Promise<string> {
const idfPathDir = idfConf.readParameter(
"idf.espIdfPath",
workspace
) as string;
const toolsPath = idfConf.readParameter("idf.toolsPath", workspace) as string;
const userExtraVars = idfConf.readParameter(
"idf.customExtraVars",
workspace
) as { [key: string]: string };
const idfPathDir = readParameter("idf.espIdfPath", workspace) as string;
const toolsPath = readParameter("idf.toolsPath", workspace) as string;
const userExtraVars = readParameter("idf.customExtraVars", workspace) as {
[key: string]: string;
};
const idfToolsManager = await IdfToolsManager.createIdfToolsManager(
idfPathDir
);
Expand Down Expand Up @@ -113,3 +110,98 @@ export async function getBoards(
return idfTarget ? filteredDefaultBoards : defaultBoards;
}
}

export async function selectOpenOcdConfigFiles(
workspaceFolder: Uri,
idfTarget?: string
) {
try {
const openOcdScriptsPath = await getOpenOcdScripts(workspaceFolder);
if (!idfTarget) {
idfTarget = await getIdfTargetFromSdkconfig(workspaceFolder);
if (!idfTarget) {
commands.executeCommand("espIdf.setTarget");
return;
}
}
const currentOpenOcdConfigs = readParameter(
"idf.openOcdConfigs",
workspaceFolder
) as string[];
const boards = await getBoards(openOcdScriptsPath, idfTarget);
const choices = boards.map((b) => {
return {
description: `${b.description} (${b.configFiles})`,
label: b.name,
target: b,
picked: currentOpenOcdConfigs
.join(",")
.includes(b.configFiles.join(",")),
};
});
const selectOpenOCdConfigsMsg = l10n.t(
"Enter OpenOCD Configuration File Paths list"
);
const boardQuickPick = window.createQuickPick<{
description: string;
label: string;
target: IdfBoard;
picked: boolean;
}>();
boardQuickPick.items = choices;
boardQuickPick.placeholder = selectOpenOCdConfigsMsg;
boardQuickPick.onDidHide(() => {
boardQuickPick.dispose();
});
boardQuickPick.activeItems = boardQuickPick.items.filter(
(item) => item.picked
);

return new Promise<void>((resolve) => {
boardQuickPick.onDidHide(() => {
boardQuickPick.dispose();
resolve();
});
boardQuickPick.onDidAccept(async () => {
const selectedBoard = boardQuickPick.selectedItems[0];
if (!selectedBoard) {
Logger.infoNotify(
`ESP-IDF board not selected. Remember to set the configuration files for OpenOCD with idf.openOcdConfigs`
);
} else if (selectedBoard && selectedBoard.target) {
if (selectedBoard.label.indexOf("Custom board") !== -1) {
const inputBoard = await window.showInputBox({
placeHolder: "Enter comma-separated configuration files",
value: selectedBoard.target.configFiles.join(","),
});
if (inputBoard) {
selectedBoard.target.configFiles = inputBoard.split(",");
}
}
await writeParameter(
"idf.openOcdConfigs",
selectedBoard.target.configFiles,
ConfigurationTarget.WorkspaceFolder,
workspaceFolder
);
Logger.infoNotify(
l10n.t("OpenOCD Board configuration files are updated.")
);
boardQuickPick.dispose();
resolve();
}
boardQuickPick.hide();
});
boardQuickPick.show();
});
} catch (error) {
const errMsg =
error.message || "Failed to select openOCD configuration files";
Logger.errorNotify(
errMsg,
error,
"boardConfiguration selectOpenOcdConfigFiles"
);
return;
}
}
41 changes: 4 additions & 37 deletions src/espIdf/setTarget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from "../../idfConfiguration";
import { Logger } from "../../logger/logger";
import { OutputChannel } from "../../logger/outputChannel";
import { getBoards, getOpenOcdScripts } from "../openOcd/boardConfiguration";
import { selectOpenOcdConfigFiles } from "../openOcd/boardConfiguration";
import { getTargetsFromEspIdf } from "./getTargets";
import { setTargetInIDF } from "./setTargetInIdf";
import { updateCurrentProfileIdfTarget } from "../../project-conf";
Expand Down Expand Up @@ -74,45 +74,12 @@ export async function setIdfTarget(
if (!selectedTarget) {
return;
}
const openOcdScriptsPath = await getOpenOcdScripts(workspaceFolder.uri);
const boards = await getBoards(
openOcdScriptsPath,
await selectOpenOcdConfigFiles(
workspaceFolder.uri,
selectedTarget.target
);
const choices = boards.map((b) => {
return {
description: `${b.description} (${b.configFiles})`,
label: b.name,
target: b.configFiles,
};
});
const selectedBoard = await window.showQuickPick(choices, {
placeHolder: "Enter OpenOCD Configuration File Paths list",
});
if (!selectedBoard) {
Logger.infoNotify(
`ESP-IDF board not selected. Remember to set the configuration files for OpenOCD with idf.openOcdConfigs`
);
}
await setTargetInIDF(workspaceFolder, selectedTarget);
if (selectedBoard && selectedBoard.target) {
if (selectedBoard.label.indexOf("Custom board") !== -1) {
const inputBoard = await window.showInputBox({
placeHolder: "Enter comma-separated configuration files",
value: selectedBoard.target.join(","),
});
if (inputBoard) {
selectedBoard.target = inputBoard.split(",");
}
}
await writeParameter(
"idf.openOcdConfigs",
selectedBoard.target,
configurationTarget,
workspaceFolder.uri
);
}

await setTargetInIDF(workspaceFolder, selectedTarget);
const customExtraVars = readParameter(
"idf.customExtraVars",
workspaceFolder
Expand Down
67 changes: 4 additions & 63 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ import {
import del from "del";
import { NVSPartitionTable } from "./espIdf/nvs/partitionTable/panel";
import {
getBoards,
getOpenOcdScripts,
selectOpenOcdConfigFiles,
} from "./espIdf/openOcd/boardConfiguration";
import { generateConfigurationReport } from "./support";
import { initializeReportObject } from "./support/initReportObj";
Expand Down Expand Up @@ -2294,68 +2294,9 @@ export async function activate(context: vscode.ExtensionContext) {
return result.trim();
});

registerIDFCommand("espIdf.selectOpenOcdConfigFiles", async () => {
try {
const openOcdScriptsPath = await getOpenOcdScripts(workspaceRoot);
let idfTarget = await getIdfTargetFromSdkconfig(workspaceRoot);
if (!idfTarget) {
vscode.commands.executeCommand("espIdf.setTarget");
return;
}
const boards = await getBoards(openOcdScriptsPath, idfTarget);
const choices = boards.map((b) => {
return {
description: `${b.description} (${b.configFiles})`,
label: b.name,
target: b,
};
});
const selectOpenOCdConfigsMsg = vscode.l10n.t(
"Enter OpenOCD Configuration File Paths list"
);
const selectedBoard = await vscode.window.showQuickPick(choices, {
placeHolder: selectOpenOCdConfigsMsg,
});
if (!selectedBoard) {
return;
}

if (selectedBoard.target.name.indexOf("Custom board") !== -1) {
const inputBoard = await vscode.window.showInputBox({
placeHolder: vscode.l10n.t(
"Enter comma-separated configuration files"
),
value: selectedBoard.target.configFiles.join(","),
});
if (inputBoard) {
selectedBoard.target.configFiles = inputBoard.split(",");
}
}

const target = idfConf.readParameter("idf.saveScope");
if (
!PreCheck.isWorkspaceFolderOpen() &&
target !== vscode.ConfigurationTarget.Global
) {
const noWsOpenMSg = vscode.l10n.t(`Open a workspace or folder first.`);
Logger.warnNotify(noWsOpenMSg);
throw new Error(noWsOpenMSg);
}
await idfConf.writeParameter(
"idf.openOcdConfigs",
selectedBoard.target.configFiles,
target
);
Logger.infoNotify(
vscode.l10n.t("OpenOCD Board configuration files are updated.")
);
} catch (error) {
const errMsg =
error.message || "Failed to select openOCD configuration files";
Logger.errorNotify(errMsg, error, "extension selectOpenOcdConfigFiles");
return;
}
});
registerIDFCommand("espIdf.selectOpenOcdConfigFiles", async () =>
selectOpenOcdConfigFiles(workspaceRoot)
);

registerIDFCommand("espIdf.getOpenOcdScriptValue", async () => {
return await getOpenOcdScripts(workspaceRoot);
Expand Down