TinyWifiDongle 0.1.0
Header-only USB WiFi dongle for Arduino
Loading...
Searching...
No Matches
twd::Esp32UsbNcm Class Reference

USB CDC-NCM network device for the ESP32-S2/S3 (TinyUSB). More...

#include <Esp32UsbNcm.h>

Inheritance diagram for twd::Esp32UsbNcm:
Collaboration diagram for twd::Esp32UsbNcm:

Classes

struct  Stats
 Counters since start: frames received from and sent to the host, frames dropped on the way out, polls that found the driver busy, and stall recoveries (USB re-enumerations). More...

Public Member Functions

bool begin (const char *productName) override
 Registers the USB network interface (before the USB stack is started).
bool ready () override
 The host has enumerated and configured the device.
void setReceiver (FrameReceiver *receiver) override
 Frames coming from the host are passed to receiver.
void setHostMac (const uint8_t mac[6]) override
bool send (const uint8_t *frame, uint16_t len) override
 Runs in the caller's task: copy, enqueue, never block.
void setMaxFrame (uint16_t bytes)
 Largest Ethernet frame announced to the host; call before begin().
void setStallTimeout (uint32_t ms)
const uint8_t * hostMac () const
 MAC address of the adapter as the host sees it.
Stats stats () const
 Current counters.
void logControllerState ()
uint32_t txQueued () const
 Number of frames waiting to be sent to the host.
void onNcmReceive (const uint8_t *src, uint16_t size)
 A frame from the host (TinyUSB task; must not block).
Public Member Functions inherited from twd::UsbTransport
virtual ~UsbTransport ()=default

Static Public Member Functions

static Esp32UsbNcm * instance_ ()
 The instance that receives the TinyUSB callbacks.

Detailed Description

USB CDC-NCM network device for the ESP32-S2/S3 (TinyUSB).

Implements UsbTransport on top of the TinyUSB NCM class that the Arduino core ships:

  • registers the NCM interface and its descriptors,
  • queues outgoing frames and feeds them to the driver, one frame per USB transfer, from the TinyUSB task,
  • re-arms reception after every frame,
  • re-enumerates the device if the send path stalls for longer than the stall timeout (1 second by default, see setStallTimeout()).

The TinyUSB callbacks are C functions, so the class is a singleton in effect: the instance that ran begin() receives them.

Definition at line 38 of file Esp32UsbNcm.h.

Member Function Documentation

◆ begin()

bool twd::Esp32UsbNcm::begin ( const char * productName)
inlineoverridevirtual

Registers the USB network interface (before the USB stack is started).

Implements twd::UsbTransport.

Definition at line 51 of file Esp32UsbNcm.h.

◆ hostMac()

const uint8_t * twd::Esp32UsbNcm::hostMac ( ) const
inline

MAC address of the adapter as the host sees it.

Definition at line 127 of file Esp32UsbNcm.h.

◆ instance_()

Esp32UsbNcm * twd::Esp32UsbNcm::instance_ ( )
inlinestatic

The instance that receives the TinyUSB callbacks.

Definition at line 156 of file Esp32UsbNcm.h.

◆ logControllerState()

void twd::Esp32UsbNcm::logControllerState ( )
inline

Logs the USB controller's registers of the data IN endpoint: control, transfer size, interrupt flags, FIFO space, and the interrupt masks. A debugging aid for a stalled send path. Only available on the ESP32-S2/S3, where the controller sits at a known address; on other chips it only reports that.

Definition at line 136 of file Esp32UsbNcm.h.

◆ onNcmReceive()

void twd::Esp32UsbNcm::onNcmReceive ( const uint8_t * src,
uint16_t size )
inline

A frame from the host (TinyUSB task; must not block).

Definition at line 159 of file Esp32UsbNcm.h.

◆ ready()

bool twd::Esp32UsbNcm::ready ( )
inlineoverridevirtual

The host has enumerated and configured the device.

Implements twd::UsbTransport.

Definition at line 83 of file Esp32UsbNcm.h.

◆ send()

bool twd::Esp32UsbNcm::send ( const uint8_t * frame,
uint16_t len )
inlineoverridevirtual

Runs in the caller's task: copy, enqueue, never block.

Implements twd::UsbTransport.

Definition at line 93 of file Esp32UsbNcm.h.

◆ setHostMac()

void twd::Esp32UsbNcm::setHostMac ( const uint8_t mac[6])
inlineoverridevirtual

MAC address of the adapter as the host sees it (default: derived from the chip id). Call before begin().

Implements twd::UsbTransport.

Definition at line 87 of file Esp32UsbNcm.h.

◆ setMaxFrame()

void twd::Esp32UsbNcm::setMaxFrame ( uint16_t bytes)
inline

Largest Ethernet frame announced to the host; call before begin().

Definition at line 120 of file Esp32UsbNcm.h.

◆ setReceiver()

void twd::Esp32UsbNcm::setReceiver ( FrameReceiver * receiver)
inlineoverridevirtual

Frames coming from the host are passed to receiver.

Implements twd::UsbTransport.

Definition at line 85 of file Esp32UsbNcm.h.

◆ setStallTimeout()

void twd::Esp32UsbNcm::setStallTimeout ( uint32_t ms)
inline

Re-enumerate USB if sending makes no progress for ms milliseconds. 0 switches the watchdog off: a stalled send path then stays stalled.

Definition at line 124 of file Esp32UsbNcm.h.

◆ stats()

Stats twd::Esp32UsbNcm::stats ( ) const
inline

Current counters.

Definition at line 130 of file Esp32UsbNcm.h.

◆ txQueued()

uint32_t twd::Esp32UsbNcm::txQueued ( ) const
inline

Number of frames waiting to be sent to the host.

Definition at line 152 of file Esp32UsbNcm.h.


The documentation for this class was generated from the following file: