BSP Drivers

Dependencies:   CMSIS_STM32L4xx CMSIS_DSP_401 STM32L4xx_HAL_Driver

Dependents:   DiscoAudioRecord

Committer:
EricLew
Date:
Sun Nov 22 21:15:34 2015 +0000
Revision:
4:a1219ef3537f
Parent:
0:ad9dfc0179dc
11/22/2015

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EricLew 0:ad9dfc0179dc 1 /**
EricLew 0:ad9dfc0179dc 2 ******************************************************************************
EricLew 0:ad9dfc0179dc 3 * @file wm8994.h
EricLew 0:ad9dfc0179dc 4 * @author MCD Application Team
EricLew 0:ad9dfc0179dc 5 * @version V2.0.0
EricLew 0:ad9dfc0179dc 6 * @date 24-June-2015
EricLew 0:ad9dfc0179dc 7 * @brief This file contains all the functions prototypes for the
EricLew 0:ad9dfc0179dc 8 * wm8994.c driver.
EricLew 0:ad9dfc0179dc 9 ******************************************************************************
EricLew 0:ad9dfc0179dc 10 * @attention
EricLew 0:ad9dfc0179dc 11 *
EricLew 0:ad9dfc0179dc 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
EricLew 0:ad9dfc0179dc 13 *
EricLew 0:ad9dfc0179dc 14 * Redistribution and use in source and binary forms, with or without modification,
EricLew 0:ad9dfc0179dc 15 * are permitted provided that the following conditions are met:
EricLew 0:ad9dfc0179dc 16 * 1. Redistributions of source code must retain the above copyright notice,
EricLew 0:ad9dfc0179dc 17 * this list of conditions and the following disclaimer.
EricLew 0:ad9dfc0179dc 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
EricLew 0:ad9dfc0179dc 19 * this list of conditions and the following disclaimer in the documentation
EricLew 0:ad9dfc0179dc 20 * and/or other materials provided with the distribution.
EricLew 0:ad9dfc0179dc 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
EricLew 0:ad9dfc0179dc 22 * may be used to endorse or promote products derived from this software
EricLew 0:ad9dfc0179dc 23 * without specific prior written permission.
EricLew 0:ad9dfc0179dc 24 *
EricLew 0:ad9dfc0179dc 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
EricLew 0:ad9dfc0179dc 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
EricLew 0:ad9dfc0179dc 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
EricLew 0:ad9dfc0179dc 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
EricLew 0:ad9dfc0179dc 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
EricLew 0:ad9dfc0179dc 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
EricLew 0:ad9dfc0179dc 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
EricLew 0:ad9dfc0179dc 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
EricLew 0:ad9dfc0179dc 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
EricLew 0:ad9dfc0179dc 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EricLew 0:ad9dfc0179dc 35 *
EricLew 0:ad9dfc0179dc 36 ******************************************************************************
EricLew 0:ad9dfc0179dc 37 */
EricLew 0:ad9dfc0179dc 38
EricLew 0:ad9dfc0179dc 39 /* Define to prevent recursive inclusion -------------------------------------*/
EricLew 0:ad9dfc0179dc 40 #ifndef __WM8994_H
EricLew 0:ad9dfc0179dc 41 #define __WM8994_H
EricLew 0:ad9dfc0179dc 42
EricLew 0:ad9dfc0179dc 43 /* Includes ------------------------------------------------------------------*/
EricLew 0:ad9dfc0179dc 44 #include "../Common/audio.h"
EricLew 0:ad9dfc0179dc 45
EricLew 0:ad9dfc0179dc 46 /** @addtogroup BSP
EricLew 0:ad9dfc0179dc 47 * @{
EricLew 0:ad9dfc0179dc 48 */
EricLew 0:ad9dfc0179dc 49
EricLew 0:ad9dfc0179dc 50 /** @addtogroup Component
EricLew 0:ad9dfc0179dc 51 * @{
EricLew 0:ad9dfc0179dc 52 */
EricLew 0:ad9dfc0179dc 53
EricLew 0:ad9dfc0179dc 54 /** @addtogroup WM8994
EricLew 0:ad9dfc0179dc 55 * @{
EricLew 0:ad9dfc0179dc 56 */
EricLew 0:ad9dfc0179dc 57
EricLew 0:ad9dfc0179dc 58 /** @defgroup WM8994_Exported_Types
EricLew 0:ad9dfc0179dc 59 * @{
EricLew 0:ad9dfc0179dc 60 */
EricLew 0:ad9dfc0179dc 61
EricLew 0:ad9dfc0179dc 62 /**
EricLew 0:ad9dfc0179dc 63 * @}
EricLew 0:ad9dfc0179dc 64 */
EricLew 0:ad9dfc0179dc 65
EricLew 0:ad9dfc0179dc 66 /** @defgroup WM8994_Exported_Constants
EricLew 0:ad9dfc0179dc 67 * @{
EricLew 0:ad9dfc0179dc 68 */
EricLew 0:ad9dfc0179dc 69
EricLew 0:ad9dfc0179dc 70 /******************************************************************************/
EricLew 0:ad9dfc0179dc 71 /*************************** Codec User defines ******************************/
EricLew 0:ad9dfc0179dc 72 /******************************************************************************/
EricLew 0:ad9dfc0179dc 73 /* Codec output DEVICE */
EricLew 0:ad9dfc0179dc 74 #define OUTPUT_DEVICE_SPEAKER ((uint16_t)0x0001)
EricLew 0:ad9dfc0179dc 75 #define OUTPUT_DEVICE_HEADPHONE ((uint16_t)0x0002)
EricLew 0:ad9dfc0179dc 76 #define OUTPUT_DEVICE_BOTH ((uint16_t)0x0003)
EricLew 0:ad9dfc0179dc 77 #define OUTPUT_DEVICE_AUTO ((uint16_t)0x0004)
EricLew 0:ad9dfc0179dc 78 #define INPUT_DEVICE_DIGITAL_MICROPHONE_1 ((uint16_t)0x0100)
EricLew 0:ad9dfc0179dc 79 #define INPUT_DEVICE_DIGITAL_MICROPHONE_2 ((uint16_t)0x0200)
EricLew 0:ad9dfc0179dc 80 #define INPUT_DEVICE_INPUT_LINE_1 ((uint16_t)0x0300)
EricLew 0:ad9dfc0179dc 81 #define INPUT_DEVICE_INPUT_LINE_2 ((uint16_t)0x0400)
EricLew 0:ad9dfc0179dc 82
EricLew 0:ad9dfc0179dc 83 /* Volume Levels values */
EricLew 0:ad9dfc0179dc 84 #define DEFAULT_VOLMIN 0x00
EricLew 0:ad9dfc0179dc 85 #define DEFAULT_VOLMAX 0xFF
EricLew 0:ad9dfc0179dc 86 #define DEFAULT_VOLSTEP 0x04
EricLew 0:ad9dfc0179dc 87
EricLew 0:ad9dfc0179dc 88 #define AUDIO_PAUSE 0
EricLew 0:ad9dfc0179dc 89 #define AUDIO_RESUME 1
EricLew 0:ad9dfc0179dc 90
EricLew 0:ad9dfc0179dc 91 /* Codec POWER DOWN modes */
EricLew 0:ad9dfc0179dc 92 #define CODEC_PDWN_HW 1
EricLew 0:ad9dfc0179dc 93 #define CODEC_PDWN_SW 2
EricLew 0:ad9dfc0179dc 94
EricLew 0:ad9dfc0179dc 95 /* MUTE commands */
EricLew 0:ad9dfc0179dc 96 #define AUDIO_MUTE_ON 1
EricLew 0:ad9dfc0179dc 97 #define AUDIO_MUTE_OFF 0
EricLew 0:ad9dfc0179dc 98
EricLew 0:ad9dfc0179dc 99 /* AUDIO FREQUENCY */
EricLew 0:ad9dfc0179dc 100 #define AUDIO_FREQUENCY_192K ((uint32_t)192000)
EricLew 0:ad9dfc0179dc 101 #define AUDIO_FREQUENCY_96K ((uint32_t)96000)
EricLew 0:ad9dfc0179dc 102 #define AUDIO_FREQUENCY_48K ((uint32_t)48000)
EricLew 0:ad9dfc0179dc 103 #define AUDIO_FREQUENCY_44K ((uint32_t)44100)
EricLew 0:ad9dfc0179dc 104 #define AUDIO_FREQUENCY_32K ((uint32_t)32000)
EricLew 0:ad9dfc0179dc 105 #define AUDIO_FREQUENCY_22K ((uint32_t)22050)
EricLew 0:ad9dfc0179dc 106 #define AUDIO_FREQUENCY_16K ((uint32_t)16000)
EricLew 0:ad9dfc0179dc 107 #define AUDIO_FREQUENCY_11K ((uint32_t)11025)
EricLew 0:ad9dfc0179dc 108 #define AUDIO_FREQUENCY_8K ((uint32_t)8000)
EricLew 0:ad9dfc0179dc 109
EricLew 0:ad9dfc0179dc 110 #define VOLUME_CONVERT(Volume) (((Volume) > 100)? 100:((uint8_t)(((Volume) * 63) / 100)))
EricLew 0:ad9dfc0179dc 111 #define VOLUME_IN_CONVERT(Volume) (((Volume) >= 100)? 239:((uint8_t)(((Volume) * 240) / 100)))
EricLew 0:ad9dfc0179dc 112
EricLew 0:ad9dfc0179dc 113 /******************************************************************************/
EricLew 0:ad9dfc0179dc 114 /****************************** REGISTER MAPPING ******************************/
EricLew 0:ad9dfc0179dc 115 /******************************************************************************/
EricLew 0:ad9dfc0179dc 116 /**
EricLew 0:ad9dfc0179dc 117 * @brief WM8994 ID
EricLew 0:ad9dfc0179dc 118 */
EricLew 0:ad9dfc0179dc 119 #define WM8994_ID 0x8994
EricLew 0:ad9dfc0179dc 120
EricLew 0:ad9dfc0179dc 121 /**
EricLew 0:ad9dfc0179dc 122 * @brief Device ID Register: Reading from this register will indicate device
EricLew 0:ad9dfc0179dc 123 * family ID 8994h
EricLew 0:ad9dfc0179dc 124 */
EricLew 0:ad9dfc0179dc 125 #define WM8994_CHIPID_ADDR 0x00
EricLew 0:ad9dfc0179dc 126
EricLew 0:ad9dfc0179dc 127 /**
EricLew 0:ad9dfc0179dc 128 * @}
EricLew 0:ad9dfc0179dc 129 */
EricLew 0:ad9dfc0179dc 130
EricLew 0:ad9dfc0179dc 131 /** @defgroup WM8994_Exported_Macros
EricLew 0:ad9dfc0179dc 132 * @{
EricLew 0:ad9dfc0179dc 133 */
EricLew 0:ad9dfc0179dc 134 /**
EricLew 0:ad9dfc0179dc 135 * @}
EricLew 0:ad9dfc0179dc 136 */
EricLew 0:ad9dfc0179dc 137
EricLew 0:ad9dfc0179dc 138 /** @defgroup WM8994_Exported_Functions
EricLew 0:ad9dfc0179dc 139 * @{
EricLew 0:ad9dfc0179dc 140 */
EricLew 0:ad9dfc0179dc 141
EricLew 0:ad9dfc0179dc 142 /*------------------------------------------------------------------------------
EricLew 0:ad9dfc0179dc 143 Audio Codec functions
EricLew 0:ad9dfc0179dc 144 ------------------------------------------------------------------------------*/
EricLew 0:ad9dfc0179dc 145 /* High Layer codec functions */
EricLew 0:ad9dfc0179dc 146 uint32_t wm8994_Init(uint16_t DeviceAddr, uint16_t OutputInputDevice, uint8_t Volume, uint32_t AudioFreq);
EricLew 0:ad9dfc0179dc 147 void wm8994_DeInit(void);
EricLew 0:ad9dfc0179dc 148 uint32_t wm8994_ReadID(uint16_t DeviceAddr);
EricLew 0:ad9dfc0179dc 149 uint32_t wm8994_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size);
EricLew 0:ad9dfc0179dc 150 uint32_t wm8994_Pause(uint16_t DeviceAddr);
EricLew 0:ad9dfc0179dc 151 uint32_t wm8994_Resume(uint16_t DeviceAddr);
EricLew 0:ad9dfc0179dc 152 uint32_t wm8994_Stop(uint16_t DeviceAddr, uint32_t Cmd);
EricLew 0:ad9dfc0179dc 153 uint32_t wm8994_SetVolume(uint16_t DeviceAddr, uint8_t Volume);
EricLew 0:ad9dfc0179dc 154 uint32_t wm8994_SetMute(uint16_t DeviceAddr, uint32_t Cmd);
EricLew 0:ad9dfc0179dc 155 uint32_t wm8994_SetOutputMode(uint16_t DeviceAddr, uint8_t Output);
EricLew 0:ad9dfc0179dc 156 uint32_t wm8994_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq);
EricLew 0:ad9dfc0179dc 157 uint32_t wm8994_Reset(uint16_t DeviceAddr);
EricLew 0:ad9dfc0179dc 158
EricLew 0:ad9dfc0179dc 159 /* AUDIO IO functions */
EricLew 0:ad9dfc0179dc 160 void AUDIO_IO_Init(void);
EricLew 0:ad9dfc0179dc 161 void AUDIO_IO_DeInit(void);
EricLew 0:ad9dfc0179dc 162 void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
EricLew 0:ad9dfc0179dc 163 uint8_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg);
EricLew 0:ad9dfc0179dc 164 void AUDIO_IO_Delay(uint32_t Delay);
EricLew 0:ad9dfc0179dc 165
EricLew 0:ad9dfc0179dc 166 /* Audio driver structure */
EricLew 0:ad9dfc0179dc 167 extern AUDIO_DrvTypeDef wm8994_drv;
EricLew 0:ad9dfc0179dc 168
EricLew 0:ad9dfc0179dc 169 #endif /* __WM8994_H */
EricLew 0:ad9dfc0179dc 170
EricLew 0:ad9dfc0179dc 171 /**
EricLew 0:ad9dfc0179dc 172 * @}
EricLew 0:ad9dfc0179dc 173 */
EricLew 0:ad9dfc0179dc 174
EricLew 0:ad9dfc0179dc 175 /**
EricLew 0:ad9dfc0179dc 176 * @}
EricLew 0:ad9dfc0179dc 177 */
EricLew 0:ad9dfc0179dc 178
EricLew 0:ad9dfc0179dc 179 /**
EricLew 0:ad9dfc0179dc 180 * @}
EricLew 0:ad9dfc0179dc 181 */
EricLew 0:ad9dfc0179dc 182
EricLew 0:ad9dfc0179dc 183 /**
EricLew 0:ad9dfc0179dc 184 * @}
EricLew 0:ad9dfc0179dc 185 */
EricLew 0:ad9dfc0179dc 186
EricLew 0:ad9dfc0179dc 187 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
EricLew 0:ad9dfc0179dc 188