Skip to content

Commit

Permalink
issue Marus#370: add toggle pin button to peripherals
Browse files Browse the repository at this point in the history
It allows to pin a peripheral node to the top of the list
for quicker access. Useful when debugging some peripheral
to avoid scrolling or searching it everytime the debug
session is restarted. The state is persisted across
debugging sessions.

Signed-off-by: Manuel Argüelles <[email protected]>
  • Loading branch information
manuargue committed Jan 21, 2021
1 parent 5be6c1a commit 8fcc626
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface NodeSetting {
node: string;
expanded?: boolean;
format?: NumberFormat;
pinned?: boolean;
}

export class AdapterOutputEvent extends Event implements DebugProtocol.Event {
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),

Expand Down Expand Up @@ -346,6 +347,11 @@ export class CortexDebugExtension {
});
}

private async peripheralsTogglePin(node: PeripheralBaseNode): Promise<void> {
this.peripheralProvider.togglePinPeripheral(node);
this.peripheralProvider.refresh();
}

// Registers
private registersCopyValue(node: BaseNode): void {
const cv = node.getCopyValue();
Expand Down
10 changes: 1 addition & 9 deletions src/frontend/svd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/views/nodes/basenode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand Down
30 changes: 27 additions & 3 deletions src/frontend/views/nodes/peripheralnode.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -52,13 +52,18 @@ export class PeripheralNode extends PeripheralBaseNode {
public getPeripheral(): PeripheralBaseNode {
return this;
}

public getTreeItem(): TreeItem | Promise<TreeItem> {
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.');
}
Expand Down Expand Up @@ -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) => {
Expand All @@ -189,4 +199,18 @@ export class PeripheralNode extends PeripheralBaseNode {
public performUpdate(): Thenable<any> {
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;
}
}
}
7 changes: 7 additions & 0 deletions src/frontend/views/peripheral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider<Periphera
const node = this.findNodeByPath(s.node);
if (node) {
node.expanded = s.expanded || false;
node.pinned = s.pinned || false;
node.format = s.format;
}
});
this.peripherials.sort(PeripheralNode.compare);
this._onDidChangeTreeData.fire();
}
}, (error) => {
Expand Down Expand Up @@ -154,4 +156,9 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider<Periphera
public debugContinued() {

}

public togglePinPeripheral(node: PeripheralBaseNode) {
node.pinned = !node.pinned;
this.peripherials.sort(PeripheralNode.compare);
}
}

0 comments on commit 8fcc626

Please sign in to comment.