3#if defined(USE_ESP32_VARIANT_ESP32P4) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || \
4 defined(USE_ESP32_VARIANT_ESP32S31) || defined(USE_ESP32_VARIANT_ESP32H4)
19class USBUartTypeCdcAcm;
20class USBUartComponent;
21class USBUartChannelBase;
22class USBUartTypePL2303;
26static constexpr uint8_t USB_CDC_SUBCLASS_ACM = 0x02;
27static constexpr uint8_t USB_SUBCLASS_COMMON = 0x02;
28static constexpr uint8_t USB_SUBCLASS_NULL = 0x00;
29static constexpr uint8_t USB_PROTOCOL_NULL = 0x00;
30static constexpr uint8_t USB_DEVICE_PROTOCOL_IAD = 0x01;
31static constexpr uint8_t USB_VENDOR_IFC = usb_host::USB_TYPE_VENDOR | usb_host::USB_RECIP_INTERFACE;
32static constexpr uint8_t USB_VENDOR_DEV = usb_host::USB_TYPE_VENDOR | usb_host::USB_RECIP_DEVICE;
104static const char *
const PARITY_NAMES[] = {
"NONE",
"ODD",
"EVEN",
"MARK",
"SPACE"};
106static const char *
const STOP_BITS_NAMES[] = {
"1",
"1.5",
"2"};
124 void push(uint8_t item);
125 void push(
const uint8_t *data,
size_t len);
127 size_t pop(uint8_t *data,
size_t len);
139 uint8_t
data[usb_host::USB_MAX_PACKET_SIZE];
182 using UARTComponent::load_settings;
259 void setup()
override;
260 void loop()
override;
296 const std::vector<uint8_t> &data = {}, uint8_t *dest =
nullptr);
308 const uint8_t *response) = 0;
398 const char *chip_name_{
"unknown"};
399 uint8_t num_ports_{1};
BedjetMode mode
BedJet operating mode.
Helper class to easily give an object a parent of type T.
StringRef is a reference to a string owned by something else.
void load_settings()
Load the UART settings.
USBClient(uint16_t vid, uint16_t pid)
RingBuffer(uint16_t buffer_size)
size_t get_free_space() const
size_t get_available() const
uint8_t get_interface_class() const
bInterfaceClass of the interface get_interface_number() names
uart::UARTFlushResult flush() override
uint32_t flush_timeout_ms_
bool read_array(uint8_t *data, size_t len) override
EventPool< UsbOutputChunk, USB_OUTPUT_CHUNK_COUNT - 1 > output_pool_
bool peek_byte(uint8_t *data) override
void set_debug(bool debug)
LineParity line_parity_() const
std::function< void()> rx_callback_
void set_rx_callback(std::function< void()> cb)
Register a callback invoked immediately after data is pushed to the input ring buffer.
USBUartChannelBase(uint8_t index, uint16_t buffer_size)
LockFreeQueue< UsbOutputChunk, USB_OUTPUT_CHUNK_COUNT > output_queue_
size_t available() override
uint8_t get_port_number() const
Index of this port among the ports on its interface.
void check_logger_conflict() override
static constexpr uint8_t USB_OUTPUT_CHUNK_COUNT
std::atomic< bool > input_started_
uint8_t get_interface_number() const
USB interface number a host driver binds to for this channel: the communication interface of a CDC AC...
void set_dummy_receiver(bool dummy_receiver)
void set_debug_prefix(const char *prefix)
std::atomic< bool > initialised_
std::atomic< bool > output_started_
void set_flush_timeout(uint32_t flush_timeout_ms) override
void write_array(const uint8_t *data, size_t len) override
bool set_modem_control(bool dtr, bool rts)
Store DTR/RTS and send them to the device. False when not connected.
LineStopBits line_stop_bits_() const
bool is_connected() override
USBUartChannel(uint8_t index, uint16_t buffer_size)
USBUartChannelBase * cfg_single_
std::atomic< uint8_t > cfg_done_
std::vector< USBUartChannelBase * > channels_
void start_config_(ConfigMode mode)
USBUartComponent(uint16_t vid, uint16_t pid)
bool reports_connection_itself() const override
LockFreeQueue< UsbDataChunk, USB_DATA_QUEUE_SIZE > usb_data_queue_
virtual void on_rx_overflow(USBUartChannelBase *channel)
virtual void modem_control_transfer(USBUartChannelBase *channel)=0
std::vector< USBUartChannelBase * > get_channels()
bool run_config_machine_()
void config_transfer_(uint8_t type, uint8_t request, uint16_t value, uint16_t index, const std::vector< uint8_t > &data={}, uint8_t *dest=nullptr)
virtual bool config_device_step(uint8_t step, bool ok, const uint8_t *response)
void dump_config() override
virtual void start_input(USBUartChannelBase *channel)
void apply_modem_control(USBUartChannelBase *channel)
void apply_channel_settings(USBUartChannelBase *channel)
void start_output(USBUartChannelBase *channel)
void add_channel(USBUartChannelBase *channel)
static constexpr int USB_DATA_QUEUE_SIZE
EventPool< UsbDataChunk, USB_DATA_QUEUE_SIZE - 1 > chunk_pool_
virtual bool config_step(USBUartChannelBase *channel, uint8_t step, bool reload, bool ok, const uint8_t *response)=0
void dump_config() override
void modem_control_transfer(USBUartChannelBase *channel) override
bool config_device_step(uint8_t step, bool ok, const uint8_t *response) override
USBUartTypeCH34X(uint16_t vid, uint16_t pid)
bool config_step(USBUartChannelBase *channel, uint8_t step, bool reload, bool ok, const uint8_t *response) override
void modem_control_transfer(USBUartChannelBase *channel) override
bool config_device_step(uint8_t step, bool ok, const uint8_t *response) override
USBUartTypeCP210X(uint16_t vid, uint16_t pid)
void set_flow_transfer_(USBUartChannelBase *channel)
std::vector< CdcEps > parse_descriptors(usb_device_handle_t dev_hdl) override
bool config_step(USBUartChannelBase *channel, uint8_t step, bool reload, bool ok, const uint8_t *response) override
std::array< CP210xFlowBlock, MAX_CHANNELS > flow_blocks_
static constexpr uint8_t MAX_CHANNELS
void on_disconnected() override
bool config_step(USBUartChannelBase *channel, uint8_t step, bool reload, bool ok, const uint8_t *response) override
bool claim_comm_interface_
void on_connected() override
USBUartTypeCdcAcm(uint16_t vid, uint16_t pid)
void set_claim_comm_interface(bool claim)
virtual std::vector< CdcEps > parse_descriptors(usb_device_handle_t dev_hdl)
void modem_control_transfer(USBUartChannelBase *channel) override
USBUartTypeFT23XX(uint16_t vid, uint16_t pid)
void modem_control_transfer(USBUartChannelBase *channel) override
bool config_step(USBUartChannelBase *channel, uint8_t step, bool reload, bool ok, const uint8_t *response) override
void on_rx_overflow(USBUartChannelBase *channel) override
std::vector< CdcEps > parse_descriptors(usb_device_handle_t dev_hdl) override
void start_input(USBUartChannelBase *channel) override
USBUartTypePL2303(uint16_t vid, uint16_t pid)
std::vector< CdcEps > parse_descriptors(usb_device_handle_t dev_hdl) override
bool config_step(USBUartChannelBase *channel, uint8_t step, bool reload, bool ok, const uint8_t *response) override
Pl2303ChipType chip_type_
void modem_control_transfer(USBUartChannelBase *channel) override
UARTFlushResult
Result of a flush() call.
ConfigMode
What the config state machine is applying.
@ CONFIG_MODE_RELOAD
Re-apply the line settings of one already-open channel.
@ CONFIG_MODE_MODEM
Apply the DTR/RTS state of one already-open channel.
@ CONFIG_MODE_INIT
Full initialisation of every channel after the device connected.
ESPHOME_LOG_TAG(TAG, "usb_uart")
@ UART_CONFIG_STOP_BITS_1_5
@ UART_CONFIG_STOP_BITS_1
@ UART_CONFIG_STOP_BITS_2
uint32_t control_handshake
const usb_ep_desc_t * out_ep
bool interrupt_interface_claimed
uint8_t interrupt_interface_class
uint8_t bulk_interface_number
const usb_ep_desc_t * notify_ep
const usb_ep_desc_t * in_ep
uint8_t bulk_interface_class
uint8_t interrupt_interface_number
uint8_t data[usb_host::USB_MAX_PACKET_SIZE]
USBUartChannelBase * channel
uint8_t data[MAX_CHUNK_SIZE]
static constexpr size_t MAX_CHUNK_SIZE