1 /*
2  * Copyright  2021 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_CODEC_WM8524_ADAPTER_H_
10 #define _FSL_CODEC_WM8524_ADAPTER_H_
11 
12 #include "fsl_wm8524.h"
13 
14 /*!
15  * @addtogroup wm8524_adapter
16  * @ingroup codec_common
17  * @{
18  */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 /*!@brief codec handler size */
24 #define HAL_CODEC_WM8524_HANDLER_SIZE (4)
25 /*******************************************************************************
26  * API
27  ******************************************************************************/
28 
29 #if defined(__cplusplus)
30 extern "C" {
31 #endif
32 /*!
33  * @brief Codec initilization.
34  *
35  * @param handle codec handle.
36  * @param config codec configuration.
37  * @return kStatus_Success is success, else initial failed.
38  */
39 status_t HAL_CODEC_WM8524_Init(void *handle, void *config);
40 
41 /*!
42  * @brief Codec de-initilization.
43  *
44  * @param handle codec handle.
45  * @return kStatus_Success is success, else de-initial failed.
46  */
47 status_t HAL_CODEC_WM8524_Deinit(void *handle);
48 
49 /*!
50  * @brief set audio data format.
51  *
52  * @param handle codec handle.
53  * @param mclk master clock frequency in HZ.
54  * @param sampleRate sample rate in HZ.
55  * @param bitWidth bit width.
56  * @return kStatus_Success is success, else configure failed.
57  */
58 status_t HAL_CODEC_WM8524_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth);
59 
60 /*!
61  * @brief set audio codec module volume.
62  *
63  * @param handle codec handle.
64  * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel.
65  * @param volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value.
66  * @return kStatus_Success is success, else configure failed.
67  */
68 status_t HAL_CODEC_WM8524_SetVolume(void *handle, uint32_t playChannel, uint32_t volume);
69 
70 /*!
71  * @brief set audio codec module mute.
72  *
73  * @param handle codec handle.
74  * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel.
75  * @param isMute true is mute, false is unmute.
76  * @return kStatus_Success is success, else configure failed.
77  */
78 status_t HAL_CODEC_WM8524_SetMute(void *handle, uint32_t playChannel, bool isMute);
79 
80 /*!
81  * @brief set audio codec module power.
82  *
83  * @param handle codec handle.
84  * @param module audio codec module.
85  * @param powerOn true is power on, false is power down.
86  * @return kStatus_Success is success, else configure failed.
87  */
88 status_t HAL_CODEC_WM8524_SetPower(void *handle, uint32_t module, bool powerOn);
89 
90 /*!
91  * @brief codec set record source.
92  *
93  * @param handle codec handle.
94  * @param recordSource audio codec record source, can be a value or combine value of _codec_record_source.
95  *
96  * @return kStatus_Success is success, else configure failed.
97  */
98 status_t HAL_CODEC_WM8524_SetRecord(void *handle, uint32_t recordSource);
99 
100 /*!
101  * @brief codec set record channel.
102  *
103  * @param handle codec handle.
104  * @param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value
105  of member in _codec_record_channel.
106  * @param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of
107  member in _codec_record_channel.
108 
109  * @return kStatus_Success is success, else configure failed.
110  */
111 status_t HAL_CODEC_WM8524_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel);
112 
113 /*!
114  * @brief codec set play source.
115  *
116  * @param handle codec handle.
117  * @param playSource audio codec play source, can be a value or combine value of _codec_play_source.
118  *
119  * @return kStatus_Success is success, else configure failed.
120  */
121 status_t HAL_CODEC_WM8524_SetPlay(void *handle, uint32_t playSource);
122 
123 /*!
124  * @brief codec module control.
125  *
126  * This function is used for codec module control, support switch digital interface cmd, can be expand to support codec
127  * module specific feature
128  *
129  * @param handle codec handle.
130  * @param cmd module control cmd, reference _codec_module_ctrl_cmd.
131  * @param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine
132  *  of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference
133  *  codec specific driver for detail configurations.
134  * @return kStatus_Success is success, else configure failed.
135  */
136 status_t HAL_CODEC_WM8524_ModuleControl(void *handle, uint32_t cmd, uint32_t data);
137 
138 #if !(defined CODEC_MULTI_ADAPTERS && CODEC_MULTI_ADAPTERS)
139 /*!
140  * @brief Codec initilization.
141  *
142  * @param handle codec handle.
143  * @param config codec configuration.
144  * @return kStatus_Success is success, else initial failed.
145  */
HAL_CODEC_Init(void * handle,void * config)146 static inline status_t HAL_CODEC_Init(void *handle, void *config)
147 {
148     return HAL_CODEC_WM8524_Init(handle, config);
149 }
150 
151 /*!
152  * @brief Codec de-initilization.
153  *
154  * @param handle codec handle.
155  * @return kStatus_Success is success, else de-initial failed.
156  */
HAL_CODEC_Deinit(void * handle)157 static inline status_t HAL_CODEC_Deinit(void *handle)
158 {
159     return HAL_CODEC_WM8524_Deinit(handle);
160 }
161 
162 /*!
163  * @brief set audio data format.
164  *
165  * @param handle codec handle.
166  * @param mclk master clock frequency in HZ.
167  * @param sampleRate sample rate in HZ.
168  * @param bitWidth bit width.
169  * @return kStatus_Success is success, else configure failed.
170  */
HAL_CODEC_SetFormat(void * handle,uint32_t mclk,uint32_t sampleRate,uint32_t bitWidth)171 static inline status_t HAL_CODEC_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
172 {
173     return HAL_CODEC_WM8524_SetFormat(handle, mclk, sampleRate, bitWidth);
174 }
175 
176 /*!
177  * @brief set audio codec module volume.
178  *
179  * @param handle codec handle.
180  * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel.
181  * @param volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value.
182  * @return kStatus_Success is success, else configure failed.
183  */
HAL_CODEC_SetVolume(void * handle,uint32_t playChannel,uint32_t volume)184 static inline status_t HAL_CODEC_SetVolume(void *handle, uint32_t playChannel, uint32_t volume)
185 {
186     return HAL_CODEC_WM8524_SetVolume(handle, playChannel, volume);
187 }
188 
189 /*!
190  * @brief set audio codec module mute.
191  *
192  * @param handle codec handle.
193  * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel.
194  * @param isMute true is mute, false is unmute.
195  * @return kStatus_Success is success, else configure failed.
196  */
HAL_CODEC_SetMute(void * handle,uint32_t playChannel,bool isMute)197 static inline status_t HAL_CODEC_SetMute(void *handle, uint32_t playChannel, bool isMute)
198 {
199     return HAL_CODEC_WM8524_SetMute(handle, playChannel, isMute);
200 }
201 
202 /*!
203  * @brief set audio codec module power.
204  *
205  * @param handle codec handle.
206  * @param module audio codec module.
207  * @param powerOn true is power on, false is power down.
208  * @return kStatus_Success is success, else configure failed.
209  */
HAL_CODEC_SetPower(void * handle,uint32_t module,bool powerOn)210 static inline status_t HAL_CODEC_SetPower(void *handle, uint32_t module, bool powerOn)
211 {
212     return HAL_CODEC_WM8524_SetPower(handle, module, powerOn);
213 }
214 
215 /*!
216  * @brief codec set record source.
217  *
218  * @param handle codec handle.
219  * @param recordSource audio codec record source, can be a value or combine value of _codec_record_source.
220  *
221  * @return kStatus_Success is success, else configure failed.
222  */
HAL_CODEC_SetRecord(void * handle,uint32_t recordSource)223 static inline status_t HAL_CODEC_SetRecord(void *handle, uint32_t recordSource)
224 {
225     return HAL_CODEC_WM8524_SetRecord(handle, recordSource);
226 }
227 
228 /*!
229  * @brief codec set record channel.
230  *
231  * @param handle codec handle.
232  * @param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value
233  of member in _codec_record_channel.
234  * @param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of
235  member in _codec_record_channel.
236 
237  * @return kStatus_Success is success, else configure failed.
238  */
HAL_CODEC_SetRecordChannel(void * handle,uint32_t leftRecordChannel,uint32_t rightRecordChannel)239 static inline status_t HAL_CODEC_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
240 {
241     return HAL_CODEC_WM8524_SetRecordChannel(handle, leftRecordChannel, rightRecordChannel);
242 }
243 
244 /*!
245  * @brief codec set play source.
246  *
247  * @param handle codec handle.
248  * @param playSource audio codec play source, can be a value or combine value of _codec_play_source.
249  *
250  * @return kStatus_Success is success, else configure failed.
251  */
HAL_CODEC_SetPlay(void * handle,uint32_t playSource)252 static inline status_t HAL_CODEC_SetPlay(void *handle, uint32_t playSource)
253 {
254     return HAL_CODEC_WM8524_SetPlay(handle, playSource);
255 }
256 
257 /*!
258  * @brief codec module control.
259  *
260  * This function is used for codec module control, support switch digital interface cmd, can be expand to support codec
261  * module specific feature
262  *
263  * @param handle codec handle.
264  * @param cmd module control cmd, reference _codec_module_ctrl_cmd.
265  * @param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine
266  *  of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference
267  *  codec specific driver for detail configurations.
268  * @return kStatus_Success is success, else configure failed.
269  */
HAL_CODEC_ModuleControl(void * handle,uint32_t cmd,uint32_t data)270 static inline status_t HAL_CODEC_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
271 {
272     return HAL_CODEC_WM8524_ModuleControl(handle, cmd, data);
273 }
274 #endif
275 
276 #if defined(__cplusplus)
277 }
278 #endif
279 
280 /*! @} */
281 
282 #endif /* _FSL_CODEC_WM8524_ADAPTER_H_ */
283