|
3 | 3 | \brief the header file of USB audio device class core functions
|
4 | 4 |
|
5 | 5 | \version 2020-08-01, V3.0.0, firmware for GD32F30x
|
| 6 | + \version 2022-06-10, V3.1.0, firmware for GD32F30x |
6 | 7 | */
|
7 | 8 |
|
8 | 9 | /*
|
9 |
| - Copyright (c) 2020, GigaDevice Semiconductor Inc. |
| 10 | + Copyright (c) 2022, GigaDevice Semiconductor Inc. |
10 | 11 |
|
11 | 12 | Redistribution and use in source and binary forms, with or without modification,
|
12 | 13 | are permitted provided that the following conditions are met:
|
@@ -39,84 +40,90 @@ OF SUCH DAMAGE.
|
39 | 40 |
|
40 | 41 | #define FORMAT_24BIT(x) (uint8_t)(x);(uint8_t)((x) >> 8);(uint8_t)((x) >> 16)
|
41 | 42 |
|
42 |
| -/* audio_freq * data_size (2 bytes) * num_channels (stereo: 2) */ |
43 |
| -#define DEFAULT_OUT_BIT_RESOLUTION 16U |
44 |
| -#define DEFAULT_OUT_CHANNEL_NBR 2U /* mono = 1, stereo = 2 */ |
45 |
| -#define AUDIO_OUT_PACKET (uint32_t)(((USBD_AUDIO_FREQ_16K * \ |
46 |
| - (DEFAULT_OUT_BIT_RESOLUTION / 8U) *\ |
47 |
| - DEFAULT_OUT_CHANNEL_NBR) / 1000U)) |
48 |
| - |
49 |
| -/* number of sub-packets in the audio transfer buffer. you can modify this value but always make sure |
| 43 | +/* number of sub-packets in the audio transfer buffer. user can modify this value but always make sure |
50 | 44 | that it is an even number and higher than 3 */
|
51 |
| -#define OUT_PACKET_NUM 4U |
| 45 | +#define OUT_PACKET_NUM 120U |
52 | 46 |
|
53 | 47 | /* total size of the audio transfer buffer */
|
54 |
| -#define OUT_BUF_MARGIN 4U |
55 |
| -#define TOTAL_OUT_BUF_SIZE ((uint32_t)((AUDIO_OUT_PACKET + OUT_BUF_MARGIN) * OUT_PACKET_NUM)) |
| 48 | +#define OUT_BUF_MARGIN 0U |
| 49 | +#define TOTAL_OUT_BUF_SIZE ((uint32_t)((SPEAKER_OUT_PACKET + OUT_BUF_MARGIN) * OUT_PACKET_NUM)) |
56 | 50 |
|
57 |
| -#define AUDIO_CONFIG_DESC_SET_LEN 109U |
58 |
| -#define AUDIO_INTERFACE_DESC_SIZE 9U |
| 51 | +#define AD_CONFIG_DESC_SET_LEN (sizeof(usb_desc_config_set)) |
| 52 | +#define AD_INTERFACE_DESC_SIZE 9U |
59 | 53 |
|
60 |
| -#define USB_AUDIO_DESC_SIZ 0x09U |
61 |
| -#define AUDIO_STANDARD_EP_DESC_SIZE 0x09U |
62 |
| -#define AUDIO_STREAMING_EP_DESC_SIZE 0x07U |
| 54 | +#define USB_AD_DESC_SIZ 0x09U |
| 55 | +#define AD_STANDARD_EP_DESC_SIZE 0x09U |
| 56 | +#define AD_STREAMING_EP_DESC_SIZE 0x07U |
63 | 57 |
|
64 | 58 | /* audio interface class code */
|
65 |
| -#define USB_CLASS_AUDIO 0x01U |
| 59 | +#define USB_CLASS_AUDIO 0x01U |
66 | 60 |
|
67 | 61 | /* audio interface subclass codes */
|
68 |
| -#define AUDIO_SUBCLASS_CONTROL 0x01U |
69 |
| -#define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02U |
70 |
| -#define AUDIO_SUBCLASS_MIDISTREAMING 0x03U |
| 62 | +#define AD_SUBCLASS_CONTROL 0x01U |
| 63 | +#define AD_SUBCLASS_AUDIOSTREAMING 0x02U |
| 64 | +#define AD_SUBCLASS_MIDISTREAMING 0x03U |
71 | 65 |
|
72 | 66 | /* audio interface protocol codes */
|
73 |
| -#define AUDIO_PROTOCOL_UNDEFINED 0x00U |
74 |
| -#define AUDIO_STREAMING_GENERAL 0x01U |
75 |
| -#define AUDIO_STREAMING_FORMAT_TYPE 0x02U |
| 67 | +#define AD_PROTOCOL_UNDEFINED 0x00U |
| 68 | +#define AD_STREAMING_GENERAL 0x01U |
| 69 | +#define AD_STREAMING_FORMAT_TYPE 0x02U |
76 | 70 |
|
77 | 71 | /* audio class-specific descriptor types */
|
78 |
| -#define AUDIO_DESCTYPE_UNDEFINED 0x20U |
79 |
| -#define AUDIO_DESCTYPE_DEVICE 0x21U |
80 |
| -#define AUDIO_DESCTYPE_CONFIGURATION 0x22U |
81 |
| -#define AUDIO_DESCTYPE_STRING 0x23U |
82 |
| -#define AUDIO_DESCTYPE_INTERFACE 0x24U |
83 |
| -#define AUDIO_DESCTYPE_ENDPOINT 0x25U |
| 72 | +#define AD_DESCTYPE_UNDEFINED 0x20U |
| 73 | +#define AD_DESCTYPE_DEVICE 0x21U |
| 74 | +#define AD_DESCTYPE_CONFIGURATION 0x22U |
| 75 | +#define AD_DESCTYPE_STRING 0x23U |
| 76 | +#define AD_DESCTYPE_INTERFACE 0x24U |
| 77 | +#define AD_DESCTYPE_ENDPOINT 0x25U |
84 | 78 |
|
85 | 79 | /* audio control interface descriptor subtypes */
|
86 |
| -#define AUDIO_CONTROL_HEADER 0x01U |
87 |
| -#define AUDIO_CONTROL_INPUT_TERMINAL 0x02U |
88 |
| -#define AUDIO_CONTROL_OUTPUT_TERMINAL 0x03U |
89 |
| -#define AUDIO_CONTROL_MIXER_UNIT 0x04U |
90 |
| -#define AUDIO_CONTROL_SELECTOR_UNIT 0x05U |
91 |
| -#define AUDIO_CONTROL_FEATURE_UNIT 0x06U |
92 |
| -#define AUDIO_CONTROL_PROCESSING_UNIT 0x07U |
93 |
| -#define AUDIO_CONTROL_EXTENSION_UNIT 0x08U |
94 |
| - |
95 |
| -#define AUDIO_INPUT_TERMINAL_DESC_SIZE 0x0CU |
96 |
| -#define AUDIO_OUTPUT_TERMINAL_DESC_SIZE 0x09U |
97 |
| -#define AUDIO_STREAMING_INTERFACE_DESC_SIZE 0x07U |
98 |
| - |
99 |
| -#define AUDIO_CONTROL_MUTE 0x0001U |
100 |
| - |
101 |
| -#define AUDIO_FORMAT_TYPE_I 0x01U |
102 |
| -#define AUDIO_FORMAT_TYPE_III 0x03U |
103 |
| - |
104 |
| -#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01U |
105 |
| -#define AUDIO_ENDPOINT_GENERAL 0x01U |
106 |
| - |
107 |
| -#define AUDIO_REQ_GET_CUR 0x81U |
108 |
| -#define AUDIO_REQ_SET_CUR 0x01U |
109 |
| - |
110 |
| -#define AUDIO_OUT_STREAMING_CTRL 0x02U |
111 |
| - |
112 |
| -#define PACKET_SIZE(freq) (((freq) * 2U) * 2U / 1000U) |
113 |
| - |
114 |
| -#define AUDIO_PACKET_SIZE(frq) (uint8_t)(PACKET_SIZE(frq) & 0xFFU), \ |
115 |
| - (uint8_t)((PACKET_SIZE(frq) >> 8U) & 0xFFU) |
116 |
| - |
117 |
| -#define SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq) >> 8U), \ |
118 |
| - (uint8_t)((frq) >> 16U) |
| 80 | +#define AD_CONTROL_HEADER 0x01U |
| 81 | +#define AD_CONTROL_INPUT_TERMINAL 0x02U |
| 82 | +#define AD_CONTROL_OUTPUT_TERMINAL 0x03U |
| 83 | +#define AD_CONTROL_MIXER_UNIT 0x04U |
| 84 | +#define AD_CONTROL_SELECTOR_UNIT 0x05U |
| 85 | +#define AD_CONTROL_FEATURE_UNIT 0x06U |
| 86 | +#define AD_CONTROL_PROCESSING_UNIT 0x07U |
| 87 | +#define AD_CONTROL_EXTENSION_UNIT 0x08U |
| 88 | + |
| 89 | +#define AD_INPUT_TERMINAL_DESC_SIZE 0x0CU |
| 90 | +#define AD_OUTPUT_TERMINAL_DESC_SIZE 0x09U |
| 91 | +#define AD_STREAMING_INTERFACE_DESC_SIZE 0x07U |
| 92 | + |
| 93 | +#define AD_CONTROL_MUTE 0x01U |
| 94 | +#define AD_CONTROL_VOLUME 0x02U |
| 95 | + |
| 96 | +#define AD_FORMAT_TYPE_I 0x01U |
| 97 | +#define AD_FORMAT_TYPE_III 0x03U |
| 98 | + |
| 99 | +#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01U |
| 100 | +#define AD_ENDPOINT_GENERAL 0x01U |
| 101 | + |
| 102 | +#define AD_REQ_UNDEFINED 0x00U |
| 103 | +#define AD_REQ_SET_CUR 0x01U |
| 104 | +#define AD_REQ_GET_CUR 0x81U |
| 105 | +#define AD_REQ_SET_MIN 0x02U |
| 106 | +#define AD_REQ_GET_MIN 0x82U |
| 107 | +#define AD_REQ_SET_MAX 0x03U |
| 108 | +#define AD_REQ_GET_MAX 0x83U |
| 109 | +#define AD_REQ_SET_RES 0x04U |
| 110 | +#define AD_REQ_GET_RES 0x84U |
| 111 | +#define AD_REQ_SET_MEM 0x05U |
| 112 | +#define AD_REQ_GET_MEM 0x85U |
| 113 | +#define AD_REQ_GET_STAT 0xFFU |
| 114 | + |
| 115 | +#define AD_OUT_STREAMING_CTRL 0x02U |
| 116 | +#define AD_IN_STREAMING_CTRL 0x05U |
| 117 | + |
| 118 | +/* audio stream interface number */ |
| 119 | +enum |
| 120 | +{ |
| 121 | + SPEAK_INTERFACE_COUNT, |
| 122 | + CONFIG_DESC_AS_ITF_COUNT, |
| 123 | +}; |
119 | 124 |
|
| 125 | +#define AC_ITF_TOTAL_LEN (sizeof(usb_desc_AC_itf) + CONFIG_DESC_AS_ITF_COUNT*(sizeof(usb_desc_input_terminal) + \ |
| 126 | + sizeof(usb_desc_mono_feature_unit) + sizeof(usb_desc_output_terminal))) |
120 | 127 |
|
121 | 128 | #pragma pack(1)
|
122 | 129 |
|
@@ -246,6 +253,12 @@ typedef struct
|
246 | 253 | uint8_t* isoc_out_wrptr;
|
247 | 254 | uint8_t* isoc_out_rdptr;
|
248 | 255 |
|
| 256 | + uint16_t buf_free_size; |
| 257 | + uint16_t dam_tx_len; |
| 258 | + |
| 259 | + /* usb receive buffer */ |
| 260 | + uint8_t usb_rx_buffer[SPEAKER_OUT_MAX_PACKET]; |
| 261 | + |
249 | 262 | /* main buffer for audio control requests transfers and its relative variables */
|
250 | 263 | uint8_t audioctl[64];
|
251 | 264 | uint8_t audioctl_unit;
|
|
0 commit comments