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
103 protected:
107 bool begin_called_ = false;
108
109 USBAudioBackend& backend() override { return backend_impl_; }
110
115 void serviceTinyUSB() override {}
116
125 bool beginUSB() override {
126 if (begin_called_) return true;
127 begin_called_ = true;
128 __USBStart();
129 return true;
130 }
131
134 void resizeBuffers() override {
135 uint16_t block_sz = packetSize();
136 uint8_t block_cnt = config_.fifo_packets;
137 if (isEpInEnabled()) buffer_tx_.resize(block_sz * block_cnt);
138 if (isEpOutEnabled()) buffer_rx_.resize(block_sz * block_cnt);
139 }
140};
141
147class Emulated_TinyUSB {
148 public:
149 bool isInitialized() { return tud_inited(); }
150 bool begin(int) { return true; }
151 bool mounted() {
152 if (!device().begin_called_) return true;
153 return tud_mounted();
154 }
155 bool detach() {
156 if (!device().begin_called_) return true;
157 return tud_disconnect();
158 }
159 bool attach() {
160 if (!device().begin_called_) {
161 device().beginUSB();
162 return true;
163 }
164 return tud_connect();
165 }
170};
171
173
181
182} // namespace audio_tools
183
184// ── Composite descriptor registration ───────────────────────────────────────
185// Overrides the weak __USBGetCustomInterfaceDescriptor hook declared in the
186// core's USB.h. Deliberately plain external linkage (not `inline`), for the
187// same reason usbd_app_driver_get_cb() in USBAudioBackendTinyUSB.h is not
188// `inline`: this header is only ever included from one translation unit in
189// practice, and a `static`/`inline` definition here would leave the core's
190// own weak default (which returns nullptr, i.e. "no custom interface") free
191// to win the link instead in some configurations.
192uint8_t* __USBGetCustomInterfaceDescriptor(uint8_t itfnum, size_t* len,
193 uint8_t* num_interfaces) {
195 itfnum, len, num_interfaces);
196}
197
198#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:192
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:219
bool isInitialized()
Definition USBAudioDeviceRenesas.h:149
bool mounted()
Definition USBAudioDeviceRenesas.h:151
bool detach()
Definition USBAudioDeviceRenesas.h:155
USBAudioDeviceESP32 & device()
Definition USBAudioDeviceESP32.h:243
USBAudioDeviceRenesas & device()
Definition USBAudioDeviceRenesas.h:166
bool attach()
Definition USBAudioDeviceRenesas.h:159
bool begin(int)
Definition USBAudioDeviceRenesas.h:150
Lock-free Single-Producer Single-Consumer ring buffer.
Definition RingBufferSPSC.h:40
bool resize(size_t capacity) override
Resizes the buffer if supported: returns false if not supported.
Definition RingBufferSPSC.h:120
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:387
USBAudioConfig config_
Definition USBAudioDeviceBase.h:804
static USBAudioDeviceBase & activeInstance()
Returns the most-recently-constructed instance (base or subclass).
Definition USBAudioDeviceBase.h:384
uint16_t packetSize() const
Definition USBAudioDeviceBase.h:1043
bool isEpOutEnabled() const
Returns true if the OUT endpoint is enabled.
Definition USBAudioDeviceBase.h:390
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:186
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:105
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 serviceTinyUSB() override
No-op: _usbfs_interrupt_handler() in the core's USB.cpp already calls tud_task() directly from the US...
Definition USBAudioDeviceRenesas.h:115
bool begin_called_
Definition USBAudioDeviceRenesas.h:107
bool beginUSB() override
Starts the RA4M1's native USB peripheral via the core's __USBStart(). Endpoint addresses are fixed (s...
Definition USBAudioDeviceRenesas.h:125
USBAudioDeviceRenesas(USBAudioConfig cfg)
Definition USBAudioDeviceRenesas.h:67
RingBufferSPSC< uint8_t > buffer_rx_
Definition USBAudioDeviceRenesas.h:106
void resizeBuffers() override
Resize buffers as block pools: block size = one USB frame at the current sample rate,...
Definition USBAudioDeviceRenesas.h:134
USBAudioBackend & backend() override
Returns the backend used for all raw USB-stack calls (TinyUSB today, or a future native-HAL backend)....
Definition USBAudioDeviceRenesas.h:109
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:104
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:249
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