diff --git a/package.json b/package.json index e5ac57fa..f01bce87 100644 --- a/package.json +++ b/package.json @@ -131,6 +131,11 @@ "command": "cortex-debug.peripherals.forceRefresh", "title": "Refresh" }, + { + "command": "cortex-debug.peripherals.togglePin", + "title": "Toggle Pin", + "icon": "$(pin)" + }, { "category": "Cortex-Debug", "command": "cortex-debug.examineMemory", @@ -1447,6 +1452,10 @@ "command": "cortex-debug.peripherals.forceRefresh", "when": "false" }, + { + "command": "cortex-debug.peripherals.togglePin", + "when": "false" + }, { "command": "cortex-debug.registers.copyValue", "when": "false" @@ -1516,6 +1525,11 @@ "command": "cortex-debug.peripherals.forceRefresh", "when": "view == cortex-debug.peripherals && viewItem == peripheral" }, + { + "command": "cortex-debug.peripherals.togglePin", + "when": "view == cortex-debug.peripherals && viewItem == peripheral", + "group": "inline" + }, { "command": "cortex-debug.registers.copyValue", "when": "view == cortex-debug.registers && viewItem == register", diff --git a/src/common.ts b/src/common.ts index 64982a24..488c4642 100644 --- a/src/common.ts +++ b/src/common.ts @@ -13,6 +13,7 @@ export interface NodeSetting { node: string; expanded?: boolean; format?: NumberFormat; + pinned?: boolean; } export class AdapterOutputEvent extends Event implements DebugProtocol.Event { diff --git a/src/frontend/extension.ts b/src/frontend/extension.ts index 221d71ad..a8571c20 100644 --- a/src/frontend/extension.ts +++ b/src/frontend/extension.ts @@ -72,6 +72,7 @@ export class CortexDebugExtension { vscode.commands.registerCommand('cortex-debug.peripherals.copyValue', this.peripheralsCopyValue.bind(this)), vscode.commands.registerCommand('cortex-debug.peripherals.setFormat', this.peripheralsSetFormat.bind(this)), vscode.commands.registerCommand('cortex-debug.peripherals.forceRefresh', this.peripheralsForceRefresh.bind(this)), + vscode.commands.registerCommand('cortex-debug.peripherals.togglePin', this.peripheralsTogglePin.bind(this)), vscode.commands.registerCommand('cortex-debug.registers.copyValue', this.registersCopyValue.bind(this)), @@ -346,6 +347,11 @@ export class CortexDebugExtension { }); } + private async peripheralsTogglePin(node: PeripheralBaseNode): Promise { + this.peripheralProvider.togglePinPeripheral(node); + this.peripheralProvider.refresh(); + } + // Registers private registersCopyValue(node: BaseNode): void { const cv = node.getCopyValue(); diff --git a/src/frontend/svd.ts b/src/frontend/svd.ts index 85046b0d..8a5042f4 100644 --- a/src/frontend/svd.ts +++ b/src/frontend/svd.ts @@ -83,15 +83,7 @@ export class SVDParser { } } - peripherials.sort((p1, p2) => { - if (p1.groupName > p2.groupName) { return 1; } - else if (p1.groupName < p2.groupName) { return -1; } - else { - if (p1.name > p2.name) { return 1; } - else if (p1.name < p2.name) { return -1; } - else { return 0; } - } - }); + peripherials.sort(PeripheralNode.compare); for (const p of peripherials) { p.markAddresses(); diff --git a/src/frontend/views/nodes/basenode.ts b/src/frontend/views/nodes/basenode.ts index 06b7d893..880a8f38 100644 --- a/src/frontend/views/nodes/basenode.ts +++ b/src/frontend/views/nodes/basenode.ts @@ -25,11 +25,13 @@ export abstract class BaseNode { export abstract class PeripheralBaseNode extends BaseNode { public format: NumberFormat; + public pinned: boolean; public readonly name: string; constructor(protected readonly parent?: PeripheralBaseNode) { super(parent); this.format = NumberFormat.Auto; + this.pinned = false; } public selected(): Thenable { diff --git a/src/frontend/views/nodes/peripheralnode.ts b/src/frontend/views/nodes/peripheralnode.ts index db05badc..5d7becab 100644 --- a/src/frontend/views/nodes/peripheralnode.ts +++ b/src/frontend/views/nodes/peripheralnode.ts @@ -1,4 +1,4 @@ -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { TreeItem, TreeItemCollapsibleState, ThemeIcon } from 'vscode'; import { AccessType } from '../../svd'; import { PeripheralBaseNode } from './basenode'; import { AddrRange, AddressRangesInUse } from '../../addrranges'; @@ -52,13 +52,18 @@ export class PeripheralNode extends PeripheralBaseNode { public getPeripheral(): PeripheralBaseNode { return this; } + public getTreeItem(): TreeItem | Promise { const label = `${this.name} @ ${hexFormat(this.baseAddress)}`; const item = new TreeItem(label, this.expanded ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed); item.contextValue = 'peripheral'; item.tooltip = this.description; + if (this.pinned) + // TODO: requires to update vscode to new typing dependency + item.iconPath = new ThemeIcon('pinned'); return item; } + public getCopyValue(): string { throw new Error('Method not implemented.'); } @@ -166,8 +171,13 @@ export class PeripheralNode extends PeripheralBaseNode { public saveState(path?: string): NodeSetting[] { const results: NodeSetting[] = []; - if (this.format !== NumberFormat.Auto || this.expanded) { - results.push({ node: `${this.name}`, expanded: this.expanded, format: this.format }); + if (this.format !== NumberFormat.Auto || this.expanded || this.pinned) { + results.push({ + node: `${this.name}`, + expanded: this.expanded, + format: this.format, + pinned: this.pinned + }); } this.children.forEach((c) => { @@ -189,4 +199,18 @@ export class PeripheralNode extends PeripheralBaseNode { public performUpdate(): Thenable { throw new Error('Method not implemented.'); } + + public static compare(p1: PeripheralNode, p2: PeripheralNode): number { + if ((p1.pinned && p2.pinned) || (!p1.pinned && !p2.pinned)) { + // none or both peripherals are pinned, sort by name prioritizing groupname + if (p1.groupName !== p2.groupName) + return p1.groupName > p2.groupName ? 1 : -1; + else if (p1.name !== p2.name) + return p1.name > p2.name ? 1 : -1; + else + return 0; + } else { + return p1.pinned ? -1 : 1; + } + } } diff --git a/src/frontend/views/peripheral.ts b/src/frontend/views/peripheral.ts index 604e32c1..4540d79f 100644 --- a/src/frontend/views/peripheral.ts +++ b/src/frontend/views/peripheral.ts @@ -98,9 +98,11 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider { @@ -154,4 +156,9 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider