2 ******************************************************************************
3 * @file stm32f4_discovery_audio_codec.h
4 * @author MCD Application Team
6 * @date 19-September-2011
7 * @brief This file contains all the functions prototypes for the
8 * stm32f4_discovery_audio_codec.c driver.
9 ******************************************************************************
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
20 ******************************************************************************
23 /* Define to prevent recursive inclusion -------------------------------------*/
24 #ifndef __STM32F4_DISCOVERY_AUDIOCODEC_H
25 #define __STM32F4_DISCOVERY_AUDIOCODEC_H
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f4xx.h"
29 #include "stm32f4xx_gpio.h"
31 /** @addtogroup Utilities
36 /** @addtogroup STM32F4_DISCOVERY
40 /** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC
45 /** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Types
49 /** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Constants
53 /*------------------------------------
54 CONFIGURATION: Audio Codec Driver Configuration parameters
55 ----------------------------------------*/
57 /* Audio Transfer mode (DMA, Interrupt or Polling) */
58 #define AUDIO_MAL_MODE_NORMAL /* Uncomment this line to enable the audio
60 /* #define AUDIO_MAL_MODE_CIRCULAR */ /* Uncomment this line to enable the audio
63 /* For the DMA modes select the interrupt that will be used */
64 #define AUDIO_MAL_DMA_IT_TC_EN /* Uncomment this line to enable DMA Transfer Complete interrupt */
65 /* #define AUDIO_MAL_DMA_IT_HT_EN */ /* Uncomment this line to enable DMA Half Transfer Complete interrupt */
66 /* #define AUDIO_MAL_DMA_IT_TE_EN */ /* Uncomment this line to enable DMA Transfer Error interrupt */
68 /* Select the interrupt preemption priority and subpriority for the DMA interrupt */
69 #define EVAL_AUDIO_IRQ_PREPRIO 0 /* Select the preemption priority level(0 is the highest) */
70 #define EVAL_AUDIO_IRQ_SUBRIO 0 /* Select the sub-priority level (0 is the highest) */
72 /* Uncomment the following line to use the default Codec_TIMEOUT_UserCallback()
73 function implemented in stm32f4_discovery_audio_codec.c file.
74 Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
75 occurs during communication (waiting on an event that doesn't occur, bus
76 errors, busy devices ...). */
77 /* #define USE_DEFAULT_TIMEOUT_CALLBACK */
79 /* Enable this define to use the I2S DMA for writing into DAC register */
80 //#define DAC_USE_I2S_DMA
81 /*----------------------------------------------------------------------------*/
83 /*------------------------------------
84 OPTIONAL Configuration defines parameters
85 ----------------------------------------*/
86 /* I2C clock speed configuration (in Hz)
88 Make sure that this define is not already declared in other files (ie.
89 stm322xg_eval.h file). It can be used in parallel by other modules. */
91 #define I2C_SPEED 100000
92 #endif /* I2C_SPEED */
94 /* Uncomment defines below to select standard for audio communication between
95 Codec and I2S peripheral */
96 #define I2S_STANDARD_PHILLIPS
97 /* #define I2S_STANDARD_MSB */
98 /* #define I2S_STANDARD_LSB */
100 /* Uncomment the defines below to select if the Master clock mode should be
102 #define CODEC_MCLK_ENABLED
103 /* #deine CODEC_MCLK_DISABLED */
105 /* Uncomment this line to enable verifying data sent to codec after each write
107 #define VERIFY_WRITTENDATA
108 /*----------------------------------------------------------------------------*/
110 /*-----------------------------------
111 Hardware Configuration defines parameters
112 -----------------------------------------*/
113 /* Audio Reset Pin definition */
114 #define AUDIO_RESET_GPIO_CLK RCC_AHB1Periph_GPIOD
115 #define AUDIO_RESET_PIN GPIO_Pin_4
116 #define AUDIO_RESET_GPIO GPIOD
118 /* I2S peripheral configuration defines */
119 #define CODEC_I2S SPI3
120 #define CODEC_I2S_CLK RCC_APB1Periph_SPI3
121 #define CODEC_I2S_ADDRESS 0x40003C0C
122 #define CODEC_I2S_GPIO_AF GPIO_AF_SPI3
123 #define CODEC_I2S_IRQ SPI3_IRQn
124 #define CODEC_I2S_GPIO_CLOCK (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOA)
125 #define CODEC_I2S_WS_PIN GPIO_Pin_4
126 #define CODEC_I2S_SCK_PIN GPIO_Pin_10
127 #define CODEC_I2S_SD_PIN GPIO_Pin_12
128 #define CODEC_I2S_MCK_PIN GPIO_Pin_7
129 #define CODEC_I2S_WS_PINSRC GPIO_PinSource4
130 #define CODEC_I2S_SCK_PINSRC GPIO_PinSource10
131 #define CODEC_I2S_SD_PINSRC GPIO_PinSource12
132 #define CODEC_I2S_MCK_PINSRC GPIO_PinSource7
133 #define CODEC_I2S_GPIO GPIOC
134 #define CODEC_I2S_WS_GPIO GPIOA
135 #define CODEC_I2S_MCK_GPIO GPIOC
136 #define Audio_I2S_IRQHandler SPI3_IRQHandler
139 #define AUDIO_MAL_DMA_PERIPH_DATA_SIZE DMA_PeripheralDataSize_HalfWord
140 #define AUDIO_MAL_DMA_MEM_DATA_SIZE DMA_MemoryDataSize_HalfWord
141 #define DMA_MAX_SZE 0xFFFF
144 #define DAC_DHR12L1_ADDRESS 0x4000740C
145 #define DAC_DHR12R1_ADDRESS 0x40007408
146 #define DAC_DHR8R1_ADDRESS 0x40007410
147 #define AUDIO_DAC_CHANNEL DAC_Channel_1
149 /* I2S DMA Stream definitions */
150 #define AUDIO_I2S_DMA_CLOCK RCC_AHB1Periph_DMA1
151 #define AUDIO_I2S_DMA_STREAM DMA1_Stream7
152 #define AUDIO_I2S_DMA_DREG CODEC_I2S_ADDRESS
153 #define AUDIO_I2S_DMA_CHANNEL DMA_Channel_0
154 #define AUDIO_I2S_DMA_IRQ DMA1_Stream7_IRQn
155 #define AUDIO_I2S_DMA_FLAG_TC DMA_FLAG_TCIF7
156 #define AUDIO_I2S_DMA_FLAG_HT DMA_FLAG_HTIF7
157 #define AUDIO_I2S_DMA_FLAG_FE DMA_FLAG_FEIF7
158 #define AUDIO_I2S_DMA_FLAG_TE DMA_FLAG_TEIF7
159 #define AUDIO_I2S_DMA_FLAG_DME DMA_FLAG_DMEIF7
161 #define Audio_MAL_I2S_IRQHandler DMA1_Stream7_IRQHandler
164 /* DAC DMA Stream definitions */
165 #define AUDIO_DAC_DMA_CLOCK RCC_AHB1Periph_DMA1
166 #define AUDIO_DAC_DMA_STREAM DMA1_Stream0
167 #define AUDIO_DAC_DMA_DREG DAC_DHR12L1_ADDRESS
168 #define AUDIO_DAC_DMA_CHANNEL DMA_Channel_0
169 #define AUDIO_DAC_DMA_IRQ DMA1_Stream0_IRQn
170 #define AUDIO_DAC_DMA_FLAG_TC DMA_FLAG_TCIF0
171 #define AUDIO_DAC_DMA_FLAG_HT DMA_FLAG_HTIF0
172 #define AUDIO_DAC_DMA_FLAG_FE DMA_FLAG_FEIF0
173 #define AUDIO_DAC_DMA_FLAG_TE DMA_FLAG_TEIF0
174 #define AUDIO_DAC_DMA_FLAG_DME DMA_FLAG_DMEIF0
176 #define Audio_MAL_DAC_IRQHandler DMA1_Stream0_IRQHandler
179 /* I2C peripheral configuration defines (control interface of the audio codec) */
180 #define CODEC_I2C I2C1
181 #define CODEC_I2C_CLK RCC_APB1Periph_I2C1
182 #define CODEC_I2C_GPIO_CLOCK RCC_AHB1Periph_GPIOB
183 #define CODEC_I2C_GPIO_AF GPIO_AF_I2C1
184 #define CODEC_I2C_GPIO GPIOB
185 #define CODEC_I2C_SCL_PIN GPIO_Pin_6
186 #define CODEC_I2C_SDA_PIN GPIO_Pin_9
187 #define CODEC_I2S_SCL_PINSRC GPIO_PinSource6
188 #define CODEC_I2S_SDA_PINSRC GPIO_PinSource9
190 /* Maximum Timeout values for flags and events waiting loops. These timeouts are
191 not based on accurate values, they just guarantee that the application will
192 not remain stuck if the I2C communication is corrupted.
193 You may modify these timeout values depending on CPU frequency and application
194 conditions (interrupts routines ...). */
195 #define CODEC_FLAG_TIMEOUT ((uint32_t)0x1000)
196 #define CODEC_LONG_TIMEOUT ((uint32_t)(300 * CODEC_FLAG_TIMEOUT))
197 /*----------------------------------------------------------------------------*/
199 /*-----------------------------------
200 Audio Codec User defines
201 -----------------------------------------*/
202 /* Audio interface : I2S or DAC */
203 #define AUDIO_INTERFACE_I2S 1
204 #define AUDIO_INTERFACE_DAC 2
206 /* Codec output DEVICE */
207 #define OUTPUT_DEVICE_SPEAKER 1
208 #define OUTPUT_DEVICE_HEADPHONE 2
209 #define OUTPUT_DEVICE_BOTH 3
210 #define OUTPUT_DEVICE_AUTO 4
212 /* Volume Levels values */
213 #define DEFAULT_VOLMIN 0x00
214 #define DEFAULT_VOLMAX 0xFF
215 #define DEFAULT_VOLSTEP 0x04
217 #define AUDIO_PAUSE 0
218 #define AUDIO_RESUME 1
220 /* Codec POWER DOWN modes */
221 #define CODEC_PDWN_HW 1
222 #define CODEC_PDWN_SW 2
225 #define AUDIO_MUTE_ON 1
226 #define AUDIO_MUTE_OFF 0
227 /*----------------------------------------------------------------------------*/
232 /** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Macros
235 #define VOLUME_CONVERT(x) ((Volume > 100)? 100:((uint8_t)((Volume * 255) / 100)))
236 #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
242 /** @defgroup STM32F4_DISCOVERY_AUDIO_CODEC_Exported_Functions
245 void EVAL_AUDIO_SetAudioInterface(uint32_t Interface);
246 uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
247 uint32_t EVAL_AUDIO_DeInit(void);
248 uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size);
249 uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd);
250 uint32_t EVAL_AUDIO_Stop(uint32_t CodecPowerDown_Mode);
251 uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume);
252 uint32_t EVAL_AUDIO_Mute(uint32_t Command);
253 void DAC_Config(void);
255 /* User Callbacks: user has to implement these functions in his code if
256 they are needed. -----------------------------------------------------------*/
258 uint16_t EVAL_AUDIO_GetSampleCallBack(void);
260 /* This function is called when the requested data has been completely transferred.
261 In Normal mode (when the define AUDIO_MAL_MODE_NORMAL is enabled) this function
262 is called at the end of the whole audio file.
263 In circular mode (when the define AUDIO_MAL_MODE_CIRCULAR is enabled) this
264 function is called at the end of the current buffer transmission. */
265 void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size);
267 /* This function is called when half of the requested buffer has been transferred
268 This callback is useful in Circular mode only (when AUDIO_MAL_MODE_CIRCULAR
270 void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size);
272 /* This function is called when an Interrupt due to transfer error on or peripheral
274 void EVAL_AUDIO_Error_CallBack(void* pData);
276 /* Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
277 occurs during communication (waiting on an event that doesn't occur, bus
278 errors, busy devices ...) on the Codec control interface (I2C).
279 You can use the default timeout callback implementation by uncommenting the
280 define USE_DEFAULT_TIMEOUT_CALLBACK in stm32f4_discovery_audio_codec.h file.
281 Typically the user implementation of this callback should reset I2C peripheral
282 and re-initialize communication or in worst case reset all the application. */
283 uint32_t Codec_TIMEOUT_UserCallback(void);
285 #endif /* __STM32F4_DISCOVERY_AUDIOCODEC_H */
304 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/