Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Workaround so we can use upstream dapjs
  • Loading branch information
microbit-matt-hillsdon committed Jan 27, 2025
commit a92d48097ebdd3c56cef4768059e48bc99261069
24 changes: 15 additions & 9 deletions lib/usb-device-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
*
* SPDX-License-Identifier: MIT
*/
import { CortexM, DAPLink, WebUSB } from "dapjs";
import * as dapjs from "dapjs";
import type { CortexM, DAPLink, WebUSB } from "dapjs";
const {
CortexM: CortexMValue,
DAPLink: DAPLinkValue,
WebUSB: WebUSBValue,
} = dapjs;
import { Logging } from "./logging.js";
import {
ApReg,
Expand Down Expand Up @@ -38,9 +44,9 @@ export class DAPWrapper {
public device: USBDevice,
private logging: Logging,
) {
this.transport = new WebUSB(this.device);
this.daplink = new DAPLink(this.transport);
this.cortexM = new CortexM(this.transport);
this.transport = new WebUSBValue(this.device);
this.daplink = new DAPLinkValue(this.transport);
this.cortexM = new CortexMValue(this.transport);
}

/**
Expand Down Expand Up @@ -82,9 +88,9 @@ export class DAPWrapper {
if (this.initialConnectionComplete) {
await this.disconnectAsync();

this.transport = new WebUSB(this.device);
this.daplink = new DAPLink(this.transport);
this.cortexM = new CortexM(this.transport);
this.transport = new WebUSBValue(this.device);
this.daplink = new DAPLinkValue(this.transport);
this.cortexM = new CortexMValue(this.transport);
} else {
this.initialConnectionComplete = true;
}
Expand Down Expand Up @@ -153,13 +159,13 @@ export class DAPWrapper {
// Changing the baud rate causes a micro:bit reset, so only do it if necessary
await this.daplink.setSerialBaudrate(115200);
}
this.daplink.addListener(DAPLink.EVENT_SERIAL_DATA, listener);
this.daplink.addListener(DAPLinkValue.EVENT_SERIAL_DATA, listener);
await this.daplink.startSerialRead(1);
}

stopSerial(listener: (data: string) => void): void {
this.daplink.stopSerialRead();
this.daplink.removeListener(DAPLink.EVENT_SERIAL_DATA, listener);
this.daplink.removeListener(DAPLinkValue.EVENT_SERIAL_DATA, listener);
}

async disconnectAsync(): Promise<void> {
Expand Down
7 changes: 4 additions & 3 deletions lib/usb-partial-flashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
* Latest Microsoft implementation is here:
* https://github.com/microsoft/pxt-microbit/blob/master/editor/flash.ts
*/
import { DAPLink } from "dapjs";
import * as dapjs from "dapjs";
const { DAPLink: DAPLinkValue } = dapjs;
import { Logging } from "./logging.js";
import { withTimeout, TimeoutError } from "./async-util.js";
import { DAPWrapper } from "./usb-device-wrapper.js";
Expand Down Expand Up @@ -259,7 +260,7 @@ export class PartialFlashing {
const fullFlashProgress = (progress: number) => {
updateProgress(progress, false);
};
this.dapwrapper.daplink.on(DAPLink.EVENT_PROGRESS, fullFlashProgress);
this.dapwrapper.daplink.on(DAPLinkValue.EVENT_PROGRESS, fullFlashProgress);
try {
data = this.convertDataToHexString(data);
await this.dapwrapper.transport.open();
Expand All @@ -270,7 +271,7 @@ export class PartialFlashing {
});
} finally {
this.dapwrapper.daplink.removeListener(
DAPLink.EVENT_PROGRESS,
DAPLinkValue.EVENT_PROGRESS,
fullFlashProgress,
);
}
Expand Down
Loading