diff --git a/lib/constants.ts b/lib/constants.ts index 1ad71a4..207c780 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -15,6 +15,8 @@ export const FICR = { CODEPAGESIZE: 0x10000000 | 0x10, CODESIZE: 0x10000000 | 0x14, + + DEVICE_ID_1: 0x10000000 | 0x64, }; export const DapCmd = { diff --git a/lib/usb-device-wrapper.ts b/lib/usb-device-wrapper.ts index d980466..37c95ce 100644 --- a/lib/usb-device-wrapper.ts +++ b/lib/usb-device-wrapper.ts @@ -28,6 +28,7 @@ export class DAPWrapper { _pageSize: number | undefined; _numPages: number | undefined; + _deviceId: number | undefined; private loggedBoardSerialInfo: BoardSerialInfo | undefined; @@ -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, @@ -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 { diff --git a/lib/usb.ts b/lib/usb.ts index 1f58803..ef5dd87 100644 --- a/lib/usb.ts +++ b/lib/usb.ts @@ -196,6 +196,10 @@ export class MicrobitWebUSBConnection }); } + getDeviceId(): number | undefined { + return this.connection?.deviceId; + } + getBoardVersion(): BoardVersion | undefined { return this.connection?.boardSerialInfo?.id.toBoardVersion(); }