Add native USB CDC broker transport

This commit is contained in:
2026-08-23 00:47:56 +02:00
parent 6793f6bcc2
commit aa5fa207b6
11 changed files with 1394 additions and 9 deletions
+82
View File
@@ -0,0 +1,82 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#include "session_broker.h"
#ifdef __cplusplus
extern "C" {
#endif
/* USB CDC line-coding values are the numeric encodings defined by USB PSTN. */
#define USB_CDC_TRANSPORT_STOP_BITS_1 0U
#define USB_CDC_TRANSPORT_STOP_BITS_1_5 1U
#define USB_CDC_TRANSPORT_STOP_BITS_2 2U
#define USB_CDC_TRANSPORT_PARITY_NONE 0U
#define USB_CDC_TRANSPORT_PARITY_ODD 1U
#define USB_CDC_TRANSPORT_PARITY_EVEN 2U
#define USB_CDC_TRANSPORT_PARITY_MARK 3U
#define USB_CDC_TRANSPORT_PARITY_SPACE 4U
typedef struct {
uint32_t baud_rate;
uint8_t stop_bits;
uint8_t parity;
uint8_t data_bits;
} usb_cdc_transport_line_coding_t;
typedef struct {
uint64_t host_rx_bytes;
uint64_t host_rx_stream_dropped_bytes;
uint64_t broker_accepted_bytes;
uint64_t broker_rejected_bytes;
uint64_t broker_to_usb_bytes;
/* Bytes admitted to TinyUSB's TX FIFO, not a host-delivery acknowledgement. */
uint64_t usb_tx_queued_bytes;
uint64_t usb_tx_dropped_bytes;
uint64_t connections;
uint64_t disconnections;
uint64_t writer_grants;
uint64_t writer_denials;
uint64_t writer_revocations;
uint64_t writer_events;
uint64_t service_start_failures;
uint64_t line_coding_applied;
uint64_t line_coding_rejected;
uint64_t line_coding_failed;
uint64_t callback_drops;
uint64_t control_drops;
} usb_cdc_transport_counters_t;
typedef struct {
bool initialized;
bool attached;
bool dtr;
bool rts;
session_broker_client_id_t broker_client_id;
bool writer;
usb_cdc_transport_line_coding_t line_coding;
usb_cdc_transport_counters_t counters;
} usb_cdc_transport_snapshot_t;
/*
* Installs the native ESP32-S3 USB-OTG device on GPIO19/20 as CDC-ACM 0.
* UART0 console/logging configuration is not changed.
*/
esp_err_t usb_cdc_transport_init(void);
esp_err_t usb_cdc_transport_get_snapshot(usb_cdc_transport_snapshot_t *snapshot);
/* Requests are asynchronous and execute in the transport task. */
esp_err_t usb_cdc_transport_request_writer(void);
esp_err_t usb_cdc_transport_release_writer(void);
/* Clearing counters does not alter connection, ownership, or queued data. */
esp_err_t usb_cdc_transport_clear_counters(void);
#ifdef __cplusplus
}
#endif