@@ -31,10 +31,10 @@
|
||||
* $ python3 plot_audio_samples.py
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bsp/board_api.h"
|
||||
#include "tusb.h"
|
||||
@@ -43,38 +43,38 @@
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#define USBD_STACK_SIZE 4096
|
||||
#define USBD_STACK_SIZE 4096
|
||||
#else
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "queue.h"
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
|
||||
// Increase stack size when debug log is enabled
|
||||
#define USBD_STACK_SIZE (4*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
|
||||
#define USBD_STACK_SIZE (4 * configMINIMAL_STACK_SIZE / 2) * (CFG_TUSB_DEBUG ? 2 : 1)
|
||||
#endif
|
||||
|
||||
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define AUDIO_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define AUDIO_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||
//--------------------------------------------------------------------+
|
||||
#define AUDIO_SAMPLE_RATE CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE
|
||||
#define AUDIO_SAMPLE_RATE CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE
|
||||
|
||||
/* Blink pattern
|
||||
* - 250 ms : device not mounted
|
||||
* - 1000 ms : device mounted
|
||||
* - 2500 ms : device is suspended
|
||||
*/
|
||||
enum {
|
||||
enum {
|
||||
BLINK_NOT_MOUNTED = 250,
|
||||
BLINK_MOUNTED = 1000,
|
||||
BLINK_SUSPENDED = 2500,
|
||||
@@ -82,13 +82,13 @@ enum {
|
||||
|
||||
// static task
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
StackType_t blinky_stack[BLINKY_STACK_SIZE];
|
||||
StackType_t blinky_stack[BLINKY_STACK_SIZE];
|
||||
StaticTask_t blinky_taskdef;
|
||||
|
||||
StackType_t usb_device_stack[USBD_STACK_SIZE];
|
||||
StackType_t usb_device_stack[USBD_STACK_SIZE];
|
||||
StaticTask_t usb_device_taskdef;
|
||||
|
||||
StackType_t audio_stack[AUDIO_STACK_SIZE];
|
||||
StackType_t audio_stack[AUDIO_STACK_SIZE];
|
||||
StaticTask_t audio_taskdef;
|
||||
#endif
|
||||
|
||||
@@ -96,25 +96,24 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
|
||||
// Audio controls
|
||||
// Current states
|
||||
bool mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
|
||||
uint16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
|
||||
bool mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
|
||||
uint16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// +1 for master channel 0
|
||||
uint32_t sampFreq;
|
||||
uint8_t clkValid;
|
||||
|
||||
// Range states
|
||||
audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX+1]; // Volume range state
|
||||
audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
|
||||
audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
|
||||
audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
|
||||
|
||||
// Audio test data, 4 channels muxed together, buffer[0] for CH0, buffer[1] for CH1, buffer[2] for CH2, buffer[3] for CH3
|
||||
uint16_t i2s_dummy_buffer[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX*CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE/1000];
|
||||
uint16_t i2s_dummy_buffer[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX * CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE / 1000];
|
||||
|
||||
void led_blinking_task(void* param);
|
||||
void usb_device_task(void* param);
|
||||
void audio_task(void* param);
|
||||
void led_blinking_task(void *param);
|
||||
void usb_device_task(void *param);
|
||||
void audio_isr_task(void *param);
|
||||
|
||||
/*------------- MAIN -------------*/
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
board_init();
|
||||
|
||||
// Init values
|
||||
@@ -127,20 +126,19 @@ int main(void)
|
||||
sampleFreqRng.subrange[0].bRes = 0;
|
||||
|
||||
// Generate dummy data
|
||||
uint16_t * p_buff = i2s_dummy_buffer;
|
||||
uint16_t *p_buff = i2s_dummy_buffer;
|
||||
uint16_t dataVal = 0;
|
||||
for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
|
||||
{
|
||||
for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE / 1000; cnt++) {
|
||||
// CH0 saw wave
|
||||
*p_buff++ = dataVal;
|
||||
// CH1 inverted saw wave
|
||||
*p_buff++ = 3200 + AUDIO_SAMPLE_RATE/1000 - dataVal;
|
||||
dataVal+= 32;
|
||||
*p_buff++ = 3200 + AUDIO_SAMPLE_RATE / 1000 - dataVal;
|
||||
dataVal += 32;
|
||||
// CH3 square wave
|
||||
*p_buff++ = cnt < (AUDIO_SAMPLE_RATE/1000/2) ? 3400:5000;
|
||||
*p_buff++ = cnt < (AUDIO_SAMPLE_RATE / 1000 / 2) ? 3400 : 5000;
|
||||
// CH4 sinus wave
|
||||
float t = 2*3.1415f * cnt / (AUDIO_SAMPLE_RATE/1000);
|
||||
*p_buff++ = (uint16_t)((int16_t)(sinf(t) * 750) + 6000);
|
||||
float t = 2 * 3.1415f * cnt / (AUDIO_SAMPLE_RATE / 1000);
|
||||
*p_buff++ = (uint16_t) ((int16_t) (sinf(t) * 750) + 6000);
|
||||
}
|
||||
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
@@ -148,44 +146,42 @@ int main(void)
|
||||
xTaskCreateStatic(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, blinky_stack, &blinky_taskdef);
|
||||
|
||||
// Create a task for tinyusb device stack
|
||||
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
|
||||
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, usb_device_stack, &usb_device_taskdef);
|
||||
|
||||
// Create a task for audio
|
||||
xTaskCreateStatic(audio_task, "audio", AUDIO_STACK_SIZE, NULL, configMAX_PRIORITIES-1, audio_stack, &audio_taskdef);
|
||||
// Audio receive (I2S) ISR simulation
|
||||
// To simulate a ISR the priority is set to the highest
|
||||
xTaskCreateStatic(audio_isr_task, "audio", AUDIO_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, audio_stack, &audio_taskdef);
|
||||
#else
|
||||
xTaskCreate(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, NULL);
|
||||
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
xTaskCreate(audio_task, "audio", AUDIO_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, NULL);
|
||||
xTaskCreate(audio_isr_task, "audio", AUDIO_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
#endif
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
void app_main(void)
|
||||
{
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
#endif
|
||||
|
||||
// USB Device Driver task
|
||||
// This top level thread process all usb events and invoke callbacks
|
||||
void usb_device_task(void* param)
|
||||
{
|
||||
void usb_device_task(void *param) {
|
||||
(void) param;
|
||||
|
||||
// init device stack on configured roothub port
|
||||
// This should be called after scheduler/kernel is started.
|
||||
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
|
||||
tusb_rhport_init_t dev_init = {
|
||||
.role = TUSB_ROLE_DEVICE,
|
||||
.speed = TUSB_SPEED_AUTO
|
||||
};
|
||||
.role = TUSB_ROLE_DEVICE,
|
||||
.speed = TUSB_SPEED_AUTO};
|
||||
tusb_init(BOARD_TUD_RHPORT, &dev_init);
|
||||
|
||||
if (board_init_after_tusb) {
|
||||
@@ -193,8 +189,7 @@ void usb_device_task(void* param)
|
||||
}
|
||||
|
||||
// RTOS forever loop
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
// tinyusb device task
|
||||
tud_task();
|
||||
}
|
||||
@@ -205,29 +200,25 @@ void usb_device_task(void* param)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when device is mounted
|
||||
void tud_mount_cb(void)
|
||||
{
|
||||
void tud_mount_cb(void) {
|
||||
blink_interval_ms = BLINK_MOUNTED;
|
||||
}
|
||||
|
||||
// Invoked when device is unmounted
|
||||
void tud_umount_cb(void)
|
||||
{
|
||||
void tud_umount_cb(void) {
|
||||
blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
}
|
||||
|
||||
// Invoked when usb bus is suspended
|
||||
// remote_wakeup_en : if host allow us to perform remote wakeup
|
||||
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
|
||||
void tud_suspend_cb(bool remote_wakeup_en)
|
||||
{
|
||||
void tud_suspend_cb(bool remote_wakeup_en) {
|
||||
(void) remote_wakeup_en;
|
||||
blink_interval_ms = BLINK_SUSPENDED;
|
||||
}
|
||||
|
||||
// Invoked when usb bus is resumed
|
||||
void tud_resume_cb(void)
|
||||
{
|
||||
void tud_resume_cb(void) {
|
||||
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
|
||||
}
|
||||
|
||||
@@ -235,14 +226,14 @@ void tud_resume_cb(void)
|
||||
// AUDIO Task
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void audio_task(void* param)
|
||||
{
|
||||
// This task simulates an audio receive ISR, one frame is received every 1ms.
|
||||
// We assume that the audio data is read from an I2S buffer.
|
||||
// In a real application, this would be replaced with actual I2S receive callback.
|
||||
void audio_isr_task(void *param) {
|
||||
(void) param;
|
||||
// Yet to be filled - e.g. read audio from I2S buffer.
|
||||
// Here we simulate a I2S receive callback every 1ms.
|
||||
while (1) {
|
||||
vTaskDelay(1);
|
||||
tud_audio_write(i2s_dummy_buffer, AUDIO_SAMPLE_RATE/1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX);
|
||||
tud_audio_write(i2s_dummy_buffer, AUDIO_SAMPLE_RATE / 1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,8 +242,7 @@ void audio_task(void* param)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when audio class specific set request received for an EP
|
||||
bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff)
|
||||
{
|
||||
bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
|
||||
(void) rhport;
|
||||
(void) pBuff;
|
||||
|
||||
@@ -264,14 +254,15 @@ bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_re
|
||||
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
|
||||
uint8_t ep = TU_U16_LOW(p_request->wIndex);
|
||||
|
||||
(void) channelNum; (void) ctrlSel; (void) ep;
|
||||
(void) channelNum;
|
||||
(void) ctrlSel;
|
||||
(void) ep;
|
||||
|
||||
return false; // Yet not implemented
|
||||
return false;// Yet not implemented
|
||||
}
|
||||
|
||||
// Invoked when audio class specific set request received for an interface
|
||||
bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff)
|
||||
{
|
||||
bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
|
||||
(void) rhport;
|
||||
(void) pBuff;
|
||||
|
||||
@@ -283,14 +274,15 @@ bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_r
|
||||
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
|
||||
uint8_t itf = TU_U16_LOW(p_request->wIndex);
|
||||
|
||||
(void) channelNum; (void) ctrlSel; (void) itf;
|
||||
(void) channelNum;
|
||||
(void) ctrlSel;
|
||||
(void) itf;
|
||||
|
||||
return false; // Yet not implemented
|
||||
return false;// Yet not implemented
|
||||
}
|
||||
|
||||
// Invoked when audio class specific set request received for an entity
|
||||
bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff)
|
||||
{
|
||||
bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
|
||||
(void) rhport;
|
||||
|
||||
// Page 91 in UAC2 specification
|
||||
@@ -305,40 +297,36 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
|
||||
TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
|
||||
|
||||
// If request is for our feature unit
|
||||
if ( entityID == 2 )
|
||||
{
|
||||
switch ( ctrlSel )
|
||||
{
|
||||
if (entityID == 2) {
|
||||
switch (ctrlSel) {
|
||||
case AUDIO_FU_CTRL_MUTE:
|
||||
// Request uses format layout 1
|
||||
TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_1_t));
|
||||
|
||||
mute[channelNum] = ((audio_control_cur_1_t*) pBuff)->bCur;
|
||||
mute[channelNum] = ((audio_control_cur_1_t *) pBuff)->bCur;
|
||||
|
||||
TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
|
||||
return true;
|
||||
TU_LOG1(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
|
||||
return true;
|
||||
|
||||
case AUDIO_FU_CTRL_VOLUME:
|
||||
// Request uses format layout 2
|
||||
TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
|
||||
|
||||
volume[channelNum] = ((audio_control_cur_2_t*) pBuff)->bCur;
|
||||
|
||||
TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
|
||||
return true;
|
||||
volume[channelNum] = ((audio_control_cur_2_t *) pBuff)->bCur;
|
||||
TU_LOG1(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
|
||||
return true;
|
||||
|
||||
// Unknown/Unsupported control
|
||||
default:
|
||||
TU_BREAKPOINT();
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false; // Yet not implemented
|
||||
return false;// Yet not implemented
|
||||
}
|
||||
|
||||
// Invoked when audio class specific get request received for an EP
|
||||
bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
|
||||
(void) rhport;
|
||||
|
||||
// Page 91 in UAC2 specification
|
||||
@@ -346,14 +334,15 @@ bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_re
|
||||
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
|
||||
uint8_t ep = TU_U16_LOW(p_request->wIndex);
|
||||
|
||||
(void) channelNum; (void) ctrlSel; (void) ep;
|
||||
(void) channelNum;
|
||||
(void) ctrlSel;
|
||||
(void) ep;
|
||||
|
||||
return false; // Yet not implemented
|
||||
return false;// Yet not implemented
|
||||
}
|
||||
|
||||
// Invoked when audio class specific get request received for an interface
|
||||
bool tud_audio_get_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
bool tud_audio_get_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
|
||||
(void) rhport;
|
||||
|
||||
// Page 91 in UAC2 specification
|
||||
@@ -361,14 +350,15 @@ bool tud_audio_get_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_r
|
||||
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
|
||||
uint8_t itf = TU_U16_LOW(p_request->wIndex);
|
||||
|
||||
(void) channelNum; (void) ctrlSel; (void) itf;
|
||||
(void) channelNum;
|
||||
(void) ctrlSel;
|
||||
(void) itf;
|
||||
|
||||
return false; // Yet not implemented
|
||||
return false;// Yet not implemented
|
||||
}
|
||||
|
||||
// Invoked when audio class specific get request received for an entity
|
||||
bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
|
||||
(void) rhport;
|
||||
|
||||
// Page 91 in UAC2 specification
|
||||
@@ -378,12 +368,9 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
|
||||
uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
|
||||
|
||||
// Input terminal (Microphone input)
|
||||
if (entityID == 1)
|
||||
{
|
||||
switch ( ctrlSel )
|
||||
{
|
||||
case AUDIO_TE_CTRL_CONNECTOR:
|
||||
{
|
||||
if (entityID == 1) {
|
||||
switch (ctrlSel) {
|
||||
case AUDIO_TE_CTRL_CONNECTOR: {
|
||||
// The terminal connector control only has a get request with only the CUR attribute.
|
||||
audio_desc_channel_cluster_t ret;
|
||||
|
||||
@@ -392,11 +379,10 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
|
||||
ret.bmChannelConfig = 0;
|
||||
ret.iChannelNames = 0;
|
||||
|
||||
TU_LOG2(" Get terminal connector\r\n");
|
||||
TU_LOG1(" Get terminal connector\r\n");
|
||||
|
||||
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, (void*) &ret, sizeof(ret));
|
||||
}
|
||||
break;
|
||||
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, (void *) &ret, sizeof(ret));
|
||||
} break;
|
||||
|
||||
// Unknown/Unsupported control selector
|
||||
default:
|
||||
@@ -406,43 +392,39 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
|
||||
}
|
||||
|
||||
// Feature unit
|
||||
if (entityID == 2)
|
||||
{
|
||||
switch ( ctrlSel )
|
||||
{
|
||||
if (entityID == 2) {
|
||||
switch (ctrlSel) {
|
||||
case AUDIO_FU_CTRL_MUTE:
|
||||
// Audio control mute cur parameter block consists of only one byte - we thus can send it right away
|
||||
// There does not exist a range parameter block for mute
|
||||
TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
|
||||
TU_LOG1(" Get Mute of channel: %u\r\n", channelNum);
|
||||
return tud_control_xfer(rhport, p_request, &mute[channelNum], 1);
|
||||
|
||||
case AUDIO_FU_CTRL_VOLUME:
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
switch (p_request->bRequest) {
|
||||
case AUDIO_CS_REQ_CUR:
|
||||
TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
|
||||
TU_LOG1(" Get Volume of channel: %u\r\n", channelNum);
|
||||
return tud_control_xfer(rhport, p_request, &volume[channelNum], sizeof(volume[channelNum]));
|
||||
|
||||
case AUDIO_CS_REQ_RANGE:
|
||||
TU_LOG2(" Get Volume range of channel: %u\r\n", channelNum);
|
||||
TU_LOG1(" Get Volume range of channel: %u\r\n", channelNum);
|
||||
|
||||
// Copy values - only for testing - better is version below
|
||||
audio_control_range_2_n_t(1)
|
||||
ret;
|
||||
audio_control_range_2_n_t(1) ret;
|
||||
|
||||
ret.wNumSubRanges = 1;
|
||||
ret.subrange[0].bMin = -90; // -90 dB
|
||||
ret.subrange[0].bMax = 90; // +90 dB
|
||||
ret.subrange[0].bRes = 1; // 1 dB steps
|
||||
ret.subrange[0].bMin = -90;// -90 dB
|
||||
ret.subrange[0].bMax = 90; // +90 dB
|
||||
ret.subrange[0].bRes = 1; // 1 dB steps
|
||||
|
||||
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, (void*) &ret, sizeof(ret));
|
||||
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, (void *) &ret, sizeof(ret));
|
||||
|
||||
// Unknown/Unsupported control
|
||||
default:
|
||||
TU_BREAKPOINT();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
// Unknown/Unsupported control
|
||||
default:
|
||||
@@ -452,33 +434,30 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
|
||||
}
|
||||
|
||||
// Clock Source unit
|
||||
if ( entityID == 4 )
|
||||
{
|
||||
switch ( ctrlSel )
|
||||
{
|
||||
if (entityID == 4) {
|
||||
switch (ctrlSel) {
|
||||
case AUDIO_CS_CTRL_SAM_FREQ:
|
||||
// channelNum is always zero in this case
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
switch (p_request->bRequest) {
|
||||
case AUDIO_CS_REQ_CUR:
|
||||
TU_LOG2(" Get Sample Freq.\r\n");
|
||||
TU_LOG1(" Get Sample Freq.\r\n");
|
||||
// Buffered control transfer is needed for IN flow control to work
|
||||
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
|
||||
|
||||
case AUDIO_CS_REQ_RANGE:
|
||||
TU_LOG2(" Get Sample Freq. range\r\n");
|
||||
TU_LOG1(" Get Sample Freq. range\r\n");
|
||||
return tud_control_xfer(rhport, p_request, &sampleFreqRng, sizeof(sampleFreqRng));
|
||||
|
||||
// Unknown/Unsupported control
|
||||
// Unknown/Unsupported control
|
||||
default:
|
||||
TU_BREAKPOINT();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case AUDIO_CS_CTRL_CLK_VALID:
|
||||
// Only cur attribute exists for this request
|
||||
TU_LOG2(" Get Sample Freq. valid\r\n");
|
||||
TU_LOG1(" Get Sample Freq. valid\r\n");
|
||||
return tud_control_xfer(rhport, p_request, &clkValid, sizeof(clkValid));
|
||||
|
||||
// Unknown/Unsupported control
|
||||
@@ -488,52 +467,14 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
|
||||
}
|
||||
}
|
||||
|
||||
TU_LOG2(" Unsupported entity: %d\r\n", entityID);
|
||||
return false; // Yet not implemented
|
||||
}
|
||||
|
||||
bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, uint8_t cur_alt_setting)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) itf;
|
||||
(void) ep_in;
|
||||
(void) cur_alt_setting;
|
||||
|
||||
|
||||
// In read world application data flow is driven by I2S clock,
|
||||
// both tud_audio_tx_done_pre_load_cb() & tud_audio_tx_done_post_load_cb() are hardly used.
|
||||
// For example in your I2S receive callback:
|
||||
// void I2S_Rx_Callback(int channel, const void* data, uint16_t samples)
|
||||
// {
|
||||
// tud_audio_write_support_ff(channel, data, samples * N_BYTES_PER_SAMPLE * N_CHANNEL_PER_FIFO);
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uint8_t itf, uint8_t ep_in, uint8_t cur_alt_setting)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) n_bytes_copied;
|
||||
(void) itf;
|
||||
(void) ep_in;
|
||||
(void) cur_alt_setting;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_audio_set_itf_close_EP_cb(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) p_request;
|
||||
|
||||
return true;
|
||||
TU_LOG1(" Unsupported entity: %d\r\n", entityID);
|
||||
return false;// Yet not implemented
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------+
|
||||
// BLINKING TASK
|
||||
//--------------------------------------------------------------------+
|
||||
void led_blinking_task(void* param) {
|
||||
void led_blinking_task(void *param) {
|
||||
(void) param;
|
||||
static uint32_t start_ms = 0;
|
||||
static bool led_state = false;
|
||||
@@ -544,6 +485,6 @@ void led_blinking_task(void* param) {
|
||||
start_ms += blink_interval_ms;
|
||||
|
||||
board_led_write(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
led_state = 1 - led_state;// toggle
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user