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

USB CDC-NCM network device for the Raspberry Pi Pico W / Pico 2 W. More...

#include <Rp2040UsbNcm.h>

Inheritance diagram for twd::Rp2040UsbNcm:
Collaboration diagram for twd::Rp2040UsbNcm:

Classes

struct  Stats
 Counters since start. 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
void setBuffers (uint8_t toHost, uint8_t fromHost)
bool send (const uint8_t *frame, uint16_t len) override
 Queues the frame; never blocks. Returns false if it was dropped.
Stats stats () const
 Current counters.
uint32_t txQueued ()
 Number of frames waiting to be sent to the host.
bool onNcmReceive (const uint8_t *src, uint16_t size)
 A frame from the host. May run in interrupt context: copy and queue only.
Public Member Functions inherited from twd::UsbTransport
virtual ~UsbTransport ()=default

Static Public Member Functions

static Rp2040UsbNcm * instance_ ()
 The instance that receives the TinyUSB callbacks.
static uint16_t copyFrame (uint8_t *dst, void *ref)
 Copies the frame ref (as passed to tud_network_xmit()) to dst; returns its length.

Detailed Description

USB CDC-NCM network device for the Raspberry Pi Pico W / Pico 2 W.

Implements UsbTransport on top of the TinyUSB NCM class of the arduino-pico core (USB stack "Pico SDK"). Frames from the host are queued by the TinyUSB receive callback and handed to the FrameReceiver by a worker in the core's lwIP async context; frames to the host are queued by send() and pushed into the USB stack by the same worker, which holds the USB mutex while it does so. The frame buffers are allocated by begin(); their number per direction is set with setBuffers() (TinyWifiDongleConfig::framesToHost and framesFromHost).

The TinyUSB callbacks are C functions, so the instance that ran begin() receives them.

Definition at line 45 of file Rp2040UsbNcm.h.

Member Function Documentation

◆ begin()

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

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

Implements twd::UsbTransport.

Definition at line 55 of file Rp2040UsbNcm.h.

◆ copyFrame()

uint16_t twd::Rp2040UsbNcm::copyFrame ( uint8_t * dst,
void * ref )
inlinestatic

Copies the frame ref (as passed to tud_network_xmit()) to dst; returns its length.

Definition at line 153 of file Rp2040UsbNcm.h.

◆ instance_()

Rp2040UsbNcm * twd::Rp2040UsbNcm::instance_ ( )
inlinestatic

The instance that receives the TinyUSB callbacks.

Definition at line 150 of file Rp2040UsbNcm.h.

◆ onNcmReceive()

bool twd::Rp2040UsbNcm::onNcmReceive ( const uint8_t * src,
uint16_t size )
inline

A frame from the host. May run in interrupt context: copy and queue only.

Definition at line 160 of file Rp2040UsbNcm.h.

◆ ready()

bool twd::Rp2040UsbNcm::ready ( )
inlineoverridevirtual

The host has enumerated and configured the device.

Implements twd::UsbTransport.

Definition at line 110 of file Rp2040UsbNcm.h.

◆ send()

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

Queues the frame; never blocks. Returns false if it was dropped.

Implements twd::UsbTransport.

Definition at line 124 of file Rp2040UsbNcm.h.

◆ setBuffers()

void twd::Rp2040UsbNcm::setBuffers ( uint8_t toHost,
uint8_t fromHost )
inline

Number of frame buffers for frames to the host and from the host; 0 = the default of the chip. Call before begin().

Definition at line 118 of file Rp2040UsbNcm.h.

◆ setHostMac()

void twd::Rp2040UsbNcm::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 114 of file Rp2040UsbNcm.h.

◆ setReceiver()

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

Frames coming from the host are passed to receiver.

Implements twd::UsbTransport.

Definition at line 112 of file Rp2040UsbNcm.h.

◆ stats()

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

Current counters.

Definition at line 143 of file Rp2040UsbNcm.h.

◆ txQueued()

uint32_t twd::Rp2040UsbNcm::txQueued ( )
inline

Number of frames waiting to be sent to the host.

Definition at line 146 of file Rp2040UsbNcm.h.


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