STM32Cube BSP FW for STM32F769I-Discovery

Dependents:   mbed-os-example-blinky-5 DISCO-F769NI_TOUCHSCREEN_demo_custom_1 Datarecorder2 DISCO-F769NI_TOUCHSCREEN_demo ... more

Committer:
Jerome Coutant
Date:
Fri Feb 10 13:08:21 2017 +0100
Revision:
0:c0f3bbab73d2
Child:
4:72a949940ad6
STM32Cube_FW_F7_V1.5.1 BSP STM32F769I-Discovery

Who changed what in which revision?

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