arduino-audio-tools
Loading...
Searching...
No Matches
USBAudioDeviceRenesas.h
Go to the documentation of this file.
1#pragma once
2#include <Arduino.h>
3
4#ifdef ARDUINO_ARCH_RENESAS
5
6// Not "usb/USB.h" via <> -- this core only puts cores/arduino itself (not
7// its usb/ subdirectory) on the include path, unlike ESP32's USB.h which
8// lives in a separate library and is reachable as <USB.h>.
9#include "usb/USB.h"
10
11#include <cstring>
12
16
17namespace audio_tools {
18
63 friend class Emulated_TinyUSB;
64
65 public:
68
77 static uint8_t* customDescriptorCallback(uint8_t itfnum, size_t* len,
78 uint8_t* num_interfaces) {
79 auto& dev = getActualInstance();
80 dev.config_.itf_num_ac = itfnum;
81 static uint8_t desc[USB_DESCR_MAX_LEN];
82 uint16_t l = dev.getDescriptor(desc);
83 if (len) *len = l;
84 if (num_interfaces) *num_interfaces = dev.numInterfaces();
85 return desc;
86 }
87
92
96 BaseBuffer<uint8_t>& bufferTx() override { return buffer_tx_; }
97
102
107 void serviceUSB() override {}
108
109
110 protected:
114 bool begin_called_ = false;
115
116 USBAudioBackend& backend() override { return backend_impl_; }
117
126 bool beginUSB() override {
127 if (begin_called_) return true;
128 begin_called_ = true;
129 __USBStart();
130 return true;
131 }
132
135 void resizeBuffers() override {
136 uint16_t block_sz = packetSize();
137 uint8_t block_cnt = config_.fifo_packets;
138 if (isEpInEnabled()) buffer_tx_.resize(block_sz * block_cnt);
139 if (isEpOutEnabled()) buffer_rx_.resize(block_sz * block_cnt);
140 }
141};
142
148class Emulated_TinyUSB {
149 public:
150 bool isInitialized() { return tud_inited(); }
151 bool begin(int) { return true; }
152 bool mounted() {
153 if (!device().begin_called_) return true;
154 return tud_mounted();
155 }
156 bool detach() {
157 if (!device().begin_called_) return true;
158 return tud_disconnect();
159 }
160 bool attach() {
161 if (!device().begin_called_) {
162 device().beginUSB();
163 return true;
164 }
165 return tud_connect();
166 }
171};
172
174
182
183} // namespace audio_tools
184
185// ── Composite descriptor registration ───────────────────────────────────────
186// Overrides the weak __USBGetCustomInterfaceDescriptor hook declared in the
187// core's USB.h. Deliberately plain external linkage (not `inline`), for the
188// same reason usbd_app_driver_get_cb() in USBAudioBackendTinyUSB.h is not
189// `inline`: this header is only ever included from one translation unit in
190// practice, and a `static`/`inline` definition here would leave the core's
191// own weak default (which returns nullptr, i.e. "no custom interface") free
192// to win the link instead in some configurations.
193uint8_t* __USBGetCustomInterfaceDescriptor(uint8_t itfnum, size_t* len,
194 uint8_t* num_interfaces) {
196 itfnum, len, num_interfaces);
197}
198
199#endif // ARDUINO_ARCH_RENESAS
If you want to use the framework w/o Arduino you need to provide the implementation of a couple of cl...
#define USB_DESCR_MAX_LEN
Definition USBAudioDeviceBase.h:47
uint8_t * __USBGetCustomInterfaceDescriptor(uint8_t itfnum, size_t *len, uint8_t *num_interfaces)
Definition USBAudioDeviceRenesas.h:193
Shared functionality of all buffers.
Definition Buffers.h:23
Minimal wrapper around the ESP32 TinyUSB API. We emulate the basic functionality so that we can use t...
Definition USBAudioDeviceESP32.h:223
bool isInitialized()
Definition USBAudioDeviceRenesas.h:150
bool mounted()
Definition USBAudioDeviceRenesas.h:152
bool detach()
Definition USBAudioDeviceRenesas.h:156
USBAudioDeviceESP32 & device()
Definition USBAudioDeviceESP32.h:247
USBAudioDeviceRenesas & device()
Definition USBAudioDeviceRenesas.h:167
bool attach()
Definition USBAudioDeviceRenesas.h:160
bool begin(int)
Definition USBAudioDeviceRenesas.h:151
Lock-free Single-Producer Single-Consumer ring buffer.
Definition RingBufferSPSC.h:50
bool resize(size_t capacity) override
Resizes the buffer if supported: returns false if not supported.
Definition RingBufferSPSC.h:137
Abstract seam for every raw USB-stack call the UAC2 driver (USBAudioDeviceBase) needs....
Definition USBAudioBackend.h:160
USBAudioBackend implementation wrapping the real TinyUSB device stack. Injected by the ESP32,...
Definition USBAudioBackendTinyUSB.h:48
USB Audio Device class for audio streaming over USB.
Definition USBAudioDeviceBase.h:109
bool isEpInEnabled() const
Returns true if the IN endpoint is enabled.
Definition USBAudioDeviceBase.h:391
USBAudioConfig config_
Definition USBAudioDeviceBase.h:856
static USBAudioDeviceBase & activeInstance()
Returns the most-recently-constructed instance (base or subclass).
Definition USBAudioDeviceBase.h:388
uint16_t packetSize() const
Definition USBAudioDeviceBase.h:1101
bool isEpOutEnabled() const
Returns true if the OUT endpoint is enabled.
Definition USBAudioDeviceBase.h:394
USBAudioDeviceBase subclass for ESP32-S2/S3 using the arduino-esp32 stack.
Definition USBAudioDeviceESP32.h:55
bool beginUSB() override
Configure and start the ESP32 USB stack.
Definition USBAudioDeviceESP32.h:190
USBAudioDeviceBase subclass for the Arduino UNO R4 / Nano R4 (Renesas RA4M1, arduino:renesas_uno core...
Definition USBAudioDeviceRenesas.h:62
RingBufferSPSC< uint8_t > buffer_tx_
Definition USBAudioDeviceRenesas.h:112
BaseBuffer< uint8_t > & bufferTx() override
Returns the TX audio buffer (public to match USBAudioDeviceESP32, so sketches using the portable USBA...
Definition USBAudioDeviceRenesas.h:96
void serviceUSB() override
No-op: _usbfs_interrupt_handler() in the core's USB.cpp already calls tud_task() directly from the US...
Definition USBAudioDeviceRenesas.h:107
bool begin_called_
Definition USBAudioDeviceRenesas.h:114
bool beginUSB() override
Starts the RA4M1's native USB peripheral via the core's __USBStart(). Endpoint addresses are fixed (s...
Definition USBAudioDeviceRenesas.h:126
USBAudioDeviceRenesas(USBAudioConfig cfg)
Definition USBAudioDeviceRenesas.h:67
RingBufferSPSC< uint8_t > buffer_rx_
Definition USBAudioDeviceRenesas.h:113
void resizeBuffers() override
Resize buffers as block pools: block size = one USB frame at the current sample rate,...
Definition USBAudioDeviceRenesas.h:135
USBAudioBackend & backend() override
Returns the backend used for all raw USB-stack calls (TinyUSB today, or a future native-HAL backend)....
Definition USBAudioDeviceRenesas.h:116
BaseBuffer< uint8_t > & bufferRx() override
Returns the RX audio buffer (public to match USBAudioDeviceESP32, so sketches using the portable USBA...
Definition USBAudioDeviceRenesas.h:101
USBAudioBackendTinyUSB backend_impl_
Definition USBAudioDeviceRenesas.h:111
static uint8_t * customDescriptorCallback(uint8_t itfnum, size_t *len, uint8_t *num_interfaces)
Definition USBAudioDeviceRenesas.h:77
static USBAudioDeviceRenesas & getActualInstance()
Definition USBAudioDeviceRenesas.h:88
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
static Emulated_TinyUSB TinyUSBDevice
Definition USBAudioDeviceESP32.h:253
Configuration for USB Audio (inherits sample_rate / channels / bits_per_sample from AudioInfo).
Definition USBAudioConfig.h:117
uint8_t fifo_packets
Definition USBAudioConfig.h:148