1 /*
2 * Copyright 2021-2022 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_codec_wm8524_adapter.h"
10 #include "fsl_codec_common.h"
11
12 /*******************************************************************************
13 * Definitions
14 ******************************************************************************/
15
16 /*******************************************************************************
17 * Prototypes
18 ******************************************************************************/
19
20 /*******************************************************************************
21 * Variables
22 ******************************************************************************/
23 static const codec_capability_t s_wm8524_capability;
24 /*******************************************************************************
25 * Code
26 ******************************************************************************/
27 /*!
28 * brief Codec initilization.
29 *
30 * param handle codec handle.
31 * param config codec configuration.
32 * return kStatus_Success is success, else initial failed.
33 */
HAL_CODEC_WM8524_Init(void * handle,void * config)34 status_t HAL_CODEC_WM8524_Init(void *handle, void *config)
35 {
36 assert((config != NULL) && (handle != NULL));
37
38 codec_config_t *codecConfig = (codec_config_t *)config;
39
40 wm8524_config_t *devConfig = (wm8524_config_t *)(codecConfig->codecDevConfig);
41 wm8524_handle_t *devHandle = (wm8524_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle));
42
43 ((codec_handle_t *)handle)->codecCapability = &s_wm8524_capability;
44
45 /* codec device initialization */
46 return WM8524_Init(devHandle, devConfig);
47 }
48
49 /*!
50 * brief Codec de-initilization.
51 *
52 * param handle codec handle.
53 * return kStatus_Success is success, else de-initial failed.
54 */
HAL_CODEC_WM8524_Deinit(void * handle)55 status_t HAL_CODEC_WM8524_Deinit(void *handle)
56 {
57 return kStatus_CODEC_NotSupport;
58 }
59
60 /*!
61 * brief set audio data format.
62 *
63 * param handle codec handle.
64 * param mclk master clock frequency in HZ.
65 * param sampleRate sample rate in HZ.
66 * param bitWidth bit width.
67 * return kStatus_Success is success, else configure failed.
68 */
HAL_CODEC_WM8524_SetFormat(void * handle,uint32_t mclk,uint32_t sampleRate,uint32_t bitWidth)69 status_t HAL_CODEC_WM8524_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
70 {
71 /* wm8524 support sample rate range:8K~192k */
72 if ((sampleRate < 8000U) || ((sampleRate > 192000U)))
73 {
74 return kStatus_CODEC_NotSupport;
75 }
76
77 return kStatus_Success;
78 }
79
80 /*!
81 * brief set audio codec module volume.
82 *
83 * param handle codec handle.
84 * param channel audio codec play channel, can be a value or combine value of _codec_play_channel.
85 * param volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value.
86 * return kStatus_Success is success, else configure failed.
87 */
HAL_CODEC_WM8524_SetVolume(void * handle,uint32_t playChannel,uint32_t volume)88 status_t HAL_CODEC_WM8524_SetVolume(void *handle, uint32_t playChannel, uint32_t volume)
89 {
90 return kStatus_CODEC_NotSupport;
91 }
92
93 /*!
94 * brief set audio codec module mute.
95 *
96 * param handle codec handle.
97 * param channel audio codec play channel, can be a value or combine value of _codec_play_channel.
98 * param isMute true is mute, false is unmute.
99 * return kStatus_Success is success, else configure failed.
100 */
HAL_CODEC_WM8524_SetMute(void * handle,uint32_t playChannel,bool isMute)101 status_t HAL_CODEC_WM8524_SetMute(void *handle, uint32_t playChannel, bool isMute)
102 {
103 assert(handle != NULL);
104
105 WM8524_SetMute((wm8524_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle)), isMute);
106
107 return kStatus_Success;
108 }
109
110 /*!
111 * brief set audio codec module power.
112 *
113 * param handle codec handle.
114 * param module audio codec module.
115 * param powerOn true is power on, false is power down.
116 * return kStatus_Success is success, else configure failed.
117 */
HAL_CODEC_WM8524_SetPower(void * handle,uint32_t module,bool powerOn)118 status_t HAL_CODEC_WM8524_SetPower(void *handle, uint32_t module, bool powerOn)
119 {
120 return kStatus_CODEC_NotSupport;
121 }
122
123 /*!
124 * brief codec set record channel.
125 *
126 * param handle codec handle.
127 * param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value
128 of member in _codec_record_channel.
129 * param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of
130 member in _codec_record_channel.
131
132 * return kStatus_Success is success, else configure failed.
133 */
HAL_CODEC_WM8524_SetRecordChannel(void * handle,uint32_t leftRecordChannel,uint32_t rightRecordChannel)134 status_t HAL_CODEC_WM8524_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
135 {
136 return kStatus_CODEC_NotSupport;
137 }
138
139 /*!
140 * brief codec set record source.
141 *
142 * param handle codec handle.
143 * param source audio codec record source, can be a value or combine value of _codec_record_source.
144 *
145 * return kStatus_Success is success, else configure failed.
146 */
HAL_CODEC_WM8524_SetRecord(void * handle,uint32_t recordSource)147 status_t HAL_CODEC_WM8524_SetRecord(void *handle, uint32_t recordSource)
148 {
149 return kStatus_CODEC_NotSupport;
150 }
151
152 /*!
153 * brief codec set play source.
154 *
155 * param handle codec handle.
156 * param playSource audio codec play source, can be a value or combine value of _codec_play_source.
157 *
158 * return kStatus_Success is success, else configure failed.
159 */
HAL_CODEC_WM8524_SetPlay(void * handle,uint32_t playSource)160 status_t HAL_CODEC_WM8524_SetPlay(void *handle, uint32_t playSource)
161 {
162 return kStatus_CODEC_NotSupport;
163 }
164
165 /*!
166 * brief codec module control.
167 *
168 * param handle codec handle.
169 * param cmd module control cmd, reference _codec_module_ctrl_cmd.
170 * param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine
171 * of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference
172 * codec specific driver for detail configurations.
173 * return kStatus_Success is success, else configure failed.
174 */
HAL_CODEC_WM8524_ModuleControl(void * handle,uint32_t cmd,uint32_t data)175 status_t HAL_CODEC_WM8524_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
176 {
177 return kStatus_CODEC_NotSupport;
178 }
179