fsl_codec_common.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2019 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_codec_common.h"
10 /*******************************************************************************
11  * Definitions
12  ******************************************************************************/
14 #define GET_PLAY_CHANNEL_CAPABILITY(capability) (capability & 0xFFU)
15 #define GET_PLAY_SOURCE_CAPABILITY(capability) (capability >> 8U)
16 #define GET_RECORD_SOURCE_CAPABILITY(capability) (capability & 0x3FU)
17 #define GET_RECORD_CHANNEL_CAPABILITY(capability) (capability >> 6U)
18 /*******************************************************************************
19  * Variables
20  ******************************************************************************/
21 
22 /*******************************************************************************
23  * Code
24  ******************************************************************************/
33 {
34  assert((config != NULL) && (handle != NULL));
35 
36  /* Set the handle information */
37  handle->codecConfig = config;
38 
39  return HAL_CODEC_Init(handle, config);
40 }
41 
49 {
50  assert((handle != NULL) && (handle->codecConfig != NULL));
51 
52  return HAL_CODEC_Deinit(handle);
53 }
54 
64 status_t CODEC_SetFormat(codec_handle_t *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
65 {
66  assert((handle != NULL) && (handle->codecConfig != NULL));
67 
68  return HAL_CODEC_SetFormat(handle, mclk, sampleRate, bitWidth);
69 }
70 
85 {
86  assert((handle != NULL) && (handle->codecConfig != NULL));
87  assert(handle->codecCapability != NULL);
88 
89  switch (cmd)
90  {
93  {
95  }
96  break;
97 
98  default:
100  }
101 
102  return HAL_CODEC_ModuleControl(handle, (uint32_t)cmd, data);
103 }
104 
113 status_t CODEC_SetVolume(codec_handle_t *handle, uint32_t playChannel, uint32_t volume)
114 {
115  assert((handle != NULL) && (handle->codecConfig != NULL));
116  assert(volume <= CODEC_VOLUME_MAX_VALUE);
117  assert(handle->codecCapability != NULL);
118 
119  /* check capability of set volume */
120  if ((GET_PLAY_CHANNEL_CAPABILITY(handle->codecCapability->codecPlayCapability) & playChannel) == 0U)
121  {
123  }
124 
125  return HAL_CODEC_SetVolume(handle, playChannel, volume);
126 }
127 
136 status_t CODEC_SetMute(codec_handle_t *handle, uint32_t playChannel, bool mute)
137 {
138  assert((handle != NULL) && (handle->codecConfig != NULL));
139  assert(handle->codecCapability != NULL);
140 
141  /* check capability of mute */
142  if ((GET_PLAY_CHANNEL_CAPABILITY(handle->codecCapability->codecPlayCapability) & playChannel) == 0U)
143  {
145  }
146 
147  return HAL_CODEC_SetMute(handle, playChannel, mute);
148 }
149 
158 status_t CODEC_SetPower(codec_handle_t *handle, codec_module_t module, bool powerOn)
159 {
160  assert((handle != NULL) && (handle->codecConfig != NULL));
161  assert(handle->codecCapability != NULL);
162 
163  /* check capability of power switch */
164  if ((handle->codecCapability->codecModuleCapability & (1U << module)) == 0U)
165  {
167  }
168 
169  return HAL_CODEC_SetPower(handle, (uint32_t)module, powerOn);
170 }
171 
180 status_t CODEC_SetRecord(codec_handle_t *handle, uint32_t recordSource)
181 {
182  assert((handle != NULL) && (handle->codecConfig != NULL));
183  assert(handle->codecCapability != NULL);
184 
185  /* check capability of record capability */
186  if ((GET_RECORD_SOURCE_CAPABILITY(handle->codecCapability->codecRecordCapability) & recordSource) == 0U)
187  {
189  }
190 
191  return HAL_CODEC_SetRecord(handle, recordSource);
192 }
193 
205 status_t CODEC_SetRecordChannel(codec_handle_t *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
206 {
207  assert((handle != NULL) && (handle->codecConfig != NULL));
208  assert(handle->codecCapability != NULL);
209 
210  /* check capability of record capability */
211  if ((GET_RECORD_CHANNEL_CAPABILITY(handle->codecCapability->codecRecordCapability) & leftRecordChannel) == 0U)
212  {
214  }
215 
216  if ((GET_RECORD_CHANNEL_CAPABILITY(handle->codecCapability->codecRecordCapability) & rightRecordChannel) == 0U)
217  {
219  }
220 
221  return HAL_CODEC_SetRecordChannel(handle, leftRecordChannel, rightRecordChannel);
222 }
223 
232 status_t CODEC_SetPlay(codec_handle_t *handle, uint32_t playSource)
233 {
234  assert((handle != NULL) && (handle->codecConfig != NULL));
235  assert(handle->codecCapability != NULL);
236 
237  /* check capability of record capability */
238  if ((GET_PLAY_SOURCE_CAPABILITY(handle->codecCapability->codecPlayCapability) & playSource) == 0U)
239  {
241  }
242 
243  return HAL_CODEC_SetPlay(handle, playSource);
244 }
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
GET_RECORD_SOURCE_CAPABILITY
#define GET_RECORD_SOURCE_CAPABILITY(capability)
Definition: fsl_codec_common.c:16
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_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
_codec_handle::codecConfig
codec_config_t * codecConfig
Definition: fsl_codec_common.h:242
codec_module_ctrl_cmd_t
enum _codec_module_ctrl_cmd codec_module_ctrl_cmd_t
audio codec module control cmd
GET_RECORD_CHANNEL_CAPABILITY
#define GET_RECORD_CHANNEL_CAPABILITY(capability)
Definition: fsl_codec_common.c:17
kCODEC_ModuleSwitchI2SInInterface
@ kCODEC_ModuleSwitchI2SInInterface
Definition: fsl_codec_common.h:100
CODEC_VOLUME_MAX_VALUE
#define CODEC_VOLUME_MAX_VALUE
codec maximum volume range
Definition: fsl_codec_common.h:29
CODEC_SetFormat
status_t CODEC_SetFormat(codec_handle_t *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth)
set audio data format.
Definition: fsl_codec_common.c:64
kCODEC_SupportModuleI2SInSwitchInterface
@ kCODEC_SupportModuleI2SInSwitchInterface
Definition: fsl_codec_common.h:185
CODEC_Init
status_t CODEC_Init(codec_handle_t *handle, codec_config_t *config)
Codec initilization.
Definition: fsl_codec_common.c:32
fsl_codec_common.h
CODEC_SetRecordChannel
status_t CODEC_SetRecordChannel(codec_handle_t *handle, uint32_t leftRecordChannel, uint32_t rightRecordChannel)
codec set record channel.
Definition: fsl_codec_common.c:205
HAL_CODEC_Deinit
status_t HAL_CODEC_Deinit(void *handle)
Codec de-initilization.
Definition: fsl_codec_adapter.c:102
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
CODEC_ModuleControl
status_t CODEC_ModuleControl(codec_handle_t *handle, codec_module_ctrl_cmd_t cmd, uint32_t data)
codec module control.
Definition: fsl_codec_common.c:84
_codec_handle::codecCapability
const codec_capability_t * codecCapability
Definition: fsl_codec_common.h:243
kStatus_CODEC_NotSupport
@ kStatus_CODEC_NotSupport
Definition: fsl_codec_common.h:34
codec_module_t
enum _codec_module codec_module_t
audio codec module
CODEC_SetRecord
status_t CODEC_SetRecord(codec_handle_t *handle, uint32_t recordSource)
codec set record source.
Definition: fsl_codec_common.c:180
CODEC_Deinit
status_t CODEC_Deinit(codec_handle_t *handle)
Codec de-initilization.
Definition: fsl_codec_common.c:48
GET_PLAY_SOURCE_CAPABILITY
#define GET_PLAY_SOURCE_CAPABILITY(capability)
Definition: fsl_codec_common.c:15
HAL_CODEC_SetPlay
status_t HAL_CODEC_SetPlay(void *handle, uint32_t playSource)
codec set play source.
Definition: fsl_codec_adapter.c:237
CODEC_SetMute
status_t CODEC_SetMute(codec_handle_t *handle, uint32_t playChannel, bool mute)
set audio codec module mute.
Definition: fsl_codec_common.c:136
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
CODEC_SetPlay
status_t CODEC_SetPlay(codec_handle_t *handle, uint32_t playSource)
codec set play source.
Definition: fsl_codec_common.c:232
_codec_capability::codecRecordCapability
uint32_t codecRecordCapability
Definition: fsl_codec_common.h:232
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
cmd
string cmd
HAL_CODEC_SetRecord
status_t HAL_CODEC_SetRecord(void *handle, uint32_t recordSource)
codec set record source.
Definition: fsl_codec_adapter.c:224
CODEC_SetPower
status_t CODEC_SetPower(codec_handle_t *handle, codec_module_t module, bool powerOn)
set audio codec power.
Definition: fsl_codec_common.c:158
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:189
CODEC_SetVolume
status_t CODEC_SetVolume(codec_handle_t *handle, uint32_t playChannel, uint32_t volume)
set audio codec pl volume.
Definition: fsl_codec_common.c:113
HAL_CODEC_Init
status_t HAL_CODEC_Init(void *handle, void *config)
Codec initilization.
Definition: fsl_codec_adapter.c:81
_codec_handle
Codec handle definition.
Definition: fsl_codec_common.h:240
_codec_capability::codecModuleCapability
uint32_t codecModuleCapability
Definition: fsl_codec_common.h:230
GET_PLAY_CHANNEL_CAPABILITY
#define GET_PLAY_CHANNEL_CAPABILITY(capability)
codec play and record capability
Definition: fsl_codec_common.c:14


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