1 /*
2  * Copyright  2021 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_codec_ak4497_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_ak4497_capability = {
24     .codecModuleCapability = kCODEC_SupportModuleI2SInSwitchInterface,
25 };
26 /*******************************************************************************
27  * Code
28  ******************************************************************************/
29 /*!
30  * brief Codec initilization.
31  *
32  * param handle codec handle.
33  * param config codec configuration.
34  * return kStatus_Success is success, else initial failed.
35  */
HAL_CODEC_AK4497_Init(void * handle,void * config)36 status_t HAL_CODEC_AK4497_Init(void *handle, void *config)
37 {
38     assert((config != NULL) && (handle != NULL));
39 
40     codec_config_t *codecConfig = (codec_config_t *)config;
41 
42     ak4497_config_t *devConfig = (ak4497_config_t *)(codecConfig->codecDevConfig);
43     ak4497_handle_t *devHandle = (ak4497_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle));
44 
45     ((codec_handle_t *)handle)->codecCapability = &s_ak4497_capability;
46 
47     /* codec device initialization */
48     return AK4497_Init(devHandle, devConfig);
49 }
50 
51 /*!
52  * brief Codec de-initilization.
53  *
54  * param handle codec handle.
55  * return kStatus_Success is success, else de-initial failed.
56  */
HAL_CODEC_AK4497_Deinit(void * handle)57 status_t HAL_CODEC_AK4497_Deinit(void *handle)
58 {
59     assert(handle != NULL);
60 
61     return AK4497_Deinit((ak4497_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)));
62 }
63 
64 /*!
65  * brief set audio data format.
66  *
67  * param handle codec handle.
68  * param mclk master clock frequency in HZ.
69  * param sampleRate sample rate in HZ.
70  * param bitWidth bit width.
71  * return kStatus_Success is success, else configure failed.
72  */
HAL_CODEC_AK4497_SetFormat(void * handle,uint32_t mclk,uint32_t sampleRate,uint32_t bitWidth)73 status_t HAL_CODEC_AK4497_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
74 {
75     assert(handle != NULL);
76 
77     return AK4497_ConfigDataFormat((ak4497_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)), mclk,
78                                    sampleRate, bitWidth);
79 }
80 
81 /*!
82  * brief set audio codec module volume.
83  *
84  * param handle codec handle.
85  * param channel audio codec play channel, can be a value or combine value of _codec_play_channel.
86  * param volume volume value, support 0 ~ 100, 0 is mute, 100 is the maximum volume value.
87  * return kStatus_Success is success, else configure failed.
88  */
HAL_CODEC_AK4497_SetVolume(void * handle,uint32_t playChannel,uint32_t volume)89 status_t HAL_CODEC_AK4497_SetVolume(void *handle, uint32_t playChannel, uint32_t volume)
90 {
91     return kStatus_CODEC_NotSupport;
92 }
93 
94 /*!
95  * brief set audio codec module mute.
96  *
97  * param handle codec handle.
98  * param channel audio codec play channel, can be a value or combine value of _codec_play_channel.
99  * param isMute true is mute, false is unmute.
100  * return kStatus_Success is success, else configure failed.
101  */
HAL_CODEC_AK4497_SetMute(void * handle,uint32_t playChannel,bool isMute)102 status_t HAL_CODEC_AK4497_SetMute(void *handle, uint32_t playChannel, bool isMute)
103 {
104     return kStatus_CODEC_NotSupport;
105 }
106 
107 /*!
108  * brief set audio codec module power.
109  *
110  * param handle codec handle.
111  * param module audio codec module.
112  * param powerOn true is power on, false is power down.
113  * return kStatus_Success is success, else configure failed.
114  */
HAL_CODEC_AK4497_SetPower(void * handle,uint32_t module,bool powerOn)115 status_t HAL_CODEC_AK4497_SetPower(void *handle, uint32_t module, bool powerOn)
116 {
117     return kStatus_CODEC_NotSupport;
118 }
119 
120 /*!
121  * brief codec set record source.
122  *
123  * param handle codec handle.
124  * param source audio codec record source, can be a value or combine value of _codec_record_source.
125  *
126  * return kStatus_Success is success, else configure failed.
127  */
HAL_CODEC_AK4497_SetRecord(void * handle,uint32_t recordSource)128 status_t HAL_CODEC_AK4497_SetRecord(void *handle, uint32_t recordSource)
129 {
130     return kStatus_CODEC_NotSupport;
131 }
132 
133 /*!
134  * brief codec set record channel.
135  *
136  * param handle codec handle.
137  * param leftRecordChannel audio codec record channel, reference _codec_record_channel, can be a value or combine value
138  of member in _codec_record_channel.
139  * param rightRecordChannel audio codec record channel, reference _codec_record_channel, can be a value combine of
140  member in _codec_record_channel.
141 
142  * return kStatus_Success is success, else configure failed.
143  */
HAL_CODEC_AK4497_SetRecordChannel(void * handle,uint32_t leftRecordChannel,uint32_t rightRecordChannel)144 status_t HAL_CODEC_AK4497_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
145 {
146     return kStatus_CODEC_NotSupport;
147 }
148 
149 /*!
150  * brief codec set play source.
151  *
152  * param handle codec handle.
153  * param playSource audio codec play source, can be a value or combine value of _codec_play_source.
154  *
155  * return kStatus_Success is success, else configure failed.
156  */
HAL_CODEC_AK4497_SetPlay(void * handle,uint32_t playSource)157 status_t HAL_CODEC_AK4497_SetPlay(void *handle, uint32_t playSource)
158 {
159     return kStatus_CODEC_NotSupport;
160 }
161 
162 /*!
163  * brief codec module control.
164  *
165  * param handle codec handle.
166  * param cmd module control cmd, reference _codec_module_ctrl_cmd.
167  * param data value to write.
168  *  codec specific driver for detail configurations.
169  * return kStatus_Success is success, else configure failed.
170  */
HAL_CODEC_AK4497_ModuleControl(void * handle,uint32_t cmd,uint32_t data)171 status_t HAL_CODEC_AK4497_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
172 {
173     assert(cmd == (uint32_t)kCODEC_ModuleSwitchI2SInInterface);
174 
175     return AK4497_ModuleControl((ak4497_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)),
176                                 (ak4497_module_ctrl_cmd_t)cmd, data);
177 }
178