Skip to content

Commit 1c9c4f0

Browse files
Add device id.
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.
1 parent 087cd8a commit 1c9c4f0

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
export const FICR = {
1616
CODEPAGESIZE: 0x10000000 | 0x10,
1717
CODESIZE: 0x10000000 | 0x14,
18+
19+
DEVICE_ID_1: 0x10000000 | 0x64,
1820
};
1921

2022
export const DapCmd = {

lib/usb-device-wrapper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class DAPWrapper {
2828

2929
_pageSize: number | undefined;
3030
_numPages: number | undefined;
31+
_deviceId: number | undefined;
3132

3233
private loggedBoardSerialInfo: BoardSerialInfo | undefined;
3334

@@ -62,6 +63,13 @@ export class DAPWrapper {
6263
return this._numPages;
6364
}
6465

66+
/**
67+
* The number of pages. Undefined if we've not connected.
68+
*/
69+
get deviceId() {
70+
return this._deviceId;
71+
}
72+
6573
get boardSerialInfo(): BoardSerialInfo {
6674
return BoardSerialInfo.parse(
6775
this.device,
@@ -112,6 +120,8 @@ export class DAPWrapper {
112120

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

117127
async startSerial(listener: (data: string) => void): Promise<void> {

lib/usb.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ export class MicrobitWebUSBConnection
196196
});
197197
}
198198

199+
getDeviceId(): number | undefined {
200+
return this.connection?.deviceId;
201+
}
202+
199203
getBoardVersion(): BoardVersion | undefined {
200204
return this.connection?.boardSerialInfo?.id.toBoardVersion();
201205
}

0 commit comments

Comments
 (0)