Skip to content

Commit

Permalink
fix lint issues add exported types
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 committed Feb 1, 2024
1 parent a3508c8 commit f8414ee
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/esploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export interface LoaderOptions {

/**
* Reset functions for connection. If undefined will use default ones.
* @type {ResetFunctions}
*/
resetFunctions?: ResetFunctions;
}
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
6 changes: 3 additions & 3 deletions src/targets/esp32c2.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -68,7 +68,7 @@ export class ESP32C2ROM extends ESP32C3ROM {
return desc;
}

public async getChipFeatures(loader: ESPLoader) {
public async getChipFeatures() {
return ["Wi-Fi", "BLE"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/targets/esp32c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/targets/esp32c6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/targets/esp32h2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/targets/esp32s2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/targets/esp32s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/transport/AbstractTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;

Expand Down
28 changes: 23 additions & 5 deletions src/utils/slip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Uint8Array>} 8 bit unsigned data array read from device.
Expand All @@ -95,19 +114,18 @@ 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)}`);
}

if (transport.slipReaderEnabled) {
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;
Expand Down

0 comments on commit f8414ee

Please sign in to comment.