arduino-audio-tools
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
USBAudioHostBackendESP32 Class Reference

USBAudioHostBackend for the ESP-IDF usb_host library which is part of arduino-esp32 (ESP32-S2, ESP32-S3 and ESP32-P4). More...

#include <USBAudioHostBackendESP32.h>

Inheritance diagram for USBAudioHostBackendESP32:
USBAudioHostBackend

Classes

struct  Interface
 
struct  Stream
 

Public Member Functions

 ~USBAudioHostBackendESP32 ()
 
bool begin (USBAudioHostEvents *events, const USBAudioConfig &cfg) override
 Start the host stack and register the event receiver.
 
void closeStream (uint8_t daddr, uint8_t ep_addr) override
 Stop streaming the indicated endpoint.
 
bool control (uint8_t daddr, const UsbSetupPacket &setup, uint8_t *data) override
 
void end () override
 Stop all streams (the host stack itself keeps running).
 
uint32_t millis () const override
 Milliseconds since start (for control request timeouts).
 
bool openStream (uint8_t daddr, const UsbEndpointDescriptorView &ep, UsbHostStreamRole role) override
 
bool setInterface (uint8_t daddr, uint8_t itf, uint8_t alt) override
 
UsbSpeed speed () const override
 Bus speed of the attached device.
 
void task () override
 Pump the host stack on platforms where the application drives it.
 

Static Public Attributes

static constexpr int kPacketsPerTransfer = 4
 Number of isochronous packets (1 ms at full speed) per transfer.
 
static constexpr int kTransfersInFlight = 2
 Number of transfers which are kept in flight per endpoint.
 

Protected Member Functions

void closeDevice ()
 
Interface * findInterface (uint8_t itf)
 
Stream * findStream (uint8_t ep_addr)
 
Stream * findStream (usb_transfer_t *xfer)
 
void freeTransfers (Stream &s)
 
void openDevice (uint8_t address)
 
bool releaseInterface (Interface &itf)
 
void submit (Stream &s, usb_transfer_t *xfer)
 

Static Protected Member Functions

static void clientEvent (const usb_host_client_event_msg_t *msg, void *arg)
 
static void controlComplete (usb_transfer_t *xfer)
 
static bool installLibrary ()
 
static void isoComplete (usb_transfer_t *xfer)
 
static void libraryTask (void *)
 

Protected Attributes

usb_host_client_handle_t client_ = nullptr
 
uint8_t * ctrl_data_ = nullptr
 
uint16_t ctrl_len_ = 0
 
usb_transfer_t * ctrl_xfer_ = nullptr
 
uint8_t daddr_ = 0
 
usb_device_handle_t dev_ = nullptr
 
USBAudioHostEvents * events_ = nullptr
 
std::vector< Interface > interfaces_
 
std::vector< Stream > streams_
 

Static Protected Attributes

static constexpr size_t kCtrlXferSize = 8 + 512
 
static bool s_library_installed_ = false
 
static TaskHandle_t s_library_task_ = nullptr
 

Detailed Description

USBAudioHostBackend for the ESP-IDF usb_host library which is part of arduino-esp32 (ESP32-S2, ESP32-S3 and ESP32-P4).

begin() installs the USB host library (unless it was already installed, e.g. by another library) and starts a task which processes the library events. The client events and transfer completions are processed by task(), which is called continuously by the USB task of USBAudioHostESP32.

Isochronous endpoints are streamed with two transfers in flight, each covering kPacketsPerTransfer service intervals.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ ~USBAudioHostBackendESP32()

Member Function Documentation

◆ begin()

bool begin ( USBAudioHostEvents *  events,
const USBAudioConfig &  cfg 
)
inlineoverridevirtual

Start the host stack and register the event receiver.

Implements USBAudioHostBackend.

◆ clientEvent()

static void clientEvent ( const usb_host_client_event_msg_t *  msg,
void *  arg 
)
inlinestaticprotected

◆ closeDevice()

void closeDevice ( )
inlineprotected

◆ closeStream()

void closeStream ( uint8_t  daddr,
uint8_t  ep_addr 
)
inlineoverridevirtual

Stop streaming the indicated endpoint.

Implements USBAudioHostBackend.

◆ control()

bool control ( uint8_t  daddr,
const UsbSetupPacket &  setup,
uint8_t *  data 
)
inlineoverridevirtual

Asynchronous control request on EP0. For IN requests data receives up to setup.wLength bytes; for OUT requests it holds the payload. data must stay valid until onControlComplete().

Implements USBAudioHostBackend.

◆ controlComplete()

static void controlComplete ( usb_transfer_t *  xfer)
inlinestaticprotected

◆ end()

void end ( )
inlineoverridevirtual

Stop all streams (the host stack itself keeps running).

Implements USBAudioHostBackend.

◆ findInterface()

Interface * findInterface ( uint8_t  itf)
inlineprotected

◆ findStream() [1/2]

Stream * findStream ( uint8_t  ep_addr)
inlineprotected

◆ findStream() [2/2]

Stream * findStream ( usb_transfer_t *  xfer)
inlineprotected

◆ freeTransfers()

void freeTransfers ( Stream &  s)
inlineprotected

◆ installLibrary()

static bool installLibrary ( )
inlinestaticprotected

Installs the USB host library and starts the task which handles its events

◆ isoComplete()

static void isoComplete ( usb_transfer_t *  xfer)
inlinestaticprotected

◆ libraryTask()

static void libraryTask ( void *  )
inlinestaticprotected

◆ millis()

uint32_t millis ( ) const
inlineoverridevirtual

Milliseconds since start (for control request timeouts).

Implements USBAudioHostBackend.

◆ openDevice()

void openDevice ( uint8_t  address)
inlineprotected

Opens a newly enumerated device and provides its audio control interface to the class logic

◆ openStream()

bool openStream ( uint8_t  daddr,
const UsbEndpointDescriptorView &  ep,
UsbHostStreamRole  role 
)
inlineoverridevirtual

Open an isochronous endpoint of the currently selected alternate setting and start streaming it in the indicated role.

Implements USBAudioHostBackend.

◆ releaseInterface()

bool releaseInterface ( Interface &  itf)
inlineprotected

Releasing an interface requires that its endpoints are idle: when transfers are still being returned this fails and setInterface() is retried by the class logic.

◆ setInterface()

bool setInterface ( uint8_t  daddr,
uint8_t  itf,
uint8_t  alt 
)
inlineoverridevirtual

Claims the interface with the alternate setting (which allocates its endpoints) and sends SET_INTERFACE.

Implements USBAudioHostBackend.

◆ speed()

UsbSpeed speed ( ) const
inlineoverridevirtual

Bus speed of the attached device.

Reimplemented from USBAudioHostBackend.

◆ submit()

void submit ( Stream &  s,
usb_transfer_t *  xfer 
)
inlineprotected

◆ task()

void task ( )
inlineoverridevirtual

Pump the host stack on platforms where the application drives it.

Implements USBAudioHostBackend.

Member Data Documentation

◆ client_

usb_host_client_handle_t client_ = nullptr
protected

◆ ctrl_data_

uint8_t* ctrl_data_ = nullptr
protected

◆ ctrl_len_

uint16_t ctrl_len_ = 0
protected

◆ ctrl_xfer_

usb_transfer_t* ctrl_xfer_ = nullptr
protected

◆ daddr_

uint8_t daddr_ = 0
protected

◆ dev_

usb_device_handle_t dev_ = nullptr
protected

◆ events_

USBAudioHostEvents* events_ = nullptr
protected

◆ interfaces_

std::vector<Interface> interfaces_
protected

◆ kCtrlXferSize

constexpr size_t kCtrlXferSize = 8 + 512
staticconstexprprotected

◆ kPacketsPerTransfer

constexpr int kPacketsPerTransfer = 4
staticconstexpr

Number of isochronous packets (1 ms at full speed) per transfer.

◆ kTransfersInFlight

constexpr int kTransfersInFlight = 2
staticconstexpr

Number of transfers which are kept in flight per endpoint.

◆ s_library_installed_

bool s_library_installed_ = false
inlinestaticprotected

◆ s_library_task_

TaskHandle_t s_library_task_ = nullptr
inlinestaticprotected

◆ streams_

std::vector<Stream> streams_
protected

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