7
7
* Date Author Notes
8
8
* 2017-05-09 Urey first version
9
9
* 2019-07-09 Zero-Free improve device ops interface and data flows
10
- *
10
+ * 2025-03-04 wumingzi add doxygen comments.
11
11
*/
12
12
13
13
#ifndef __DEV_AUDIO_H__
21
21
* @ingroup group_Drivers RT-Thread Drivers
22
22
*
23
23
* @brief Audio driver API.
24
- */
25
-
26
- /**
27
- * @addtogroup group_Audio
24
+ *
28
25
* @{
29
26
*/
30
27
31
28
/**
32
29
* @defgroup audio_control AUDIO_CTL
33
30
*
34
31
* @brief Control audio device.
35
- */
36
-
37
- /**
38
- * @addtogroup audio_control
32
+ *
39
33
* @{
40
34
*/
41
35
54
48
#define AUDIO_CTL_STOP _AUDIO_CTL(4) /**< Stop audio device */
55
49
#define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(5) /**< Get audio device buffer information */
56
50
57
- /** @} */ /* End of audio_control*/
51
+ /** @} */ /* End of audio_control */
58
52
59
53
/**
60
54
* @defgroup audio_type AUDIO_TYPE
61
55
*
62
56
* @brief Audio Device Types
63
- */
64
-
65
- /**
66
- * @addtogroup audio_type
57
+ *
67
58
* @{
68
59
*/
69
60
#define AUDIO_TYPE_QUERY 0x00 /**< Query audio device type */
70
61
#define AUDIO_TYPE_INPUT 0x01 /**< Set audio device type to input type */
71
62
#define AUDIO_TYPE_OUTPUT 0x02 /**< Set audio device type to output type */
72
63
#define AUDIO_TYPE_MIXER 0x04 /**< Set audio device type to mixer type */
73
- /** @} */ /* End of audio_type*/
64
+ /** @} */ /* End of audio_type */
74
65
75
66
/**
76
67
* @defgroup audio_samp_rates AUDIO_SAMP_RATES
77
68
*
78
69
* @brief Supported audio sample rates for the audio device.
79
- */
80
-
81
- /**
82
- * @addtogroup audio_samp_rates
70
+ *
83
71
* @{
84
72
*/
85
73
#define AUDIO_SAMP_RATE_8K 0x0001 /**< Set audio device sample rate to 8K */
94
82
#define AUDIO_SAMP_RATE_160K 0x0200 /**< Set audio device sample rate to 160K */
95
83
#define AUDIO_SAMP_RATE_172K 0x0400 /**< Set audio device sample rate to 172K */
96
84
#define AUDIO_SAMP_RATE_192K 0x0800 /**< Set audio device sample rate to 192K */
97
- /** @} */ /* End of audio_samp_rates*/
85
+ /** @} */ /* End of audio_samp_rates */
98
86
99
87
/**
100
88
* @defgroup audio_bit_rates AUDIO_BIT_RATES
101
89
*
102
90
* @brief Supported bit rates for the audio device.
103
- */
104
-
105
- /**
106
- * @addtogroup audio_bit_rates
91
+ *
107
92
* @{
108
93
*/
109
94
#define AUDIO_BIT_RATE_22K 0x01 /**< Set audio device bit rates to 22K */
114
99
#define AUDIO_BIT_RATE_160K 0x20 /**< Set audio device bit rates to 160K */
115
100
#define AUDIO_BIT_RATE_172K 0x40 /**< Set audio device bit rates to 172K */
116
101
#define AUDIO_BIT_RATE_192K 0x80 /**< Set audio device bit rates to 192K */
117
- /** @} */ /* End of audio_bit_rates*/
102
+ /** @} */ /* End of audio_bit_rates */
118
103
119
104
120
105
/**
121
106
* @defgroup audio_dsp AUDIO_DSP
122
107
*
123
- * @brief Support Dsp(input/output) Units controls
124
- */
125
-
126
- /**
127
- * @addtogroup audio_dsp
108
+ * @brief Support Dsp(input/output) Units controls. The macro group from application level, can
109
+ * set audio mixer parameters including samplerate, channels etc.
110
+ *
128
111
* @{
129
112
*/
130
113
#define AUDIO_DSP_PARAM 0 /**< get/set all params */
131
114
#define AUDIO_DSP_SAMPLERATE 1 /**< samplerate */
132
115
#define AUDIO_DSP_CHANNELS 2 /**< channels */
133
116
#define AUDIO_DSP_SAMPLEBITS 3 /**< sample bits width */
134
- /** @} */ /* End of audio_dsp*/
117
+ /** @} */ /* End of audio_dsp */
135
118
136
119
/**
137
120
* @defgroup audio_mixer AUDIO_MIXER
138
121
*
139
- * @brief Supported Mixer Units controls
140
- */
141
-
142
- /**
143
- * @addtogroup audio_mixer
122
+ * @brief Supported Mixer Units controls. The macro group from driver level, can set audio mixer
123
+ * parameters including volume, frequence db, microphone etc.
124
+ *
144
125
* @{
145
126
*/
146
127
#define AUDIO_MIXER_QUERY 0x0000 /**< Query mixer capabilities */
147
128
#define AUDIO_MIXER_MUTE 0x0001 /**< Mute audio device */
148
129
#define AUDIO_MIXER_VOLUME 0x0002 /**< Set mixer volume */
149
130
#define AUDIO_MIXER_BASS 0x0004 /**< Set the low-frequency section of the mixer */
150
- #define AUDIO_MIXER_MID 0x0008 /**< Set the mid-frequency section of the mixer*/
131
+ #define AUDIO_MIXER_MID 0x0008 /**< Set the mid-frequency section of the mixer */
151
132
#define AUDIO_MIXER_TREBLE 0x0010 /**< Set the high-frequency section of the mixer */
152
133
#define AUDIO_MIXER_EQUALIZER 0x0020 /**< Set equalizer option */
153
134
#define AUDIO_MIXER_LINE 0x0040 /**< Set line control option */
154
135
#define AUDIO_MIXER_DIGITAL 0x0080 /**< Set digital source */
155
136
#define AUDIO_MIXER_MIC 0x0100 /**< Set microphone option */
156
137
#define AUDIO_MIXER_VITURAL 0x0200 /**< Set virtual audio option */
157
138
#define AUDIO_MIXER_EXTEND 0x8000 /**< Extend mixer command */
158
- /** @} */ /* End of audio_mixer*/
139
+ /** @} */ /* End of audio_mixer */
159
140
160
141
#define AUDIO_VOLUME_MAX (100)
161
142
#define AUDIO_VOLUME_MIN (0)
@@ -181,24 +162,35 @@ enum
181
162
*/
182
163
struct rt_audio_buf_info
183
164
{
184
- rt_uint8_t * buffer ;
185
- rt_uint16_t block_size ;
186
- rt_uint16_t block_count ;
187
- rt_uint32_t total_size ;
165
+ rt_uint8_t * buffer ; /**< Audio buffer information */
166
+ rt_uint16_t block_size ; /**< Audio block_size information for replay function */
167
+ rt_uint16_t block_count ; /**< Audio block_count information for replay function */
168
+ rt_uint32_t total_size ; /**< Audio total_size which is equal to block_size multiplying
169
+ * block_count information for replay function */
188
170
};
189
171
190
172
struct rt_audio_device ;
191
173
struct rt_audio_caps ;
192
174
struct rt_audio_configure ;
175
+
176
+ /**
177
+ * @brief Aduio device operators
178
+ */
193
179
struct rt_audio_ops
194
180
{
181
+ /** Get audio capabilities information */
195
182
rt_err_t (* getcaps )(struct rt_audio_device * audio , struct rt_audio_caps * caps );
183
+ /** Configure audio devices */
196
184
rt_err_t (* configure )(struct rt_audio_device * audio , struct rt_audio_caps * caps );
185
+ /** Initialize audio device */
197
186
rt_err_t (* init )(struct rt_audio_device * audio );
187
+ /** Turn on the audio device */
198
188
rt_err_t (* start )(struct rt_audio_device * audio , int stream );
189
+ /** Turn off the audio device */
199
190
rt_err_t (* stop )(struct rt_audio_device * audio , int stream );
191
+ /** Transmit data between application and device */
200
192
rt_ssize_t (* transmit )(struct rt_audio_device * audio , const void * writeBuf , void * readBuf , rt_size_t size );
201
- /* get page size of codec or private buffer's info */
193
+ /** Get page size of codec or private buffer's info */
202
194
void (* buffer_info )(struct rt_audio_device * audio , struct rt_audio_buf_info * info );
203
195
};
204
196
@@ -211,43 +203,45 @@ struct rt_audio_ops
211
203
*/
212
204
struct rt_audio_configure
213
205
{
214
- rt_uint32_t samplerate ;
215
- rt_uint16_t channels ;
216
- rt_uint16_t samplebits ;
206
+ rt_uint32_t samplerate ; /**< Audio samplerate information */
207
+ rt_uint16_t channels ; /**< Audio channels information */
208
+ rt_uint16_t samplebits ; /**< Audio samplebits information */
217
209
};
218
210
219
211
/**
220
212
* @brief Audio capabilities
221
213
*/
222
214
struct rt_audio_caps
223
215
{
224
- int main_type ;
225
- int sub_type ;
216
+ int main_type ; /**< Audio main type, one value of @ref audio_type */
217
+ int sub_type ; /**< Audio sub type, one value of @ref audio_dsp @ref audio_mixer */
226
218
227
219
union
228
220
{
229
- rt_uint32_t mask ;
230
- int value ;
231
- struct rt_audio_configure config ;
232
- } udata ;
221
+ rt_uint32_t mask ; /**< Capabilities mask */
222
+ int value ; /**< Capabilities value */
223
+ struct rt_audio_configure config ; /**< Audio samplebits information */
224
+ } udata ; /**< User data */
233
225
};
234
226
235
227
/**
236
228
* @brief Audio replay
237
229
*/
238
230
struct rt_audio_replay
239
231
{
240
- struct rt_mempool * mp ;
241
- struct rt_data_queue queue ;
242
- struct rt_mutex lock ;
243
- struct rt_completion cmp ;
244
- struct rt_audio_buf_info buf_info ;
245
- rt_uint8_t * write_data ;
246
- rt_uint16_t write_index ;
247
- rt_uint16_t read_index ;
248
- rt_uint32_t pos ;
249
- rt_uint8_t event ;
250
- rt_bool_t activated ;
232
+ struct rt_mempool * mp ; /**< Memory pool for audio replay */
233
+ struct rt_data_queue queue ; /**< Replay data queue */
234
+ struct rt_mutex lock ; /**< Replay mutex lock */
235
+ struct rt_completion cmp ; /**< Replay completion, it will be */
236
+ struct rt_audio_buf_info buf_info ; /**< Replay buffer information */
237
+ rt_uint8_t * write_data ; /**< Pointer to the data to be written into data queue */
238
+ rt_uint16_t write_index ; /**< Index of pointer write_data.It records how much data
239
+ * has been written in currently being played block */
240
+ rt_uint16_t read_index ; /**< Index of replaying data for audio device, it indicates index
241
+ * of replay in the blocks which is currently being played */
242
+ rt_uint32_t pos ; /**< Global position of audio replay */
243
+ rt_uint8_t event ; /**< Event flag */
244
+ rt_bool_t activated ; /**< Activaty flag */
251
245
};
252
246
253
247
/**
@@ -264,10 +258,10 @@ struct rt_audio_record
264
258
*/
265
259
struct rt_audio_device
266
260
{
267
- struct rt_device parent ;
268
- struct rt_audio_ops * ops ;
269
- struct rt_audio_replay * replay ;
270
- struct rt_audio_record * record ;
261
+ struct rt_device parent ; /**< Audio device parents */
262
+ struct rt_audio_ops * ops ; /**< Audio device operator */
263
+ struct rt_audio_replay * replay ; /**< Pointer to audio replay structure */
264
+ struct rt_audio_record * record ; /**< Pointer to audio record structure */
271
265
};
272
266
273
267
rt_err_t rt_audio_register (struct rt_audio_device * audio , const char * name , rt_uint32_t flag , void * data );
@@ -277,11 +271,9 @@ void rt_audio_rx_done(struct rt_audio_device *audio, rt_uint8_t *pbuf, rt
277
271
/**
278
272
* @defgroup audio_codec_cmd CODEC_CMD
279
273
*
280
- * @brief Device Control Commands
281
- */
282
-
283
- /**
284
- * @addtogroup audio_codec_cmd
274
+ * @brief Device Control Commands. The macro group from hardware level, can set codec
275
+ * parametes including volume, EQ and 3D etc.
276
+ *
285
277
* @{
286
278
*/
287
279
#define CODEC_CMD_RESET 0 /**< Reset audio device by codec */
@@ -292,7 +284,7 @@ void rt_audio_rx_done(struct rt_audio_device *audio, rt_uint8_t *pbuf, rt
292
284
#define CODEC_CMD_3D 5 /**< Set 3D effect by codec */
293
285
294
286
#define CODEC_VOLUME_MAX (63)
295
- /** @} */ /* End of audio_codec_cmd*/
287
+ /** @} */ /* End of audio_codec_cmd */
296
288
297
289
/** @} group_Audio */
298
290
0 commit comments