-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
further refactoring of transport and esploader
- Loading branch information
1 parent
c033caf
commit 260e5ea
Showing
9 changed files
with
355 additions
and
284 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export { IEspLoaderTerminal, ESPLoader, FlashOptions, LoaderOptions } from "./esploader"; | ||
export { classicReset, customReset, hardReset, usbJTAGSerialReset, validateCustomResetStringSequence } from "./reset"; | ||
export { ROM } from "./targets/rom"; | ||
export { AbstractTransport, ISerialOptions } from "./transport/ITransport"; | ||
export { AbstractTransport, ISerialOptions } from "./transport/AbstractTransport"; | ||
export { SerialOptions, WebSerialTransport } from "./transport/WebSerialTransport"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Options for device connection. | ||
* @interface ISerialOptions | ||
*/ | ||
export interface ISerialOptions { | ||
/** | ||
* A positive, non-zero value indicating the baud rate at which serial communication should be established. | ||
* @type {number} | ||
*/ | ||
baudRate: number; | ||
} | ||
|
||
/** | ||
* Template to define Transport class which can be consumed by the ESPLoader. | ||
* A Webserial reference implementation is found at src/transport/WebSerialTransport.ts | ||
*/ | ||
export abstract class AbstractTransport { | ||
public abstract tracing: boolean; | ||
public abstract slipReaderEnabled: boolean; | ||
|
||
/** | ||
* Request the serial device information as string. | ||
* @returns {string} Return the serial device information as formatted string. | ||
*/ | ||
public abstract getInfo(): string; | ||
|
||
/** | ||
* Request the serial device product id. | ||
* @returns {number | undefined} Return the product ID. | ||
*/ | ||
public abstract getPID(): number | undefined; | ||
|
||
/** | ||
* Format received or sent data for tracing output. | ||
* @param {string} message Message to format as trace line. | ||
*/ | ||
public abstract trace(message: string): void; | ||
|
||
/** | ||
* Write binary data to device. | ||
* @param {Uint8Array} data 8 bit unsigned data array to write to device. | ||
*/ | ||
public abstract write(data: Uint8Array): Promise<void>; | ||
|
||
/** | ||
* Read from serial device. | ||
* @param {number} timeout Read timeout number | ||
* @param {number} minData Minimum packet array length | ||
* @returns {Promise<Uint8Array>} 8 bit unsigned data array read from device. | ||
*/ | ||
public abstract read(timeout?: number, minData?: number): Promise<Uint8Array>; | ||
|
||
/** | ||
* Read from serial device without formatting. | ||
* @param {number} timeout Read timeout in milliseconds (ms) | ||
* @returns {Promise<Uint8Array>} 8 bit unsigned data array read from device. | ||
*/ | ||
public abstract rawRead(timeout?: number): Promise<Uint8Array>; | ||
|
||
/** | ||
* Send the RequestToSend (RTS) signal to given state | ||
* # True for EN=LOW, chip in reset and False EN=HIGH, chip out of reset | ||
* @param {boolean} state Boolean state to set the signal | ||
*/ | ||
public abstract setRTS(state: boolean): Promise<void>; | ||
|
||
/** | ||
* Send the dataTerminalReady (DTS) signal to given state | ||
* # True for IO0=LOW, chip in reset and False IO0=HIGH | ||
* @param {boolean} state Boolean state to set the signal | ||
*/ | ||
public abstract setDTR(state: boolean): Promise<void>; | ||
|
||
/** | ||
* Connect to serial device using the Webserial open method. | ||
* @param {SerialOptions} serialOptions Serial Options for WebUSB SerialPort class. | ||
*/ | ||
public abstract connect(serialOptions: ISerialOptions): Promise<void>; | ||
|
||
/** | ||
* Disconnect from serial device by running SerialPort.close() after streams unlock. | ||
*/ | ||
public abstract disconnect(): Promise<void>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Concatenate array 2 to array 1 and return the resulting UInt8Array. | ||
* @param {Uint8Array} array1 First array to concatenate. | ||
* @param {Uint8Array} array2 Second array to concatenate. | ||
* @returns {Uint8Array} Result UInt8Array. | ||
*/ | ||
export function appendArray(array1: Uint8Array, array2: Uint8Array): Uint8Array { | ||
const result = new Uint8Array(array1.length + array2.length); | ||
result.set(array1, 0); | ||
result.set(array2, array1.length); | ||
return result; | ||
} | ||
|
||
/** | ||
* Convert short integer to byte array | ||
* @param {number} i - Number to convert. | ||
* @returns {Uint8Array} Byte array. | ||
*/ | ||
export function shortToBytearray(i: number): Uint8Array { | ||
return new Uint8Array([i & 0xff, (i >> 8) & 0xff]); | ||
} | ||
|
||
/** | ||
* Convert an integer to byte array | ||
* @param {number} i - Number to convert. | ||
* @returns {Uint8Array} Array of byte from interger | ||
*/ | ||
export function intToByteArray(i: number): Uint8Array { | ||
return new Uint8Array([i & 0xff, (i >> 8) & 0xff, (i >> 16) & 0xff, (i >> 24) & 0xff]); | ||
} | ||
|
||
/** | ||
* Convert a byte array to short integer. | ||
* @param {number} i - Number to convert. | ||
* @param {number} j - Number to convert. | ||
* @returns {number} Return a short integer number. | ||
*/ | ||
export function byteArrayToShort(i: number, j: number): number { | ||
return i | (j >> 8); | ||
} | ||
|
||
/** | ||
* Convert a byte array to integer. | ||
* @param {number} i - Number to convert. | ||
* @param {number} j - Number to convert. | ||
* @param {number} k - Number to convert. | ||
* @param {number} l - Number to convert. | ||
* @returns {number} Return a integer number. | ||
*/ | ||
export function byteArrayToInt(i: number, j: number, k: number, l: number): number { | ||
return i | (j << 8) | (k << 16) | (l << 24); | ||
} | ||
|
||
/** | ||
* Convert a unsigned 8 bit integer array to byte string. | ||
* @param {Uint8Array} u8Array - magic hex number to select ROM. | ||
* @returns {string} Return the equivalent string. | ||
*/ | ||
export function ui8ToBstr(u8Array: Uint8Array): string { | ||
let bStr = ""; | ||
for (let i = 0; i < u8Array.length; i++) { | ||
bStr += String.fromCharCode(u8Array[i]); | ||
} | ||
return bStr; | ||
} | ||
|
||
/** | ||
* Convert a byte string to unsigned 8 bit integer array. | ||
* @param {string} bStr - binary string input | ||
* @returns {Uint8Array} Return a 8 bit unsigned integer array. | ||
*/ | ||
export function bstrToUi8(bStr: string): Uint8Array { | ||
const u8Array = new Uint8Array(bStr.length); | ||
for (let i = 0; i < bStr.length; i++) { | ||
u8Array[i] = bStr.charCodeAt(i); | ||
} | ||
return u8Array; | ||
} |
Oops, something went wrong.