API referencestd/embedded

std/embedded/peripheral/esp_usb_serial

Public declarations, types, methods, and source contracts for std/embedded/peripheral/esp_usb_serial.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/embedded/peripheral/esp_usb_serial"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
hal std/embedded/hal esp_usb_serial.dodo
io std/io esp_usb_serial.dodo
serial std/embedded/hal/serial esp_usb_serial.dodo

RX_INTERRUPT

Constant · Source

Interrupt sources, as bits of listen, ignore, pending_interrupts, and clear_interrupts. The controller raises its one interrupt line, USB_DEVICE on the ESP32-C6, while any listened-to source is pending.

RX_INTERRUPT: a packet from the host arrived in the receive FIFO.

pub const RX_INTERRUPT: u32 = 1 << 2

TX_INTERRUPT

Constant · Source

TX_INTERRUPT: the host took everything in the transmit FIFO.

pub const TX_INTERRUPT: u32 = 1 << 3

DTR_INTERRUPT

Constant · Source

The host turned DTR on or off, opening or closing the port.

pub const DTR_INTERRUPT: u32 = 1 << 13

FIFO_SIZE

Constant · Source

Bytes in each FIFO.

pub const FIFO_SIZE: usize = 64

WRITE_TIMEOUT_FRAMES

Constant · Source

How long, in milliseconds, a write or flush waits for a host that has the port open but takes no output, before dropping it.

pub const WRITE_TIMEOUT_FRAMES: u32 = 50

Controller

Struct · Source

The USB serial port of one controller with registers R. Implements the std/io Reader and Writer interfaces and the serial port protocols.

pub struct Controller<R: hal.Registers>: serial.Port + serial.PollPort {
    // Private implementation fields omitted.
}

Controller.new

Function · Source

Take over a controller as the boot ROM leaves it: enumerated by the host if a cable is connected. Output and input already in the FIFOs stay.

pub fn new(registers: R) -> Controller<R>

Controller.set_crlf

Function · Source

Translate newlines for a serial terminal: write each “\n” as “\r\n”, and read the carriage return that a terminal’s Enter key sends, alone or followed by “\n”, as one “\n”. Off at first.

pub fn set_crlf(&mut self, on: bool)

Controller.is_connected

Function · Source

Whether a program on the host has the port open (DTR on), so what is written now is read now.

pub fn is_connected(&mut self) -> bool

Controller.available

Function · Source

The bytes in the receive FIFO: at least one when nonzero; the controller reports only whether it is empty.

pub fn available(&mut self) -> usize

Controller.listen

Function · Source

Raise the controller’s interrupt for these sources, in addition to those already listened to.

pub fn listen(&mut self, sources: u32)

Controller.ignore

Function · Source

Stop raising the interrupt for these sources.

pub fn ignore(&mut self, sources: u32)

Controller.pending_interrupts

Function · Source

The listened-to sources that are pending now.

pub fn pending_interrupts(&mut self) -> u32

Controller.clear_interrupts

Function · Source

Acknowledge sources. RX_INTERRUPT comes back while the receive FIFO still holds data, TX_INTERRUPT while the transmit FIFO is empty.

pub fn clear_interrupts(&mut self, sources: u32)

Controller.write

Function · Source

Send bytes, waiting while the transmit FIFO is full and a terminal takes output, as the package comment describes. Never fails.

pub fn write(&mut self, bytes: &[u8]) -> usize!io.Error

Controller.poll_write

Function · Source

Queue what fits in the transmit FIFO without waiting; Pending, with what was queued, once it is full.

pub fn poll_write(&mut self, bytes: &[u8]) -> io.Poll!io.Error

Controller.flush

Function · Source

Wait until the host has taken everything written, while a terminal has the port open and keeps taking output; gives up as write does. Never fails.

pub fn flush(&mut self) -> void!io.Error

Controller.poll_flush

Function · Source

flush without waiting: true once the host has taken everything written, or no terminal has the port open (DTR off). Every write ends its packet (WR_DONE), and the controller keeps the transmit FIFO closed (IN_FREE low) until the host has read it. Never fails.

pub fn poll_flush(&mut self) -> bool!io.Error

Controller.read

Function · Source

Wait for the first byte, then return what has arrived, up to buffer.len. A USB serial port never reaches end of input.

pub fn read(&mut self, buffer: &mut[u8]) -> usize!io.Error

Controller.poll_read

Function · Source

Return what the receive FIFO holds, up to buffer.len, without waiting: Pending, with nothing, while it is empty.

pub fn poll_read(&mut self, buffer: &mut[u8]) -> io.Poll!io.Error

Controller.send_report

Function · Source

Write bytes for a panic report: as write, without newline translation, and waiting for the host only while a terminal has the port open.

pub fn send_report(&mut self, bytes: &[u8])

Controller.release

Function · Source

Give back the controller’s registers; the FIFOs keep their contents.

pub fn release(self) -> R

Search every guide, reference page, and API declaration.