2 #define CFG_TUSB_DEBUG_PRINTF 3
3 #include "Adafruit_TinyUSB.h"
4 #include "USBDeviceAudio.h"
6 #if !defined(USE_TINYUSB) && \
7 (defined(ARDUINO_ARCH_SAMD) || (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)))
8 # error TinyUSB is not selected, please select it in "Tools->Menu->USB Stack"
20 self_USBDeviceAudioAdafruit =
this;
25 if (interface_descriptor.size() != 512){
26 interface_descriptor.resize(512);
27 TinyUSBDevice.setConfigurationBuffer(interface_descriptor.data(), 512);
32 _stridx = TinyUSBDevice.addStringDescriptor(
"TinyUSB Audio");
35 if (!USBDeviceAudio::begin(config)) {
36 LOG_AUDIO_ERROR(
"begin failed");
41 if (!TinyUSBDevice.addInterface(*self_USBDeviceAudioAdafruit)) {
43 LOG_AUDIO_ERROR(
"addInterface failed");
50 uint8_t allocInterface(uint8_t count = 1)
override {
51 return TinyUSBDevice.allocInterface(count);
54 uint8_t allocEndpoint(uint8_t in)
override {
55 return TinyUSBDevice.allocEndpoint(in);
58 uint16_t getInterfaceDescriptor(uint8_t itfnum, uint8_t *buf,
59 uint16_t bufsize)
override {
60 return USBDeviceAudio::getInterfaceDescriptor(buf, bufsize);
66 usbd_class_driver_t
const* usbd_app_driver_get_cb(uint8_t* driver_count) {
67 static usbd_class_driver_t audio_class_driver;
68 audio_class_driver.name =
"AUDIO";
69 audio_class_driver.init = []() {
70 self_USBDeviceAudioAdafruit->begin(self_USBDeviceAudioAdafruit->api().config());
71 self_USBDeviceAudioAdafruit->api().audiod_init();
73 audio_class_driver.deinit = []() {
return self_USBDeviceAudioAdafruit->api().audiod_deinit(); };
74 audio_class_driver.reset = [](uint8_t rhport) { self_USBDeviceAudioAdafruit->api().audiod_reset(rhport); };
75 audio_class_driver.open = [](uint8_t rhport, tusb_desc_interface_t
const * desc_intf, uint16_t max_len) {
76 return self_USBDeviceAudioAdafruit->api().audiod_open(rhport, desc_intf, max_len);
78 audio_class_driver.control_xfer_cb = [](uint8_t rhport, uint8_t stage, tusb_control_request_t
const * request){
79 return self_USBDeviceAudioAdafruit->api().audiod_control_xfer_cb(rhport, stage, request);
81 audio_class_driver.xfer_cb = [](uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes){
82 return self_USBDeviceAudioAdafruit->api().audiod_xfer_cb(rhport, ep_addr, result, xferred_bytes);
84 audio_class_driver.sof = [](uint8_t rhport, uint32_t frame_count) { self_USBDeviceAudioAdafruit->api().audiod_sof_isr(self_USBDeviceAudioAdafruit->api().config().rh_port, 0); };
89 return &audio_class_driver;
Configuration for TinyUSB Audio.
Definition: USBDeviceAudioAPI.h:43
Definition: USBDeviceAudioAdafruit.h:17
Definition: USBDeviceAudio.h:104
void setStatus(AudioProcessingStatus status)
Define the led delay.
Definition: USBDeviceAudio.h:615