Martin Johnson / STM32F3-Discovery

Dependents:   Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f30x_dac.h Source File

stm32f30x_dac.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f30x_dac.h
00004   * @author  MCD Application Team
00005   * @version V1.2.3
00006   * @date    10-July-2015
00007   * @brief   This file contains all the functions prototypes for the DAC firmware 
00008   *          library.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
00013   *
00014   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00015   * You may not use this file except in compliance with the License.
00016   * You may obtain a copy of the License at:
00017   *
00018   *        http://www.st.com/software_license_agreement_liberty_v2
00019   *
00020   * Unless required by applicable law or agreed to in writing, software 
00021   * distributed under the License is distributed on an "AS IS" BASIS, 
00022   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00023   * See the License for the specific language governing permissions and
00024   * limitations under the License.
00025   *
00026   ******************************************************************************
00027   */
00028 
00029 /* Define to prevent recursive inclusion -------------------------------------*/
00030 #ifndef __STM32F30x_DAC_H
00031 #define __STM32F30x_DAC_H
00032 
00033 #ifdef __cplusplus
00034  extern "C" {
00035 #endif
00036 
00037 /* Includes ------------------------------------------------------------------*/
00038 #include "stm32f30x.h"
00039 
00040 /** @addtogroup STM32F30x_StdPeriph_Driver
00041   * @{
00042   */
00043 
00044 /** @addtogroup DAC
00045   * @{
00046   */
00047 
00048 /* Exported types ------------------------------------------------------------*/
00049 #define DAC_CR_DMAUDRIE                  ((uint32_t)0x00002000)        /*!< DAC channel DMA underrun interrupt enable */
00050 
00051 /** 
00052   * @brief  DAC Init structure definition
00053   */
00054 
00055 typedef struct
00056 {
00057   uint32_t DAC_Trigger;                      /*!< Specifies the external trigger for the selected DAC channel.
00058                                                   This parameter can be a value of @ref DAC_trigger_selection */
00059 
00060   uint32_t DAC_WaveGeneration;               /*!< Specifies whether DAC channel noise waves or triangle waves
00061                                                   are generated, or whether no wave is generated.
00062                                                   This parameter can be a value of @ref DAC_wave_generation */
00063 
00064   uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
00065                                                   the maximum amplitude triangle generation for the DAC channel. 
00066                                                   This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
00067 
00068   uint32_t DAC_Buffer_Switch;                /*!< Specifies whether the DAC channel output buffer is enabled or disabled or 
00069                                                   the DAC channel output switch is enabled or disabled.
00070                                                   This parameter can be a value of @ref DAC_buffer_switch */
00071 }DAC_InitTypeDef;
00072 
00073 /* Exported constants --------------------------------------------------------*/
00074 
00075 /** @defgroup DAC_Exported_Constants
00076   * @{
00077   */
00078 
00079 #define IS_DAC_ALL_PERIPH(PERIPH) (((PERIPH) == DAC1) || \
00080                                    ((PERIPH) == DAC2))
00081 
00082 #define IS_DAC_LIST1_PERIPH(PERIPH) (((PERIPH) == DAC1))
00083 
00084 /** @defgroup DAC_trigger_selection 
00085   * @{
00086   */
00087 
00088 #define DAC_Trigger_None                     ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register 
00089                                                                          has been loaded, and not by external trigger */
00090 #define DAC_Trigger_T6_TRGO                  ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
00091 #define DAC_Trigger_T3_TRGO                  ((uint32_t)0x0000000C) /*!< TIM3 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
00092 #define DAC_Trigger_T8_TRGO                  ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC1 channel1/2 */
00093 #define DAC_Trigger_T7_TRGO                  ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
00094 #define DAC_Trigger_T15_TRGO                 ((uint32_t)0x0000001C) /*!< TIM15 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
00095 #define DAC_Trigger_HRTIM1_DACTRG1           ((uint32_t)0x0000001C)  /*!< HRTIM1 DACTRG1 selected as external conversion trigger for DAC1 channel1/2 */                                                                         
00096 #define DAC_Trigger_T2_TRGO                  ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
00097 #define DAC_Trigger_T4_TRGO                  ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
00098 #define DAC_Trigger_HRTIM1_DACTRG2           ((uint32_t)0x0000002C) /*!< HRTIM1 DACTRG2 selected as external conversion trigger for DAC1 channel1/2 */
00099 #define DAC_Trigger_HRTIM1_DACTRG3           ((uint32_t)0x0000002C) /*!< HRTIM1 DACTRG3 selected as external conversion trigger for DAC2 channel1 */
00100 #define DAC_Trigger_Ext_IT9                  ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC1/2 channel1/2 */
00101 #define DAC_Trigger_Software                 ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC1/2 channel1/2 */
00102 
00103 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None)          || \
00104                                  ((TRIGGER) == DAC_Trigger_T6_TRGO)       || \
00105                                  ((TRIGGER) == DAC_Trigger_T3_TRGO)       || \
00106                                  ((TRIGGER) == DAC_Trigger_T8_TRGO)       || \
00107                                  ((TRIGGER) == DAC_Trigger_T7_TRGO)       || \
00108                                  ((TRIGGER) == DAC_Trigger_T15_TRGO)      || \
00109                                  ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG1)|| \
00110                                  ((TRIGGER) == DAC_Trigger_T2_TRGO)       || \
00111                                  ((TRIGGER) == DAC_Trigger_T4_TRGO)       || \
00112                                  ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG2)|| \
00113                                  ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG3)|| \
00114                                  ((TRIGGER) == DAC_Trigger_Ext_IT9)       || \
00115                                  ((TRIGGER) == DAC_Trigger_Software))
00116 
00117 /**
00118   * @}
00119   */
00120 
00121 /** @defgroup DAC_wave_generation 
00122   * @{
00123   */
00124 
00125 #define DAC_WaveGeneration_None            ((uint32_t)0x00000000)
00126 #define DAC_WaveGeneration_Noise           ((uint32_t)0x00000040)
00127 #define DAC_WaveGeneration_Triangle        ((uint32_t)0x00000080)
00128 
00129 #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None)  || \
00130                                     ((WAVE) == DAC_WaveGeneration_Noise) || \
00131                                     ((WAVE) == DAC_WaveGeneration_Triangle))
00132 /**
00133   * @}
00134   */
00135 
00136 /** @defgroup DAC_lfsrunmask_triangleamplitude
00137   * @{
00138   */
00139 
00140 #define DAC_LFSRUnmask_Bit0                ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
00141 #define DAC_LFSRUnmask_Bits1_0             ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
00142 #define DAC_LFSRUnmask_Bits2_0             ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
00143 #define DAC_LFSRUnmask_Bits3_0             ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
00144 #define DAC_LFSRUnmask_Bits4_0             ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
00145 #define DAC_LFSRUnmask_Bits5_0             ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
00146 #define DAC_LFSRUnmask_Bits6_0             ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
00147 #define DAC_LFSRUnmask_Bits7_0             ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
00148 #define DAC_LFSRUnmask_Bits8_0             ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
00149 #define DAC_LFSRUnmask_Bits9_0             ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
00150 #define DAC_LFSRUnmask_Bits10_0            ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
00151 #define DAC_LFSRUnmask_Bits11_0            ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
00152 #define DAC_TriangleAmplitude_1            ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
00153 #define DAC_TriangleAmplitude_3            ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
00154 #define DAC_TriangleAmplitude_7            ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
00155 #define DAC_TriangleAmplitude_15           ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
00156 #define DAC_TriangleAmplitude_31           ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
00157 #define DAC_TriangleAmplitude_63           ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
00158 #define DAC_TriangleAmplitude_127          ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
00159 #define DAC_TriangleAmplitude_255          ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
00160 #define DAC_TriangleAmplitude_511          ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
00161 #define DAC_TriangleAmplitude_1023         ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
00162 #define DAC_TriangleAmplitude_2047         ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
00163 #define DAC_TriangleAmplitude_4095         ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
00164 
00165 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
00166                                                       ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
00167                                                       ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
00168                                                       ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
00169                                                       ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
00170                                                       ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
00171                                                       ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
00172                                                       ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
00173                                                       ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
00174                                                       ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
00175                                                       ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
00176                                                       ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
00177                                                       ((VALUE) == DAC_TriangleAmplitude_1) || \
00178                                                       ((VALUE) == DAC_TriangleAmplitude_3) || \
00179                                                       ((VALUE) == DAC_TriangleAmplitude_7) || \
00180                                                       ((VALUE) == DAC_TriangleAmplitude_15) || \
00181                                                       ((VALUE) == DAC_TriangleAmplitude_31) || \
00182                                                       ((VALUE) == DAC_TriangleAmplitude_63) || \
00183                                                       ((VALUE) == DAC_TriangleAmplitude_127) || \
00184                                                       ((VALUE) == DAC_TriangleAmplitude_255) || \
00185                                                       ((VALUE) == DAC_TriangleAmplitude_511) || \
00186                                                       ((VALUE) == DAC_TriangleAmplitude_1023) || \
00187                                                       ((VALUE) == DAC_TriangleAmplitude_2047) || \
00188                                                       ((VALUE) == DAC_TriangleAmplitude_4095))
00189 /**
00190   * @}
00191   */
00192 
00193 /** @defgroup DAC_buffer_switch 
00194   * @{
00195   */
00196 
00197 #define DAC_BufferSwitch_Disable                 ((uint32_t)0x00000000)
00198 #define DAC_BufferSwitch_Enable                  ((uint32_t)0x00000002)
00199   
00200 #define IS_DAC_BUFFER_SWITCH_STATE(STATE) (((STATE) == DAC_BufferSwitch_Enable) || \
00201                                            ((STATE) == DAC_BufferSwitch_Disable))
00202 /**
00203   * @}
00204   */
00205 
00206 /** @defgroup DAC_Channel_selection 
00207   * @{
00208   */
00209 #define DAC_Channel_1                     ((uint32_t)0x00000000)
00210 #define DAC_Channel_2                     ((uint32_t)0x00000010)
00211 
00212 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
00213                                  ((CHANNEL) == DAC_Channel_2))
00214 /**
00215   * @}
00216   */
00217 
00218 /** @defgroup DAC_data_alignement 
00219   * @{
00220   */
00221 
00222 #define DAC_Align_12b_R                    ((uint32_t)0x00000000)
00223 #define DAC_Align_12b_L                    ((uint32_t)0x00000004)
00224 #define DAC_Align_8b_R                     ((uint32_t)0x00000008)
00225 
00226 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
00227                              ((ALIGN) == DAC_Align_12b_L) || \
00228                              ((ALIGN) == DAC_Align_8b_R))
00229 /**
00230   * @}
00231   */
00232 
00233 /** @defgroup DAC_wave_generation 
00234   * @{
00235   */
00236 
00237 #define DAC_Wave_Noise                     ((uint32_t)0x00000040)
00238 #define DAC_Wave_Triangle                  ((uint32_t)0x00000080)
00239 
00240 #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
00241                            ((WAVE) == DAC_Wave_Triangle))
00242 /**
00243   * @}
00244   */
00245 
00246 /** @defgroup DAC_data 
00247   * @{
00248   */
00249 
00250 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0) 
00251 /**
00252   * @}
00253   */
00254   
00255 /** @defgroup DAC_interrupts_definition 
00256   * @{
00257   */   
00258 #define DAC_IT_DMAUDR                      ((uint32_t)0x00002000)  
00259 #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR)) 
00260 
00261 /**
00262   * @}
00263   */ 
00264 
00265 /** @defgroup DAC_flags_definition 
00266   * @{
00267   */ 
00268   
00269 #define DAC_FLAG_DMAUDR                    ((uint32_t)0x00002000)  
00270 #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))  
00271 
00272 /**
00273   * @}
00274   */
00275 
00276 /**
00277   * @}
00278   */
00279 
00280 /* Exported macro ------------------------------------------------------------*/
00281 /* Exported functions --------------------------------------------------------*/  
00282 
00283 /*  Function used to set the DAC configuration to the default reset state *****/  
00284 void DAC_DeInit(DAC_TypeDef* DACx);
00285 
00286 /*  DAC channels configuration: trigger, output buffer, data format functions */
00287 void DAC_Init(DAC_TypeDef* DACx, uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
00288 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
00289 void DAC_Cmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
00290 void DAC_SoftwareTriggerCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
00291 void DAC_DualSoftwareTriggerCmd(DAC_TypeDef* DACx, FunctionalState NewState);
00292 void DAC_WaveGenerationCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
00293 void DAC_SetChannel1Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data);
00294 void DAC_SetChannel2Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data);
00295 void DAC_SetDualChannelData(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
00296 uint16_t DAC_GetDataOutputValue(DAC_TypeDef* DACx, uint32_t DAC_Channel);
00297 
00298 /* DMA management functions ***************************************************/
00299 void DAC_DMACmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
00300 
00301 /* Interrupts and flags management functions **********************************/
00302 void DAC_ITConfig(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
00303 FlagStatus DAC_GetFlagStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG);
00304 void DAC_ClearFlag(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG);
00305 ITStatus DAC_GetITStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT);
00306 void DAC_ClearITPendingBit(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT);
00307 
00308 #ifdef __cplusplus
00309 }
00310 #endif
00311 
00312 #endif /*__STM32F30x_DAC_H */
00313 
00314 /**
00315   * @}
00316   */
00317 
00318 /**
00319   * @}
00320   */
00321 
00322 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/