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