Subversion Repositories LedShow

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f1xx_hal_dac.h
  4.   * @author  MCD Application Team
  5.   * @brief   Header file of DAC HAL module.
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19.  
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef STM32F1xx_HAL_DAC_H
  22. #define STM32F1xx_HAL_DAC_H
  23.  
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. /** @addtogroup STM32F1xx_HAL_Driver
  29.   * @{
  30.   */
  31.  
  32. /* Includes ------------------------------------------------------------------*/
  33. #include "stm32f1xx_hal_def.h"
  34.  
  35. #if defined(DAC)
  36.  
  37. /** @addtogroup DAC
  38.   * @{
  39.   */
  40.  
  41. /* Exported types ------------------------------------------------------------*/
  42.  
  43. /** @defgroup DAC_Exported_Types DAC Exported Types
  44.   * @{
  45.   */
  46.  
  47. /**
  48.   * @brief  HAL State structures definition
  49.   */
  50. typedef enum
  51. {
  52.   HAL_DAC_STATE_RESET             = 0x00U,  /*!< DAC not yet initialized or disabled  */
  53.   HAL_DAC_STATE_READY             = 0x01U,  /*!< DAC initialized and ready for use    */
  54.   HAL_DAC_STATE_BUSY              = 0x02U,  /*!< DAC internal processing is ongoing   */
  55.   HAL_DAC_STATE_TIMEOUT           = 0x03U,  /*!< DAC timeout state                    */
  56.   HAL_DAC_STATE_ERROR             = 0x04U   /*!< DAC error state                      */
  57.  
  58. } HAL_DAC_StateTypeDef;
  59.  
  60. /**
  61.   * @brief  DAC handle Structure definition
  62.   */
  63. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  64. typedef struct __DAC_HandleTypeDef
  65. #else
  66. typedef struct
  67. #endif
  68. {
  69.   DAC_TypeDef                 *Instance;     /*!< Register base address             */
  70.  
  71.   __IO HAL_DAC_StateTypeDef   State;         /*!< DAC communication state           */
  72.  
  73.   HAL_LockTypeDef             Lock;          /*!< DAC locking object                */
  74.  
  75.   DMA_HandleTypeDef           *DMA_Handle1;  /*!< Pointer DMA handler for channel 1 */
  76.  
  77.   DMA_HandleTypeDef           *DMA_Handle2;  /*!< Pointer DMA handler for channel 2 */
  78.  
  79.   __IO uint32_t               ErrorCode;     /*!< DAC Error code                    */
  80.  
  81. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  82.   void (* ConvCpltCallbackCh1)            (struct __DAC_HandleTypeDef *hdac);
  83.   void (* ConvHalfCpltCallbackCh1)        (struct __DAC_HandleTypeDef *hdac);
  84.   void (* ErrorCallbackCh1)               (struct __DAC_HandleTypeDef *hdac);
  85.   void (* DMAUnderrunCallbackCh1)         (struct __DAC_HandleTypeDef *hdac);
  86.   void (* ConvCpltCallbackCh2)            (struct __DAC_HandleTypeDef *hdac);
  87.   void (* ConvHalfCpltCallbackCh2)        (struct __DAC_HandleTypeDef *hdac);
  88.   void (* ErrorCallbackCh2)               (struct __DAC_HandleTypeDef *hdac);
  89.   void (* DMAUnderrunCallbackCh2)         (struct __DAC_HandleTypeDef *hdac);
  90.  
  91.   void (* MspInitCallback)                (struct __DAC_HandleTypeDef *hdac);
  92.   void (* MspDeInitCallback )             (struct __DAC_HandleTypeDef *hdac);
  93. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  94.  
  95. } DAC_HandleTypeDef;
  96.  
  97.  
  98. /**
  99.   * @brief   DAC Configuration regular Channel structure definition
  100.   */
  101. typedef struct
  102. {
  103.   uint32_t DAC_Trigger;                  /*!< Specifies the external trigger for the selected DAC channel.
  104.                                               This parameter can be a value of @ref DAC_trigger_selection */
  105.  
  106.   uint32_t DAC_OutputBuffer;             /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  107.                                                This parameter can be a value of @ref DAC_output_buffer */
  108.  
  109. } DAC_ChannelConfTypeDef;
  110.  
  111. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  112. /**
  113.   * @brief  HAL DAC Callback ID enumeration definition
  114.   */
  115. typedef enum
  116. {
  117.   HAL_DAC_CH1_COMPLETE_CB_ID                 = 0x00U,  /*!< DAC CH1 Complete Callback ID      */
  118.   HAL_DAC_CH1_HALF_COMPLETE_CB_ID            = 0x01U,  /*!< DAC CH1 half Complete Callback ID */
  119.   HAL_DAC_CH1_ERROR_ID                       = 0x02U,  /*!< DAC CH1 error Callback ID         */
  120.   HAL_DAC_CH1_UNDERRUN_CB_ID                 = 0x03U,  /*!< DAC CH1 underrun Callback ID      */
  121.   HAL_DAC_CH2_COMPLETE_CB_ID                 = 0x04U,  /*!< DAC CH2 Complete Callback ID      */
  122.   HAL_DAC_CH2_HALF_COMPLETE_CB_ID            = 0x05U,  /*!< DAC CH2 half Complete Callback ID */
  123.   HAL_DAC_CH2_ERROR_ID                       = 0x06U,  /*!< DAC CH2 error Callback ID         */
  124.   HAL_DAC_CH2_UNDERRUN_CB_ID                 = 0x07U,  /*!< DAC CH2 underrun Callback ID      */
  125.   HAL_DAC_MSPINIT_CB_ID                      = 0x08U,  /*!< DAC MspInit Callback ID           */
  126.   HAL_DAC_MSPDEINIT_CB_ID                    = 0x09U,  /*!< DAC MspDeInit Callback ID         */
  127.   HAL_DAC_ALL_CB_ID                          = 0x0AU   /*!< DAC All ID                        */
  128. } HAL_DAC_CallbackIDTypeDef;
  129.  
  130. /**
  131.   * @brief  HAL DAC Callback pointer definition
  132.   */
  133. typedef void (*pDAC_CallbackTypeDef)(DAC_HandleTypeDef *hdac);
  134. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  135.  
  136. /**
  137.   * @}
  138.   */
  139.  
  140. /* Exported constants --------------------------------------------------------*/
  141.  
  142. /** @defgroup DAC_Exported_Constants DAC Exported Constants
  143.   * @{
  144.   */
  145.  
  146. /** @defgroup DAC_Error_Code DAC Error Code
  147.   * @{
  148.   */
  149. #define  HAL_DAC_ERROR_NONE              0x00U    /*!< No error                          */
  150. #define  HAL_DAC_ERROR_DMAUNDERRUNCH1    0x01U    /*!< DAC channel1 DMA underrun error   */
  151. #define  HAL_DAC_ERROR_DMAUNDERRUNCH2    0x02U    /*!< DAC channel2 DMA underrun error   */
  152. #define  HAL_DAC_ERROR_DMA               0x04U    /*!< DMA error                         */
  153. #define  HAL_DAC_ERROR_TIMEOUT           0x08U    /*!< Timeout error                     */
  154. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  155. #define HAL_DAC_ERROR_INVALID_CALLBACK   0x10U    /*!< Invalid callback error            */
  156. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  157.  
  158. /**
  159.   * @}
  160.   */
  161.  
  162. /** @defgroup DAC_output_buffer DAC output buffer
  163.   * @{
  164.   */
  165. #define DAC_OUTPUTBUFFER_ENABLE            0x00000000U
  166. #define DAC_OUTPUTBUFFER_DISABLE           (DAC_CR_BOFF1)
  167.  
  168. /**
  169.   * @}
  170.   */
  171.  
  172. /** @defgroup DAC_Channel_selection DAC Channel selection
  173.   * @{
  174.   */
  175. #define DAC_CHANNEL_1                      0x00000000U
  176. #define DAC_CHANNEL_2                      0x00000010U
  177. /**
  178.   * @}
  179.   */
  180.  
  181. /** @defgroup DAC_data_alignment DAC data alignment
  182.   * @{
  183.   */
  184. #define DAC_ALIGN_12B_R                    0x00000000U
  185. #define DAC_ALIGN_12B_L                    0x00000004U
  186. #define DAC_ALIGN_8B_R                     0x00000008U
  187.  
  188. /**
  189.   * @}
  190.   */
  191.  
  192. /** @defgroup DAC_flags_definition DAC flags definition
  193.   * @{
  194.   */
  195. #define DAC_FLAG_DMAUDR1                   (DAC_SR_DMAUDR1)
  196. #define DAC_FLAG_DMAUDR2                   (DAC_SR_DMAUDR2)
  197.  
  198. /**
  199.   * @}
  200.   */
  201.  
  202. /** @defgroup DAC_IT_definition  DAC IT definition
  203.   * @{
  204.   */
  205. #define DAC_IT_DMAUDR1                   (DAC_SR_DMAUDR1)
  206. #define DAC_IT_DMAUDR2                   (DAC_SR_DMAUDR2)
  207.  
  208. /**
  209.   * @}
  210.   */
  211.  
  212. /**
  213.   * @}
  214.   */
  215.  
  216. /* Exported macro ------------------------------------------------------------*/
  217.  
  218. /** @defgroup DAC_Exported_Macros DAC Exported Macros
  219.   * @{
  220.   */
  221.  
  222. /** @brief Reset DAC handle state.
  223.   * @param  __HANDLE__ specifies the DAC handle.
  224.   * @retval None
  225.   */
  226. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  227. #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) do {                                                        \
  228.                                                       (__HANDLE__)->State             = HAL_DAC_STATE_RESET; \
  229.                                                       (__HANDLE__)->MspInitCallback   = NULL;                \
  230.                                                       (__HANDLE__)->MspDeInitCallback = NULL;                \
  231.                                                      } while(0)
  232. #else
  233. #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
  234. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  235.  
  236. /** @brief Enable the DAC channel.
  237.   * @param  __HANDLE__ specifies the DAC handle.
  238.   * @param  __DAC_Channel__ specifies the DAC channel
  239.   * @retval None
  240.   */
  241. #define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) \
  242.   ((__HANDLE__)->Instance->CR |=  (DAC_CR_EN1 << ((__DAC_Channel__) & 0x10UL)))
  243.  
  244. /** @brief Disable the DAC channel.
  245.   * @param  __HANDLE__ specifies the DAC handle
  246.   * @param  __DAC_Channel__ specifies the DAC channel.
  247.   * @retval None
  248.   */
  249. #define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) \
  250.   ((__HANDLE__)->Instance->CR &=  ~(DAC_CR_EN1 << ((__DAC_Channel__) & 0x10UL)))
  251.  
  252. /** @brief Set DHR12R1 alignment.
  253.   * @param  __ALIGNMENT__ specifies the DAC alignment
  254.   * @retval None
  255.   */
  256. #define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (0x00000008U + (__ALIGNMENT__))
  257.  
  258. /** @brief  Set DHR12R2 alignment.
  259.   * @param  __ALIGNMENT__ specifies the DAC alignment
  260.   * @retval None
  261.   */
  262. #define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (0x00000014U + (__ALIGNMENT__))
  263.  
  264. /** @brief  Set DHR12RD alignment.
  265.   * @param  __ALIGNMENT__ specifies the DAC alignment
  266.   * @retval None
  267.   */
  268. #define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (0x00000020U + (__ALIGNMENT__))
  269.  
  270. /** @brief Enable the DAC interrupt.
  271.   * @param  __HANDLE__ specifies the DAC handle
  272.   * @param  __INTERRUPT__ specifies the DAC interrupt.
  273.   *          This parameter can be any combination of the following values:
  274.   *            @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  275.   *            @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  276.   * @retval None
  277.   */
  278. #define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
  279.  
  280. /** @brief Disable the DAC interrupt.
  281.   * @param  __HANDLE__ specifies the DAC handle
  282.   * @param  __INTERRUPT__ specifies the DAC interrupt.
  283.   *          This parameter can be any combination of the following values:
  284.   *            @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  285.   *            @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  286.   * @retval None
  287.   */
  288. #define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
  289.  
  290. /** @brief  Check whether the specified DAC interrupt source is enabled or not.
  291.   * @param __HANDLE__ DAC handle
  292.   * @param __INTERRUPT__ DAC interrupt source to check
  293.   *          This parameter can be any combination of the following values:
  294.   *            @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
  295.   *            @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
  296.   * @retval State of interruption (SET or RESET)
  297.   */
  298. #define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__))
  299.  
  300. /** @brief  Get the selected DAC's flag status.
  301.   * @param  __HANDLE__ specifies the DAC handle.
  302.   * @param  __FLAG__ specifies the DAC flag to get.
  303.   *          This parameter can be any combination of the following values:
  304.   *            @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
  305.   *            @arg DAC_FLAG_DMAUDR2: DAC channel 2 DMA underrun flag
  306.   * @retval None
  307.   */
  308. #define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  309.  
  310. /** @brief  Clear the DAC's flag.
  311.   * @param  __HANDLE__ specifies the DAC handle.
  312.   * @param  __FLAG__ specifies the DAC flag to clear.
  313.   *          This parameter can be any combination of the following values:
  314.   *            @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
  315.   *            @arg DAC_FLAG_DMAUDR2: DAC channel 2 DMA underrun flag
  316.   * @retval None
  317.   */
  318. #define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__))
  319.  
  320. /**
  321.   * @}
  322.   */
  323.  
  324. /* Private macro -------------------------------------------------------------*/
  325.  
  326. /** @defgroup DAC_Private_Macros DAC Private Macros
  327.   * @{
  328.   */
  329. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
  330.                                            ((STATE) == DAC_OUTPUTBUFFER_DISABLE))
  331.  
  332. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
  333.                                  ((CHANNEL) == DAC_CHANNEL_2))
  334.  
  335. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
  336.                              ((ALIGN) == DAC_ALIGN_12B_L) || \
  337.                              ((ALIGN) == DAC_ALIGN_8B_R))
  338.  
  339. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
  340.  
  341. /**
  342.   * @}
  343.   */
  344.  
  345. /* Include DAC HAL Extended module */
  346. #include "stm32f1xx_hal_dac_ex.h"
  347.  
  348. /* Exported functions --------------------------------------------------------*/
  349.  
  350. /** @addtogroup DAC_Exported_Functions
  351.   * @{
  352.   */
  353.  
  354. /** @addtogroup DAC_Exported_Functions_Group1
  355.   * @{
  356.   */
  357. /* Initialization and de-initialization functions *****************************/
  358. HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef *hdac);
  359. HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef *hdac);
  360. void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac);
  361. void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac);
  362.  
  363. /**
  364.   * @}
  365.   */
  366.  
  367. /** @addtogroup DAC_Exported_Functions_Group2
  368.   * @{
  369.   */
  370. /* IO operation functions *****************************************************/
  371. HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef *hdac, uint32_t Channel);
  372. HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef *hdac, uint32_t Channel);
  373. HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length,
  374.                                     uint32_t Alignment);
  375. HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel);
  376.  
  377. void HAL_DAC_IRQHandler(DAC_HandleTypeDef *hdac);
  378.  
  379. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
  380.  
  381. void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef *hdac);
  382. void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac);
  383. void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
  384. void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac);
  385.  
  386. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  387. /* DAC callback registering/unregistering */
  388. HAL_StatusTypeDef     HAL_DAC_RegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID,
  389.                                                pDAC_CallbackTypeDef pCallback);
  390. HAL_StatusTypeDef     HAL_DAC_UnRegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID);
  391. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  392.  
  393. /**
  394.   * @}
  395.   */
  396.  
  397. /** @addtogroup DAC_Exported_Functions_Group3
  398.   * @{
  399.   */
  400. /* Peripheral Control functions ***********************************************/
  401. uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef *hdac, uint32_t Channel);
  402.  
  403. HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel);
  404. /**
  405.   * @}
  406.   */
  407.  
  408. /** @addtogroup DAC_Exported_Functions_Group4
  409.   * @{
  410.   */
  411. /* Peripheral State and Error functions ***************************************/
  412. HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef *hdac);
  413. uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
  414.  
  415. /**
  416.   * @}
  417.   */
  418.  
  419. /**
  420.   * @}
  421.   */
  422.  
  423. /** @defgroup DAC_Private_Functions DAC Private Functions
  424.   * @{
  425.   */
  426. void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
  427. void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
  428. void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
  429. /**
  430.   * @}
  431.   */
  432.  
  433. /**
  434.   * @}
  435.   */
  436.  
  437. #endif /* DAC */
  438.  
  439. /**
  440.   * @}
  441.   */
  442.  
  443. #ifdef __cplusplus
  444. }
  445. #endif
  446.  
  447.  
  448. #endif /*STM32F1xx_HAL_DAC_H */
  449.  
  450. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  451.  
  452.