Skip to content

Commit 65fd6b5

Browse files
committed
update(demo): add usbd_audio_set_sampling_freq and usbd_audio_get_sampling_freq for feedback
Signed-off-by: sakumisu <[email protected]>
1 parent ca71e74 commit 65fd6b5

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

demo/audio_v1_mic_speaker_multichan_template.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t s_speaker_feedback_buffer[4];
258258
volatile bool tx_flag = 0;
259259
volatile bool rx_flag = 0;
260260
volatile bool ep_tx_busy_flag = false;
261+
volatile uint32_t s_speaker_sample_rate;
261262

262263
static void usbd_event_handler(uint8_t busid, uint8_t event)
263264
{
@@ -315,6 +316,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
315316
}
316317
}
317318

319+
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
320+
{
321+
if (ep == AUDIO_OUT_EP) {
322+
s_speaker_sample_rate = sampling_freq;
323+
}
324+
}
325+
326+
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
327+
{
328+
(void)busid;
329+
330+
uint32_t freq = 0;
331+
332+
if (ep == AUDIO_OUT_EP) {
333+
freq = s_speaker_sample_rate;
334+
}
335+
336+
return freq;
337+
}
338+
318339
void usbd_audio_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
319340
{
320341
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
@@ -331,7 +352,7 @@ void usbd_audio_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
331352
void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
332353
{
333354
USB_LOG_RAW("actual feedback len:%d\r\n", (unsigned int)nbytes);
334-
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_SPEAKER_FREQ);
355+
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
335356
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
336357
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
337358
}

demo/audio_v2_mic_speaker_multichan_template.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET];
342342
volatile bool tx_flag = 0;
343343
volatile bool rx_flag = 0;
344344
volatile bool ep_tx_busy_flag = false;
345+
volatile uint32_t s_speaker_sample_rate;
345346

346347
static void usbd_event_handler(uint8_t busid, uint8_t event)
347348
{
@@ -402,6 +403,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
402403
}
403404
}
404405

406+
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
407+
{
408+
if (ep == AUDIO_OUT_EP) {
409+
s_speaker_sample_rate = sampling_freq;
410+
}
411+
}
412+
413+
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
414+
{
415+
(void)busid;
416+
417+
uint32_t freq = 0;
418+
419+
if (ep == AUDIO_OUT_EP) {
420+
freq = s_speaker_sample_rate;
421+
}
422+
423+
return freq;
424+
}
425+
405426
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
406427
{
407428
if (ep == AUDIO_OUT_EP) {
@@ -429,10 +450,10 @@ void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nb
429450
{
430451
USB_LOG_RAW("actual feedback len:%d\r\n", nbytes);
431452
#ifdef CONFIG_USB_HS
432-
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(AUDIO_FREQ);
453+
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate);
433454
AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value);
434455
#else
435-
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_FREQ);
456+
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
436457
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
437458
#endif
438459
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);

demo/audio_v2_speaker_multichan_template.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[AUDIO_OUT_PACKET];
274274
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t s_speaker_feedback_buffer[4];
275275

276276
volatile bool rx_flag = 0;
277+
volatile uint32_t s_speaker_sample_rate;
277278

278279
static void usbd_event_handler(uint8_t busid, uint8_t event)
279280
{
@@ -307,10 +308,10 @@ void usbd_audio_open(uint8_t busid, uint8_t intf)
307308
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
308309
#if USING_FEEDBACK == 1
309310
#ifdef CONFIG_USB_HS
310-
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(AUDIO_FREQ);
311+
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate);
311312
AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value);
312313
#else
313-
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_FREQ);
314+
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
314315
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
315316
#endif
316317
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
@@ -324,6 +325,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
324325
rx_flag = 0;
325326
}
326327

328+
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
329+
{
330+
if (ep == AUDIO_OUT_EP) {
331+
s_speaker_sample_rate = sampling_freq;
332+
}
333+
}
334+
335+
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
336+
{
337+
(void)busid;
338+
339+
uint32_t freq = 0;
340+
341+
if (ep == AUDIO_OUT_EP) {
342+
freq = s_speaker_sample_rate;
343+
}
344+
345+
return freq;
346+
}
347+
327348
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
328349
{
329350
if (ep == AUDIO_OUT_EP) {
@@ -342,10 +363,10 @@ void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nb
342363
{
343364
USB_LOG_RAW("actual feedback len:%d\r\n", (unsigned int)nbytes);
344365
#ifdef CONFIG_USB_HS
345-
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(AUDIO_FREQ);
366+
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate);
346367
AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value);
347368
#else
348-
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_FREQ);
369+
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
349370
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
350371
#endif
351372
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);

0 commit comments

Comments
 (0)