Subversion Repositories LedShow

Rev

Go to most recent revision | 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</center></h2>
  10.   *
  11.   * Redistribution and use in source and binary forms, with or without modification,
  12.   * are permitted provided that the following conditions are met:
  13.   *   1. Redistributions of source code must retain the above copyright notice,
  14.   *      this list of conditions and the following disclaimer.
  15.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  16.   *      this list of conditions and the following disclaimer in the documentation
  17.   *      and/or other materials provided with the distribution.
  18.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  19.   *      may be used to endorse or promote products derived from this software
  20.   *      without specific prior written permission.
  21.   *
  22.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.   *
  33.   ******************************************************************************
  34.   */
  35.  
  36. /* Define to prevent recursive inclusion -------------------------------------*/
  37. #ifndef __STM32F1xx_HAL_DAC_H
  38. #define __STM32F1xx_HAL_DAC_H
  39.  
  40. #ifdef __cplusplus
  41.  extern "C" {
  42. #endif
  43.  
  44. #if defined (STM32F100xB) || defined (STM32F100xE) || defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC)
  45.    
  46. /* Includes ------------------------------------------------------------------*/
  47. #include "stm32f1xx_hal_def.h"
  48.  
  49. /** @addtogroup STM32F1xx_HAL_Driver
  50.   * @{
  51.   */
  52.  
  53. /** @addtogroup DAC
  54.   * @{
  55.   */
  56.  
  57. /* Exported types ------------------------------------------------------------*/
  58.  
  59. /** @defgroup DAC_Exported_Types DAC Exported Types
  60.   * @{
  61.   */
  62.  
  63. /**
  64.   * @brief  HAL State structures definition  
  65.   */
  66. typedef enum
  67. {
  68.   HAL_DAC_STATE_RESET             = 0x00U,  /*!< DAC not yet initialized or disabled  */
  69.   HAL_DAC_STATE_READY             = 0x01U,  /*!< DAC initialized and ready for use    */
  70.   HAL_DAC_STATE_BUSY              = 0x02U,  /*!< DAC internal processing is ongoing   */
  71.   HAL_DAC_STATE_TIMEOUT           = 0x03U,  /*!< DAC timeout state                    */
  72.   HAL_DAC_STATE_ERROR             = 0x04U   /*!< DAC error state                      */
  73.  
  74. }HAL_DAC_StateTypeDef;
  75.  
  76. /**
  77.   * @brief  DAC handle Structure definition  
  78.   */
  79. typedef struct
  80. {
  81.   DAC_TypeDef                 *Instance;     /*!< Register base address             */
  82.  
  83.   __IO HAL_DAC_StateTypeDef   State;         /*!< DAC communication state           */
  84.  
  85.   HAL_LockTypeDef             Lock;          /*!< DAC locking object                */
  86.  
  87.   DMA_HandleTypeDef           *DMA_Handle1;  /*!< Pointer DMA handler for channel 1 */
  88.  
  89.   DMA_HandleTypeDef           *DMA_Handle2;  /*!< Pointer DMA handler for channel 2 */
  90.  
  91.   __IO uint32_t               ErrorCode;     /*!< DAC Error code                    */
  92.  
  93. }DAC_HandleTypeDef;
  94.  
  95. /**
  96.   * @brief   DAC Configuration regular Channel structure definition  
  97.   */
  98. typedef struct
  99. {
  100.   uint32_t DAC_Trigger;       /*!< Specifies the external trigger for the selected DAC channel.
  101.                                    This parameter can be a value of @ref DACEx_trigger_selection
  102.                                    Note: For STM32F100x high-density value line devices, additional trigger sources are available. */
  103.  
  104.   uint32_t DAC_OutputBuffer;  /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  105.                                    This parameter can be a value of @ref DAC_output_buffer */
  106.  
  107. }DAC_ChannelConfTypeDef;
  108.  
  109. /**
  110.   * @}
  111.   */
  112.  
  113. /* Exported constants --------------------------------------------------------*/
  114.  
  115. /** @defgroup DAC_Exported_Constants DAC Exported Constants
  116.   * @{
  117.   */
  118.  
  119. /** @defgroup DAC_Error_Code DAC Error Code
  120.   * @{
  121.   */
  122. #define  HAL_DAC_ERROR_NONE              0x00000000U    /*!< No error                          */
  123. #define  HAL_DAC_ERROR_DMAUNDERRUNCH1    0x00000001U    /*!< DAC channel1 DMA underrun error   */
  124. #define  HAL_DAC_ERROR_DMAUNDERRUNCH2    0x00000002U    /*!< DAC channel2 DMA underrun error   */
  125. #define  HAL_DAC_ERROR_DMA               0x00000004U    /*!< DMA error                         */  
  126. /**
  127.   * @}
  128.   */
  129.  
  130. /** @defgroup DAC_output_buffer DAC output buffer
  131.   * @{
  132.   */
  133. #define DAC_OUTPUTBUFFER_ENABLE            0x00000000U
  134. #define DAC_OUTPUTBUFFER_DISABLE           ((uint32_t)DAC_CR_BOFF1)
  135.  
  136. /**
  137.   * @}
  138.   */
  139.  
  140. /** @defgroup DAC_Channel_selection DAC Channel selection
  141.   * @{
  142.   */
  143. #define DAC_CHANNEL_1                      0x00000000U
  144. #define DAC_CHANNEL_2                      0x00000010U
  145.  
  146. /**
  147.   * @}
  148.   */
  149.  
  150. /** @defgroup DAC_data_alignement DAC data alignement
  151.   * @{
  152.   */
  153. #define DAC_ALIGN_12B_R                    0x00000000U
  154. #define DAC_ALIGN_12B_L                    0x00000004U
  155. #define DAC_ALIGN_8B_R                     0x00000008U
  156.  
  157. /**
  158.   * @}
  159.   */
  160.  
  161. /**
  162.   * @}
  163.   */
  164.  
  165. /* Exported macro ------------------------------------------------------------*/
  166.  
  167. /** @defgroup DAC_Exported_Macros DAC Exported Macros
  168.   * @{
  169.   */
  170.  
  171. /** @brief Reset DAC handle state
  172.   * @param  __HANDLE__: specifies the DAC handle.
  173.   * @retval None
  174.   */
  175. #define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
  176.  
  177. /** @brief Enable the DAC channel
  178.   * @param  __HANDLE__: specifies the DAC handle.
  179.   * @param  __DAC_Channel__: specifies the DAC channel
  180.   * @retval None
  181.   */
  182. #define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) \
  183. ((__HANDLE__)->Instance->CR |=  (DAC_CR_EN1 << (__DAC_Channel__)))
  184.  
  185. /** @brief Disable the DAC channel
  186.   * @param  __HANDLE__: specifies the DAC handle
  187.   * @param  __DAC_Channel__: specifies the DAC channel.
  188.   * @retval None
  189.   */
  190. #define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) \
  191. ((__HANDLE__)->Instance->CR &=  ~(DAC_CR_EN1 << (__DAC_Channel__)))
  192.  
  193.  
  194. /**
  195.   * @}
  196.   */
  197.  
  198. /* Private macro -------------------------------------------------------------*/
  199.  
  200. /** @defgroup DAC_Private_Macros DAC Private Macros
  201.   * @{
  202.   */
  203. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
  204.                                            ((STATE) == DAC_OUTPUTBUFFER_DISABLE))
  205.  
  206. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
  207.                                  ((CHANNEL) == DAC_CHANNEL_2))
  208.  
  209. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
  210.                              ((ALIGN) == DAC_ALIGN_12B_L) || \
  211.                              ((ALIGN) == DAC_ALIGN_8B_R))
  212.  
  213. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
  214.  
  215. #define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (0x00000008U + (__ALIGNMENT__))
  216.  
  217. #define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (0x00000014U + (__ALIGNMENT__))
  218.  
  219. #define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (0x00000020U + (__ALIGNMENT__))
  220.  
  221. /**
  222.   * @}
  223.   */
  224.  
  225.  
  226. /* Include DAC HAL Extension module */
  227. #include "stm32f1xx_hal_dac_ex.h"
  228.  
  229. /* Exported functions --------------------------------------------------------*/
  230.  
  231. /** @addtogroup DAC_Exported_Functions
  232.   * @{
  233.   */
  234.  
  235. /** @addtogroup DAC_Exported_Functions_Group1
  236.   * @{
  237.   */
  238. /* Initialization and de-initialization functions *****************************/
  239. HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac);
  240. HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac);
  241. void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac);
  242. void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac);
  243.  
  244. /**
  245.   * @}
  246.   */
  247.  
  248. /** @addtogroup DAC_Exported_Functions_Group2
  249.   * @{
  250.   */
  251. /* IO operation functions *****************************************************/
  252. HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);
  253. HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel);
  254. HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment);
  255. HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel);
  256. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
  257. uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel);
  258.  
  259. /**
  260.   * @}
  261.   */
  262.  
  263. /** @addtogroup DAC_Exported_Functions_Group3
  264.   * @{
  265.   */
  266. /* Peripheral Control functions ***********************************************/
  267. HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel);
  268.  
  269. /**
  270.   * @}
  271.   */
  272.  
  273. /** @addtogroup DAC_Exported_Functions_Group4
  274.   * @{
  275.   */
  276. /* Peripheral State functions *************************************************/
  277. HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac);
  278. uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
  279.  
  280. void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac);
  281. void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac);
  282. void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
  283.  
  284.  
  285. /**
  286.   * @}
  287.   */
  288.  
  289. /**
  290.   * @}
  291.   */
  292.  
  293. /** @addtogroup DAC_Private_Functions DAC Private Functions
  294.   * @{
  295.   */
  296. void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
  297. void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
  298. void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
  299.  
  300. /**
  301.   * @}
  302.   */
  303.  
  304. /**
  305.   * @}
  306.   */
  307.  
  308. /**
  309.   * @}
  310.   */
  311.  
  312. #endif /* STM32F100xB || STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
  313.  
  314. #ifdef __cplusplus
  315. }
  316. #endif
  317.  
  318.  
  319. #endif /*__STM32F1xx_HAL_DAC_H */
  320.  
  321. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  322.  
  323.