瀏覽代碼

Extend example s.t. a saw tooth is sent.

Reinhard Panhuber 5 年之前
父節點
當前提交
63f18cef19

+ 44 - 0
examples/device/audio_test/src/main.c

@@ -58,6 +58,10 @@ uint8_t clkValid;
 audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_N_CHANNELS_TX+1]; 			// Volume range state
 audio_control_range_4_n_t(1) sampleFreqRng; 						// Sample frequency range state
 
+// Audio test data
+uint8_t test_buffer_audio[CFG_TUD_AUDIO_TX_FIFO_SIZE];
+uint16_t startVal = 0;
+
 void led_blinking_task(void);
 void audio_task(void);
 
@@ -364,6 +368,46 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
   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;
+
+  tud_audio_write (test_buffer_audio, CFG_TUD_AUDIO_TX_FIFO_SIZE);
+
+  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) rhport;
+  (void) itf;
+  (void) ep_in;
+  (void) cur_alt_setting;
+
+  uint8_t * pBuffer = test_buffer_audio;
+
+  for (size_t cnt = 0; cnt < CFG_TUD_AUDIO_TX_FIFO_SIZE/2; cnt++)
+  {
+    *(uint16_t *)pBuffer = startVal++;
+    pBuffer += 2;
+  }
+
+  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;
+  startVal = 0;
+
+  return true;
+}
+
 //--------------------------------------------------------------------+
 // BLINKING TASK
 //--------------------------------------------------------------------+

+ 6 - 4
examples/device/audio_test/src/tusb_config.h

@@ -93,18 +93,20 @@ extern "C" {
 // Audio format type I specifications
 #define CFG_TUD_AUDIO_FORMAT_TYPE_I_TX 				AUDIO_DATA_FORMAT_TYPE_I_PCM
 #define CFG_TUD_AUDIO_N_CHANNELS_TX 				1
-#define CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX			3
+#define CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX			2
 
 // EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
-#define CFG_TUD_AUDIO_EPSIZE_IN    				45*CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX*CFG_TUD_AUDIO_N_CHANNELS_TX 	// 45 Samples (44.1 kHz) x 3 Bytes/Sample x 1 Channels
-#define CFG_TUD_AUDIO_TX_FIFO_SIZE 				45*4 									// 45 Samples (44.1 kHz) x 4 Bytes/Sample (1 word)
+#define CFG_TUD_AUDIO_EPSIZE_IN                                       48*CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX*CFG_TUD_AUDIO_N_CHANNELS_TX    // 48 Samples (48 kHz) x 2 Bytes/Sample x 1 Channels
+#define CFG_TUD_AUDIO_TX_FIFO_SIZE                                    48*2                                                                  // 48 Samples (48 kHz) x 2 Bytes/Sample (1/2 word)
 
 // Number of Standard AS Interface Descriptors (4.9.1) defined per audio function - this is required to be able to remember the current alternate settings of these interfaces - We restrict us here to have a constant number for all audio functions (which means this has to be the maximum number of AS interfaces an audio function has and a second audio function with less AS interfaces just wastes a few bytes)
-#define CFG_TUD_AUDIO_N_AS_INT 			   		1
+#define CFG_TUD_AUDIO_N_AS_INT 			          1
 
 // Size of control request buffer
 #define CFG_TUD_AUDIO_CTRL_BUF_SIZE 				64
 
+#define CFG_TUSB_DEBUG                                                0
+
 #ifdef __cplusplus
 }
 #endif

+ 1 - 1
examples/device/audio_test/src/usb_descriptors.c

@@ -102,7 +102,7 @@ uint8_t const desc_configuration[] =
     TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
 
     // Interface number, string index, EP Out & EP In address, EP size
-    TUD_AUDIO_MIC_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ 3, /*_nBitsUsedPerSample*/ 24, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ 45*3)
+    TUD_AUDIO_MIC_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ 3, /*_nBitsUsedPerSample*/ 24, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ 48*4)
 };
 
 // Invoked when received GET CONFIGURATION DESCRIPTOR