@microbit/microbit-connection 0.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +36 -0
  2. package/build/accelerometer-service.d.ts +17 -0
  3. package/build/accelerometer-service.js +84 -0
  4. package/build/accelerometer-service.js.map +1 -0
  5. package/build/accelerometer.d.ts +9 -0
  6. package/build/accelerometer.js +12 -0
  7. package/build/accelerometer.js.map +1 -0
  8. package/build/async-util.d.ts +13 -0
  9. package/build/async-util.js +22 -0
  10. package/build/async-util.js.map +1 -0
  11. package/build/bluetooth-device-wrapper.d.ts +39 -0
  12. package/build/bluetooth-device-wrapper.js +316 -0
  13. package/build/bluetooth-device-wrapper.js.map +1 -0
  14. package/build/bluetooth-profile.d.ts +139 -0
  15. package/build/bluetooth-profile.js +83 -0
  16. package/build/bluetooth-profile.js.map +1 -0
  17. package/build/bluetooth.d.ts +50 -0
  18. package/build/bluetooth.js +247 -0
  19. package/build/bluetooth.js.map +1 -0
  20. package/build/board-id.d.ts +35 -0
  21. package/build/board-id.js +69 -0
  22. package/build/board-id.js.map +1 -0
  23. package/build/board-serial-info.d.ts +14 -0
  24. package/build/board-serial-info.js +47 -0
  25. package/build/board-serial-info.js.map +1 -0
  26. package/build/constants.d.ts +47 -0
  27. package/build/constants.js +69 -0
  28. package/build/constants.js.map +1 -0
  29. package/build/device.d.ts +202 -0
  30. package/build/device.js +153 -0
  31. package/build/device.js.map +1 -0
  32. package/build/events.d.ts +101 -0
  33. package/build/events.js +19 -0
  34. package/build/events.js.map +1 -0
  35. package/build/hex-flash-data-source.d.ts +9 -0
  36. package/build/hex-flash-data-source.js +50 -0
  37. package/build/hex-flash-data-source.js.map +1 -0
  38. package/build/index.d.ts +7 -0
  39. package/build/index.js +7 -0
  40. package/build/index.js.map +1 -0
  41. package/build/logging.d.ts +21 -0
  42. package/build/logging.js +10 -0
  43. package/build/logging.js.map +1 -0
  44. package/build/service-events.d.ts +9 -0
  45. package/build/service-events.js +11 -0
  46. package/build/service-events.js.map +1 -0
  47. package/build/setupTests.d.ts +6 -0
  48. package/build/setupTests.js.map +1 -0
  49. package/build/usb-device-wrapper.d.ts +46 -0
  50. package/build/usb-device-wrapper.js +347 -0
  51. package/build/usb-device-wrapper.js.map +1 -0
  52. package/build/usb-partial-flashing-utils.d.ts +17 -0
  53. package/build/usb-partial-flashing-utils.js +122 -0
  54. package/build/usb-partial-flashing-utils.js.map +1 -0
  55. package/build/usb-partial-flashing.d.ts +63 -0
  56. package/build/usb-partial-flashing.js +270 -0
  57. package/build/usb-partial-flashing.js.map +1 -0
  58. package/build/usb-radio-bridge.d.ts +28 -0
  59. package/build/usb-radio-bridge.js +318 -0
  60. package/build/usb-radio-bridge.js.map +1 -0
  61. package/build/usb-serial-protocol.d.ts +66 -0
  62. package/build/usb-serial-protocol.js +171 -0
  63. package/build/usb-serial-protocol.js.map +1 -0
  64. package/build/usb.d.ts +61 -0
  65. package/build/usb.js +451 -0
  66. package/build/usb.js.map +1 -0
  67. package/package.json +32 -0
  68. package/vite.config.ts +32 -0
@@ -0,0 +1,50 @@
1
+ import { FlashDataError as FlashDataError } from "./device";
2
+ import { isUniversalHex, separateUniversalHex, } from "@microbit/microbit-universal-hex";
3
+ // I think we'd end up with two independently bundled copies of this for clients who also depend on microbit-fs.
4
+ import MemoryMap from "nrf-intel-hex";
5
+ export class HexFlashDataSource {
6
+ constructor(hex) {
7
+ Object.defineProperty(this, "hex", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: hex
12
+ });
13
+ }
14
+ partialFlashData(boardId) {
15
+ // Perhaps this would make more sense if we returned a MemoryMap?
16
+ // Then the partial flashing code could be given everything including UICR without
17
+ // passing a very large Uint8Array.
18
+ // Or use MM inside PF and return a (partial) hex string in the microbit-fs case?
19
+ const part = this.matchingPart(boardId);
20
+ const hex = MemoryMap.fromHex(part);
21
+ const keys = Array.from(hex.keys()).filter((k) => k < 0x10000000);
22
+ const lastKey = keys[keys.length - 1];
23
+ if (lastKey === undefined) {
24
+ throw new FlashDataError("Empty hex");
25
+ }
26
+ const lastPart = hex.get(lastKey);
27
+ if (!lastPart) {
28
+ throw new FlashDataError("Empty hex");
29
+ }
30
+ const length = lastKey + lastPart.length;
31
+ const data = hex.slicePad(0, length, 0);
32
+ return Promise.resolve(data);
33
+ }
34
+ fullFlashData(boardId) {
35
+ const part = this.matchingPart(boardId);
36
+ return Promise.resolve(part);
37
+ }
38
+ matchingPart(boardId) {
39
+ if (isUniversalHex(this.hex)) {
40
+ const parts = separateUniversalHex(this.hex);
41
+ const matching = parts.find((p) => p.boardId == boardId.normalize().id);
42
+ if (!matching) {
43
+ throw new FlashDataError("No matching part");
44
+ }
45
+ return matching.hex;
46
+ }
47
+ return this.hex;
48
+ }
49
+ }
50
+ //# sourceMappingURL=hex-flash-data-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-flash-data-source.js","sourceRoot":"","sources":["../lib/hex-flash-data-source.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,cAAc,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EACL,cAAc,EACd,oBAAoB,GACrB,MAAM,kCAAkC,CAAC;AAE1C,gHAAgH;AAChH,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,MAAM,OAAO,kBAAkB;IAC7B,YAAoB,GAAW;QAAnB;;;;mBAAQ,GAAG;WAAQ;IAAG,CAAC;IAEnC,gBAAgB,CAAC,OAAgB;QAC/B,iEAAiE;QACjE,kFAAkF;QAClF,mCAAmC;QAEnC,iFAAiF;QAEjF,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,C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QACtB,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import { MicrobitWebUSBConnection } from "./usb";
2
+ import { MicrobitWebBluetoothConnection } from "./bluetooth";
3
+ import { BoardId } from "./board-id";
4
+ import { DeviceConnection, AfterRequestDevice, BeforeRequestDevice, BoardVersion, ConnectOptions, ConnectionStatus, ConnectionStatusEvent, DeviceError, DeviceErrorCode, DeviceConnectionEventMap, FlashDataError, FlashDataSource, FlashEvent, SerialDataEvent, SerialErrorEvent, SerialResetEvent } from "./device";
5
+ import { HexFlashDataSource } from "./hex-flash-data-source";
6
+ export { MicrobitWebUSBConnection, MicrobitWebBluetoothConnection, BoardId, HexFlashDataSource, AfterRequestDevice, BeforeRequestDevice, ConnectionStatus, ConnectionStatusEvent, DeviceConnectionEventMap, DeviceError, FlashDataError, FlashEvent, SerialDataEvent, SerialErrorEvent, SerialResetEvent, };
7
+ export type { DeviceConnection, BoardVersion, ConnectOptions, DeviceErrorCode, FlashDataSource, };
package/build/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { MicrobitWebUSBConnection } from "./usb";
2
+ import { MicrobitWebBluetoothConnection } from "./bluetooth";
3
+ import { BoardId } from "./board-id";
4
+ import { AfterRequestDevice, BeforeRequestDevice, ConnectionStatus, ConnectionStatusEvent, DeviceError, DeviceConnectionEventMap, FlashDataError, FlashEvent, SerialDataEvent, SerialErrorEvent, SerialResetEvent, } from "./device";
5
+ import { HexFlashDataSource } from "./hex-flash-data-source";
6
+ export { MicrobitWebUSBConnection, MicrobitWebBluetoothConnection, BoardId, HexFlashDataSource, AfterRequestDevice, BeforeRequestDevice, ConnectionStatus, ConnectionStatusEvent, DeviceConnectionEventMap, DeviceError, FlashDataError, FlashEvent, SerialDataEvent, SerialErrorEvent, SerialResetEvent, };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAEL,kBAAkB,EAClB,mBAAmB,EAGnB,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EAEX,wBAAwB,EACxB,cAAc,EAEd,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC9B,OAAO,EACP,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,WAAW,EACX,cAAc,EACd,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GACjB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * (c) 2024, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ export interface Event {
7
+ type: string;
8
+ message?: string;
9
+ value?: number;
10
+ detail?: any;
11
+ }
12
+ export interface Logging {
13
+ event(event: Event): void;
14
+ error(message: string, e: unknown): void;
15
+ log(e: any): void;
16
+ }
17
+ export declare class NullLogging implements Logging {
18
+ event(_event: Event): void;
19
+ error(_m: string, _e: unknown): void;
20
+ log(_e: any): void;
21
+ }
@@ -0,0 +1,10 @@
1
+ export class NullLogging {
2
+ event(_event) { }
3
+ error(_m, _e) {
4
+ console.error(_m, _e);
5
+ }
6
+ log(_e) {
7
+ console.log(_e);
8
+ }
9
+ }
10
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.js","sourceRoot":"","sources":["../lib/logging.ts"],"names":[],"mappings":"AAkBA,MAAM,OAAO,WAAW;IACtB,KAAK,CAAC,MAAa,IAAS,CAAC;IAC7B,KAAK,CAAC,EAAU,EAAE,EAAW;QAC3B,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACxB,CAAC;IACD,GAAG,CAAC,EAAO;QACT,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { AccelerometerDataEvent } from "./accelerometer";
2
+ export declare class ServiceConnectionEventMap {
3
+ "accelerometerdatachanged": AccelerometerDataEvent;
4
+ }
5
+ export type CharacteristicDataTarget = EventTarget & {
6
+ value: DataView;
7
+ };
8
+ export type TypedServiceEvent = keyof ServiceConnectionEventMap;
9
+ export type TypedServiceEventDispatcher = (_type: TypedServiceEvent, event: ServiceConnectionEventMap[TypedServiceEvent]) => boolean;
@@ -0,0 +1,11 @@
1
+ export class ServiceConnectionEventMap {
2
+ constructor() {
3
+ Object.defineProperty(this, "accelerometerdatachanged", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: void 0
8
+ });
9
+ }
10
+ }
11
+ //# sourceMappingURL=service-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-events.js","sourceRoot":"","sources":["../lib/service-events.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,yBAAyB;IAAtC;QACE,4BAAA,0BAA0B;;;;;WAAyB;IACrD,CAAC;CAAA"}
@@ -0,0 +1,6 @@
1
+ export {};
2
+ /**
3
+ * (c) 2024, Micro:bit Educational Foundation and contributors
4
+ *
5
+ * SPDX-License-Identifier: MIT
6
+ */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupTests.js","sourceRoot":"","sources":["../lib/setupTests.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { CortexM, DAPLink, WebUSB } from "dapjs";
7
+ import { Logging } from "./logging";
8
+ import { BoardSerialInfo } from "./board-serial-info";
9
+ export declare class DAPWrapper {
10
+ device: USBDevice;
11
+ private logging;
12
+ transport: WebUSB;
13
+ daplink: DAPLink;
14
+ cortexM: CortexM;
15
+ _pageSize: number | undefined;
16
+ _numPages: number | undefined;
17
+ private loggedBoardSerialInfo;
18
+ private initialConnectionComplete;
19
+ constructor(device: USBDevice, logging: Logging);
20
+ /**
21
+ * The page size. Throws if we've not connected.
22
+ */
23
+ get pageSize(): number;
24
+ /**
25
+ * The number of pages. Throws if we've not connected.
26
+ */
27
+ get numPages(): number;
28
+ get boardSerialInfo(): BoardSerialInfo;
29
+ reconnectAsync(): Promise<void>;
30
+ startSerial(listener: (data: string) => void): Promise<void>;
31
+ stopSerial(listener: (data: string) => void): void;
32
+ disconnectAsync(): Promise<void>;
33
+ private send;
34
+ private cmdNums;
35
+ private readRegRepeat;
36
+ private writeRegRepeat;
37
+ private readBlockCore;
38
+ private writeBlockCore;
39
+ readBlockAsync(addr: number, words: number): Promise<Uint8Array>;
40
+ writeBlockAsync(address: number, data: Uint32Array): Promise<void>;
41
+ executeAsync(address: number, code: Uint32Array, sp: number, pc: number, lr: number, ...registers: number[]): Promise<void>;
42
+ private waitForHaltCore;
43
+ waitForHalt(timeToWait?: number): Promise<void>;
44
+ private softwareReset;
45
+ reset(halt?: boolean): Promise<void>;
46
+ }
@@ -0,0 +1,347 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { CortexM, DAPLink, WebUSB } from "dapjs";
7
+ import { ApReg, CortexSpecialReg, Csw, DapCmd, DapVal, FICR, } from "./constants";
8
+ import { apReg, bufferConcat, CoreRegister, regRequest, } from "./usb-partial-flashing-utils";
9
+ import { BoardSerialInfo } from "./board-serial-info";
10
+ export class DAPWrapper {
11
+ constructor(device, logging) {
12
+ Object.defineProperty(this, "device", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: device
17
+ });
18
+ Object.defineProperty(this, "logging", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: logging
23
+ });
24
+ Object.defineProperty(this, "transport", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "daplink", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "cortexM", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "_pageSize", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "_numPages", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "loggedBoardSerialInfo", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "initialConnectionComplete", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: false
65
+ });
66
+ this.transport = new WebUSB(this.device);
67
+ this.daplink = new DAPLink(this.transport);
68
+ this.cortexM = new CortexM(this.transport);
69
+ }
70
+ /**
71
+ * The page size. Throws if we've not connected.
72
+ */
73
+ get pageSize() {
74
+ if (this._pageSize === undefined) {
75
+ throw new Error("pageSize not defined until connected");
76
+ }
77
+ return this._pageSize;
78
+ }
79
+ /**
80
+ * The number of pages. Throws if we've not connected.
81
+ */
82
+ get numPages() {
83
+ if (this._numPages === undefined) {
84
+ throw new Error("numPages not defined until connected");
85
+ }
86
+ return this._numPages;
87
+ }
88
+ get boardSerialInfo() {
89
+ return BoardSerialInfo.parse(this.device, this.logging.log.bind(this.logging));
90
+ }
91
+ // Drawn from https://github.com/microsoft/pxt-microbit/blob/dec5b8ce72d5c2b4b0b20aafefce7474a6f0c7b2/editor/extension.tsx#L119
92
+ async reconnectAsync() {
93
+ if (this.initialConnectionComplete) {
94
+ await this.disconnectAsync();
95
+ this.transport = new WebUSB(this.device);
96
+ this.daplink = new DAPLink(this.transport);
97
+ this.cortexM = new CortexM(this.transport);
98
+ }
99
+ else {
100
+ this.initialConnectionComplete = true;
101
+ }
102
+ await this.daplink.connect();
103
+ await this.cortexM.connect();
104
+ this.logging.event({
105
+ type: "WebUSB-info",
106
+ message: "connected",
107
+ });
108
+ const serialInfo = this.boardSerialInfo;
109
+ this.logging.log(`Detected board ID ${serialInfo.id}`);
110
+ if (!this.loggedBoardSerialInfo ||
111
+ !this.loggedBoardSerialInfo.eq(this.boardSerialInfo)) {
112
+ this.loggedBoardSerialInfo = this.boardSerialInfo;
113
+ this.logging.event({
114
+ type: "WebUSB-info",
115
+ message: "board-id/" + this.boardSerialInfo.id,
116
+ });
117
+ this.logging.event({
118
+ type: "WebUSB-info",
119
+ message: "board-family-hic/" +
120
+ this.boardSerialInfo.familyId +
121
+ this.boardSerialInfo.hic,
122
+ });
123
+ }
124
+ this._pageSize = await this.cortexM.readMem32(FICR.CODEPAGESIZE);
125
+ this._numPages = await this.cortexM.readMem32(FICR.CODESIZE);
126
+ }
127
+ async startSerial(listener) {
128
+ const currentBaud = await this.daplink.getSerialBaudrate();
129
+ if (currentBaud !== 115200) {
130
+ // Changing the baud rate causes a micro:bit reset, so only do it if necessary
131
+ await this.daplink.setSerialBaudrate(115200);
132
+ }
133
+ this.daplink.on(DAPLink.EVENT_SERIAL_DATA, listener);
134
+ await this.daplink.startSerialRead(1);
135
+ }
136
+ stopSerial(listener) {
137
+ this.daplink.stopSerialRead();
138
+ this.daplink.removeListener(DAPLink.EVENT_SERIAL_DATA, listener);
139
+ }
140
+ async disconnectAsync() {
141
+ if (this.device.opened &&
142
+ this.transport.interfaceNumber !== undefined) {
143
+ return this.daplink.disconnect();
144
+ }
145
+ }
146
+ // Send a packet to the micro:bit directly via WebUSB and return the response.
147
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/transport/cmsis_dap.ts#L161
148
+ async send(packet) {
149
+ const array = Uint8Array.from(packet);
150
+ await this.transport.write(array.buffer);
151
+ const response = await this.transport.read();
152
+ return new Uint8Array(response.buffer);
153
+ }
154
+ // Send a command along with relevant data to the micro:bit directly via WebUSB and handle the response.
155
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/transport/cmsis_dap.ts#L74
156
+ async cmdNums(op /* DapCmd */, data) {
157
+ data.unshift(op);
158
+ const buf = await this.send(data);
159
+ if (buf[0] !== op) {
160
+ throw new Error(`Bad response for ${op} -> ${buf[0]}`);
161
+ }
162
+ switch (op) {
163
+ case DapCmd.DAP_CONNECT:
164
+ case DapCmd.DAP_INFO:
165
+ case DapCmd.DAP_TRANSFER:
166
+ case DapCmd.DAP_TRANSFER_BLOCK:
167
+ break;
168
+ default:
169
+ if (buf[1] !== 0) {
170
+ throw new Error(`Bad status for ${op} -> ${buf[1]}`);
171
+ }
172
+ }
173
+ return buf;
174
+ }
175
+ // Read a certain register a specified amount of times.
176
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/dap/dap.ts#L117
177
+ async readRegRepeat(regId /* Reg */, cnt) {
178
+ const request = regRequest(regId);
179
+ const sendargs = [0, cnt];
180
+ for (let i = 0; i < cnt; ++i) {
181
+ sendargs.push(request);
182
+ }
183
+ // Transfer the read requests to the micro:bit and retrieve the data read.
184
+ const buf = await this.cmdNums(DapCmd.DAP_TRANSFER, sendargs);
185
+ if (buf[1] !== cnt) {
186
+ throw new Error("(many) Bad #trans " + buf[1]);
187
+ }
188
+ else if (buf[2] !== 1) {
189
+ throw new Error("(many) Bad transfer status " + buf[2]);
190
+ }
191
+ return buf.subarray(3, 3 + cnt * 4);
192
+ }
193
+ // Write to a certain register a specified amount of data.
194
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/dap/dap.ts#L138
195
+ async writeRegRepeat(regId /* Reg */, data) {
196
+ const request = regRequest(regId, true);
197
+ const sendargs = [0, data.length, 0, request];
198
+ data.forEach((d) => {
199
+ // separate d into bytes
200
+ sendargs.push(d & 0xff, (d >> 8) & 0xff, (d >> 16) & 0xff, (d >> 24) & 0xff);
201
+ });
202
+ // Transfer the write requests to the micro:bit and retrieve the response status.
203
+ const buf = await this.cmdNums(DapCmd.DAP_TRANSFER_BLOCK, sendargs);
204
+ if (buf[3] !== 1) {
205
+ throw new Error("(many-wr) Bad transfer status " + buf[2]);
206
+ }
207
+ }
208
+ // Core functionality reading a block of data from micro:bit RAM at a specified address.
209
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/memory/memory.ts#L181
210
+ async readBlockCore(addr, words) {
211
+ // Set up CMSIS-DAP to read/write from/to the RAM address addr using the register
212
+ // ApReg.DRW to write to or read from.
213
+ await this.cortexM.writeAP(ApReg.CSW, Csw.CSW_VALUE | Csw.CSW_SIZE32);
214
+ await this.cortexM.writeAP(ApReg.TAR, addr);
215
+ let lastSize = words % 15;
216
+ if (lastSize === 0) {
217
+ lastSize = 15;
218
+ }
219
+ const blocks = [];
220
+ for (let i = 0; i < Math.ceil(words / 15); i++) {
221
+ const b = await this.readRegRepeat(apReg(ApReg.DRW, DapVal.READ), i === blocks.length - 1 ? lastSize : 15);
222
+ blocks.push(b);
223
+ }
224
+ return bufferConcat(blocks).subarray(0, words * 4);
225
+ }
226
+ // Core functionality writing a block of data to micro:bit RAM at a specified address.
227
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/memory/memory.ts#L205
228
+ async writeBlockCore(addr, words) {
229
+ try {
230
+ // Set up CMSIS-DAP to read/write from/to the RAM address addr using the register ApReg.DRW to write to or read from.
231
+ await this.cortexM.writeAP(ApReg.CSW, Csw.CSW_VALUE | Csw.CSW_SIZE32);
232
+ await this.cortexM.writeAP(ApReg.TAR, addr);
233
+ await this.writeRegRepeat(apReg(ApReg.DRW, DapVal.WRITE), words);
234
+ }
235
+ catch (e) {
236
+ if (e.dapWait) {
237
+ // Retry after a delay if required.
238
+ this.logging.log(`Transfer wait, write block`);
239
+ await new Promise((resolve) => setTimeout(resolve, 100));
240
+ return await this.writeBlockCore(addr, words);
241
+ }
242
+ else {
243
+ throw e;
244
+ }
245
+ }
246
+ }
247
+ // Reads a block of data from micro:bit RAM at a specified address.
248
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/memory/memory.ts#L143
249
+ async readBlockAsync(addr, words) {
250
+ const bufs = [];
251
+ const end = addr + words * 4;
252
+ let ptr = addr;
253
+ // Read a single page at a time.
254
+ while (ptr < end) {
255
+ let nextptr = ptr + this.pageSize;
256
+ if (ptr === addr) {
257
+ nextptr &= ~(this.pageSize - 1);
258
+ }
259
+ const len = Math.min(nextptr - ptr, end - ptr);
260
+ bufs.push(await this.readBlockCore(ptr, len >> 2));
261
+ ptr = nextptr;
262
+ }
263
+ const result = bufferConcat(bufs);
264
+ return result.subarray(0, words * 4);
265
+ }
266
+ // Writes a block of data to micro:bit RAM at a specified address.
267
+ async writeBlockAsync(address, data) {
268
+ let payloadSize = this.transport.packetSize - 8;
269
+ if (data.buffer.byteLength > payloadSize) {
270
+ let start = 0;
271
+ let end = payloadSize;
272
+ // Split write up into smaller writes whose data can each be held in a single packet.
273
+ while (start !== end) {
274
+ let temp = new Uint32Array(data.buffer.slice(start, end));
275
+ await this.writeBlockCore(address + start, temp);
276
+ start = end;
277
+ end = Math.min(data.buffer.byteLength, end + payloadSize);
278
+ }
279
+ }
280
+ else {
281
+ await this.writeBlockCore(address, data);
282
+ }
283
+ }
284
+ // Execute code at a certain address with specified values in the registers.
285
+ // Waits for execution to halt.
286
+ async executeAsync(address, code, sp, pc, lr, ...registers) {
287
+ if (registers.length > 12) {
288
+ throw new Error(`Only 12 general purpose registers but got ${registers.length} values`);
289
+ }
290
+ await this.cortexM.halt(true);
291
+ await this.writeBlockAsync(address, code);
292
+ await this.cortexM.writeCoreRegister(CoreRegister.PC, pc);
293
+ await this.cortexM.writeCoreRegister(CoreRegister.LR, lr);
294
+ await this.cortexM.writeCoreRegister(CoreRegister.SP, sp);
295
+ for (let i = 0; i < registers.length; ++i) {
296
+ await this.cortexM.writeCoreRegister(i, registers[i]);
297
+ }
298
+ await this.cortexM.resume(true);
299
+ return this.waitForHalt();
300
+ }
301
+ // Checks whether the micro:bit has halted or timeout has been reached.
302
+ // Recurses otherwise.
303
+ async waitForHaltCore(halted, deadline) {
304
+ if (new Date().getTime() > deadline) {
305
+ throw new Error("timeout");
306
+ }
307
+ if (!halted) {
308
+ const isHalted = await this.cortexM.isHalted();
309
+ // NB this is a Promise so no stack risk.
310
+ return this.waitForHaltCore(isHalted, deadline);
311
+ }
312
+ }
313
+ // Initial function to call to wait for the micro:bit halt.
314
+ async waitForHalt(timeToWait = 10000) {
315
+ const deadline = new Date().getTime() + timeToWait;
316
+ return this.waitForHaltCore(false, deadline);
317
+ }
318
+ // Resets the micro:bit in software by writing to NVIC_AIRCR.
319
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/cortex/cortex.ts#L347
320
+ async softwareReset() {
321
+ await this.cortexM.writeMem32(CortexSpecialReg.NVIC_AIRCR, CortexSpecialReg.NVIC_AIRCR_VECTKEY |
322
+ CortexSpecialReg.NVIC_AIRCR_SYSRESETREQ);
323
+ // wait for the system to come out of reset
324
+ let dhcsr = await this.cortexM.readMem32(CortexSpecialReg.DHCSR);
325
+ while ((dhcsr & CortexSpecialReg.S_RESET_ST) !== 0) {
326
+ dhcsr = await this.cortexM.readMem32(CortexSpecialReg.DHCSR);
327
+ }
328
+ }
329
+ // Reset the micro:bit, possibly halting the core on reset.
330
+ // Drawn from https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/cortex/cortex.ts#L248
331
+ async reset(halt = false) {
332
+ if (halt) {
333
+ await this.cortexM.halt(true);
334
+ // VC_CORERESET causes the core to halt on reset.
335
+ const demcr = await this.cortexM.readMem32(CortexSpecialReg.DEMCR);
336
+ await this.cortexM.writeMem32(CortexSpecialReg.DEMCR, CortexSpecialReg.DEMCR | CortexSpecialReg.DEMCR_VC_CORERESET);
337
+ await this.softwareReset();
338
+ await this.waitForHalt();
339
+ // Unset the VC_CORERESET bit
340
+ await this.cortexM.writeMem32(CortexSpecialReg.DEMCR, demcr);
341
+ }
342
+ else {
343
+ await this.softwareReset();
344
+ }
345
+ }
346
+ }
347
+ //# sourceMappingURL=usb-device-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usb-device-wrapper.js","sourceRoot":"","sources":["../lib/usb-device-wrapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEjD,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,GAAG,EACH,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,OAAO,UAAU;IAYrB,YACS,MAAiB,EAChB,OAAgB;QADxB;;;;mBAAO,MAAM;WAAW;QACxB;;;;mBAAQ,OAAO;WAAS;QAb1B;;;;;WAAkB;QAClB;;;;;WAAiB;QACjB;;;;;WAAiB;QAEjB;;;;;WAA8B;QAC9B;;;;;WAA8B;QAEtB;;;;;WAAmD;QAEnD;;;;mBAAqC,KAAK;WAAC;QAMjD,IAAI,CA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AAC;QAC/D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ export declare const CoreRegister: {
2
+ SP: number;
3
+ LR: number;
4
+ PC: number;
5
+ };
6
+ export declare const read32FromUInt8Array: (data: Uint8Array, i: number) => number;
7
+ export declare const bufferConcat: (bufs: Uint8Array[]) => Uint8Array;
8
+ export declare const murmur3_core: (data: Uint8Array) => [number, number];
9
+ export declare const apReg: (r: number, mode: number) => number;
10
+ export declare const regRequest: (regId: number, isWrite?: boolean) => number;
11
+ export declare class Page {
12
+ readonly targetAddr: number;
13
+ readonly data: Uint8Array;
14
+ constructor(targetAddr: number, data: Uint8Array);
15
+ }
16
+ export declare const pageAlignBlocks: (buffer: Uint8Array, targetAddr: number, pageSize: number) => Page[];
17
+ export declare const onlyChanged: (pages: Page[], checksums: Uint8Array, pageSize: number) => Page[];