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