Skip to content

Commit

Permalink
Add device id.
Browse files Browse the repository at this point in the history
It's available from the serial too but I'd like to move away from that
for version identification too now we know that Brave randomises it.
  • Loading branch information
microbit-matt-hillsdon committed Jul 18, 2024
1 parent 087cd8a commit 1c9c4f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
export const FICR = {
CODEPAGESIZE: 0x10000000 | 0x10,
CODESIZE: 0x10000000 | 0x14,

DEVICE_ID_1: 0x10000000 | 0x64,
};

export const DapCmd = {
Expand Down
10 changes: 10 additions & 0 deletions lib/usb-device-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class DAPWrapper {

_pageSize: number | undefined;
_numPages: number | undefined;
_deviceId: number | undefined;

private loggedBoardSerialInfo: BoardSerialInfo | undefined;

Expand Down Expand Up @@ -62,6 +63,13 @@ export class DAPWrapper {
return this._numPages;
}

/**
* The number of pages. Undefined if we've not connected.
*/
get deviceId() {
return this._deviceId;
}

get boardSerialInfo(): BoardSerialInfo {
return BoardSerialInfo.parse(
this.device,
Expand Down Expand Up @@ -112,6 +120,8 @@ export class DAPWrapper {

this._pageSize = await this.cortexM.readMem32(FICR.CODEPAGESIZE);
this._numPages = await this.cortexM.readMem32(FICR.CODESIZE);
// https://support.microbit.org/support/solutions/articles/19000067679-how-to-find-the-name-of-your-micro-bit
this._deviceId = await this.cortexM.readMem32(FICR.DEVICE_ID_1);
}

async startSerial(listener: (data: string) => void): Promise<void> {
Expand Down
4 changes: 4 additions & 0 deletions lib/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export class MicrobitWebUSBConnection
});
}

getDeviceId(): number | undefined {
return this.connection?.deviceId;
}

getBoardVersion(): BoardVersion | undefined {
return this.connection?.boardSerialInfo?.id.toBoardVersion();
}
Expand Down

0 comments on commit 1c9c4f0

Please sign in to comment.