BSP files for STM32H747I-Discovery Copy from ST Cube delivery
Dependents: DISCO_H747I_LCD_demo DISCO_H747I_AUDIO_demo
Components/wm8994/wm8994.c@0:146cf26a9bbb, 2019-09-25 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Wed Sep 25 13:37:39 2019 +0200
- Revision:
- 0:146cf26a9bbb
STM32Cube_FW_H7_V1.5.0 BSP STM32H747I-DISCO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jerome Coutant
0:146cf26a9bbb
|
1
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
2
|
******************************************************************************
|
|
Jerome Coutant
0:146cf26a9bbb
|
3
|
* @file wm8994.c
|
|
Jerome Coutant
0:146cf26a9bbb
|
4
|
* @author MCD Application Team
|
|
Jerome Coutant
0:146cf26a9bbb
|
5
|
* @version V2.1.0
|
|
Jerome Coutant
0:146cf26a9bbb
|
6
|
* @date 22-February-2016
|
|
Jerome Coutant
0:146cf26a9bbb
|
7
|
* @brief This file provides the WM8994 Audio Codec driver.
|
|
Jerome Coutant
0:146cf26a9bbb
|
8
|
******************************************************************************
|
|
Jerome Coutant
0:146cf26a9bbb
|
9
|
* @attention
|
|
Jerome Coutant
0:146cf26a9bbb
|
10
|
*
|
|
Jerome Coutant
0:146cf26a9bbb
|
11
|
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
|
Jerome Coutant
0:146cf26a9bbb
|
12
|
*
|
|
Jerome Coutant
0:146cf26a9bbb
|
13
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
Jerome Coutant
0:146cf26a9bbb
|
14
|
* are permitted provided that the following conditions are met:
|
|
Jerome Coutant
0:146cf26a9bbb
|
15
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
Jerome Coutant
0:146cf26a9bbb
|
16
|
* this list of conditions and the following disclaimer.
|
|
Jerome Coutant
0:146cf26a9bbb
|
17
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
Jerome Coutant
0:146cf26a9bbb
|
18
|
* this list of conditions and the following disclaimer in the documentation
|
|
Jerome Coutant
0:146cf26a9bbb
|
19
|
* and/or other materials provided with the distribution.
|
|
Jerome Coutant
0:146cf26a9bbb
|
20
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
Jerome Coutant
0:146cf26a9bbb
|
21
|
* may be used to endorse or promote products derived from this software
|
|
Jerome Coutant
0:146cf26a9bbb
|
22
|
* without specific prior written permission.
|
|
Jerome Coutant
0:146cf26a9bbb
|
23
|
*
|
|
Jerome Coutant
0:146cf26a9bbb
|
24
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Jerome Coutant
0:146cf26a9bbb
|
25
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Jerome Coutant
0:146cf26a9bbb
|
26
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Jerome Coutant
0:146cf26a9bbb
|
27
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
Jerome Coutant
0:146cf26a9bbb
|
28
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Jerome Coutant
0:146cf26a9bbb
|
29
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Jerome Coutant
0:146cf26a9bbb
|
30
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
Jerome Coutant
0:146cf26a9bbb
|
31
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Jerome Coutant
0:146cf26a9bbb
|
32
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Jerome Coutant
0:146cf26a9bbb
|
33
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Jerome Coutant
0:146cf26a9bbb
|
34
|
*
|
|
Jerome Coutant
0:146cf26a9bbb
|
35
|
******************************************************************************
|
|
Jerome Coutant
0:146cf26a9bbb
|
36
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
37
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
38
|
/* Includes ------------------------------------------------------------------*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
39
|
#include "wm8994.h"
|
|
Jerome Coutant
0:146cf26a9bbb
|
40
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
41
|
/** @addtogroup BSP
|
|
Jerome Coutant
0:146cf26a9bbb
|
42
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
43
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
44
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
45
|
/** @addtogroup Components
|
|
Jerome Coutant
0:146cf26a9bbb
|
46
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
47
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
48
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
49
|
/** @addtogroup wm8994
|
|
Jerome Coutant
0:146cf26a9bbb
|
50
|
* @brief This file provides a set of functions needed to drive the
|
|
Jerome Coutant
0:146cf26a9bbb
|
51
|
* WM8994 audio codec.
|
|
Jerome Coutant
0:146cf26a9bbb
|
52
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
53
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
54
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
55
|
/** @defgroup WM8994_Private_Types
|
|
Jerome Coutant
0:146cf26a9bbb
|
56
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
57
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
58
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
59
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
60
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
61
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
62
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
63
|
/** @defgroup WM8994_Private_Defines
|
|
Jerome Coutant
0:146cf26a9bbb
|
64
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
65
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
66
|
/* Uncomment this line to enable verifying data sent to codec after each write
|
|
Jerome Coutant
0:146cf26a9bbb
|
67
|
operation (for debug purpose) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
68
|
#if !defined (VERIFY_WRITTENDATA)
|
|
Jerome Coutant
0:146cf26a9bbb
|
69
|
/*#define VERIFY_WRITTENDATA*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
70
|
#endif /* VERIFY_WRITTENDATA */
|
|
Jerome Coutant
0:146cf26a9bbb
|
71
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
72
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
73
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
74
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
75
|
/** @defgroup WM8994_Private_Macros
|
|
Jerome Coutant
0:146cf26a9bbb
|
76
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
77
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
78
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
79
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
80
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
81
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
82
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
83
|
/** @defgroup WM8994_Private_Variables
|
|
Jerome Coutant
0:146cf26a9bbb
|
84
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
85
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
86
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
87
|
/* Audio codec driver structure initialization */
|
|
Jerome Coutant
0:146cf26a9bbb
|
88
|
AUDIO_DrvTypeDef wm8994_drv =
|
|
Jerome Coutant
0:146cf26a9bbb
|
89
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
90
|
wm8994_Init,
|
|
Jerome Coutant
0:146cf26a9bbb
|
91
|
wm8994_DeInit,
|
|
Jerome Coutant
0:146cf26a9bbb
|
92
|
wm8994_ReadID,
|
|
Jerome Coutant
0:146cf26a9bbb
|
93
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
94
|
wm8994_Play,
|
|
Jerome Coutant
0:146cf26a9bbb
|
95
|
wm8994_Pause,
|
|
Jerome Coutant
0:146cf26a9bbb
|
96
|
wm8994_Resume,
|
|
Jerome Coutant
0:146cf26a9bbb
|
97
|
wm8994_Stop,
|
|
Jerome Coutant
0:146cf26a9bbb
|
98
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
99
|
wm8994_SetFrequency,
|
|
Jerome Coutant
0:146cf26a9bbb
|
100
|
wm8994_SetVolume,
|
|
Jerome Coutant
0:146cf26a9bbb
|
101
|
wm8994_SetMute,
|
|
Jerome Coutant
0:146cf26a9bbb
|
102
|
wm8994_SetOutputMode,
|
|
Jerome Coutant
0:146cf26a9bbb
|
103
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
104
|
wm8994_Reset
|
|
Jerome Coutant
0:146cf26a9bbb
|
105
|
};
|
|
Jerome Coutant
0:146cf26a9bbb
|
106
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
107
|
static uint32_t outputEnabled = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
108
|
static uint32_t inputEnabled = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
109
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
110
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
111
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
112
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
113
|
/** @defgroup WM8994_Function_Prototypes
|
|
Jerome Coutant
0:146cf26a9bbb
|
114
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
115
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
116
|
static uint8_t CODEC_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
|
|
Jerome Coutant
0:146cf26a9bbb
|
117
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
118
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
119
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
120
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
121
|
/** @defgroup WM8994_Private_Functions
|
|
Jerome Coutant
0:146cf26a9bbb
|
122
|
* @{
|
|
Jerome Coutant
0:146cf26a9bbb
|
123
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
124
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
125
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
126
|
* @brief Initializes the audio codec and the control interface.
|
|
Jerome Coutant
0:146cf26a9bbb
|
127
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
128
|
* @param OutputInputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
|
|
Jerome Coutant
0:146cf26a9bbb
|
129
|
* OUTPUT_DEVICE_BOTH, OUTPUT_DEVICE_AUTO, INPUT_DEVICE_DIGITAL_MICROPHONE_1,
|
|
Jerome Coutant
0:146cf26a9bbb
|
130
|
* INPUT_DEVICE_DIGITAL_MICROPHONE_2, INPUT_DEVICE_DIGITAL_MIC1_MIC2,
|
|
Jerome Coutant
0:146cf26a9bbb
|
131
|
* INPUT_DEVICE_INPUT_LINE_1 or INPUT_DEVICE_INPUT_LINE_2.
|
|
Jerome Coutant
0:146cf26a9bbb
|
132
|
* @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
|
|
Jerome Coutant
0:146cf26a9bbb
|
133
|
* @param AudioFreq: Audio Frequency
|
|
Jerome Coutant
0:146cf26a9bbb
|
134
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
135
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
136
|
uint32_t wm8994_Init(uint16_t DeviceAddr, uint16_t OutputInputDevice, uint8_t Volume, uint32_t AudioFreq)
|
|
Jerome Coutant
0:146cf26a9bbb
|
137
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
138
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
139
|
uint16_t output_device = OutputInputDevice & 0xFF;
|
|
Jerome Coutant
0:146cf26a9bbb
|
140
|
uint16_t input_device = OutputInputDevice & 0xFF00;
|
|
Jerome Coutant
0:146cf26a9bbb
|
141
|
uint16_t power_mgnt_reg_1 = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
142
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
143
|
/* Initialize the Control interface of the Audio Codec */
|
|
Jerome Coutant
0:146cf26a9bbb
|
144
|
AUDIO_IO_Init();
|
|
Jerome Coutant
0:146cf26a9bbb
|
145
|
/* wm8994 Errata Work-Arounds */
|
|
Jerome Coutant
0:146cf26a9bbb
|
146
|
counter += CODEC_IO_Write(DeviceAddr, 0x102, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
147
|
counter += CODEC_IO_Write(DeviceAddr, 0x817, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
148
|
counter += CODEC_IO_Write(DeviceAddr, 0x102, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
149
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
150
|
/* Enable VMID soft start (fast), Start-up Bias Current Enabled */
|
|
Jerome Coutant
0:146cf26a9bbb
|
151
|
counter += CODEC_IO_Write(DeviceAddr, 0x39, 0x006C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
152
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
153
|
/* Enable bias generator, Enable VMID */
|
|
Jerome Coutant
0:146cf26a9bbb
|
154
|
if (input_device > 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
155
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
156
|
counter += CODEC_IO_Write(DeviceAddr, 0x01, 0x0013);
|
|
Jerome Coutant
0:146cf26a9bbb
|
157
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
158
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
159
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
160
|
counter += CODEC_IO_Write(DeviceAddr, 0x01, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
161
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
162
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
163
|
/* Add Delay */
|
|
Jerome Coutant
0:146cf26a9bbb
|
164
|
AUDIO_IO_Delay(50);
|
|
Jerome Coutant
0:146cf26a9bbb
|
165
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
166
|
/* Path Configurations for output */
|
|
Jerome Coutant
0:146cf26a9bbb
|
167
|
if (output_device > 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
168
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
169
|
outputEnabled = 1;
|
|
Jerome Coutant
0:146cf26a9bbb
|
170
|
switch (output_device)
|
|
Jerome Coutant
0:146cf26a9bbb
|
171
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
172
|
case OUTPUT_DEVICE_SPEAKER:
|
|
Jerome Coutant
0:146cf26a9bbb
|
173
|
/* Enable DAC1 (Left), Enable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
174
|
Disable DAC2 (Left), Disable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
175
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0C0C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
176
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
177
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
178
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
179
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
180
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
181
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
182
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
183
|
/* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
184
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
185
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
186
|
/* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
187
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
188
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
189
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
190
|
case OUTPUT_DEVICE_HEADPHONE:
|
|
Jerome Coutant
0:146cf26a9bbb
|
191
|
/* Disable DAC1 (Left), Disable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
192
|
Enable DAC2 (Left), Enable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
193
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
|
|
Jerome Coutant
0:146cf26a9bbb
|
194
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
195
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
196
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
197
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
198
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
199
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
200
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
201
|
/* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
202
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
203
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
204
|
/* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
205
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
206
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
207
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
208
|
case OUTPUT_DEVICE_BOTH:
|
|
Jerome Coutant
0:146cf26a9bbb
|
209
|
if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2)
|
|
Jerome Coutant
0:146cf26a9bbb
|
210
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
211
|
/* Enable DAC1 (Left), Enable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
212
|
also Enable DAC2 (Left), Enable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
213
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303 | 0x0C0C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
214
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
215
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path
|
|
Jerome Coutant
0:146cf26a9bbb
|
216
|
Enable the AIF1 Timeslot 1 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
217
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
218
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
219
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path
|
|
Jerome Coutant
0:146cf26a9bbb
|
220
|
Enable the AIF1 Timeslot 1 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
221
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
222
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
223
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 2 (Left) mixer path
|
|
Jerome Coutant
0:146cf26a9bbb
|
224
|
Enable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
225
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
226
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
227
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 2 (Right) mixer path
|
|
Jerome Coutant
0:146cf26a9bbb
|
228
|
Enable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
229
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
230
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
231
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
232
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
233
|
/* Enable DAC1 (Left), Enable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
234
|
also Enable DAC2 (Left), Enable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
235
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303 | 0x0C0C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
236
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
237
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
238
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
239
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
240
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
241
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
242
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
243
|
/* Enable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
244
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
245
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
246
|
/* Enable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
247
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
248
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
249
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
250
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
251
|
case OUTPUT_DEVICE_AUTO :
|
|
Jerome Coutant
0:146cf26a9bbb
|
252
|
default:
|
|
Jerome Coutant
0:146cf26a9bbb
|
253
|
/* Disable DAC1 (Left), Disable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
254
|
Enable DAC2 (Left), Enable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
255
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
|
|
Jerome Coutant
0:146cf26a9bbb
|
256
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
257
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
258
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
259
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
260
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
261
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
262
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
263
|
/* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
264
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
265
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
266
|
/* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
267
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
268
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
269
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
270
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
271
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
272
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
273
|
outputEnabled = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
274
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
275
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
276
|
/* Path Configurations for input */
|
|
Jerome Coutant
0:146cf26a9bbb
|
277
|
if (input_device > 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
278
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
279
|
inputEnabled = 1;
|
|
Jerome Coutant
0:146cf26a9bbb
|
280
|
switch (input_device)
|
|
Jerome Coutant
0:146cf26a9bbb
|
281
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
282
|
case INPUT_DEVICE_DIGITAL_MICROPHONE_2 :
|
|
Jerome Coutant
0:146cf26a9bbb
|
283
|
/* Enable AIF1ADC2 (Left), Enable AIF1ADC2 (Right)
|
|
Jerome Coutant
0:146cf26a9bbb
|
284
|
* Enable DMICDAT2 (Left), Enable DMICDAT2 (Right)
|
|
Jerome Coutant
0:146cf26a9bbb
|
285
|
* Enable Left ADC, Enable Right ADC */
|
|
Jerome Coutant
0:146cf26a9bbb
|
286
|
counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0C30);
|
|
Jerome Coutant
0:146cf26a9bbb
|
287
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
288
|
/* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC2 Left/Right Timeslot 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
289
|
counter += CODEC_IO_Write(DeviceAddr, 0x450, 0x00DB);
|
|
Jerome Coutant
0:146cf26a9bbb
|
290
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
291
|
/* Disable IN1L, IN1R, IN2L, IN2R, Enable Thermal sensor & shutdown */
|
|
Jerome Coutant
0:146cf26a9bbb
|
292
|
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x6000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
293
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
294
|
/* Enable the DMIC2(Left) to AIF1 Timeslot 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
295
|
counter += CODEC_IO_Write(DeviceAddr, 0x608, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
296
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
297
|
/* Enable the DMIC2(Right) to AIF1 Timeslot 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
298
|
counter += CODEC_IO_Write(DeviceAddr, 0x609, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
299
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
300
|
/* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC2 signal detect */
|
|
Jerome Coutant
0:146cf26a9bbb
|
301
|
counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000E);
|
|
Jerome Coutant
0:146cf26a9bbb
|
302
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
303
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
304
|
case INPUT_DEVICE_INPUT_LINE_1 :
|
|
Jerome Coutant
0:146cf26a9bbb
|
305
|
/* IN1LN_TO_IN1L, IN1LP_TO_VMID, IN1RN_TO_IN1R, IN1RP_TO_VMID */
|
|
Jerome Coutant
0:146cf26a9bbb
|
306
|
counter += CODEC_IO_Write(DeviceAddr, 0x28, 0x0011);
|
|
Jerome Coutant
0:146cf26a9bbb
|
307
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
308
|
/* Disable mute on IN1L_TO_MIXINL and +30dB on IN1L PGA output */
|
|
Jerome Coutant
0:146cf26a9bbb
|
309
|
counter += CODEC_IO_Write(DeviceAddr, 0x29, 0x0035);
|
|
Jerome Coutant
0:146cf26a9bbb
|
310
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
311
|
/* Disable mute on IN1R_TO_MIXINL, Gain = +30dB */
|
|
Jerome Coutant
0:146cf26a9bbb
|
312
|
counter += CODEC_IO_Write(DeviceAddr, 0x2A, 0x0035);
|
|
Jerome Coutant
0:146cf26a9bbb
|
313
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
314
|
/* Enable AIF1ADC1 (Left), Enable AIF1ADC1 (Right)
|
|
Jerome Coutant
0:146cf26a9bbb
|
315
|
* Enable Left ADC, Enable Right ADC */
|
|
Jerome Coutant
0:146cf26a9bbb
|
316
|
counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0303);
|
|
Jerome Coutant
0:146cf26a9bbb
|
317
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
318
|
/* Enable AIF1 DRC1 Signal Detect & DRC in AIF1ADC1 Left/Right Timeslot 0 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
319
|
counter += CODEC_IO_Write(DeviceAddr, 0x440, 0x00DB);
|
|
Jerome Coutant
0:146cf26a9bbb
|
320
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
321
|
/* Enable IN1L and IN1R, Disable IN2L and IN2R, Enable Thermal sensor & shutdown */
|
|
Jerome Coutant
0:146cf26a9bbb
|
322
|
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x6350);
|
|
Jerome Coutant
0:146cf26a9bbb
|
323
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
324
|
/* Enable the ADCL(Left) to AIF1 Timeslot 0 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
325
|
counter += CODEC_IO_Write(DeviceAddr, 0x606, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
326
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
327
|
/* Enable the ADCR(Right) to AIF1 Timeslot 0 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
328
|
counter += CODEC_IO_Write(DeviceAddr, 0x607, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
329
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
330
|
/* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC1 signal detect */
|
|
Jerome Coutant
0:146cf26a9bbb
|
331
|
counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000D);
|
|
Jerome Coutant
0:146cf26a9bbb
|
332
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
333
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
334
|
case INPUT_DEVICE_DIGITAL_MICROPHONE_1 :
|
|
Jerome Coutant
0:146cf26a9bbb
|
335
|
/* Enable AIF1ADC1 (Left), Enable AIF1ADC1 (Right)
|
|
Jerome Coutant
0:146cf26a9bbb
|
336
|
* Enable DMICDAT1 (Left), Enable DMICDAT1 (Right)
|
|
Jerome Coutant
0:146cf26a9bbb
|
337
|
* Enable Left ADC, Enable Right ADC */
|
|
Jerome Coutant
0:146cf26a9bbb
|
338
|
counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x030C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
339
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
340
|
/* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC1 Left/Right Timeslot 0 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
341
|
counter += CODEC_IO_Write(DeviceAddr, 0x440, 0x00DB);
|
|
Jerome Coutant
0:146cf26a9bbb
|
342
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
343
|
/* Disable IN1L, IN1R, IN2L, IN2R, Enable Thermal sensor & shutdown */
|
|
Jerome Coutant
0:146cf26a9bbb
|
344
|
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x6350);
|
|
Jerome Coutant
0:146cf26a9bbb
|
345
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
346
|
/* Enable the DMIC2(Left) to AIF1 Timeslot 0 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
347
|
counter += CODEC_IO_Write(DeviceAddr, 0x606, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
348
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
349
|
/* Enable the DMIC2(Right) to AIF1 Timeslot 0 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
350
|
counter += CODEC_IO_Write(DeviceAddr, 0x607, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
351
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
352
|
/* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC1 signal detect */
|
|
Jerome Coutant
0:146cf26a9bbb
|
353
|
counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000D);
|
|
Jerome Coutant
0:146cf26a9bbb
|
354
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
355
|
case INPUT_DEVICE_DIGITAL_MIC1_MIC2 :
|
|
Jerome Coutant
0:146cf26a9bbb
|
356
|
/* Enable AIF1ADC1 (Left), Enable AIF1ADC1 (Right)
|
|
Jerome Coutant
0:146cf26a9bbb
|
357
|
* Enable DMICDAT1 (Left), Enable DMICDAT1 (Right)
|
|
Jerome Coutant
0:146cf26a9bbb
|
358
|
* Enable Left ADC, Enable Right ADC */
|
|
Jerome Coutant
0:146cf26a9bbb
|
359
|
counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0F3C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
360
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
361
|
/* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC2 Left/Right Timeslot 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
362
|
counter += CODEC_IO_Write(DeviceAddr, 0x450, 0x00DB);
|
|
Jerome Coutant
0:146cf26a9bbb
|
363
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
364
|
/* Enable AIF1 DRC2 Signal Detect & DRC in AIF1ADC1 Left/Right Timeslot 0 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
365
|
counter += CODEC_IO_Write(DeviceAddr, 0x440, 0x00DB);
|
|
Jerome Coutant
0:146cf26a9bbb
|
366
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
367
|
/* Disable IN1L, IN1R, Enable IN2L, IN2R, Thermal sensor & shutdown */
|
|
Jerome Coutant
0:146cf26a9bbb
|
368
|
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x63A0);
|
|
Jerome Coutant
0:146cf26a9bbb
|
369
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
370
|
/* Enable the DMIC2(Left) to AIF1 Timeslot 0 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
371
|
counter += CODEC_IO_Write(DeviceAddr, 0x606, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
372
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
373
|
/* Enable the DMIC2(Right) to AIF1 Timeslot 0 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
374
|
counter += CODEC_IO_Write(DeviceAddr, 0x607, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
375
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
376
|
/* Enable the DMIC2(Left) to AIF1 Timeslot 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
377
|
counter += CODEC_IO_Write(DeviceAddr, 0x608, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
378
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
379
|
/* Enable the DMIC2(Right) to AIF1 Timeslot 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
380
|
counter += CODEC_IO_Write(DeviceAddr, 0x609, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
381
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
382
|
/* GPIO1 pin configuration GP1_DIR = output, GP1_FN = AIF1 DRC1 signal detect */
|
|
Jerome Coutant
0:146cf26a9bbb
|
383
|
counter += CODEC_IO_Write(DeviceAddr, 0x700, 0x000D);
|
|
Jerome Coutant
0:146cf26a9bbb
|
384
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
385
|
case INPUT_DEVICE_INPUT_LINE_2 :
|
|
Jerome Coutant
0:146cf26a9bbb
|
386
|
default:
|
|
Jerome Coutant
0:146cf26a9bbb
|
387
|
/* Actually, no other input devices supported */
|
|
Jerome Coutant
0:146cf26a9bbb
|
388
|
counter++;
|
|
Jerome Coutant
0:146cf26a9bbb
|
389
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
390
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
391
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
392
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
393
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
394
|
inputEnabled = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
395
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
396
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
397
|
/* Clock Configurations */
|
|
Jerome Coutant
0:146cf26a9bbb
|
398
|
switch (AudioFreq)
|
|
Jerome Coutant
0:146cf26a9bbb
|
399
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
400
|
case AUDIO_FREQUENCY_8K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
401
|
/* AIF1 Sample Rate = 8 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
402
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
403
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
404
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
405
|
case AUDIO_FREQUENCY_16K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
406
|
/* AIF1 Sample Rate = 16 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
407
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0033);
|
|
Jerome Coutant
0:146cf26a9bbb
|
408
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
409
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
410
|
case AUDIO_FREQUENCY_32K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
411
|
/* AIF1 Sample Rate = 32 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
412
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0063);
|
|
Jerome Coutant
0:146cf26a9bbb
|
413
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
414
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
415
|
case AUDIO_FREQUENCY_48K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
416
|
/* AIF1 Sample Rate = 48 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
417
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
|
|
Jerome Coutant
0:146cf26a9bbb
|
418
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
419
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
420
|
case AUDIO_FREQUENCY_96K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
421
|
/* AIF1 Sample Rate = 96 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
422
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x00A3);
|
|
Jerome Coutant
0:146cf26a9bbb
|
423
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
424
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
425
|
case AUDIO_FREQUENCY_11K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
426
|
/* AIF1 Sample Rate = 11.025 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
427
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0013);
|
|
Jerome Coutant
0:146cf26a9bbb
|
428
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
429
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
430
|
case AUDIO_FREQUENCY_22K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
431
|
/* AIF1 Sample Rate = 22.050 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
432
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0043);
|
|
Jerome Coutant
0:146cf26a9bbb
|
433
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
434
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
435
|
case AUDIO_FREQUENCY_44K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
436
|
/* AIF1 Sample Rate = 44.1 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
437
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0073);
|
|
Jerome Coutant
0:146cf26a9bbb
|
438
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
439
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
440
|
default:
|
|
Jerome Coutant
0:146cf26a9bbb
|
441
|
/* AIF1 Sample Rate = 48 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
442
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
|
|
Jerome Coutant
0:146cf26a9bbb
|
443
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
444
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
445
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
446
|
if(input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2)
|
|
Jerome Coutant
0:146cf26a9bbb
|
447
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
448
|
/* AIF1 Word Length = 16-bits, AIF1 Format = DSP mode */
|
|
Jerome Coutant
0:146cf26a9bbb
|
449
|
counter += CODEC_IO_Write(DeviceAddr, 0x300, 0x4018);
|
|
Jerome Coutant
0:146cf26a9bbb
|
450
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
451
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
452
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
453
|
/* AIF1 Word Length = 16-bits, AIF1 Format = I2S (Default Register Value) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
454
|
counter += CODEC_IO_Write(DeviceAddr, 0x300, 0x4010);
|
|
Jerome Coutant
0:146cf26a9bbb
|
455
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
456
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
457
|
/* slave mode */
|
|
Jerome Coutant
0:146cf26a9bbb
|
458
|
counter += CODEC_IO_Write(DeviceAddr, 0x302, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
459
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
460
|
/* Enable the DSP processing clock for AIF1, Enable the core clock */
|
|
Jerome Coutant
0:146cf26a9bbb
|
461
|
counter += CODEC_IO_Write(DeviceAddr, 0x208, 0x000A);
|
|
Jerome Coutant
0:146cf26a9bbb
|
462
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
463
|
/* Enable AIF1 Clock, AIF1 Clock Source = MCLK1 pin */
|
|
Jerome Coutant
0:146cf26a9bbb
|
464
|
counter += CODEC_IO_Write(DeviceAddr, 0x200, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
465
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
466
|
if (output_device > 0) /* Audio output selected */
|
|
Jerome Coutant
0:146cf26a9bbb
|
467
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
468
|
/* Analog Output Configuration */
|
|
Jerome Coutant
0:146cf26a9bbb
|
469
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
470
|
/* Enable SPKRVOL PGA, Enable SPKMIXR, Enable SPKLVOL PGA, Enable SPKMIXL */
|
|
Jerome Coutant
0:146cf26a9bbb
|
471
|
counter += CODEC_IO_Write(DeviceAddr, 0x03, 0x0300);
|
|
Jerome Coutant
0:146cf26a9bbb
|
472
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
473
|
/* Left Speaker Mixer Volume = 0dB */
|
|
Jerome Coutant
0:146cf26a9bbb
|
474
|
counter += CODEC_IO_Write(DeviceAddr, 0x22, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
475
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
476
|
/* Speaker output mode = Class D, Right Speaker Mixer Volume = 0dB ((0x23, 0x0100) = class AB)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
477
|
counter += CODEC_IO_Write(DeviceAddr, 0x23, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
478
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
479
|
/* Unmute DAC2 (Left) to Left Speaker Mixer (SPKMIXL) path,
|
|
Jerome Coutant
0:146cf26a9bbb
|
480
|
Unmute DAC2 (Right) to Right Speaker Mixer (SPKMIXR) path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
481
|
counter += CODEC_IO_Write(DeviceAddr, 0x36, 0x0300);
|
|
Jerome Coutant
0:146cf26a9bbb
|
482
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
483
|
/* Enable bias generator, Enable VMID, Enable SPKOUTL, Enable SPKOUTR */
|
|
Jerome Coutant
0:146cf26a9bbb
|
484
|
counter += CODEC_IO_Write(DeviceAddr, 0x01, 0x3003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
485
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
486
|
/* Headphone/Speaker Enable */
|
|
Jerome Coutant
0:146cf26a9bbb
|
487
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
488
|
if (input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2)
|
|
Jerome Coutant
0:146cf26a9bbb
|
489
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
490
|
/* Enable Class W, Class W Envelope Tracking = AIF1 Timeslots 0 and 1 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
491
|
counter += CODEC_IO_Write(DeviceAddr, 0x51, 0x0205);
|
|
Jerome Coutant
0:146cf26a9bbb
|
492
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
493
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
494
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
495
|
/* Enable Class W, Class W Envelope Tracking = AIF1 Timeslot 0 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
496
|
counter += CODEC_IO_Write(DeviceAddr, 0x51, 0x0005);
|
|
Jerome Coutant
0:146cf26a9bbb
|
497
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
498
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
499
|
/* Enable bias generator, Enable VMID, Enable HPOUT1 (Left) and Enable HPOUT1 (Right) input stages */
|
|
Jerome Coutant
0:146cf26a9bbb
|
500
|
/* idem for Speaker */
|
|
Jerome Coutant
0:146cf26a9bbb
|
501
|
power_mgnt_reg_1 |= 0x0303 | 0x3003;
|
|
Jerome Coutant
0:146cf26a9bbb
|
502
|
counter += CODEC_IO_Write(DeviceAddr, 0x01, power_mgnt_reg_1);
|
|
Jerome Coutant
0:146cf26a9bbb
|
503
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
504
|
/* Enable HPOUT1 (Left) and HPOUT1 (Right) intermediate stages */
|
|
Jerome Coutant
0:146cf26a9bbb
|
505
|
counter += CODEC_IO_Write(DeviceAddr, 0x60, 0x0022);
|
|
Jerome Coutant
0:146cf26a9bbb
|
506
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
507
|
/* Enable Charge Pump */
|
|
Jerome Coutant
0:146cf26a9bbb
|
508
|
counter += CODEC_IO_Write(DeviceAddr, 0x4C, 0x9F25);
|
|
Jerome Coutant
0:146cf26a9bbb
|
509
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
510
|
/* Add Delay */
|
|
Jerome Coutant
0:146cf26a9bbb
|
511
|
AUDIO_IO_Delay(15);
|
|
Jerome Coutant
0:146cf26a9bbb
|
512
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
513
|
/* Select DAC1 (Left) to Left Headphone Output PGA (HPOUT1LVOL) path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
514
|
counter += CODEC_IO_Write(DeviceAddr, 0x2D, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
515
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
516
|
/* Select DAC1 (Right) to Right Headphone Output PGA (HPOUT1RVOL) path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
517
|
counter += CODEC_IO_Write(DeviceAddr, 0x2E, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
518
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
519
|
/* Enable Left Output Mixer (MIXOUTL), Enable Right Output Mixer (MIXOUTR) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
520
|
/* idem for SPKOUTL and SPKOUTR */
|
|
Jerome Coutant
0:146cf26a9bbb
|
521
|
counter += CODEC_IO_Write(DeviceAddr, 0x03, 0x0030 | 0x0300);
|
|
Jerome Coutant
0:146cf26a9bbb
|
522
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
523
|
/* Enable DC Servo and trigger start-up mode on left and right channels */
|
|
Jerome Coutant
0:146cf26a9bbb
|
524
|
counter += CODEC_IO_Write(DeviceAddr, 0x54, 0x0033);
|
|
Jerome Coutant
0:146cf26a9bbb
|
525
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
526
|
/* Add Delay */
|
|
Jerome Coutant
0:146cf26a9bbb
|
527
|
AUDIO_IO_Delay(250);
|
|
Jerome Coutant
0:146cf26a9bbb
|
528
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
529
|
/* Enable HPOUT1 (Left) and HPOUT1 (Right) intermediate and output stages. Remove clamps */
|
|
Jerome Coutant
0:146cf26a9bbb
|
530
|
counter += CODEC_IO_Write(DeviceAddr, 0x60, 0x00EE);
|
|
Jerome Coutant
0:146cf26a9bbb
|
531
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
532
|
/* Unmutes */
|
|
Jerome Coutant
0:146cf26a9bbb
|
533
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
534
|
/* Unmute DAC 1 (Left) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
535
|
counter += CODEC_IO_Write(DeviceAddr, 0x610, 0x00C0);
|
|
Jerome Coutant
0:146cf26a9bbb
|
536
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
537
|
/* Unmute DAC 1 (Right) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
538
|
counter += CODEC_IO_Write(DeviceAddr, 0x611, 0x00C0);
|
|
Jerome Coutant
0:146cf26a9bbb
|
539
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
540
|
/* Unmute the AIF1 Timeslot 0 DAC path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
541
|
counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
542
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
543
|
/* Unmute DAC 2 (Left) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
544
|
counter += CODEC_IO_Write(DeviceAddr, 0x612, 0x00C0);
|
|
Jerome Coutant
0:146cf26a9bbb
|
545
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
546
|
/* Unmute DAC 2 (Right) */
|
|
Jerome Coutant
0:146cf26a9bbb
|
547
|
counter += CODEC_IO_Write(DeviceAddr, 0x613, 0x00C0);
|
|
Jerome Coutant
0:146cf26a9bbb
|
548
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
549
|
/* Unmute the AIF1 Timeslot 1 DAC2 path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
550
|
counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
551
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
552
|
/* Volume Control */
|
|
Jerome Coutant
0:146cf26a9bbb
|
553
|
wm8994_SetVolume(DeviceAddr, Volume);
|
|
Jerome Coutant
0:146cf26a9bbb
|
554
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
555
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
556
|
if (input_device > 0) /* Audio input selected */
|
|
Jerome Coutant
0:146cf26a9bbb
|
557
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
558
|
if ((input_device == INPUT_DEVICE_DIGITAL_MICROPHONE_1) || (input_device == INPUT_DEVICE_DIGITAL_MICROPHONE_2))
|
|
Jerome Coutant
0:146cf26a9bbb
|
559
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
560
|
/* Enable Microphone bias 1 generator, Enable VMID */
|
|
Jerome Coutant
0:146cf26a9bbb
|
561
|
power_mgnt_reg_1 |= 0x0013;
|
|
Jerome Coutant
0:146cf26a9bbb
|
562
|
counter += CODEC_IO_Write(DeviceAddr, 0x01, power_mgnt_reg_1);
|
|
Jerome Coutant
0:146cf26a9bbb
|
563
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
564
|
/* ADC oversample enable */
|
|
Jerome Coutant
0:146cf26a9bbb
|
565
|
counter += CODEC_IO_Write(DeviceAddr, 0x620, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
566
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
567
|
/* AIF ADC2 HPF enable, HPF cut = voice mode 1 fc=127Hz at fs=8kHz */
|
|
Jerome Coutant
0:146cf26a9bbb
|
568
|
counter += CODEC_IO_Write(DeviceAddr, 0x411, 0x3800);
|
|
Jerome Coutant
0:146cf26a9bbb
|
569
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
570
|
else if(input_device == INPUT_DEVICE_DIGITAL_MIC1_MIC2)
|
|
Jerome Coutant
0:146cf26a9bbb
|
571
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
572
|
/* Enable Microphone bias 1 generator, Enable VMID */
|
|
Jerome Coutant
0:146cf26a9bbb
|
573
|
power_mgnt_reg_1 |= 0x0013;
|
|
Jerome Coutant
0:146cf26a9bbb
|
574
|
counter += CODEC_IO_Write(DeviceAddr, 0x01, power_mgnt_reg_1);
|
|
Jerome Coutant
0:146cf26a9bbb
|
575
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
576
|
/* ADC oversample enable */
|
|
Jerome Coutant
0:146cf26a9bbb
|
577
|
counter += CODEC_IO_Write(DeviceAddr, 0x620, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
578
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
579
|
/* AIF ADC1 HPF enable, HPF cut = voice mode 1 fc=127Hz at fs=8kHz */
|
|
Jerome Coutant
0:146cf26a9bbb
|
580
|
counter += CODEC_IO_Write(DeviceAddr, 0x410, 0x1800);
|
|
Jerome Coutant
0:146cf26a9bbb
|
581
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
582
|
/* AIF ADC2 HPF enable, HPF cut = voice mode 1 fc=127Hz at fs=8kHz */
|
|
Jerome Coutant
0:146cf26a9bbb
|
583
|
counter += CODEC_IO_Write(DeviceAddr, 0x411, 0x1800);
|
|
Jerome Coutant
0:146cf26a9bbb
|
584
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
585
|
else if ((input_device == INPUT_DEVICE_INPUT_LINE_1) || (input_device == INPUT_DEVICE_INPUT_LINE_2))
|
|
Jerome Coutant
0:146cf26a9bbb
|
586
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
587
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
588
|
/* Disable mute on IN1L, IN1L Volume = +0dB */
|
|
Jerome Coutant
0:146cf26a9bbb
|
589
|
counter += CODEC_IO_Write(DeviceAddr, 0x18, 0x000B);
|
|
Jerome Coutant
0:146cf26a9bbb
|
590
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
591
|
/* Disable mute on IN1R, IN1R Volume = +0dB */
|
|
Jerome Coutant
0:146cf26a9bbb
|
592
|
counter += CODEC_IO_Write(DeviceAddr, 0x1A, 0x000B);
|
|
Jerome Coutant
0:146cf26a9bbb
|
593
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
594
|
/* AIF ADC1 HPF enable, HPF cut = hifi mode fc=4Hz at fs=48kHz */
|
|
Jerome Coutant
0:146cf26a9bbb
|
595
|
counter += CODEC_IO_Write(DeviceAddr, 0x410, 0x1800);
|
|
Jerome Coutant
0:146cf26a9bbb
|
596
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
597
|
/* Volume Control */
|
|
Jerome Coutant
0:146cf26a9bbb
|
598
|
wm8994_SetVolume(DeviceAddr, Volume);
|
|
Jerome Coutant
0:146cf26a9bbb
|
599
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
600
|
/* Return communication control value */
|
|
Jerome Coutant
0:146cf26a9bbb
|
601
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
602
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
603
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
604
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
605
|
* @brief Deinitializes the audio codec.
|
|
Jerome Coutant
0:146cf26a9bbb
|
606
|
* @param None
|
|
Jerome Coutant
0:146cf26a9bbb
|
607
|
* @retval None
|
|
Jerome Coutant
0:146cf26a9bbb
|
608
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
609
|
void wm8994_DeInit(void)
|
|
Jerome Coutant
0:146cf26a9bbb
|
610
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
611
|
/* Deinitialize Audio Codec interface */
|
|
Jerome Coutant
0:146cf26a9bbb
|
612
|
AUDIO_IO_DeInit();
|
|
Jerome Coutant
0:146cf26a9bbb
|
613
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
614
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
615
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
616
|
* @brief Get the WM8994 ID.
|
|
Jerome Coutant
0:146cf26a9bbb
|
617
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
618
|
* @retval The WM8994 ID
|
|
Jerome Coutant
0:146cf26a9bbb
|
619
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
620
|
uint32_t wm8994_ReadID(uint16_t DeviceAddr)
|
|
Jerome Coutant
0:146cf26a9bbb
|
621
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
622
|
/* Initialize the Control interface of the Audio Codec */
|
|
Jerome Coutant
0:146cf26a9bbb
|
623
|
AUDIO_IO_Init();
|
|
Jerome Coutant
0:146cf26a9bbb
|
624
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
625
|
return ((uint32_t)AUDIO_IO_Read(DeviceAddr, WM8994_CHIPID_ADDR));
|
|
Jerome Coutant
0:146cf26a9bbb
|
626
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
627
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
628
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
629
|
* @brief Start the audio Codec play feature.
|
|
Jerome Coutant
0:146cf26a9bbb
|
630
|
* @note For this codec no Play options are required.
|
|
Jerome Coutant
0:146cf26a9bbb
|
631
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
632
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
633
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
634
|
uint32_t wm8994_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size)
|
|
Jerome Coutant
0:146cf26a9bbb
|
635
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
636
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
637
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
638
|
/* Resumes the audio file playing */
|
|
Jerome Coutant
0:146cf26a9bbb
|
639
|
/* Unmute the output first */
|
|
Jerome Coutant
0:146cf26a9bbb
|
640
|
counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
|
Jerome Coutant
0:146cf26a9bbb
|
641
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
642
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
643
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
644
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
645
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
646
|
* @brief Pauses playing on the audio codec.
|
|
Jerome Coutant
0:146cf26a9bbb
|
647
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
648
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
649
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
650
|
uint32_t wm8994_Pause(uint16_t DeviceAddr)
|
|
Jerome Coutant
0:146cf26a9bbb
|
651
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
652
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
653
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
654
|
/* Pause the audio file playing */
|
|
Jerome Coutant
0:146cf26a9bbb
|
655
|
/* Mute the output first */
|
|
Jerome Coutant
0:146cf26a9bbb
|
656
|
counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON);
|
|
Jerome Coutant
0:146cf26a9bbb
|
657
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
658
|
/* Put the Codec in Power save mode */
|
|
Jerome Coutant
0:146cf26a9bbb
|
659
|
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x01);
|
|
Jerome Coutant
0:146cf26a9bbb
|
660
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
661
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
662
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
663
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
664
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
665
|
* @brief Resumes playing on the audio codec.
|
|
Jerome Coutant
0:146cf26a9bbb
|
666
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
667
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
668
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
669
|
uint32_t wm8994_Resume(uint16_t DeviceAddr)
|
|
Jerome Coutant
0:146cf26a9bbb
|
670
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
671
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
672
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
673
|
/* Resumes the audio file playing */
|
|
Jerome Coutant
0:146cf26a9bbb
|
674
|
/* Unmute the output first */
|
|
Jerome Coutant
0:146cf26a9bbb
|
675
|
counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
|
Jerome Coutant
0:146cf26a9bbb
|
676
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
677
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
678
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
679
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
680
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
681
|
* @brief Stops audio Codec playing. It powers down the codec.
|
|
Jerome Coutant
0:146cf26a9bbb
|
682
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
683
|
* @param CodecPdwnMode: selects the power down mode.
|
|
Jerome Coutant
0:146cf26a9bbb
|
684
|
* - CODEC_PDWN_SW: only mutes the audio codec. When resuming from this
|
|
Jerome Coutant
0:146cf26a9bbb
|
685
|
* mode the codec keeps the previous initialization
|
|
Jerome Coutant
0:146cf26a9bbb
|
686
|
* (no need to re-Initialize the codec registers).
|
|
Jerome Coutant
0:146cf26a9bbb
|
687
|
* - CODEC_PDWN_HW: Physically power down the codec. When resuming from this
|
|
Jerome Coutant
0:146cf26a9bbb
|
688
|
* mode, the codec is set to default configuration
|
|
Jerome Coutant
0:146cf26a9bbb
|
689
|
* (user should re-Initialize the codec in order to
|
|
Jerome Coutant
0:146cf26a9bbb
|
690
|
* play again the audio stream).
|
|
Jerome Coutant
0:146cf26a9bbb
|
691
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
692
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
693
|
uint32_t wm8994_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode)
|
|
Jerome Coutant
0:146cf26a9bbb
|
694
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
695
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
696
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
697
|
if (outputEnabled != 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
698
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
699
|
/* Mute the output first */
|
|
Jerome Coutant
0:146cf26a9bbb
|
700
|
counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON);
|
|
Jerome Coutant
0:146cf26a9bbb
|
701
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
702
|
if (CodecPdwnMode == CODEC_PDWN_SW)
|
|
Jerome Coutant
0:146cf26a9bbb
|
703
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
704
|
/* Only output mute required*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
705
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
706
|
else /* CODEC_PDWN_HW */
|
|
Jerome Coutant
0:146cf26a9bbb
|
707
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
708
|
/* Mute the AIF1 Timeslot 0 DAC1 path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
709
|
counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0200);
|
|
Jerome Coutant
0:146cf26a9bbb
|
710
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
711
|
/* Mute the AIF1 Timeslot 1 DAC2 path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
712
|
counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0200);
|
|
Jerome Coutant
0:146cf26a9bbb
|
713
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
714
|
/* Disable DAC1L_TO_HPOUT1L */
|
|
Jerome Coutant
0:146cf26a9bbb
|
715
|
counter += CODEC_IO_Write(DeviceAddr, 0x2D, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
716
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
717
|
/* Disable DAC1R_TO_HPOUT1R */
|
|
Jerome Coutant
0:146cf26a9bbb
|
718
|
counter += CODEC_IO_Write(DeviceAddr, 0x2E, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
719
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
720
|
/* Disable DAC1 and DAC2 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
721
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
722
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
723
|
/* Reset Codec by writing in 0x0000 address register */
|
|
Jerome Coutant
0:146cf26a9bbb
|
724
|
counter += CODEC_IO_Write(DeviceAddr, 0x0000, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
725
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
726
|
outputEnabled = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
727
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
728
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
729
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
730
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
731
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
732
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
733
|
* @brief Sets higher or lower the codec volume level.
|
|
Jerome Coutant
0:146cf26a9bbb
|
734
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
735
|
* @param Volume: a byte value from 0 to 255 (refer to codec registers
|
|
Jerome Coutant
0:146cf26a9bbb
|
736
|
* description for more details).
|
|
Jerome Coutant
0:146cf26a9bbb
|
737
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
738
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
739
|
uint32_t wm8994_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
|
|
Jerome Coutant
0:146cf26a9bbb
|
740
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
741
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
742
|
uint8_t convertedvol = VOLUME_CONVERT(Volume);
|
|
Jerome Coutant
0:146cf26a9bbb
|
743
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
744
|
/* Output volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
745
|
if (outputEnabled != 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
746
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
747
|
if(convertedvol > 0x3E)
|
|
Jerome Coutant
0:146cf26a9bbb
|
748
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
749
|
/* Unmute audio codec */
|
|
Jerome Coutant
0:146cf26a9bbb
|
750
|
counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
|
Jerome Coutant
0:146cf26a9bbb
|
751
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
752
|
/* Left Headphone Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
753
|
counter += CODEC_IO_Write(DeviceAddr, 0x1C, 0x3F | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
754
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
755
|
/* Right Headphone Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
756
|
counter += CODEC_IO_Write(DeviceAddr, 0x1D, 0x3F | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
757
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
758
|
/* Left Speaker Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
759
|
counter += CODEC_IO_Write(DeviceAddr, 0x26, 0x3F | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
760
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
761
|
/* Right Speaker Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
762
|
counter += CODEC_IO_Write(DeviceAddr, 0x27, 0x3F | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
763
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
764
|
else if (Volume == 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
765
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
766
|
/* Mute audio codec */
|
|
Jerome Coutant
0:146cf26a9bbb
|
767
|
counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_ON);
|
|
Jerome Coutant
0:146cf26a9bbb
|
768
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
769
|
else
|
|
Jerome Coutant
0:146cf26a9bbb
|
770
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
771
|
/* Unmute audio codec */
|
|
Jerome Coutant
0:146cf26a9bbb
|
772
|
counter += wm8994_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
|
|
Jerome Coutant
0:146cf26a9bbb
|
773
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
774
|
/* Left Headphone Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
775
|
counter += CODEC_IO_Write(DeviceAddr, 0x1C, convertedvol | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
776
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
777
|
/* Right Headphone Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
778
|
counter += CODEC_IO_Write(DeviceAddr, 0x1D, convertedvol | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
779
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
780
|
/* Left Speaker Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
781
|
counter += CODEC_IO_Write(DeviceAddr, 0x26, convertedvol | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
782
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
783
|
/* Right Speaker Volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
784
|
counter += CODEC_IO_Write(DeviceAddr, 0x27, convertedvol | 0x140);
|
|
Jerome Coutant
0:146cf26a9bbb
|
785
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
786
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
787
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
788
|
/* Input volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
789
|
if (inputEnabled != 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
790
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
791
|
convertedvol = VOLUME_IN_CONVERT(Volume);
|
|
Jerome Coutant
0:146cf26a9bbb
|
792
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
793
|
/* Left AIF1 ADC1 volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
794
|
counter += CODEC_IO_Write(DeviceAddr, 0x400, convertedvol | 0x100);
|
|
Jerome Coutant
0:146cf26a9bbb
|
795
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
796
|
/* Right AIF1 ADC1 volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
797
|
counter += CODEC_IO_Write(DeviceAddr, 0x401, convertedvol | 0x100);
|
|
Jerome Coutant
0:146cf26a9bbb
|
798
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
799
|
/* Left AIF1 ADC2 volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
800
|
counter += CODEC_IO_Write(DeviceAddr, 0x404, convertedvol | 0x100);
|
|
Jerome Coutant
0:146cf26a9bbb
|
801
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
802
|
/* Right AIF1 ADC2 volume */
|
|
Jerome Coutant
0:146cf26a9bbb
|
803
|
counter += CODEC_IO_Write(DeviceAddr, 0x405, convertedvol | 0x100);
|
|
Jerome Coutant
0:146cf26a9bbb
|
804
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
805
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
806
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
807
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
808
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
809
|
* @brief Enables or disables the mute feature on the audio codec.
|
|
Jerome Coutant
0:146cf26a9bbb
|
810
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
811
|
* @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
|
|
Jerome Coutant
0:146cf26a9bbb
|
812
|
* mute mode.
|
|
Jerome Coutant
0:146cf26a9bbb
|
813
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
814
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
815
|
uint32_t wm8994_SetMute(uint16_t DeviceAddr, uint32_t Cmd)
|
|
Jerome Coutant
0:146cf26a9bbb
|
816
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
817
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
818
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
819
|
if (outputEnabled != 0)
|
|
Jerome Coutant
0:146cf26a9bbb
|
820
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
821
|
/* Set the Mute mode */
|
|
Jerome Coutant
0:146cf26a9bbb
|
822
|
if(Cmd == AUDIO_MUTE_ON)
|
|
Jerome Coutant
0:146cf26a9bbb
|
823
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
824
|
/* Soft Mute the AIF1 Timeslot 0 DAC1 path L&R */
|
|
Jerome Coutant
0:146cf26a9bbb
|
825
|
counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0200);
|
|
Jerome Coutant
0:146cf26a9bbb
|
826
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
827
|
/* Soft Mute the AIF1 Timeslot 1 DAC2 path L&R */
|
|
Jerome Coutant
0:146cf26a9bbb
|
828
|
counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0200);
|
|
Jerome Coutant
0:146cf26a9bbb
|
829
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
830
|
else /* AUDIO_MUTE_OFF Disable the Mute */
|
|
Jerome Coutant
0:146cf26a9bbb
|
831
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
832
|
/* Unmute the AIF1 Timeslot 0 DAC1 path L&R */
|
|
Jerome Coutant
0:146cf26a9bbb
|
833
|
counter += CODEC_IO_Write(DeviceAddr, 0x420, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
834
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
835
|
/* Unmute the AIF1 Timeslot 1 DAC2 path L&R */
|
|
Jerome Coutant
0:146cf26a9bbb
|
836
|
counter += CODEC_IO_Write(DeviceAddr, 0x422, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
837
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
838
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
839
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
840
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
841
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
842
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
843
|
* @brief Switch dynamically (while audio file is played) the output target
|
|
Jerome Coutant
0:146cf26a9bbb
|
844
|
* (speaker or headphone).
|
|
Jerome Coutant
0:146cf26a9bbb
|
845
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
846
|
* @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER,
|
|
Jerome Coutant
0:146cf26a9bbb
|
847
|
* OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO
|
|
Jerome Coutant
0:146cf26a9bbb
|
848
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
849
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
850
|
uint32_t wm8994_SetOutputMode(uint16_t DeviceAddr, uint8_t Output)
|
|
Jerome Coutant
0:146cf26a9bbb
|
851
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
852
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
853
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
854
|
switch (Output)
|
|
Jerome Coutant
0:146cf26a9bbb
|
855
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
856
|
case OUTPUT_DEVICE_SPEAKER:
|
|
Jerome Coutant
0:146cf26a9bbb
|
857
|
/* Enable DAC1 (Left), Enable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
858
|
Disable DAC2 (Left), Disable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
859
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0C0C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
860
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
861
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
862
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
863
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
864
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
865
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
866
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
867
|
/* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
868
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
869
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
870
|
/* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
871
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
872
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
873
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
874
|
case OUTPUT_DEVICE_HEADPHONE:
|
|
Jerome Coutant
0:146cf26a9bbb
|
875
|
/* Disable DAC1 (Left), Disable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
876
|
Enable DAC2 (Left), Enable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
877
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
|
|
Jerome Coutant
0:146cf26a9bbb
|
878
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
879
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
880
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
881
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
882
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
883
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
884
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
885
|
/* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
886
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
887
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
888
|
/* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
889
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
890
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
891
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
892
|
case OUTPUT_DEVICE_BOTH:
|
|
Jerome Coutant
0:146cf26a9bbb
|
893
|
/* Enable DAC1 (Left), Enable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
894
|
also Enable DAC2 (Left), Enable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
895
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303 | 0x0C0C);
|
|
Jerome Coutant
0:146cf26a9bbb
|
896
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
897
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
898
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
899
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
900
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
901
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
902
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
903
|
/* Enable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
904
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
905
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
906
|
/* Enable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
907
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0002);
|
|
Jerome Coutant
0:146cf26a9bbb
|
908
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
909
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
910
|
default:
|
|
Jerome Coutant
0:146cf26a9bbb
|
911
|
/* Disable DAC1 (Left), Disable DAC1 (Right),
|
|
Jerome Coutant
0:146cf26a9bbb
|
912
|
Enable DAC2 (Left), Enable DAC2 (Right)*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
913
|
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x0303);
|
|
Jerome Coutant
0:146cf26a9bbb
|
914
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
915
|
/* Enable the AIF1 Timeslot 0 (Left) to DAC 1 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
916
|
counter += CODEC_IO_Write(DeviceAddr, 0x601, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
917
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
918
|
/* Enable the AIF1 Timeslot 0 (Right) to DAC 1 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
919
|
counter += CODEC_IO_Write(DeviceAddr, 0x602, 0x0001);
|
|
Jerome Coutant
0:146cf26a9bbb
|
920
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
921
|
/* Disable the AIF1 Timeslot 1 (Left) to DAC 2 (Left) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
922
|
counter += CODEC_IO_Write(DeviceAddr, 0x604, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
923
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
924
|
/* Disable the AIF1 Timeslot 1 (Right) to DAC 2 (Right) mixer path */
|
|
Jerome Coutant
0:146cf26a9bbb
|
925
|
counter += CODEC_IO_Write(DeviceAddr, 0x605, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
926
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
927
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
928
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
929
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
930
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
931
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
932
|
* @brief Sets new frequency.
|
|
Jerome Coutant
0:146cf26a9bbb
|
933
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
934
|
* @param AudioFreq: Audio frequency used to play the audio stream.
|
|
Jerome Coutant
0:146cf26a9bbb
|
935
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
936
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
937
|
uint32_t wm8994_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq)
|
|
Jerome Coutant
0:146cf26a9bbb
|
938
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
939
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
940
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
941
|
/* Clock Configurations */
|
|
Jerome Coutant
0:146cf26a9bbb
|
942
|
switch (AudioFreq)
|
|
Jerome Coutant
0:146cf26a9bbb
|
943
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
944
|
case AUDIO_FREQUENCY_8K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
945
|
/* AIF1 Sample Rate = 8 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
946
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0003);
|
|
Jerome Coutant
0:146cf26a9bbb
|
947
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
948
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
949
|
case AUDIO_FREQUENCY_16K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
950
|
/* AIF1 Sample Rate = 16 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
951
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0033);
|
|
Jerome Coutant
0:146cf26a9bbb
|
952
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
953
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
954
|
case AUDIO_FREQUENCY_48K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
955
|
/* AIF1 Sample Rate = 48 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
956
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
|
|
Jerome Coutant
0:146cf26a9bbb
|
957
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
958
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
959
|
case AUDIO_FREQUENCY_96K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
960
|
/* AIF1 Sample Rate = 96 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
961
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x00A3);
|
|
Jerome Coutant
0:146cf26a9bbb
|
962
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
963
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
964
|
case AUDIO_FREQUENCY_11K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
965
|
/* AIF1 Sample Rate = 11.025 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
966
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0013);
|
|
Jerome Coutant
0:146cf26a9bbb
|
967
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
968
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
969
|
case AUDIO_FREQUENCY_22K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
970
|
/* AIF1 Sample Rate = 22.050 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
971
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0043);
|
|
Jerome Coutant
0:146cf26a9bbb
|
972
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
973
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
974
|
case AUDIO_FREQUENCY_44K:
|
|
Jerome Coutant
0:146cf26a9bbb
|
975
|
/* AIF1 Sample Rate = 44.1 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
976
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0073);
|
|
Jerome Coutant
0:146cf26a9bbb
|
977
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
978
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
979
|
default:
|
|
Jerome Coutant
0:146cf26a9bbb
|
980
|
/* AIF1 Sample Rate = 48 (KHz), ratio=256 */
|
|
Jerome Coutant
0:146cf26a9bbb
|
981
|
counter += CODEC_IO_Write(DeviceAddr, 0x210, 0x0083);
|
|
Jerome Coutant
0:146cf26a9bbb
|
982
|
break;
|
|
Jerome Coutant
0:146cf26a9bbb
|
983
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
984
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
985
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
986
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
987
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
988
|
* @brief Resets wm8994 registers.
|
|
Jerome Coutant
0:146cf26a9bbb
|
989
|
* @param DeviceAddr: Device address on communication Bus.
|
|
Jerome Coutant
0:146cf26a9bbb
|
990
|
* @retval 0 if correct communication, else wrong communication
|
|
Jerome Coutant
0:146cf26a9bbb
|
991
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
992
|
uint32_t wm8994_Reset(uint16_t DeviceAddr)
|
|
Jerome Coutant
0:146cf26a9bbb
|
993
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
994
|
uint32_t counter = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
995
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
996
|
/* Reset Codec by writing in 0x0000 address register */
|
|
Jerome Coutant
0:146cf26a9bbb
|
997
|
counter = CODEC_IO_Write(DeviceAddr, 0x0000, 0x0000);
|
|
Jerome Coutant
0:146cf26a9bbb
|
998
|
outputEnabled = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
999
|
inputEnabled=0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
1000
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1001
|
return counter;
|
|
Jerome Coutant
0:146cf26a9bbb
|
1002
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
1003
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1004
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
1005
|
* @brief Writes/Read a single data.
|
|
Jerome Coutant
0:146cf26a9bbb
|
1006
|
* @param Addr: I2C address
|
|
Jerome Coutant
0:146cf26a9bbb
|
1007
|
* @param Reg: Reg address
|
|
Jerome Coutant
0:146cf26a9bbb
|
1008
|
* @param Value: Data to be written
|
|
Jerome Coutant
0:146cf26a9bbb
|
1009
|
* @retval None
|
|
Jerome Coutant
0:146cf26a9bbb
|
1010
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
1011
|
static uint8_t CODEC_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
|
|
Jerome Coutant
0:146cf26a9bbb
|
1012
|
{
|
|
Jerome Coutant
0:146cf26a9bbb
|
1013
|
uint32_t result = 0;
|
|
Jerome Coutant
0:146cf26a9bbb
|
1014
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1015
|
AUDIO_IO_Write(Addr, Reg, Value);
|
|
Jerome Coutant
0:146cf26a9bbb
|
1016
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1017
|
#ifdef VERIFY_WRITTENDATA
|
|
Jerome Coutant
0:146cf26a9bbb
|
1018
|
/* Verify that the data has been correctly written */
|
|
Jerome Coutant
0:146cf26a9bbb
|
1019
|
result = (AUDIO_IO_Read(Addr, Reg) == Value)? 0:1;
|
|
Jerome Coutant
0:146cf26a9bbb
|
1020
|
#endif /* VERIFY_WRITTENDATA */
|
|
Jerome Coutant
0:146cf26a9bbb
|
1021
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1022
|
return result;
|
|
Jerome Coutant
0:146cf26a9bbb
|
1023
|
}
|
|
Jerome Coutant
0:146cf26a9bbb
|
1024
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1025
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
1026
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
1027
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
1028
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1029
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
1030
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
1031
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
1032
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1033
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
1034
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
1035
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
1036
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1037
|
/**
|
|
Jerome Coutant
0:146cf26a9bbb
|
1038
|
* @}
|
|
Jerome Coutant
0:146cf26a9bbb
|
1039
|
*/
|
|
Jerome Coutant
0:146cf26a9bbb
|
1040
|
|
|
Jerome Coutant
0:146cf26a9bbb
|
1041
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|