1 /*
2  * Copyright  2021 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_CODEC_TFA9896_ADAPTER_H_
10 #define _FSL_CODEC_TFA9896_ADAPTER_H_
11 
12 #include "fsl_tfa9896.h"
13 
14 /*!
15  * @addtogroup tfa9896_adapter
16  * @ingroup codec_common
17  * @{
18  */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 /*!@brief codec handler size */
24 #define HAL_CODEC_TFA9896_HANDLER_SIZE (TFA9896_I2C_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_TFA9896_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_TFA9896_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_TFA9896_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_TFA9896_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_TFA9896_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_TFA9896_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_TFA9896_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_TFA9896_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_TFA9896_SetPlay(void *handle, uint32_t playSource);
122 
123 /*!
124  * @brief codec module control.
125  *
126  * @param handle codec handle.
127  * @param cmd module control cmd, reference _codec_module_ctrl_cmd.
128  * @param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine
129  *  of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference
130  *  codec specific driver for detail configurations.
131  * @return kStatus_Success is success, else configure failed.
132  */
133 status_t HAL_CODEC_TFA9896_ModuleControl(void *handle, uint32_t cmd, uint32_t data);
134 
135 #if !(defined CODEC_MULTI_ADAPTERS && CODEC_MULTI_ADAPTERS)
136 /*!
137  * @brief Codec initilization.
138  *
139  * @param handle codec handle.
140  * @param config codec configuration.
141  * @return kStatus_Success is success, else initial failed.
142  */
HAL_CODEC_Init(void * handle,void * config)143 static inline status_t HAL_CODEC_Init(void *handle, void *config)
144 {
145     return HAL_CODEC_TFA9896_Init(handle, config);
146 }
147 
148 /*!
149  * @brief Codec de-initilization.
150  *
151  * @param handle codec handle.
152  * @return kStatus_Success is success, else de-initial failed.
153  */
HAL_CODEC_Deinit(void * handle)154 static inline status_t HAL_CODEC_Deinit(void *handle)
155 {
156     return HAL_CODEC_TFA9896_Deinit(handle);
157 }
158 
159 /*!
160  * @brief set audio data format.
161  *
162  * @param handle codec handle.
163  * @param mclk master clock frequency in HZ.
164  * @param sampleRate sample rate in HZ.
165  * @param bitWidth bit width.
166  * @return kStatus_Success is success, else configure failed.
167  */
HAL_CODEC_SetFormat(void * handle,uint32_t mclk,uint32_t sampleRate,uint32_t bitWidth)168 static inline status_t HAL_CODEC_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
169 {
170     return HAL_CODEC_TFA9896_SetFormat(handle, mclk, sampleRate, bitWidth);
171 }
172 
173 /*!
174  * @brief set audio codec module volume.
175  *
176  * @param handle codec handle.
177  * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel.
178  * @param volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value.
179  * @return kStatus_Success is success, else configure failed.
180  */
HAL_CODEC_SetVolume(void * handle,uint32_t playChannel,uint32_t volume)181 static inline status_t HAL_CODEC_SetVolume(void *handle, uint32_t playChannel, uint32_t volume)
182 {
183     return HAL_CODEC_TFA9896_SetVolume(handle, playChannel, volume);
184 }
185 
186 /*!
187  * @brief set audio codec module mute.
188  *
189  * @param handle codec handle.
190  * @param playChannel audio codec play channel, can be a value or combine value of _codec_play_channel.
191  * @param isMute true is mute, false is unmute.
192  * @return kStatus_Success is success, else configure failed.
193  */
HAL_CODEC_SetMute(void * handle,uint32_t playChannel,bool isMute)194 static inline status_t HAL_CODEC_SetMute(void *handle, uint32_t playChannel, bool isMute)
195 {
196     return HAL_CODEC_TFA9896_SetMute(handle, playChannel, isMute);
197 }
198 
199 /*!
200  * @brief set audio codec module power.
201  *
202  * @param handle codec handle.
203  * @param module audio codec module.
204  * @param powerOn true is power on, false is power down.
205  * @return kStatus_Success is success, else configure failed.
206  */
HAL_CODEC_SetPower(void * handle,uint32_t module,bool powerOn)207 static inline status_t HAL_CODEC_SetPower(void *handle, uint32_t module, bool powerOn)
208 {
209     return HAL_CODEC_TFA9896_SetPower(handle, module, powerOn);
210 }
211 
212 /*!
213  * @brief codec set record source.
214  *
215  * @param handle codec handle.
216  * @param recordSource audio codec record source, can be a value or combine value of _codec_record_source.
217  *
218  * @return kStatus_Success is success, else configure failed.
219  */
HAL_CODEC_SetRecord(void * handle,uint32_t recordSource)220 static inline status_t HAL_CODEC_SetRecord(void *handle, uint32_t recordSource)
221 {
222     return HAL_CODEC_TFA9896_SetRecord(handle, recordSource);
223 }
224 
225 /*!
226  * @brief codec set record channel.
227  *
228  * @param handle codec handle.
229  * @param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value
230  of member in _codec_record_channel.
231  * @param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of
232  member in _codec_record_channel.
233 
234  * @return kStatus_Success is success, else configure failed.
235  */
HAL_CODEC_SetRecordChannel(void * handle,uint32_t leftRecordChannel,uint32_t rightRecordChannel)236 static inline status_t HAL_CODEC_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
237 {
238     return HAL_CODEC_TFA9896_SetRecordChannel(handle, leftRecordChannel, rightRecordChannel);
239 }
240 
241 /*!
242  * @brief codec set play source.
243  *
244  * @param handle codec handle.
245  * @param playSource audio codec play source, can be a value or combine value of _codec_play_source.
246  *
247  * @return kStatus_Success is success, else configure failed.
248  */
HAL_CODEC_SetPlay(void * handle,uint32_t playSource)249 static inline status_t HAL_CODEC_SetPlay(void *handle, uint32_t playSource)
250 {
251     return HAL_CODEC_TFA9896_SetPlay(handle, playSource);
252 }
253 
254 /*!
255  * @brief codec module control.
256  *
257  * This function is used for codec module control, support switch digital interface cmd, can be expand to support codec
258  * module specific feature
259  *
260  * @param handle codec handle.
261  * @param cmd module control cmd, reference _codec_module_ctrl_cmd.
262  * @param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine
263  *  of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference
264  *  codec specific driver for detail configurations.
265  * @return kStatus_Success is success, else configure failed.
266  */
HAL_CODEC_ModuleControl(void * handle,uint32_t cmd,uint32_t data)267 static inline status_t HAL_CODEC_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
268 {
269     return HAL_CODEC_TFA9896_ModuleControl(handle, cmd, data);
270 }
271 #endif
272 
273 #if defined(__cplusplus)
274 }
275 #endif
276 
277 /*! @} */
278 
279 #endif /* _FSL_CODEC_TFA9896_ADAPTER_H_ */
280