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
10 changes: 8 additions & 2 deletions src/cdtDebugAdapter/debugConfProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export class CDTDebugConfigurationProvider
| "esp32c3"
| "esp32c6"
| "esp32h2"
| "esp32p4";
| "esp32p4"
| "esp32c4"
| "esp32c5"
| "esp32c61";
// Mapping of idfTarget to corresponding CPU watchpoint numbers
const idfTargetWatchpointMap: Record<IdfTarget, number> = {
esp32: 2,
Expand All @@ -121,11 +124,14 @@ export class CDTDebugConfigurationProvider
esp32c6: 4,
esp32h2: 4,
esp32p4: 3,
esp32c4: 2,
esp32c5: 4,
esp32c61: 4,
};
config.initCommands = config.initCommands.map((cmd: string) =>
cmd.replace(
"{IDF_TARGET_CPU_WATCHPOINT_NUM}",
idfTargetWatchpointMap[idfTarget]
idfTargetWatchpointMap[idfTarget] || 2
)
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/espIdf/openOcd/boardConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,26 @@ export async function selectOpenOcdConfigFiles(
return;
}
}
if (idfTarget === "linux") {
return;
}
const currentOpenOcdConfigs = readParameter(
"idf.openOcdConfigs",
workspaceFolder
) as string[];
const boards = await getBoards(openOcdScriptsPath, idfTarget);
const message = l10n.t(
"No OpenOCD boards found for target {target}. Please check your OPENOCD_SCRIPTS environment variable.",
{ target: idfTarget }
);
if (!boards || boards.length === 0) {
Logger.errorNotify(
message,
new Error(message),
"boardConfiguration selectOpenOcdConfigFiles"
);
return;
}
const choices = boards.map((b) => {
return {
description: `${b.description} (${b.configFiles})`,
Expand Down
83 changes: 49 additions & 34 deletions src/espIdf/setTarget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@ import {
import { Logger } from "../../logger/logger";
import { OutputChannel } from "../../logger/outputChannel";
import { selectOpenOcdConfigFiles } from "../openOcd/boardConfiguration";
import { getTargetsFromEspIdf } from "./getTargets";
import { getTargetsFromEspIdf, IdfTarget } from "./getTargets";
import { setTargetInIDF } from "./setTargetInIdf";
import { updateCurrentProfileIdfTarget } from "../../project-conf";
import { DevkitsCommand } from "./DevkitsCommand";

export let isSettingIDFTarget = false;

export interface ISetTargetQuickPickItems {
label: string;
idfTarget?: IdfTarget;
boardInfo?: {
location: string;
config_files: string[];
};
description?: string;
isConnected?: boolean;
kind?: QuickPickItemKind;
}

export async function setIdfTarget(
placeHolderMsg: string,
workspaceFolder: WorkspaceFolder
Expand Down Expand Up @@ -73,30 +85,35 @@ export async function setIdfTarget(
async (progress: Progress<{ message: string; increment: number }>) => {
try {
const targetsFromIdf = await getTargetsFromEspIdf(workspaceFolder.uri);
let connectedBoards: any[] = [];
let connectedBoards: ISetTargetQuickPickItems[] = [];

const isDebugging = debug.activeDebugSession !== undefined;

if (!isDebugging) {
try {
const devkitsCmd = new DevkitsCommand(workspaceFolder.uri);
const scriptPath = await devkitsCmd.getScriptPath();

if (scriptPath) {
const devkitsOutput = await devkitsCmd.runDevkitsScript();
if (devkitsOutput) {
const parsed = JSON.parse(devkitsOutput);
if (parsed && Array.isArray(parsed.boards)) {
connectedBoards = parsed.boards.map((b: any) => ({
label: b.name,
target: b.target,
description: b.description,
detail: `Status: CONNECTED${
b.location ? ` Location: ${b.location}` : ""
}`,
isConnected: true,
boardInfo: b,
}));
connectedBoards = parsed.boards.map(
(b: any) =>
({
label: b.name,
idfTarget: targetsFromIdf.find(
(t) => t.target === b.target
),
description: b.description,
detail: `Status: CONNECTED${
b.location ? ` Location: ${b.location}` : ""
}`,
isConnected: true,
boardInfo: b,
} as ISetTargetQuickPickItems)
);
}
}
} else {
Expand All @@ -115,26 +132,24 @@ export async function setIdfTarget(
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually."
);
}
let quickPickItems: any[] = [];
if (connectedBoards.length > 0) {
quickPickItems = [
...connectedBoards,
{ kind: QuickPickItemKind.Separator, label: "Default Boards" },
...targetsFromIdf.map((t) => ({
label: t.label,
target: t.target,
description: t.isPreview ? "Preview target" : undefined,
isConnected: false,
})),
];
} else {
quickPickItems = targetsFromIdf.map((t) => ({
let quickPickItems: ISetTargetQuickPickItems[] = [];
const defaultBoards: ISetTargetQuickPickItems[] = targetsFromIdf.map(
(t) => ({
label: t.label,
target: t.target,
idfTarget: t,
description: t.isPreview ? "Preview target" : undefined,
isConnected: false,
}));
}
})
);

quickPickItems =
connectedBoards.length > 0
? [
...connectedBoards,
{ kind: QuickPickItemKind.Separator, label: "Default Boards" },
...defaultBoards,
]
: defaultBoards;
const selectedTarget = await window.showQuickPick(quickPickItems, {
placeHolder: placeHolderMsg,
});
Expand Down Expand Up @@ -171,24 +186,24 @@ export async function setIdfTarget(
} else {
await selectOpenOcdConfigFiles(
workspaceFolder.uri,
selectedTarget.target
selectedTarget.idfTarget.target
);
}

await setTargetInIDF(workspaceFolder, selectedTarget);
await setTargetInIDF(workspaceFolder, selectedTarget.idfTarget);
const customExtraVars = readParameter(
"idf.customExtraVars",
workspaceFolder
) as { [key: string]: string };
customExtraVars["IDF_TARGET"] = selectedTarget.target;
customExtraVars["IDF_TARGET"] = selectedTarget.idfTarget.target;
await writeParameter(
"idf.customExtraVars",
customExtraVars,
configurationTarget,
workspaceFolder.uri
);
await updateCurrentProfileIdfTarget(
selectedTarget.target,
selectedTarget.idfTarget.target,
workspaceFolder.uri
);
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions src/espIdf/setTarget/setTargetInIdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export async function setTargetInIDF(
const setTargetResult = await spawn(pythonBinPath, setTargetArgs, {
cwd: workspaceFolder.uri.fsPath,
env: modifiedEnv,
silent: false,
});
Logger.info(setTargetResult.toString());
const msg = vscode.l10n.t(
Expand Down
5 changes: 4 additions & 1 deletion src/statusBar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
Uri,
window,
l10n,
ThemeIcon,
} from "vscode";
import { getCurrentIdfSetup } from "../versionSwitcher";
import { readParameter } from "../idfConfiguration";
Expand Down Expand Up @@ -277,7 +278,9 @@ export function updateHintsStatusBarItem(hasHints: boolean) {
statusBarItems["hints"].tooltip = l10n.t(
"ESP-IDF: Hints available. Click to view."
);
statusBarItems["hints"].backgroundColor = "statusBarItem.warningBackground";
statusBarItems["hints"].backgroundColor = new ThemeIcon(
"statusBarItem.warningBackground"
);
statusBarItems["hints"].show();
} else {
statusBarItems["hints"].hide();
Expand Down
12 changes: 8 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,21 @@ export interface ISpawnOptions extends childProcess.SpawnOptions {
export function spawn(
command: string,
args: string[] = [],
options: ISpawnOptions = { outputString: "", silent: true }
options: ISpawnOptions = {
outputString: "",
silent: false,
appendMode: "appendLine",
}
): Promise<Buffer> {
let buff = Buffer.alloc(0);
const sendToOutputChannel = (data: Buffer) => {
buff = Buffer.concat([buff, data]);
options.outputString += buff.toString();
if (!options.silent) {
if (options.appendMode === "appendLine") {
OutputChannel.appendLine(data.toString());
} else if (options.appendMode === "append") {
if (options.appendMode === "append") {
OutputChannel.append(data.toString());
} else {
OutputChannel.appendLine(data.toString());
}
}
};
Expand Down