1 /*
2 * Copyright 2021 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include "fsl_codec_adapter.h"
8 #include "fsl_codec_common.h"
9
10 /*******************************************************************************
11 * Definitions
12 ******************************************************************************/
13
14 /*******************************************************************************
15 * Prototypes
16 ******************************************************************************/
17
18 /*******************************************************************************
19 * Variables
20 ******************************************************************************/
21 static const codec_capability_t s_pcm512x_capability;
22 /*******************************************************************************
23 * Code
24 ******************************************************************************/
25 /*!
26 * brief Codec initilization.
27 *
28 * param handle codec handle.
29 * param config codec configuration.
30 * return kStatus_Success is success, else initial failed.
31 */
HAL_CODEC_Init(void * handle,void * config)32 status_t HAL_CODEC_Init(void *handle, void *config)
33 {
34 assert((config != NULL) && (handle != NULL));
35
36 codec_config_t *codecConfig = (codec_config_t *)config;
37
38 pcm512x_config_t *devConfig = (pcm512x_config_t *)(codecConfig->codecDevConfig);
39 pcm512x_handle_t *devHandle = (pcm512x_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle));
40
41 ((codec_handle_t *)handle)->codecCapability = &s_pcm512x_capability;
42
43 /* codec device initialization */
44 return PCM512x_Init(devHandle, devConfig);
45 }
46
47 /*!
48 * brief Codec de-initilization.
49 *
50 * param handle codec handle.
51 * return kStatus_Success is success, else de-initial failed.
52 */
HAL_CODEC_Deinit(void * handle)53 status_t HAL_CODEC_Deinit(void *handle)
54 {
55 assert (handle != NULL);
56
57 pcm512x_handle_t *devHandle = (pcm512x_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle));
58
59 return PCM512x_Deinit(devHandle);
60 }
61
62 /*!
63 * brief set audio data format.
64 *
65 * param handle codec handle.
66 * param mclk master clock frequency in HZ.
67 * param sampleRate sample rate in HZ.
68 * param bitWidth bit width.
69 * return kStatus_Success is success, else configure failed.
70 */
HAL_CODEC_SetFormat(void * handle,uint32_t mclk,uint32_t sampleRate,uint32_t bitWidth)71 status_t HAL_CODEC_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
72 {
73 assert(handle != NULL);
74
75 pcm512x_handle_t *devHandle = (pcm512x_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle));
76
77 return PCM512x_SetFormat(devHandle, mclk, sampleRate, bitWidth);
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_SetVolume(void * handle,uint32_t playChannel,uint32_t volume)88 status_t HAL_CODEC_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_SetMute(void * handle,uint32_t playChannel,bool isMute)101 status_t HAL_CODEC_SetMute(void *handle, uint32_t playChannel, bool isMute)
102 {
103 status_t ret;
104
105 assert(handle != NULL);
106
107 ret = PCM512x_SetMute((pcm512x_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle)), isMute);
108
109 return ret;
110 }
111
112 /*!
113 * brief set audio codec module power.
114 *
115 * param handle codec handle.
116 * param module audio codec module.
117 * param powerOn true is power on, false is power down.
118 * return kStatus_Success is success, else configure failed.
119 */
HAL_CODEC_SetPower(void * handle,uint32_t module,bool powerOn)120 status_t HAL_CODEC_SetPower(void *handle, uint32_t module, bool powerOn)
121 {
122 return kStatus_CODEC_NotSupport;
123 }
124
125 /*!
126 * brief codec set record channel.
127 *
128 * param handle codec handle.
129 * param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value
130 of member in _codec_record_channel.
131 * param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of
132 member in _codec_record_channel.
133
134 * return kStatus_Success is success, else configure failed.
135 */
HAL_CODEC_SetRecordChannel(void * handle,uint32_t leftRecordChannel,uint32_t rightRecordChannel)136 status_t HAL_CODEC_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
137 {
138 return kStatus_CODEC_NotSupport;
139 }
140
141 /*!
142 * brief codec set record source.
143 *
144 * param handle codec handle.
145 * param source audio codec record source, can be a value or combine value of _codec_record_source.
146 *
147 * return kStatus_Success is success, else configure failed.
148 */
HAL_CODEC_SetRecord(void * handle,uint32_t recordSource)149 status_t HAL_CODEC_SetRecord(void *handle, uint32_t recordSource)
150 {
151 return kStatus_CODEC_NotSupport;
152 }
153
154 /*!
155 * brief codec set play source.
156 *
157 * param handle codec handle.
158 * param playSource audio codec play source, can be a value or combine value of _codec_play_source.
159 *
160 * return kStatus_Success is success, else configure failed.
161 */
HAL_CODEC_SetPlay(void * handle,uint32_t playSource)162 status_t HAL_CODEC_SetPlay(void *handle, uint32_t playSource)
163 {
164 return kStatus_CODEC_NotSupport;
165 }
166
167 /*!
168 * brief codec module control.
169 *
170 * param handle codec handle.
171 * param cmd module control cmd, reference _codec_module_ctrl_cmd.
172 * param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine
173 * of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference
174 * codec specific driver for detail configurations.
175 * return kStatus_Success is success, else configure failed.
176 */
HAL_CODEC_ModuleControl(void * handle,uint32_t cmd,uint32_t data)177 status_t HAL_CODEC_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
178 {
179 return kStatus_CODEC_NotSupport;
180 }
181