From f8414ee86bd0808594a749594bd56f8d83eacd81 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Thu, 1 Feb 2024 19:14:28 +0800 Subject: [PATCH] fix lint issues add exported types --- src/esploader.ts | 3 ++- src/index.ts | 10 +++++++++- src/targets/esp32c2.ts | 6 +++--- src/targets/esp32c3.ts | 4 ++-- src/targets/esp32c6.ts | 4 ++-- src/targets/esp32h2.ts | 6 +++--- src/targets/esp32s2.ts | 2 +- src/targets/esp32s3.ts | 6 +++--- src/transport/AbstractTransport.ts | 2 +- src/utils/slip.ts | 28 +++++++++++++++++++++++----- 10 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/esploader.ts b/src/esploader.ts index 8627539f..d9a58b68 100644 --- a/src/esploader.ts +++ b/src/esploader.ts @@ -124,6 +124,7 @@ export interface LoaderOptions { /** * Reset functions for connection. If undefined will use default ones. + * @type {ResetFunctions} */ resetFunctions?: ResetFunctions; } @@ -134,7 +135,7 @@ export interface LoaderOptions { * @param { number } progress Progress status number * @param {number } totalSize total size of packet. */ -type FlashReadCallback = ((packet: Uint8Array, progress: number, totalSize: number) => void) | null; +export type FlashReadCallback = ((packet: Uint8Array, progress: number, totalSize: number) => void) | null; /** * Return the chip ROM based on the given magic number diff --git a/src/index.ts b/src/index.ts index 8f4cbbe7..e8908ebf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,13 @@ -export { IEspLoaderTerminal, ESPLoader, FlashOptions, LoaderOptions } from "./esploader"; +export { + IEspLoaderTerminal, + ESPLoader, + FlashOptions, + FlashReadCallback, + LoaderOptions, + ResetFunctions, +} from "./esploader"; export { classicReset, customReset, hardReset, usbJTAGSerialReset, validateCustomResetStringSequence } from "./reset"; export { ROM } from "./targets/rom"; export { AbstractTransport, ISerialOptions } from "./transport/AbstractTransport"; export { SerialOptions, WebSerialTransport } from "./transport/WebSerialTransport"; +export { slipRead, slipReaderFormat, SlipReaderOutput, slipWriter } from "./utils/slip"; diff --git a/src/targets/esp32c2.ts b/src/targets/esp32c2.ts index b16e8695..078f21f0 100644 --- a/src/targets/esp32c2.ts +++ b/src/targets/esp32c2.ts @@ -1,8 +1,8 @@ import { ESPLoader } from "../esploader"; -import { ESP32C3ROM } from "./esp32c3"; +import { ROM } from "./rom"; import ESP32C2_STUB from "./stub_flasher/stub_flasher_32c2.json"; -export class ESP32C2ROM extends ESP32C3ROM { +export class ESP32C2ROM extends ROM { public CHIP_NAME = "ESP32-C2"; public IMAGE_CHIP_ID = 12; public EFUSE_BASE = 0x60008800; @@ -68,7 +68,7 @@ export class ESP32C2ROM extends ESP32C3ROM { return desc; } - public async getChipFeatures(loader: ESPLoader) { + public async getChipFeatures() { return ["Wi-Fi", "BLE"]; } diff --git a/src/targets/esp32c3.ts b/src/targets/esp32c3.ts index 1f281efe..a993d7f5 100644 --- a/src/targets/esp32c3.ts +++ b/src/targets/esp32c3.ts @@ -67,11 +67,11 @@ export class ESP32C3ROM extends ROM { return desc; } - public async getChipFeatures(loader: ESPLoader) { + public async getChipFeatures() { return ["Wi-Fi"]; } - public async getCrystalFreq(loader: ESPLoader) { + public async getCrystalFreq() { return 40; } diff --git a/src/targets/esp32c6.ts b/src/targets/esp32c6.ts index 8480e151..1639047e 100644 --- a/src/targets/esp32c6.ts +++ b/src/targets/esp32c6.ts @@ -67,11 +67,11 @@ export class ESP32C6ROM extends ROM { return desc; } - public async getChipFeatures(loader: ESPLoader) { + public async getChipFeatures() { return ["Wi-Fi"]; } - public async getCrystalFreq(loader: ESPLoader) { + public async getCrystalFreq() { return 40; } diff --git a/src/targets/esp32h2.ts b/src/targets/esp32h2.ts index 294d3abc..38ae11b5 100644 --- a/src/targets/esp32h2.ts +++ b/src/targets/esp32h2.ts @@ -40,15 +40,15 @@ export class ESP32H2ROM extends ROM { public ROM_DATA = ESP32H2_STUB.data; public ROM_TEXT = ESP32H2_STUB.text; - public async getChipDescription(loader: ESPLoader) { + public async getChipDescription() { return this.CHIP_NAME; } - public async getChipFeatures(loader: ESPLoader) { + public async getChipFeatures() { return ["BLE", "IEEE802.15.4"]; } - public async getCrystalFreq(loader: ESPLoader) { + public async getCrystalFreq() { // ESP32H2 XTAL is fixed to 32MHz return 32; } diff --git a/src/targets/esp32s2.ts b/src/targets/esp32s2.ts index 1d7f2c47..7db830d5 100644 --- a/src/targets/esp32s2.ts +++ b/src/targets/esp32s2.ts @@ -75,7 +75,7 @@ export class ESP32S2ROM extends ROM { return features; } - public async getCrystalFreq(loader: ESPLoader) { + public async getCrystalFreq() { return 40; } public _d2h(d: number) { diff --git a/src/targets/esp32s3.ts b/src/targets/esp32s3.ts index 47492432..769f571b 100644 --- a/src/targets/esp32s3.ts +++ b/src/targets/esp32s3.ts @@ -40,13 +40,13 @@ export class ESP32S3ROM extends ROM { public ROM_DATA = ESP32S3_STUB.data; public ROM_TEXT = ESP32S3_STUB.text; - public async getChipDescription(loader: ESPLoader) { + public async getChipDescription() { return "ESP32-S3"; } - public async getChipFeatures(loader: ESPLoader) { + public async getChipFeatures() { return ["Wi-Fi", "BLE"]; } - public async getCrystalFreq(loader: ESPLoader) { + public async getCrystalFreq() { return 40; } public _d2h(d: number) { diff --git a/src/transport/AbstractTransport.ts b/src/transport/AbstractTransport.ts index 0438e4c7..a101a882 100644 --- a/src/transport/AbstractTransport.ts +++ b/src/transport/AbstractTransport.ts @@ -68,7 +68,7 @@ export abstract class AbstractTransport { /** * Connect to serial device using the Webserial open method. - * @param {SerialOptions} serialOptions Serial Options for WebUSB SerialPort class. + * @param {ISerialOptions} serialOptions Serial Options for WebUSB SerialPort class. */ public abstract connect(serialOptions: ISerialOptions): Promise; diff --git a/src/utils/slip.ts b/src/utils/slip.ts index 72c2621e..fd6e6907 100644 --- a/src/utils/slip.ts +++ b/src/utils/slip.ts @@ -22,13 +22,31 @@ export function slipWriter(data: Uint8Array): Uint8Array { return new Uint8Array(outData); } +/** + * Slip reader output packet and left over as Uint8Array. + * @interface SlipReaderOutput + */ +export interface SlipReaderOutput { + /** + * Formatted packet using SLIP escape sequences. + * @type {Uint8Array} + */ + packet: Uint8Array; + + /** + * Updated left over bytes from read operation + * @type {Uint8Array} + */ + newLeftOver: Uint8Array; +} + /** * Take a data array and return the first well formed packet after * replacing the escape sequence. Reads at least 8 bytes. * @param {Uint8Array} data Unsigned 8 bit array from the device read stream. - * @returns Formatted packet using SLIP escape sequences. + * @returns {SlipReaderOutput} packet Formatted packet using SLIP escape sequences. */ -export function slipReaderFormat(data: Uint8Array): { packet: Uint8Array; newLeftOver: Uint8Array } { +export function slipReaderFormat(data: Uint8Array): SlipReaderOutput { let i = 0; let dataStart = 0, dataEnd = 0; @@ -74,6 +92,7 @@ export function slipReaderFormat(data: Uint8Array): { packet: Uint8Array; newLef /** * Read from serial device using the device ReadableStream. + * @param {AbstractTransport} transport Implementation of serial transport class to perform serial read * @param {number} timeout Read timeout number * @param {number} minData Minimum packet array length * @returns {Promise} 8 bit unsigned data array read from device. @@ -95,11 +114,10 @@ export async function slipRead( packet = transport.leftOver; transport.leftOver = new Uint8Array(0); } - packet = await transport.rawRead(timeout, minData, packet); if (transport.tracing) { - console.log("Read bytes"); + transport.trace("Read SLIP bytes"); transport.trace(`Read ${packet.length} bytes: ${hexConvert(packet)}`); } @@ -107,7 +125,7 @@ export async function slipRead( const slipReaderResult = slipReaderFormat(packet); transport.leftOver = slipReaderResult.newLeftOver; if (transport.tracing) { - console.log("Slip reader results"); + transport.trace("Slip reader results"); transport.trace(`Read ${slipReaderResult.packet.length} bytes: ${hexConvert(slipReaderResult.packet)}`); } return slipReaderResult.packet;