2 #include "USBDeviceAudio.h"
4 #include "esp32-hal-tinyusb.h"
6 #ifndef ARDUINO_USB_MODE
7 #error This ESP32 SoC has no Native USB interface
9 #if ARDUINO_USB_MODE == 1
10 #error This sketch should be used when USB is in OTG mode
16 uint8_t *descr =
nullptr;
24 uint16_t tinyusb_audio_descriptor_cb(uint8_t *dst, uint8_t *itf) {
25 uint8_t str_index = tinyusb_add_string_descriptor(
"TinyUSB Audio");
26 *itf += usb_audio_config_esp32.itf_count;
27 memcpy(dst, usb_audio_config_esp32.descr, usb_audio_config_esp32.descr_len);
28 return usb_audio_config_esp32.descr_len;
41 int len = setupDescriptorCB();
43 tinyusb_enable_interface(USB_INTERFACE_CUSTOM, len,
44 tinyusb_audio_descriptor_cb);
51 virtual uint8_t allocInterface(uint8_t count = 1) {
52 uint8_t ret = _itf_count;
57 virtual uint8_t allocEndpoint(uint8_t in) {
58 uint8_t ret = in ? (0x80 | _epin_count++) : _epout_count++;
59 #if defined(ARDUINO_ARCH_ESP32) && ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
63 }
else if (ret == 0x84 || ret == 0x85) {
77 int setupDescriptorCB() {
79 usb_audio_config_esp32.descr_len = len;
80 interface_descriptor.resize(len);
81 usb_audio_config_esp32.descr = interface_descriptor.data();
82 usb_audio_config_esp32.itf_count = _itf_count;
83 getInterfaceDescriptor(0, usb_audio_config_esp32.descr, len);
91 static usbd_class_driver_t audio_class_driver;
93 TU_ATTR_FAST_FUNC
void audiod_init() { USBAudio.api().audiod_init(); }
94 TU_ATTR_FAST_FUNC
bool audiod_deinit() {
return USBAudio.api().audiod_deinit(); }
95 TU_ATTR_FAST_FUNC
void audiod_reset(uint8_t rhport) { USBAudio.api().audiod_reset(rhport); }
96 TU_ATTR_FAST_FUNC uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t
const * desc_intf, uint16_t max_len) {
97 return USBAudio.api().audiod_open(rhport, desc_intf, max_len);
99 TU_ATTR_FAST_FUNC
bool audiod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
const * request){
100 return USBAudio.api().audiod_control_xfer_cb(rhport, stage, request);
102 TU_ATTR_FAST_FUNC
bool audiod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes){
103 return USBAudio.api().audiod_xfer_cb(rhport, ep_addr, result, xferred_bytes);
106 TU_ATTR_FAST_FUNC
void tud_audio_feedback_interval_isr(uint8_t func_id,
107 uint32_t frame_number, uint8_t interval_shift){
108 return USBAudio.audiod_sof_isr(USBAudio.cfg.rh_port, 0);
113 usbd_class_driver_t
const* usbd_app_driver_get_cb(uint8_t* driver_count) {
114 audio_class_driver.name =
"AUDIO";
115 audio_class_driver.init = audiod_init;
116 audio_class_driver.deinit = audiod_deinit;
117 audio_class_driver.open = audiod_open;
118 audio_class_driver.control_xfer_cb = audiod_control_xfer_cb;
119 audio_class_driver.xfer_cb = audiod_xfer_cb;
121 return &audio_class_driver;
Configuration for TinyUSB Audio.
Definition: USBDeviceAudioAPI.h:43
Definition: USBDeviceAudioAdafruit.h:17
Definition: USBDeviceAudioESP32.h:36
Definition: USBDeviceAudio.h:104
void setupDebugPins()
Definition: USBDeviceAudio.h:619
size_t getInterfaceDescriptorLength(uint8_t itfnum) override
Determine the interface descriptor length.
Definition: USBDeviceAudio.h:555
Definition: USBDeviceAudioESP32.h:15