fsl_codec_adapter.c
Go to the documentation of this file.
1 /*
2  * Copyright 2019 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_codec_adapter.h"
10 #include "fsl_codec_common.h"
11 /*******************************************************************************
12  * Definitions
13  ******************************************************************************/
15 #define HAL_WM8960_MODULE_CAPABILITY \
16  (kCODEC_SupportModuleADC | kCODEC_SupportModuleDAC | kCODEC_SupportModulePGA | kCODEC_SupportModuleHeadphone | \
17  kCODEC_SupportModuleLineout | kCODEC_SupportModuleSpeaker)
18 
19 #define HAL_WM8960_PLAY_CAPABILITY \
20  (kCODEC_SupportPlayChannelLeft0 | kCODEC_SupportPlayChannelRight0 | kCODEC_SupportPlayChannelLeft1 | \
21  kCODEC_SupportPlayChannelRight1 | kCODEC_SupportPlaySourcePGA | kCODEC_SupportPlaySourceDAC | \
22  kCODEC_SupportPlaySourceInput)
23 
24 #define HAL_WM8960_RECORD_CAPABILITY \
25  (kCODEC_SupportPlayChannelLeft0 | kCODEC_SupportPlayChannelLeft1 | kCODEC_SupportPlayChannelLeft2 | \
26  kCODEC_SupportPlayChannelRight0 | kCODEC_SupportPlayChannelRight1 | kCODEC_SupportPlayChannelRight2)
27 
29 #define HAL_WM8960_MAP_PROTOCOL(protocol) \
30  (protocol == kCODEC_BusI2S ? \
31  kWM8960_BusI2S : \
32  protocol == kCODEC_BusLeftJustified ? \
33  kWM8960_BusLeftJustified : \
34  protocol == kCODEC_BusRightJustified ? \
35  kWM8960_BusRightJustified : \
36  protocol == kCODEC_BusPCMA ? kWM8960_BusPCMA : protocol == kCODEC_BusPCMB ? kWM8960_BusPCMB : kWM8960_BusI2S)
37 
39 #define HAL_WM8960_MAP_MODULE(module) \
40  (module == kCODEC_ModuleADC ? \
41  kWM8960_ModuleADC : \
42  module == kCODEC_ModuleDAC ? \
43  kWM8960_ModuleDAC : \
44  module == kCODEC_ModuleVref ? \
45  kWM8960_ModuleVREF : \
46  module == kCODEC_ModuleHeadphone ? \
47  kWM8960_ModuleHP : \
48  module == kCODEC_ModuleMicbias ? \
49  kWM8960_ModuleMICB : \
50  module == kCODEC_ModuleMic ? \
51  kWM8960_ModuleMIC : \
52  module == kCODEC_ModuleLinein ? \
53  kWM8960_ModuleLineIn : \
54  module == kCODEC_ModuleSpeaker ? \
55  kWM8960_ModuleSpeaker : \
56  module == kCODEC_ModuleMxier ? kWM8960_ModuleOMIX : \
57  module == kCODEC_ModuleLineout ? kWM8960_ModuleLineOut : kWM8960_ModuleADC)
58 
59 /*******************************************************************************
60  * Prototypes
61  ******************************************************************************/
62 
63 /*******************************************************************************
64  * Variables
65  ******************************************************************************/
68  .codecModuleCapability = HAL_WM8960_MODULE_CAPABILITY,
69  .codecRecordCapability = HAL_WM8960_RECORD_CAPABILITY,
70 };
71 /*******************************************************************************
72  * Code
73  ******************************************************************************/
81 status_t HAL_CODEC_Init(void *handle, void *config)
82 {
83  assert((config != NULL) && (handle != NULL));
84 
85  codec_config_t *codecConfig = (codec_config_t *)config;
86 
87  wm8960_config_t *wm8960Config = (wm8960_config_t *)(codecConfig->codecDevConfig);
88  wm8960_handle_t *wm8960Handle = (wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle));
89 
90  ((codec_handle_t *)handle)->codecCapability = &s_wm8960_capability;
91 
92  /* codec device initialization */
93  return WM8960_Init(wm8960Handle, wm8960Config);
94 }
95 
103 {
104  assert(handle != NULL);
105 
106  return WM8960_Deinit((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)));
107 }
108 
118 status_t HAL_CODEC_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
119 {
120  assert(handle != NULL);
121 
122  return WM8960_ConfigDataFormat((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)), mclk,
123  sampleRate, bitWidth);
124 }
125 
134 status_t HAL_CODEC_SetVolume(void *handle, uint32_t playChannel, uint32_t volume)
135 {
136  assert(handle != NULL);
137 
138  status_t retVal = kStatus_Success;
139 
140  if ((playChannel & kWM8960_HeadphoneLeft) || (playChannel & kWM8960_HeadphoneRight))
141  {
142  retVal = WM8960_SetVolume((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)),
143  kWM8960_ModuleHP, volume);
144  }
145 
146  if ((playChannel & kWM8960_SpeakerLeft) || (playChannel & kWM8960_SpeakerRight))
147  {
148  retVal = WM8960_SetVolume((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)),
149  kWM8960_ModuleSpeaker, volume);
150  }
151 
152  return retVal;
153 }
154 
163 status_t HAL_CODEC_SetMute(void *handle, uint32_t playChannel, bool isMute)
164 {
165  assert(handle != NULL);
166 
167  status_t retVal = kStatus_Success;
168 
169  if ((playChannel & kWM8960_HeadphoneLeft) || (playChannel & kWM8960_HeadphoneRight))
170  {
171  retVal = WM8960_SetMute((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)),
172  kWM8960_ModuleHP, isMute);
173  }
174 
175  if ((playChannel & kWM8960_SpeakerLeft) || (playChannel & kWM8960_SpeakerRight))
176  {
177  retVal = WM8960_SetMute((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)),
178  kWM8960_ModuleSpeaker, isMute);
179  }
180 
181  return retVal;
182 }
183 
192 status_t HAL_CODEC_SetPower(void *handle, uint32_t module, bool powerOn)
193 {
194  assert(handle != NULL);
195 
196  return WM8960_SetModule((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)),
197  HAL_WM8960_MAP_MODULE(module), powerOn);
198 }
199 
211 status_t HAL_CODEC_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
212 {
214 }
215 
224 status_t HAL_CODEC_SetRecord(void *handle, uint32_t recordSource)
225 {
227 }
228 
237 status_t HAL_CODEC_SetPlay(void *handle, uint32_t playSource)
238 {
239  assert(handle != NULL);
240 
241  return WM8960_SetPlay((wm8960_handle_t *)((uint32_t)(((codec_handle_t *)handle)->codecDevHandle)), playSource);
242 }
243 
254 status_t HAL_CODEC_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
255 {
257 }
HAL_CODEC_SetPower
status_t HAL_CODEC_SetPower(void *handle, uint32_t module, bool powerOn)
set audio codec module power.
Definition: fsl_codec_adapter.c:192
WM8960_SetVolume
status_t WM8960_SetVolume(wm8960_handle_t *handle, wm8960_module_t module, uint32_t volume)
Set the volume of different modules in WM8960.
Definition: fsl_wm8960.c:378
_codec_config::codecDevConfig
void * codecDevConfig
Definition: fsl_codec_common.h:224
WM8960_SetMute
status_t WM8960_SetMute(wm8960_handle_t *handle, wm8960_module_t module, bool isEnabled)
Mute modules in WM8960.
Definition: fsl_wm8960.c:460
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
HAL_CODEC_SetVolume
status_t HAL_CODEC_SetVolume(void *handle, uint32_t playChannel, uint32_t volume)
set audio codec module volume.
Definition: fsl_codec_adapter.c:134
_codec_config
Initialize structure of the codec.
Definition: fsl_codec_common.h:221
_codec_capability::codecPlayCapability
uint32_t codecPlayCapability
Definition: fsl_codec_common.h:231
HAL_WM8960_PLAY_CAPABILITY
#define HAL_WM8960_PLAY_CAPABILITY
Definition: fsl_codec_adapter.c:19
WM8960_SetModule
status_t WM8960_SetModule(wm8960_handle_t *handle, wm8960_module_t module, bool isEnabled)
Enable/disable expected devices.
Definition: fsl_wm8960.c:140
HAL_CODEC_SetFormat
status_t HAL_CODEC_SetFormat(void *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
set audio data format.
Definition: fsl_codec_adapter.c:118
HAL_WM8960_MODULE_CAPABILITY
#define HAL_WM8960_MODULE_CAPABILITY
module capability definition
Definition: fsl_codec_adapter.c:15
fsl_codec_common.h
WM8960_ConfigDataFormat
status_t WM8960_ConfigDataFormat(wm8960_handle_t *handle, uint32_t sysclk, uint32_t sample_rate, uint32_t bits)
Configure the data format of audio data.
Definition: fsl_wm8960.c:533
HAL_CODEC_Deinit
status_t HAL_CODEC_Deinit(void *handle)
Codec de-initilization.
Definition: fsl_codec_adapter.c:102
HAL_WM8960_RECORD_CAPABILITY
#define HAL_WM8960_RECORD_CAPABILITY
Definition: fsl_codec_adapter.c:24
HAL_CODEC_ModuleControl
status_t HAL_CODEC_ModuleControl(void *handle, uint32_t cmd, uint32_t data)
codec module control.
Definition: fsl_codec_adapter.c:254
kWM8960_SpeakerRight
@ kWM8960_SpeakerRight
Definition: fsl_wm8960.h:221
kStatus_CODEC_NotSupport
@ kStatus_CODEC_NotSupport
Definition: fsl_codec_common.h:34
kWM8960_HeadphoneLeft
@ kWM8960_HeadphoneLeft
Definition: fsl_wm8960.h:218
kWM8960_SpeakerLeft
@ kWM8960_SpeakerLeft
Definition: fsl_wm8960.h:220
WM8960_SetPlay
status_t WM8960_SetPlay(wm8960_handle_t *handle, uint32_t playSource)
SET the WM8960 play source.
Definition: fsl_wm8960.c:649
kWM8960_ModuleHP
@ kWM8960_ModuleHP
Definition: fsl_wm8960.h:206
HAL_CODEC_SetPlay
status_t HAL_CODEC_SetPlay(void *handle, uint32_t playSource)
codec set play source.
Definition: fsl_codec_adapter.c:237
wm8960_config
Initialize structure of WM8960.
Definition: fsl_wm8960.h:304
_codec_capability
codec capability
Definition: fsl_codec_common.h:228
WM8960_Init
status_t WM8960_Init(wm8960_handle_t *handle, const wm8960_config_t *wm8960Config)
WM8960 initialize function.
Definition: fsl_wm8960.c:38
HAL_CODEC_SetMute
status_t HAL_CODEC_SetMute(void *handle, uint32_t playChannel, bool isMute)
set audio codec module mute.
Definition: fsl_codec_adapter.c:163
s_wm8960_capability
static const codec_capability_t s_wm8960_capability
Definition: fsl_codec_adapter.c:66
fsl_codec_adapter.h
_wm8960_handle
wm8960 codec handler
Definition: fsl_wm8960.h:320
config
static sai_transceiver_t config
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:75
HAL_CODEC_SetRecordChannel
status_t HAL_CODEC_SetRecordChannel(void *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
codec set record channel.
Definition: fsl_codec_adapter.c:211
HAL_CODEC_SetRecord
status_t HAL_CODEC_SetRecord(void *handle, uint32_t recordSource)
codec set record source.
Definition: fsl_codec_adapter.c:224
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:189
kStatus_Success
@ kStatus_Success
Definition: fsl_common.h:179
kWM8960_HeadphoneRight
@ kWM8960_HeadphoneRight
Definition: fsl_wm8960.h:219
HAL_CODEC_Init
status_t HAL_CODEC_Init(void *handle, void *config)
Codec initilization.
Definition: fsl_codec_adapter.c:81
HAL_WM8960_MAP_MODULE
#define HAL_WM8960_MAP_MODULE(module)
wm8960 map module
Definition: fsl_codec_adapter.c:39
_codec_handle
Codec handle definition.
Definition: fsl_codec_common.h:240
kWM8960_ModuleSpeaker
@ kWM8960_ModuleSpeaker
Definition: fsl_wm8960.h:211
WM8960_Deinit
status_t WM8960_Deinit(wm8960_handle_t *handle)
Deinit the WM8960 codec.
Definition: fsl_wm8960.c:116


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:56