1 /*
2  * Copyright  2021 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include "fsl_codec_pcm186x_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_pcm186x_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_PCM186x_Init(void * handle,void * config)32 status_t HAL_CODEC_PCM186x_Init(void *handle, void *config)
33 {
34     assert((config != NULL) && (handle != NULL));
35 
36     codec_config_t *codecConfig = (codec_config_t *)config;
37 
38     pcm186x_config_t *devConfig = (pcm186x_config_t *)(codecConfig->codecDevConfig);
39     pcm186x_handle_t *devHandle = (pcm186x_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle));
40 
41     ((codec_handle_t *)handle)->codecCapability = &s_pcm186x_capability;
42 
43     /* codec device initialization */
44     return PCM186x_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_PCM186x_Deinit(void * handle)53 status_t HAL_CODEC_PCM186x_Deinit(void *handle)
54 {
55     assert (handle != NULL);
56 
57     pcm186x_handle_t *devHandle = (pcm186x_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle));
58 
59     return PCM186x_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_PCM186x_SetFormat(void * handle,uint32_t mclk,uint32_t sampleRate,uint32_t bitWidth)71 status_t HAL_CODEC_PCM186x_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
72 {
73     assert(handle != NULL);
74 
75     pcm186x_handle_t *devHandle = (pcm186x_handle_t *)((uintptr_t)(((codec_handle_t *)handle)->codecDevHandle));
76 
77     return PCM186x_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_PCM186x_SetVolume(void * handle,uint32_t playChannel,uint32_t volume)88 status_t HAL_CODEC_PCM186x_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_PCM186x_SetMute(void * handle,uint32_t playChannel,bool isMute)101 status_t HAL_CODEC_PCM186x_SetMute(void *handle, uint32_t playChannel, bool isMute)
102 {
103     return kStatus_CODEC_NotSupport;
104 }
105 
106 /*!
107  * brief set audio codec module power.
108  *
109  * param handle codec handle.
110  * param module audio codec module.
111  * param powerOn true is power on, false is power down.
112  * return kStatus_Success is success, else configure failed.
113  */
HAL_CODEC_PCM186x_SetPower(void * handle,uint32_t module,bool powerOn)114 status_t HAL_CODEC_PCM186x_SetPower(void *handle, uint32_t module, bool powerOn)
115 {
116     return kStatus_CODEC_NotSupport;
117 }
118 
119 /*!
120  * brief codec set record channel.
121  *
122  * param handle codec handle.
123  * param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value
124  of member in _codec_record_channel.
125  * param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of
126  member in _codec_record_channel.
127 
128  * return kStatus_Success is success, else configure failed.
129  */
HAL_CODEC_PCM186x_SetRecordChannel(void * handle,uint32_t leftRecordChannel,uint32_t rightRecordChannel)130 status_t HAL_CODEC_PCM186x_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
131 {
132     return kStatus_CODEC_NotSupport;
133 }
134 
135 /*!
136  * brief codec set record source.
137  *
138  * param handle codec handle.
139  * param source audio codec record source, can be a value or combine value of _codec_record_source.
140  *
141  * return kStatus_Success is success, else configure failed.
142  */
HAL_CODEC_PCM186x_SetRecord(void * handle,uint32_t recordSource)143 status_t HAL_CODEC_PCM186x_SetRecord(void *handle, uint32_t recordSource)
144 {
145     return kStatus_CODEC_NotSupport;
146 }
147 
148 /*!
149  * brief codec set play source.
150  *
151  * param handle codec handle.
152  * param playSource audio codec play source, can be a value or combine value of _codec_play_source.
153  *
154  * return kStatus_Success is success, else configure failed.
155  */
HAL_CODEC_PCM186x_SetPlay(void * handle,uint32_t playSource)156 status_t HAL_CODEC_PCM186x_SetPlay(void *handle, uint32_t playSource)
157 {
158     return kStatus_CODEC_NotSupport;
159 }
160 
161 /*!
162  * brief codec module control.
163  *
164  * param handle codec handle.
165  * param cmd module control cmd, reference _codec_module_ctrl_cmd.
166  * param data value to write, when cmd is kCODEC_ModuleRecordSourceChannel, the data should be a value combine
167  *  of channel and source, please reference macro CODEC_MODULE_RECORD_SOURCE_CHANNEL(source, LP, LN, RP, RN), reference
168  *  codec specific driver for detail configurations.
169  * return kStatus_Success is success, else configure failed.
170  */
HAL_CODEC_PCM186x_ModuleControl(void * handle,uint32_t cmd,uint32_t data)171 status_t HAL_CODEC_PCM186x_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
172 {
173     return kStatus_CODEC_NotSupport;
174 }
175