77 * Date Author Notes
88 * 2017-05-09 Urey first version
99 * 2019-07-09 Zero-Free improve device ops interface and data flows
10- *
10+ * 2025-03-04 wumingzi add doxygen comments.
1111 */
1212
1313#ifndef __DEV_AUDIO_H__
2121 * @ingroup group_Drivers RT-Thread Drivers
2222 *
2323 * @brief Audio driver API.
24- */
25-
26- /**
27- * @addtogroup group_Audio
24+ *
2825 * @{
2926 */
3027
3128/**
3229 * @defgroup audio_control AUDIO_CTL
3330 *
3431 * @brief Control audio device.
35- */
36-
37- /**
38- * @addtogroup audio_control
32+ *
3933 * @{
4034 */
4135
5448#define AUDIO_CTL_STOP _AUDIO_CTL(4) /**< Stop audio device */
5549#define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(5) /**< Get audio device buffer information */
5650
57- /** @} */ /* End of audio_control*/
51+ /** @} */ /* End of audio_control */
5852
5953/**
6054 * @defgroup audio_type AUDIO_TYPE
6155 *
6256 * @brief Audio Device Types
63- */
64-
65- /**
66- * @addtogroup audio_type
57+ *
6758 * @{
6859 */
6960#define AUDIO_TYPE_QUERY 0x00 /**< Query audio device type */
7061#define AUDIO_TYPE_INPUT 0x01 /**< Set audio device type to input type */
7162#define AUDIO_TYPE_OUTPUT 0x02 /**< Set audio device type to output type */
7263#define AUDIO_TYPE_MIXER 0x04 /**< Set audio device type to mixer type */
73- /** @} */ /* End of audio_type*/
64+ /** @} */ /* End of audio_type */
7465
7566/**
7667 * @defgroup audio_samp_rates AUDIO_SAMP_RATES
7768 *
7869 * @brief Supported audio sample rates for the audio device.
79- */
80-
81- /**
82- * @addtogroup audio_samp_rates
70+ *
8371 * @{
8472 */
8573#define AUDIO_SAMP_RATE_8K 0x0001 /**< Set audio device sample rate to 8K */
9482#define AUDIO_SAMP_RATE_160K 0x0200 /**< Set audio device sample rate to 160K */
9583#define AUDIO_SAMP_RATE_172K 0x0400 /**< Set audio device sample rate to 172K */
9684#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 */
9886
9987/**
10088 * @defgroup audio_bit_rates AUDIO_BIT_RATES
10189 *
10290 * @brief Supported bit rates for the audio device.
103- */
104-
105- /**
106- * @addtogroup audio_bit_rates
91+ *
10792 * @{
10893 */
10994#define AUDIO_BIT_RATE_22K 0x01 /**< Set audio device bit rates to 22K */
11499#define AUDIO_BIT_RATE_160K 0x20 /**< Set audio device bit rates to 160K */
115100#define AUDIO_BIT_RATE_172K 0x40 /**< Set audio device bit rates to 172K */
116101#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 */
118103
119104
120105/**
121106 * @defgroup audio_dsp AUDIO_DSP
122107 *
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+ *
128111 * @{
129112 */
130113#define AUDIO_DSP_PARAM 0 /**< get/set all params */
131114#define AUDIO_DSP_SAMPLERATE 1 /**< samplerate */
132115#define AUDIO_DSP_CHANNELS 2 /**< channels */
133116#define AUDIO_DSP_SAMPLEBITS 3 /**< sample bits width */
134- /** @} */ /* End of audio_dsp*/
117+ /** @} */ /* End of audio_dsp */
135118
136119/**
137120 * @defgroup audio_mixer AUDIO_MIXER
138121 *
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+ *
144125 * @{
145126 */
146127#define AUDIO_MIXER_QUERY 0x0000 /**< Query mixer capabilities */
147128#define AUDIO_MIXER_MUTE 0x0001 /**< Mute audio device */
148129#define AUDIO_MIXER_VOLUME 0x0002 /**< Set mixer volume */
149130#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 */
151132#define AUDIO_MIXER_TREBLE 0x0010 /**< Set the high-frequency section of the mixer */
152133#define AUDIO_MIXER_EQUALIZER 0x0020 /**< Set equalizer option */
153134#define AUDIO_MIXER_LINE 0x0040 /**< Set line control option */
154135#define AUDIO_MIXER_DIGITAL 0x0080 /**< Set digital source */
155136#define AUDIO_MIXER_MIC 0x0100 /**< Set microphone option */
156137#define AUDIO_MIXER_VITURAL 0x0200 /**< Set virtual audio option */
157138#define AUDIO_MIXER_EXTEND 0x8000 /**< Extend mixer command */
158- /** @} */ /* End of audio_mixer*/
139+ /** @} */ /* End of audio_mixer */
159140
160141#define AUDIO_VOLUME_MAX (100)
161142#define AUDIO_VOLUME_MIN (0)
@@ -181,24 +162,35 @@ enum
181162 */
182163struct rt_audio_buf_info
183164{
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 */
188170};
189171
190172struct rt_audio_device ;
191173struct rt_audio_caps ;
192174struct rt_audio_configure ;
175+
176+ /**
177+ * @brief Aduio device operators
178+ */
193179struct rt_audio_ops
194180{
181+ /** Get audio capabilities information */
195182 rt_err_t (* getcaps )(struct rt_audio_device * audio , struct rt_audio_caps * caps );
183+ /** Configure audio devices */
196184 rt_err_t (* configure )(struct rt_audio_device * audio , struct rt_audio_caps * caps );
185+ /** Initialize audio device */
197186 rt_err_t (* init )(struct rt_audio_device * audio );
187+ /** Turn on the audio device */
198188 rt_err_t (* start )(struct rt_audio_device * audio , int stream );
189+ /** Turn off the audio device */
199190 rt_err_t (* stop )(struct rt_audio_device * audio , int stream );
191+ /** Transmit data between application and device */
200192 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 */
202194 void (* buffer_info )(struct rt_audio_device * audio , struct rt_audio_buf_info * info );
203195};
204196
@@ -211,43 +203,45 @@ struct rt_audio_ops
211203 */
212204struct rt_audio_configure
213205{
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 */
217209};
218210
219211/**
220212 * @brief Audio capabilities
221213 */
222214struct rt_audio_caps
223215{
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 */
226218
227219 union
228220 {
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 */
233225};
234226
235227/**
236228 * @brief Audio replay
237229 */
238230struct rt_audio_replay
239231{
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 */
251245};
252246
253247/**
@@ -264,10 +258,10 @@ struct rt_audio_record
264258 */
265259struct rt_audio_device
266260{
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 */
271265};
272266
273267rt_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
277271/**
278272 * @defgroup audio_codec_cmd CODEC_CMD
279273 *
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+ *
285277 * @{
286278 */
287279#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
292284#define CODEC_CMD_3D 5 /**< Set 3D effect by codec */
293285
294286#define CODEC_VOLUME_MAX (63)
295- /** @} */ /* End of audio_codec_cmd*/
287+ /** @} */ /* End of audio_codec_cmd */
296288
297289/** @} group_Audio */
298290
0 commit comments