Skip to content

Commit e3f95b2

Browse files
committed
WIP upgrade to USBD firmware lib 3.1.0
1 parent 30646c3 commit e3f95b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1174
-738
lines changed

system/GD32F30x_firmware/GD32F30x_usbd_library/class/device/audio/Include/audio_core.h

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
\brief the header file of USB audio device class core functions
44
55
\version 2020-08-01, V3.0.0, firmware for GD32F30x
6+
\version 2022-06-10, V3.1.0, firmware for GD32F30x
67
*/
78

89
/*
9-
Copyright (c) 2020, GigaDevice Semiconductor Inc.
10+
Copyright (c) 2022, GigaDevice Semiconductor Inc.
1011
1112
Redistribution and use in source and binary forms, with or without modification,
1213
are permitted provided that the following conditions are met:
@@ -39,84 +40,90 @@ OF SUCH DAMAGE.
3940

4041
#define FORMAT_24BIT(x) (uint8_t)(x);(uint8_t)((x) >> 8);(uint8_t)((x) >> 16)
4142

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
5044
that it is an even number and higher than 3 */
51-
#define OUT_PACKET_NUM 4U
45+
#define OUT_PACKET_NUM 120U
5246

5347
/* 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))
5650

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
5953

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
6357

6458
/* audio interface class code */
65-
#define USB_CLASS_AUDIO 0x01U
59+
#define USB_CLASS_AUDIO 0x01U
6660

6761
/* 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
7165

7266
/* 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
7670

7771
/* 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
8478

8579
/* 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+
};
119124

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)))
120127

121128
#pragma pack(1)
122129

@@ -246,6 +253,12 @@ typedef struct
246253
uint8_t* isoc_out_wrptr;
247254
uint8_t* isoc_out_rdptr;
248255

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+
249262
/* main buffer for audio control requests transfers and its relative variables */
250263
uint8_t audioctl[64];
251264
uint8_t audioctl_unit;

system/GD32F30x_firmware/GD32F30x_usbd_library/class/device/audio/Include/audio_out_itf.h

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
\brief audio OUT (playback) interface header file
44
55
\version 2020-08-01, V3.0.0, firmware for GD32F30x
6+
\version 2022-06-10, V3.1.0, firmware for GD32F30x
67
*/
78

89
/*
9-
Copyright (c) 2020, GigaDevice Semiconductor Inc.
10+
Copyright (c) 2022, GigaDevice Semiconductor Inc.
1011
1112
Redistribution and use in source and binary forms, with or without modification,
1213
are permitted provided that the following conditions are met:
@@ -37,38 +38,10 @@ OF SUCH DAMAGE.
3738

3839
#include "usbd_conf.h"
3940

40-
/* audio commands enumeration */
41-
typedef enum
42-
{
43-
AUDIO_CMD_PLAY = 1U,
44-
AUDIO_CMD_PAUSE,
45-
AUDIO_CMD_STOP,
46-
}audio_cmd_enum;
47-
48-
/* mute commands */
49-
#define AUDIO_MUTE 0x01U
50-
#define AUDIO_UNMUTE 0x00U
51-
52-
/* functions return value */
53-
#define AUDIO_OK 0x00U
54-
#define AUDIO_FAIL 0xFFU
55-
56-
/* audio machine states */
57-
#define AUDIO_STATE_INACTIVE 0x00U
58-
#define AUDIO_STATE_ACTIVE 0x01U
59-
#define AUDIO_STATE_PLAYING 0x02U
60-
#define AUDIO_STATE_PAUSED 0x03U
61-
#define AUDIO_STATE_STOPPED 0x04U
62-
#define AUDIO_STATE_ERROR 0x05U
63-
6441
typedef struct {
65-
uint8_t (*audio_init) (uint32_t audio_freq, uint32_t volume, uint32_t options);
42+
uint8_t (*audio_init) (uint32_t audio_freq, uint32_t volume);
6643
uint8_t (*audio_deinit) (uint32_t options);
6744
uint8_t (*audio_cmd) (uint8_t* pbuf, uint32_t size, uint8_t cmd);
68-
uint8_t (*audio_volume_ctl) (uint8_t vol);
69-
uint8_t (*audio_mute_ctl) (uint8_t cmd);
70-
uint8_t (*audio_periodic_tc) (uint8_t cmd);
71-
uint8_t (*audio_state_get) (void);
7245
} audio_fops_struct;
7346

7447
extern audio_fops_struct audio_out_fops;

0 commit comments

Comments
 (0)