UNPKG

esp-web-tools

Version:
67 lines (66 loc) • 3.26 kB
/** * Building blocks shared by all USB-UART bridge drivers. * * A driver knows how to talk to one family of chips over WebUSB: which * interface to claim, how to initialise the chip, how to program baud rate and * modem lines. The generic `UsbSerialPort` (port.ts) turns any driver into the * Web Serial API surface that esptool-js, the Improv SDK and the console use. */ /** UART settings, already validated and with defaults filled in. */ export interface LineConfig { baudRate: number; dataBits: 5 | 6 | 7 | 8; stopBits: 1 | 2; parity: ParityType; } /** The bulk endpoints the port reads from and writes to. */ export interface UsbSerialEndpoints { in: USBEndpoint; out: USBEndpoint; } /** One opened chip. Created by the factory a definition's `load` resolves to. */ export interface UsbSerialDriver { /** * Claim the interfaces and initialise the chip. The USB configuration is * already selected. Returns the bulk endpoints carrying serial data. */ open(): Promise<UsbSerialEndpoints>; /** Program baud rate, data bits, stop bits and parity. */ setLineConfig(config: LineConfig): Promise<void>; /** Set both output modem lines (true = asserted). */ setSignals(dataTerminalReady: boolean, requestToSend: boolean): Promise<void>; /** Assert or release a break condition. Omit if the chip cannot do it. */ setBreak?(enabled: boolean): Promise<void>; /** * Strip chip specific framing from a transferIn result (e.g. FTDI prepends * 2 status bytes to every packet). May return an empty array. */ processRead?(data: Uint8Array): Uint8Array; /** Release anything claimed in `open`. */ close?(): Promise<void>; } /** * A registry entry describing a supported family of chips. Only the filters * are needed up front (for the device picker); the driver code itself is * fetched with `load` once a matching device has been picked. */ export interface UsbSerialDriverDefinition { name: string; /** * Used both for the `navigator.usb.requestDevice` picker and to match a * picked device to this driver. Same semantics as WebUSB: every field that * is set must match, and `classCode` matches the device or any interface. */ filters: USBDeviceFilter[]; /** Lazily fetch the driver code and resolve to its factory. */ load(): Promise<(device: USBDevice) => UsbSerialDriver>; } export declare const matchesDefinition: (device: USBDevice, definition: UsbSerialDriverDefinition) => boolean; /** Find the first interface (alternate 0) of the active configuration. */ export declare const findInterface: (device: USBDevice, classCode: number) => USBInterface | undefined; /** Find the bulk IN and OUT endpoints of an interface (alternate 0). */ export declare const findBulkEndpoints: (iface: USBInterface) => UsbSerialEndpoints; /** controlTransferOut that throws when the device does not ACK. */ export declare const controlOut: (device: USBDevice, setup: USBControlTransferParameters, data?: BufferSource) => Promise<void>; /** controlTransferIn that throws when the device does not ACK. */ export declare const controlIn: (device: USBDevice, setup: USBControlTransferParameters, length: number) => Promise<DataView>;