STM32F439xx HAL User Manual
stm32f4xx_hal_dac.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_dac.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of DAC HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32F4xx_HAL_DAC_H
00038 #define __STM32F4xx_HAL_DAC_H
00039 
00040 #ifdef __cplusplus
00041  extern "C" {
00042 #endif
00043 
00044 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
00045     defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00046     defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) ||\
00047     defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
00048 
00049 /* Includes ------------------------------------------------------------------*/
00050 #include "stm32f4xx_hal_def.h"
00051 
00052 /** @addtogroup STM32F4xx_HAL_Driver
00053   * @{
00054   */
00055 
00056 /** @addtogroup DAC
00057   * @{
00058   */
00059 
00060 /* Exported types ------------------------------------------------------------*/
00061 /** @defgroup DAC_Exported_Types DAC Exported Types
00062   * @{
00063   */
00064 
00065 /** 
00066   * @brief HAL State structures definition
00067   */
00068 typedef enum
00069 {
00070   HAL_DAC_STATE_RESET             = 0x00U,  /*!< DAC not yet initialized or disabled  */
00071   HAL_DAC_STATE_READY             = 0x01U,  /*!< DAC initialized and ready for use    */
00072   HAL_DAC_STATE_BUSY              = 0x02U,  /*!< DAC internal processing is ongoing   */
00073   HAL_DAC_STATE_TIMEOUT           = 0x03U,  /*!< DAC timeout state                    */
00074   HAL_DAC_STATE_ERROR             = 0x04U   /*!< DAC error state                      */
00075 }HAL_DAC_StateTypeDef;
00076  
00077 /** 
00078   * @brief DAC handle Structure definition
00079   */
00080 typedef struct
00081 {
00082   DAC_TypeDef                 *Instance;     /*!< Register base address             */
00083 
00084   __IO HAL_DAC_StateTypeDef   State;         /*!< DAC communication state           */
00085 
00086   HAL_LockTypeDef             Lock;          /*!< DAC locking object                */
00087 
00088   DMA_HandleTypeDef           *DMA_Handle1;  /*!< Pointer DMA handler for channel 1 */
00089 
00090   DMA_HandleTypeDef           *DMA_Handle2;  /*!< Pointer DMA handler for channel 2 */
00091 
00092   __IO uint32_t               ErrorCode;     /*!< DAC Error code                    */
00093 
00094 }DAC_HandleTypeDef;
00095 
00096 /** 
00097   * @brief DAC Configuration regular Channel structure definition
00098   */
00099 typedef struct
00100 {
00101   uint32_t DAC_Trigger;       /*!< Specifies the external trigger for the selected DAC channel.
00102                                    This parameter can be a value of @ref DAC_trigger_selection */
00103 
00104   uint32_t DAC_OutputBuffer;  /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
00105                                    This parameter can be a value of @ref DAC_output_buffer */
00106 }DAC_ChannelConfTypeDef;
00107 /**
00108   * @}
00109   */
00110 
00111 /* Exported constants --------------------------------------------------------*/
00112 /** @defgroup DAC_Exported_Constants DAC Exported Constants
00113   * @{
00114   */
00115 
00116 /** @defgroup DAC_Error_Code DAC Error Code
00117   * @{
00118   */
00119 #define  HAL_DAC_ERROR_NONE              0x00U    /*!< No error                          */
00120 #define  HAL_DAC_ERROR_DMAUNDERRUNCH1    0x01U    /*!< DAC channel1 DAM underrun error   */
00121 #define  HAL_DAC_ERROR_DMAUNDERRUNCH2    0x02U    /*!< DAC channel2 DAM underrun error   */
00122 #define  HAL_DAC_ERROR_DMA               0x04U    /*!< DMA error                         */
00123 /**
00124   * @}
00125   */
00126 
00127 /** @defgroup DAC_trigger_selection DAC Trigger Selection
00128   * @{
00129   */
00130 
00131 #define DAC_TRIGGER_NONE                   0x00000000U /*!< Conversion is automatic once the DAC1_DHRxxxx register 
00132                                                             has been loaded, and not by external trigger */
00133 #define DAC_TRIGGER_T2_TRGO                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TEN1)) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
00134 #define DAC_TRIGGER_T4_TRGO                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
00135 #define DAC_TRIGGER_T5_TRGO                ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */
00136 #define DAC_TRIGGER_T6_TRGO                ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
00137 #define DAC_TRIGGER_T7_TRGO                ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
00138 #define DAC_TRIGGER_T8_TRGO                ((uint32_t)(DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel */                                                                       
00139 
00140 #define DAC_TRIGGER_EXT_IT9                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
00141 #define DAC_TRIGGER_SOFTWARE               ((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1)) /*!< Conversion started by software trigger for DAC channel */
00142 /**
00143   * @}
00144   */
00145 
00146 /** @defgroup DAC_output_buffer  DAC Output Buffer
00147   * @{
00148   */
00149 #define DAC_OUTPUTBUFFER_ENABLE            0x00000000U
00150 #define DAC_OUTPUTBUFFER_DISABLE           ((uint32_t)DAC_CR_BOFF1)
00151 /**
00152   * @}
00153   */
00154 
00155 /** @defgroup DAC_Channel_selection DAC Channel Selection
00156   * @{
00157   */
00158 #define DAC_CHANNEL_1                      0x00000000U
00159 #define DAC_CHANNEL_2                      0x00000010U
00160 /**
00161   * @}
00162   */
00163 
00164 /** @defgroup DAC_data_alignment DAC Data Alignment
00165   * @{
00166   */
00167 #define DAC_ALIGN_12B_R                    0x00000000U
00168 #define DAC_ALIGN_12B_L                    0x00000004U
00169 #define DAC_ALIGN_8B_R                     0x00000008U
00170 /**
00171   * @}
00172   */
00173 
00174 /** @defgroup DAC_flags_definition DAC Flags Definition
00175   * @{
00176   */ 
00177 #define DAC_FLAG_DMAUDR1                   ((uint32_t)DAC_SR_DMAUDR1)
00178 #define DAC_FLAG_DMAUDR2                   ((uint32_t)DAC_SR_DMAUDR2)
00179 /**
00180   * @}
00181   */
00182 
00183 /** @defgroup DAC_IT_definition DAC IT Definition
00184   * @{
00185   */ 
00186 #define DAC_IT_DMAUDR1                   ((uint32_t)DAC_SR_DMAUDR1)
00187 #define DAC_IT_DMAUDR2                   ((uint32_t)DAC_SR_DMAUDR2)
00188 /**
00189   * @}
00190   */
00191 
00192 /**
00193   * @}
00194   */
00195 
00196 /* Exported macro ------------------------------------------------------------*/
00197 /** @defgroup DAC_Exported_Macros DAC Exported Macros
00198   * @{
00199   */
00200 
00201 /** @brief Reset DAC handle state
00202   * @param  __HANDLE__ specifies the DAC handle.
00203   * @retval None
00204   */
00205 #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
00206 
00207 /** @brief Enable the DAC channel
00208   * @param  __HANDLE__ specifies the DAC handle.
00209   * @param  __DAC_Channel__ specifies the DAC channel
00210   * @retval None
00211   */
00212 #define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) ((__HANDLE__)->Instance->CR |=  (DAC_CR_EN1 << (__DAC_Channel__)))
00213 
00214 /** @brief Disable the DAC channel
00215   * @param  __HANDLE__ specifies the DAC handle
00216   * @param  __DAC_Channel__ specifies the DAC channel.
00217   * @retval None
00218   */
00219 #define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) ((__HANDLE__)->Instance->CR &=  ~(DAC_CR_EN1 << (__DAC_Channel__)))
00220 
00221 /** @brief Enable the DAC interrupt
00222   * @param  __HANDLE__ specifies the DAC handle
00223   * @param  __INTERRUPT__ specifies the DAC interrupt.
00224   * @retval None
00225   */
00226 #define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
00227 
00228 /** @brief Disable the DAC interrupt
00229   * @param  __HANDLE__ specifies the DAC handle
00230   * @param  __INTERRUPT__ specifies the DAC interrupt.
00231   * @retval None
00232   */
00233 #define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
00234 
00235 /** @brief  Checks if the specified DAC interrupt source is enabled or disabled.
00236   * @param __HANDLE__ DAC handle
00237   * @param __INTERRUPT__ DAC interrupt source to check
00238   *          This parameter can be any combination of the following values:
00239   *            @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
00240   *            @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
00241   * @retval State of interruption (SET or RESET)
00242   */
00243 #define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__))
00244 
00245 /** @brief  Get the selected DAC's flag status.
00246   * @param  __HANDLE__ specifies the DAC handle.
00247   * @param  __FLAG__ specifies the flag to clear.
00248   *         This parameter can be any combination of the following values:
00249   *            @arg DAC_FLAG_DMAUDR1: DMA underrun 1 flag
00250   *            @arg DAC_FLAG_DMAUDR2: DMA underrun 2 flag
00251   * @retval None
00252   */
00253 #define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
00254 
00255 /** @brief  Clear the DAC's flag.
00256   * @param  __HANDLE__ specifies the DAC handle.
00257   * @param  __FLAG__ specifies the flag to clear.
00258   *         This parameter can be any combination of the following values:
00259   *            @arg DAC_FLAG_DMAUDR1: DMA underrun 1 flag
00260   *            @arg DAC_FLAG_DMAUDR2: DMA underrun 2 flag
00261   * @retval None
00262   */
00263 #define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__))
00264 /**
00265   * @}
00266   */
00267 
00268 /* Include DAC HAL Extension module */
00269 #include "stm32f4xx_hal_dac_ex.h"
00270 
00271 /* Exported functions --------------------------------------------------------*/
00272 /** @addtogroup DAC_Exported_Functions
00273   * @{
00274   */
00275 
00276 /** @addtogroup DAC_Exported_Functions_Group1
00277   * @{
00278   */
00279 /* Initialization/de-initialization functions *********************************/
00280 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac);
00281 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac);
00282 void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac);
00283 void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac);
00284 /**
00285   * @}
00286   */
00287 
00288 /** @addtogroup DAC_Exported_Functions_Group2
00289   * @{
00290   */
00291 /* I/O operation functions ****************************************************/
00292 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);
00293 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel);
00294 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment);
00295 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel);
00296 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel);
00297 /**
00298   * @}
00299   */
00300 
00301 /** @addtogroup DAC_Exported_Functions_Group3
00302   * @{
00303   */
00304 /* Peripheral Control functions ***********************************************/
00305 HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel);
00306 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
00307 /**
00308   * @}
00309   */
00310 
00311 /** @addtogroup DAC_Exported_Functions_Group4
00312   * @{
00313   */
00314 /* Peripheral State functions *************************************************/
00315 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac);
00316 void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac);
00317 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
00318 
00319 void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac);
00320 void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac);
00321 void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
00322 void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac);
00323 /**
00324   * @}
00325   */
00326 
00327 /**
00328   * @}
00329   */
00330 /* Private types -------------------------------------------------------------*/
00331 /* Private variables ---------------------------------------------------------*/
00332 /* Private constants ---------------------------------------------------------*/
00333 /** @defgroup DAC_Private_Constants DAC Private Constants
00334   * @{
00335   */
00336 
00337 /**
00338   * @}
00339   */
00340 
00341 /* Private macros ------------------------------------------------------------*/
00342 /** @defgroup DAC_Private_Macros DAC Private Macros
00343   * @{
00344   */
00345 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
00346 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
00347                              ((ALIGN) == DAC_ALIGN_12B_L) || \
00348                              ((ALIGN) == DAC_ALIGN_8B_R))
00349 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
00350                                  ((CHANNEL) == DAC_CHANNEL_2))
00351 #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
00352                                            ((STATE) == DAC_OUTPUTBUFFER_DISABLE))
00353 
00354 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
00355                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
00356                                  ((TRIGGER) == DAC_TRIGGER_T8_TRGO) || \
00357                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
00358                                  ((TRIGGER) == DAC_TRIGGER_T5_TRGO) || \
00359                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
00360                                  ((TRIGGER) == DAC_TRIGGER_T4_TRGO) || \
00361                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
00362                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
00363 
00364 /** @brief Set DHR12R1 alignment
00365   * @param  __ALIGNMENT__ specifies the DAC alignment
00366   * @retval None
00367   */
00368 #define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (0x00000008U + (__ALIGNMENT__))
00369 
00370 /** @brief  Set DHR12R2 alignment
00371   * @param  __ALIGNMENT__ specifies the DAC alignment
00372   * @retval None
00373   */
00374 #define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (((uint32_t)0x00000014U) + (__ALIGNMENT__))
00375 
00376 /** @brief  Set DHR12RD alignment
00377   * @param  __ALIGNMENT__ specifies the DAC alignment
00378   * @retval None
00379   */
00380 #define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (0x00000020U + (__ALIGNMENT__))
00381 
00382 /**
00383   * @}
00384   */
00385 
00386 /* Private functions ---------------------------------------------------------*/
00387 /** @defgroup DAC_Private_Functions DAC Private Functions
00388   * @{
00389   */
00390 /**
00391   * @}
00392   */
00393 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\
00394           STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||\
00395           STM32F410xx || STM32F446xx || STM32F469xx || STM32F479xx ||\
00396                   STM32F413xx || STM32F423xx */
00397 
00398 /**
00399   * @}
00400   */
00401 
00402 /**
00403   * @}
00404   */
00405   
00406 #ifdef __cplusplus
00407 }
00408 #endif
00409 
00410 #endif /*__STM32F4xx_HAL_DAC_H */
00411 
00412 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/