
12 changed files with 4199 additions and 32 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,52 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/**
|
|||
****************************************************************************** |
|||
* @file dac.h |
|||
* @brief This file contains all the function prototypes for |
|||
* the dac.c file |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2023 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef __DAC_H__ |
|||
#define __DAC_H__ |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "main.h" |
|||
|
|||
/* USER CODE BEGIN Includes */ |
|||
|
|||
/* USER CODE END Includes */ |
|||
|
|||
extern DAC_HandleTypeDef hdac; |
|||
|
|||
/* USER CODE BEGIN Private defines */ |
|||
|
|||
/* USER CODE END Private defines */ |
|||
|
|||
void MX_DAC_Init(void); |
|||
|
|||
/* USER CODE BEGIN Prototypes */ |
|||
|
|||
/* USER CODE END Prototypes */ |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif /* __DAC_H__ */ |
|||
|
@ -0,0 +1,125 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/**
|
|||
****************************************************************************** |
|||
* @file dac.c |
|||
* @brief This file provides code for the configuration |
|||
* of the DAC instances. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2023 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "dac.h" |
|||
|
|||
/* USER CODE BEGIN 0 */ |
|||
|
|||
/* USER CODE END 0 */ |
|||
|
|||
DAC_HandleTypeDef hdac; |
|||
|
|||
/* DAC init function */ |
|||
void MX_DAC_Init(void) |
|||
{ |
|||
|
|||
/* USER CODE BEGIN DAC_Init 0 */ |
|||
|
|||
/* USER CODE END DAC_Init 0 */ |
|||
|
|||
DAC_ChannelConfTypeDef sConfig = {0}; |
|||
|
|||
/* USER CODE BEGIN DAC_Init 1 */ |
|||
|
|||
/* USER CODE END DAC_Init 1 */ |
|||
|
|||
/** DAC Initialization
|
|||
*/ |
|||
hdac.Instance = DAC; |
|||
if (HAL_DAC_Init(&hdac) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
|
|||
/** DAC channel OUT1 config
|
|||
*/ |
|||
sConfig.DAC_Trigger = DAC_TRIGGER_NONE; |
|||
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; |
|||
if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
|
|||
/** DAC channel OUT2 config
|
|||
*/ |
|||
if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_2) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
/* USER CODE BEGIN DAC_Init 2 */ |
|||
|
|||
/* USER CODE END DAC_Init 2 */ |
|||
|
|||
} |
|||
|
|||
void HAL_DAC_MspInit(DAC_HandleTypeDef* dacHandle) |
|||
{ |
|||
|
|||
GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|||
if(dacHandle->Instance==DAC) |
|||
{ |
|||
/* USER CODE BEGIN DAC_MspInit 0 */ |
|||
|
|||
/* USER CODE END DAC_MspInit 0 */ |
|||
/* DAC clock enable */ |
|||
__HAL_RCC_DAC_CLK_ENABLE(); |
|||
|
|||
__HAL_RCC_GPIOA_CLK_ENABLE(); |
|||
/**DAC GPIO Configuration
|
|||
PA4 ------> DAC_OUT1 |
|||
PA5 ------> DAC_OUT2 |
|||
*/ |
|||
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5; |
|||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
|||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
|||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|||
|
|||
/* USER CODE BEGIN DAC_MspInit 1 */ |
|||
|
|||
/* USER CODE END DAC_MspInit 1 */ |
|||
} |
|||
} |
|||
|
|||
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* dacHandle) |
|||
{ |
|||
|
|||
if(dacHandle->Instance==DAC) |
|||
{ |
|||
/* USER CODE BEGIN DAC_MspDeInit 0 */ |
|||
|
|||
/* USER CODE END DAC_MspDeInit 0 */ |
|||
/* Peripheral clock disable */ |
|||
__HAL_RCC_DAC_CLK_DISABLE(); |
|||
|
|||
/**DAC GPIO Configuration
|
|||
PA4 ------> DAC_OUT1 |
|||
PA5 ------> DAC_OUT2 |
|||
*/ |
|||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_5); |
|||
|
|||
/* USER CODE BEGIN DAC_MspDeInit 1 */ |
|||
|
|||
/* USER CODE END DAC_MspDeInit 1 */ |
|||
} |
|||
} |
|||
|
|||
/* USER CODE BEGIN 1 */ |
|||
|
|||
/* USER CODE END 1 */ |
@ -0,0 +1,480 @@ |
|||
/**
|
|||
****************************************************************************** |
|||
* @file stm32f4xx_hal_dac.h |
|||
* @author MCD Application Team |
|||
* @brief Header file of DAC HAL module. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2016 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
|
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef STM32F4xx_HAL_DAC_H |
|||
#define STM32F4xx_HAL_DAC_H |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/** @addtogroup STM32F4xx_HAL_Driver
|
|||
* @{ |
|||
*/ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "stm32f4xx_hal_def.h" |
|||
|
|||
#if defined(DAC) |
|||
|
|||
/** @addtogroup DAC
|
|||
* @{ |
|||
*/ |
|||
|
|||
/* Exported types ------------------------------------------------------------*/ |
|||
|
|||
/** @defgroup DAC_Exported_Types DAC Exported Types
|
|||
* @{ |
|||
*/ |
|||
|
|||
/**
|
|||
* @brief HAL State structures definition |
|||
*/ |
|||
typedef enum |
|||
{ |
|||
HAL_DAC_STATE_RESET = 0x00U, /*!< DAC not yet initialized or disabled */ |
|||
HAL_DAC_STATE_READY = 0x01U, /*!< DAC initialized and ready for use */ |
|||
HAL_DAC_STATE_BUSY = 0x02U, /*!< DAC internal processing is ongoing */ |
|||
HAL_DAC_STATE_TIMEOUT = 0x03U, /*!< DAC timeout state */ |
|||
HAL_DAC_STATE_ERROR = 0x04U /*!< DAC error state */ |
|||
|
|||
} HAL_DAC_StateTypeDef; |
|||
|
|||
/**
|
|||
* @brief DAC handle Structure definition |
|||
*/ |
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
typedef struct __DAC_HandleTypeDef |
|||
#else |
|||
typedef struct |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
{ |
|||
DAC_TypeDef *Instance; /*!< Register base address */ |
|||
|
|||
__IO HAL_DAC_StateTypeDef State; /*!< DAC communication state */ |
|||
|
|||
HAL_LockTypeDef Lock; /*!< DAC locking object */ |
|||
|
|||
DMA_HandleTypeDef *DMA_Handle1; /*!< Pointer DMA handler for channel 1 */ |
|||
|
|||
DMA_HandleTypeDef *DMA_Handle2; /*!< Pointer DMA handler for channel 2 */ |
|||
|
|||
__IO uint32_t ErrorCode; /*!< DAC Error code */ |
|||
|
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
void (* ConvCpltCallbackCh1) (struct __DAC_HandleTypeDef *hdac); |
|||
void (* ConvHalfCpltCallbackCh1) (struct __DAC_HandleTypeDef *hdac); |
|||
void (* ErrorCallbackCh1) (struct __DAC_HandleTypeDef *hdac); |
|||
void (* DMAUnderrunCallbackCh1) (struct __DAC_HandleTypeDef *hdac); |
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
void (* ConvCpltCallbackCh2) (struct __DAC_HandleTypeDef *hdac); |
|||
void (* ConvHalfCpltCallbackCh2) (struct __DAC_HandleTypeDef *hdac); |
|||
void (* ErrorCallbackCh2) (struct __DAC_HandleTypeDef *hdac); |
|||
void (* DMAUnderrunCallbackCh2) (struct __DAC_HandleTypeDef *hdac); |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
void (* MspInitCallback) (struct __DAC_HandleTypeDef *hdac); |
|||
void (* MspDeInitCallback) (struct __DAC_HandleTypeDef *hdac); |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
|
|||
} DAC_HandleTypeDef; |
|||
|
|||
/**
|
|||
* @brief DAC Configuration regular Channel structure definition |
|||
*/ |
|||
typedef struct |
|||
{ |
|||
uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
|
|||
This parameter can be a value of @ref DAC_trigger_selection */ |
|||
|
|||
uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
|
|||
This parameter can be a value of @ref DAC_output_buffer */ |
|||
|
|||
} DAC_ChannelConfTypeDef; |
|||
|
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
/**
|
|||
* @brief HAL DAC Callback ID enumeration definition |
|||
*/ |
|||
typedef enum |
|||
{ |
|||
HAL_DAC_CH1_COMPLETE_CB_ID = 0x00U, /*!< DAC CH1 Complete Callback ID */ |
|||
HAL_DAC_CH1_HALF_COMPLETE_CB_ID = 0x01U, /*!< DAC CH1 half Complete Callback ID */ |
|||
HAL_DAC_CH1_ERROR_ID = 0x02U, /*!< DAC CH1 error Callback ID */ |
|||
HAL_DAC_CH1_UNDERRUN_CB_ID = 0x03U, /*!< DAC CH1 underrun Callback ID */ |
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
HAL_DAC_CH2_COMPLETE_CB_ID = 0x04U, /*!< DAC CH2 Complete Callback ID */ |
|||
HAL_DAC_CH2_HALF_COMPLETE_CB_ID = 0x05U, /*!< DAC CH2 half Complete Callback ID */ |
|||
HAL_DAC_CH2_ERROR_ID = 0x06U, /*!< DAC CH2 error Callback ID */ |
|||
HAL_DAC_CH2_UNDERRUN_CB_ID = 0x07U, /*!< DAC CH2 underrun Callback ID */ |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
HAL_DAC_MSPINIT_CB_ID = 0x08U, /*!< DAC MspInit Callback ID */ |
|||
HAL_DAC_MSPDEINIT_CB_ID = 0x09U, /*!< DAC MspDeInit Callback ID */ |
|||
HAL_DAC_ALL_CB_ID = 0x0AU /*!< DAC All ID */ |
|||
} HAL_DAC_CallbackIDTypeDef; |
|||
|
|||
/**
|
|||
* @brief HAL DAC Callback pointer definition |
|||
*/ |
|||
typedef void (*pDAC_CallbackTypeDef)(DAC_HandleTypeDef *hdac); |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/* Exported constants --------------------------------------------------------*/ |
|||
|
|||
/** @defgroup DAC_Exported_Constants DAC Exported Constants
|
|||
* @{ |
|||
*/ |
|||
|
|||
/** @defgroup DAC_Error_Code DAC Error Code
|
|||
* @{ |
|||
*/ |
|||
#define HAL_DAC_ERROR_NONE 0x00U /*!< No error */ |
|||
#define HAL_DAC_ERROR_DMAUNDERRUNCH1 0x01U /*!< DAC channel1 DMA underrun error */ |
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
#define HAL_DAC_ERROR_DMAUNDERRUNCH2 0x02U /*!< DAC channel2 DMA underrun error */ |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
#define HAL_DAC_ERROR_DMA 0x04U /*!< DMA error */ |
|||
#define HAL_DAC_ERROR_TIMEOUT 0x08U /*!< Timeout error */ |
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
#define HAL_DAC_ERROR_INVALID_CALLBACK 0x10U /*!< Invalid callback error */ |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DAC_trigger_selection DAC trigger selection
|
|||
* @{ |
|||
*/ |
|||
#define DAC_TRIGGER_NONE 0x00000000UL /*!< Conversion is automatic once the DAC1_DHRxxxx register has been loaded, and not by external trigger */ |
|||
#define DAC_TRIGGER_T2_TRGO (DAC_CR_TSEL1_2 | DAC_CR_TEN1) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */ |
|||
#define DAC_TRIGGER_T4_TRGO (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0 | DAC_CR_TEN1) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */ |
|||
#define DAC_TRIGGER_T5_TRGO ( DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0 | DAC_CR_TEN1) /*!< TIM3 TRGO selected as external conversion trigger for DAC channel */ |
|||
#define DAC_TRIGGER_T6_TRGO ( DAC_CR_TEN1) /*!< Conversion started by software trigger for DAC channel */ |
|||
#define DAC_TRIGGER_T7_TRGO ( DAC_CR_TSEL1_1 | DAC_CR_TEN1) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */ |
|||
#define DAC_TRIGGER_T8_TRGO ( DAC_CR_TSEL1_0 | DAC_CR_TEN1) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel */ |
|||
#define DAC_TRIGGER_EXT_IT9 (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TEN1) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */ |
|||
#define DAC_TRIGGER_SOFTWARE (DAC_CR_TSEL1 | DAC_CR_TEN1) /*!< Conversion started by software trigger for DAC channel */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DAC_output_buffer DAC output buffer
|
|||
* @{ |
|||
*/ |
|||
#define DAC_OUTPUTBUFFER_ENABLE 0x00000000U |
|||
#define DAC_OUTPUTBUFFER_DISABLE (DAC_CR_BOFF1) |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DAC_Channel_selection DAC Channel selection
|
|||
* @{ |
|||
*/ |
|||
#define DAC_CHANNEL_1 0x00000000U |
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
#define DAC_CHANNEL_2 0x00000010U |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DAC_data_alignment DAC data alignment
|
|||
* @{ |
|||
*/ |
|||
#define DAC_ALIGN_12B_R 0x00000000U |
|||
#define DAC_ALIGN_12B_L 0x00000004U |
|||
#define DAC_ALIGN_8B_R 0x00000008U |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DAC_flags_definition DAC flags definition
|
|||
* @{ |
|||
*/ |
|||
#define DAC_FLAG_DMAUDR1 (DAC_SR_DMAUDR1) |
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
#define DAC_FLAG_DMAUDR2 (DAC_SR_DMAUDR2) |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DAC_IT_definition DAC IT definition
|
|||
* @{ |
|||
*/ |
|||
#define DAC_IT_DMAUDR1 (DAC_SR_DMAUDR1) |
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
#define DAC_IT_DMAUDR2 (DAC_SR_DMAUDR2) |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/* Exported macro ------------------------------------------------------------*/ |
|||
|
|||
/** @defgroup DAC_Exported_Macros DAC Exported Macros
|
|||
* @{ |
|||
*/ |
|||
|
|||
/** @brief Reset DAC handle state.
|
|||
* @param __HANDLE__ specifies the DAC handle. |
|||
* @retval None |
|||
*/ |
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
#define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) do { \ |
|||
(__HANDLE__)->State = HAL_DAC_STATE_RESET; \ |
|||
(__HANDLE__)->MspInitCallback = NULL; \ |
|||
(__HANDLE__)->MspDeInitCallback = NULL; \ |
|||
} while(0) |
|||
#else |
|||
#define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET) |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
|
|||
/** @brief Enable the DAC channel.
|
|||
* @param __HANDLE__ specifies the DAC handle. |
|||
* @param __DAC_Channel__ specifies the DAC channel |
|||
* @retval None |
|||
*/ |
|||
#define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) \ |
|||
((__HANDLE__)->Instance->CR |= (DAC_CR_EN1 << ((__DAC_Channel__) & 0x10UL))) |
|||
|
|||
/** @brief Disable the DAC channel.
|
|||
* @param __HANDLE__ specifies the DAC handle |
|||
* @param __DAC_Channel__ specifies the DAC channel. |
|||
* @retval None |
|||
*/ |
|||
#define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) \ |
|||
((__HANDLE__)->Instance->CR &= ~(DAC_CR_EN1 << ((__DAC_Channel__) & 0x10UL))) |
|||
|
|||
/** @brief Set DHR12R1 alignment.
|
|||
* @param __ALIGNMENT__ specifies the DAC alignment |
|||
* @retval None |
|||
*/ |
|||
#define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) (0x00000008UL + (__ALIGNMENT__)) |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
/** @brief Set DHR12R2 alignment.
|
|||
* @param __ALIGNMENT__ specifies the DAC alignment |
|||
* @retval None |
|||
*/ |
|||
#define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) (0x00000014UL + (__ALIGNMENT__)) |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
/** @brief Set DHR12RD alignment.
|
|||
* @param __ALIGNMENT__ specifies the DAC alignment |
|||
* @retval None |
|||
*/ |
|||
#define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) (0x00000020UL + (__ALIGNMENT__)) |
|||
|
|||
/** @brief Enable the DAC interrupt.
|
|||
* @param __HANDLE__ specifies the DAC handle |
|||
* @param __INTERRUPT__ specifies the DAC interrupt. |
|||
* This parameter can be any combination of the following values: |
|||
* @arg DAC_IT_DMAUDR1 DAC channel 1 DMA underrun interrupt |
|||
* @arg DAC_IT_DMAUDR2 DAC channel 2 DMA underrun interrupt |
|||
* @retval None |
|||
*/ |
|||
#define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__)) |
|||
|
|||
/** @brief Disable the DAC interrupt.
|
|||
* @param __HANDLE__ specifies the DAC handle |
|||
* @param __INTERRUPT__ specifies the DAC interrupt. |
|||
* This parameter can be any combination of the following values: |
|||
* @arg DAC_IT_DMAUDR1 DAC channel 1 DMA underrun interrupt |
|||
* @arg DAC_IT_DMAUDR2 DAC channel 2 DMA underrun interrupt |
|||
* @retval None |
|||
*/ |
|||
#define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__)) |
|||
|
|||
/** @brief Check whether the specified DAC interrupt source is enabled or not.
|
|||
* @param __HANDLE__ DAC handle |
|||
* @param __INTERRUPT__ DAC interrupt source to check |
|||
* This parameter can be any combination of the following values: |
|||
* @arg DAC_IT_DMAUDR1 DAC channel 1 DMA underrun interrupt |
|||
* @arg DAC_IT_DMAUDR2 DAC channel 2 DMA underrun interrupt |
|||
* @retval State of interruption (SET or RESET) |
|||
*/ |
|||
#define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR\ |
|||
& (__INTERRUPT__)) == (__INTERRUPT__)) |
|||
|
|||
/** @brief Get the selected DAC's flag status.
|
|||
* @param __HANDLE__ specifies the DAC handle. |
|||
* @param __FLAG__ specifies the DAC flag to get. |
|||
* This parameter can be any combination of the following values: |
|||
* @arg DAC_FLAG_DMAUDR1 DAC channel 1 DMA underrun flag |
|||
* @arg DAC_FLAG_DMAUDR2 DAC channel 2 DMA underrun flag |
|||
* @retval None |
|||
*/ |
|||
#define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) |
|||
|
|||
/** @brief Clear the DAC's flag.
|
|||
* @param __HANDLE__ specifies the DAC handle. |
|||
* @param __FLAG__ specifies the DAC flag to clear. |
|||
* This parameter can be any combination of the following values: |
|||
* @arg DAC_FLAG_DMAUDR1 DAC channel 1 DMA underrun flag |
|||
* @arg DAC_FLAG_DMAUDR2 DAC channel 2 DMA underrun flag |
|||
* @retval None |
|||
*/ |
|||
#define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__)) |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/* Private macro -------------------------------------------------------------*/ |
|||
|
|||
/** @defgroup DAC_Private_Macros DAC Private Macros
|
|||
* @{ |
|||
*/ |
|||
#define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \ |
|||
((STATE) == DAC_OUTPUTBUFFER_DISABLE)) |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
#define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \ |
|||
((CHANNEL) == DAC_CHANNEL_2)) |
|||
#else |
|||
#define IS_DAC_CHANNEL(CHANNEL) ((CHANNEL) == DAC_CHANNEL_1) |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
#define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \ |
|||
((ALIGN) == DAC_ALIGN_12B_L) || \ |
|||
((ALIGN) == DAC_ALIGN_8B_R)) |
|||
|
|||
#define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0UL) |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/* Include DAC HAL Extended module */ |
|||
#include "stm32f4xx_hal_dac_ex.h" |
|||
|
|||
/* Exported functions --------------------------------------------------------*/ |
|||
|
|||
/** @addtogroup DAC_Exported_Functions
|
|||
* @{ |
|||
*/ |
|||
|
|||
/** @addtogroup DAC_Exported_Functions_Group1
|
|||
* @{ |
|||
*/ |
|||
/* Initialization and de-initialization functions *****************************/ |
|||
HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef *hdac); |
|||
HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef *hdac); |
|||
void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac); |
|||
void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac); |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @addtogroup DAC_Exported_Functions_Group2
|
|||
* @{ |
|||
*/ |
|||
/* IO operation functions *****************************************************/ |
|||
HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef *hdac, uint32_t Channel); |
|||
HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef *hdac, uint32_t Channel); |
|||
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length, |
|||
uint32_t Alignment); |
|||
HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel); |
|||
void HAL_DAC_IRQHandler(DAC_HandleTypeDef *hdac); |
|||
HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data); |
|||
|
|||
void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef *hdac); |
|||
void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac); |
|||
void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac); |
|||
void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac); |
|||
|
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
/* DAC callback registering/unregistering */ |
|||
HAL_StatusTypeDef HAL_DAC_RegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID, |
|||
pDAC_CallbackTypeDef pCallback); |
|||
HAL_StatusTypeDef HAL_DAC_UnRegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID); |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @addtogroup DAC_Exported_Functions_Group3
|
|||
* @{ |
|||
*/ |
|||
/* Peripheral Control functions ***********************************************/ |
|||
uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef *hdac, uint32_t Channel); |
|||
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel); |
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @addtogroup DAC_Exported_Functions_Group4
|
|||
* @{ |
|||
*/ |
|||
/* Peripheral State and Error functions ***************************************/ |
|||
HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef *hdac); |
|||
uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac); |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DAC_Private_Functions DAC Private Functions
|
|||
* @{ |
|||
*/ |
|||
void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma); |
|||
void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma); |
|||
void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma); |
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
#endif /* DAC */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
|
|||
#endif /* STM32F4xx_HAL_DAC_H */ |
|||
|
@ -0,0 +1,205 @@ |
|||
/**
|
|||
****************************************************************************** |
|||
* @file stm32f4xx_hal_dac_ex.h |
|||
* @author MCD Application Team |
|||
* @brief Header file of DAC HAL Extended module. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2016 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
|
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef STM32F4xx_HAL_DAC_EX_H |
|||
#define STM32F4xx_HAL_DAC_EX_H |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/** @addtogroup STM32F4xx_HAL_Driver
|
|||
* @{ |
|||
*/ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "stm32f4xx_hal_def.h" |
|||
|
|||
#if defined(DAC) |
|||
|
|||
/** @addtogroup DACEx
|
|||
* @{ |
|||
*/ |
|||
|
|||
/* Exported types ------------------------------------------------------------*/ |
|||
|
|||
/**
|
|||
* @brief HAL State structures definition |
|||
*/ |
|||
|
|||
/* Exported constants --------------------------------------------------------*/ |
|||
|
|||
/** @defgroup DACEx_Exported_Constants DACEx Exported Constants
|
|||
* @{ |
|||
*/ |
|||
|
|||
/** @defgroup DACEx_lfsrunmask_triangleamplitude DACEx lfsrunmask triangle amplitude
|
|||
* @{ |
|||
*/ |
|||
#define DAC_LFSRUNMASK_BIT0 0x00000000UL /*!< Unmask DAC channel LFSR bit0 for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS1_0 ( DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS2_0 ( DAC_CR_MAMP1_1 ) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS3_0 ( DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS4_0 ( DAC_CR_MAMP1_2 ) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS5_0 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS6_0 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 ) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS7_0 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS8_0 (DAC_CR_MAMP1_3 ) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS9_0 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS10_0 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 ) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */ |
|||
#define DAC_LFSRUNMASK_BITS11_0 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */ |
|||
#define DAC_TRIANGLEAMPLITUDE_1 0x00000000UL /*!< Select max triangle amplitude of 1 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_3 ( DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 3 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_7 ( DAC_CR_MAMP1_1 ) /*!< Select max triangle amplitude of 7 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_15 ( DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 15 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_31 ( DAC_CR_MAMP1_2 ) /*!< Select max triangle amplitude of 31 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_63 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 63 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_127 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 ) /*!< Select max triangle amplitude of 127 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_255 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 255 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_511 (DAC_CR_MAMP1_3 ) /*!< Select max triangle amplitude of 511 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_1023 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 1023 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_2047 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 ) /*!< Select max triangle amplitude of 2047 */ |
|||
#define DAC_TRIANGLEAMPLITUDE_4095 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 4095 */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/* Exported macro ------------------------------------------------------------*/ |
|||
|
|||
|
|||
/* Private macro -------------------------------------------------------------*/ |
|||
|
|||
/** @defgroup DACEx_Private_Macros DACEx Private Macros
|
|||
* @{ |
|||
*/ |
|||
#define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \ |
|||
((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \ |
|||
((TRIGGER) == DAC_TRIGGER_T8_TRGO) || \ |
|||
((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \ |
|||
((TRIGGER) == DAC_TRIGGER_T5_TRGO) || \ |
|||
((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \ |
|||
((TRIGGER) == DAC_TRIGGER_T4_TRGO) || \ |
|||
((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \ |
|||
((TRIGGER) == DAC_TRIGGER_SOFTWARE)) |
|||
|
|||
#define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUNMASK_BIT0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS1_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS2_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS3_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS4_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS5_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS6_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS7_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS8_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS9_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS10_0) || \ |
|||
((VALUE) == DAC_LFSRUNMASK_BITS11_0) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_1) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_3) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_7) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_15) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_31) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_63) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_127) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_255) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_511) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_1023) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_2047) || \ |
|||
((VALUE) == DAC_TRIANGLEAMPLITUDE_4095)) |
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/* Exported functions --------------------------------------------------------*/ |
|||
/* Extended features functions ***********************************************/ |
|||
|
|||
/** @addtogroup DACEx_Exported_Functions
|
|||
* @{ |
|||
*/ |
|||
|
|||
/** @addtogroup DACEx_Exported_Functions_Group2
|
|||
* @{ |
|||
*/ |
|||
/* IO operation functions *****************************************************/ |
|||
|
|||
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude); |
|||
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude); |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
#endif |
|||
HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac); |
|||
HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac); |
|||
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2); |
|||
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef *hdac); |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
#endif |
|||
void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac); |
|||
void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac); |
|||
void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac); |
|||
void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac); |
|||
|
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @addtogroup DACEx_Private_Functions
|
|||
* @{ |
|||
*/ |
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
/* DAC_DMAConvCpltCh2 / DAC_DMAErrorCh2 / DAC_DMAHalfConvCpltCh2 */ |
|||
/* are called by HAL_DAC_Start_DMA */ |
|||
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma); |
|||
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma); |
|||
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma); |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
#endif /* DAC */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif /* STM32F4xx_HAL_DAC_EX_H */ |
|||
|
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,495 @@ |
|||
/**
|
|||
****************************************************************************** |
|||
* @file stm32f4xx_hal_dac_ex.c |
|||
* @author MCD Application Team |
|||
* @brief Extended DAC HAL module driver. |
|||
* This file provides firmware functions to manage the extended |
|||
* functionalities of the DAC peripheral. |
|||
* |
|||
* |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2016 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
@verbatim |
|||
============================================================================== |
|||
##### How to use this driver ##### |
|||
============================================================================== |
|||
[..] |
|||
|
|||
*** Dual mode IO operation *** |
|||
============================== |
|||
[..] |
|||
(+) When Dual mode is enabled (i.e. DAC Channel1 and Channel2 are used simultaneously) : |
|||
Use HAL_DACEx_DualGetValue() to get digital data to be converted and use |
|||
HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in |
|||
Channel 1 and Channel 2. |
|||
|
|||
*** Signal generation operation *** |
|||
=================================== |
|||
[..] |
|||
(+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal. |
|||
(+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal. |
|||
|
|||
@endverbatim |
|||
****************************************************************************** |
|||
*/ |
|||
|
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "stm32f4xx_hal.h" |
|||
|
|||
/** @addtogroup STM32F4xx_HAL_Driver
|
|||
* @{ |
|||
*/ |
|||
|
|||
#ifdef HAL_DAC_MODULE_ENABLED |
|||
|
|||
#if defined(DAC) |
|||
|
|||
/** @defgroup DACEx DACEx
|
|||
* @brief DAC Extended HAL module driver |
|||
* @{ |
|||
*/ |
|||
|
|||
/* Private typedef -----------------------------------------------------------*/ |
|||
/* Private define ------------------------------------------------------------*/ |
|||
/* Private macro -------------------------------------------------------------*/ |
|||
/* Private variables ---------------------------------------------------------*/ |
|||
/* Private function prototypes -----------------------------------------------*/ |
|||
/* Exported functions --------------------------------------------------------*/ |
|||
|
|||
/** @defgroup DACEx_Exported_Functions DACEx Exported Functions
|
|||
* @{ |
|||
*/ |
|||
|
|||
/** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
|
|||
* @brief Extended IO operation functions |
|||
* |
|||
@verbatim |
|||
============================================================================== |
|||
##### Extended features functions ##### |
|||
============================================================================== |
|||
[..] This section provides functions allowing to: |
|||
(+) Start conversion. |
|||
(+) Stop conversion. |
|||
(+) Start conversion and enable DMA transfer. |
|||
(+) Stop conversion and disable DMA transfer. |
|||
(+) Get result of conversion. |
|||
(+) Get result of dual mode conversion. |
|||
|
|||
@endverbatim |
|||
* @{ |
|||
*/ |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
/**
|
|||
* @brief Enables DAC and starts conversion of both channels. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @retval HAL status |
|||
*/ |
|||
HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac) |
|||
{ |
|||
uint32_t tmp_swtrig = 0UL; |
|||
|
|||
|
|||
/* Process locked */ |
|||
__HAL_LOCK(hdac); |
|||
|
|||
/* Change DAC state */ |
|||
hdac->State = HAL_DAC_STATE_BUSY; |
|||
|
|||
/* Enable the Peripheral */ |
|||
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_1); |
|||
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_2); |
|||
|
|||
/* Check if software trigger enabled */ |
|||
if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE) |
|||
{ |
|||
tmp_swtrig |= DAC_SWTRIGR_SWTRIG1; |
|||
} |
|||
if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (DAC_CHANNEL_2 & 0x10UL))) |
|||
{ |
|||
tmp_swtrig |= DAC_SWTRIGR_SWTRIG2; |
|||
} |
|||
/* Enable the selected DAC software conversion*/ |
|||
SET_BIT(hdac->Instance->SWTRIGR, tmp_swtrig); |
|||
|
|||
/* Change DAC state */ |
|||
hdac->State = HAL_DAC_STATE_READY; |
|||
|
|||
/* Process unlocked */ |
|||
__HAL_UNLOCK(hdac); |
|||
|
|||
/* Return function status */ |
|||
return HAL_OK; |
|||
} |
|||
|
|||
/**
|
|||
* @brief Disables DAC and stop conversion of both channels. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @retval HAL status |
|||
*/ |
|||
HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac) |
|||
{ |
|||
|
|||
/* Disable the Peripheral */ |
|||
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_1); |
|||
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2); |
|||
|
|||
/* Change DAC state */ |
|||
hdac->State = HAL_DAC_STATE_READY; |
|||
|
|||
/* Return function status */ |
|||
return HAL_OK; |
|||
} |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
/**
|
|||
* @brief Enable or disable the selected DAC channel wave generation. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @param Channel The selected DAC channel. |
|||
* This parameter can be one of the following values: |
|||
* @arg DAC_CHANNEL_1: DAC Channel1 selected |
|||
* @arg DAC_CHANNEL_2: DAC Channel2 selected |
|||
* @param Amplitude Select max triangle amplitude. |
|||
* This parameter can be one of the following values: |
|||
* @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047 |
|||
* @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095 |
|||
* @retval HAL status |
|||
*/ |
|||
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude) |
|||
{ |
|||
/* Check the parameters */ |
|||
assert_param(IS_DAC_CHANNEL(Channel)); |
|||
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); |
|||
|
|||
/* Process locked */ |
|||
__HAL_LOCK(hdac); |
|||
|
|||
/* Change DAC state */ |
|||
hdac->State = HAL_DAC_STATE_BUSY; |
|||
|
|||
/* Enable the triangle wave generation for the selected DAC channel */ |
|||
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), |
|||
(DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL)); |
|||
|
|||
/* Change DAC state */ |
|||
hdac->State = HAL_DAC_STATE_READY; |
|||
|
|||
/* Process unlocked */ |
|||
__HAL_UNLOCK(hdac); |
|||
|
|||
/* Return function status */ |
|||
return HAL_OK; |
|||
} |
|||
|
|||
/**
|
|||
* @brief Enable or disable the selected DAC channel wave generation. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @param Channel The selected DAC channel. |
|||
* This parameter can be one of the following values: |
|||
* @arg DAC_CHANNEL_1: DAC Channel1 selected |
|||
* @arg DAC_CHANNEL_2: DAC Channel2 selected |
|||
* @param Amplitude Unmask DAC channel LFSR for noise wave generation. |
|||
* This parameter can be one of the following values: |
|||
* @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation |
|||
* @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation |
|||
* @retval HAL status |
|||
*/ |
|||
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude) |
|||
{ |
|||
/* Check the parameters */ |
|||
assert_param(IS_DAC_CHANNEL(Channel)); |
|||
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); |
|||
|
|||
/* Process locked */ |
|||
__HAL_LOCK(hdac); |
|||
|
|||
/* Change DAC state */ |
|||
hdac->State = HAL_DAC_STATE_BUSY; |
|||
|
|||
/* Enable the noise wave generation for the selected DAC channel */ |
|||
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), |
|||
(DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL)); |
|||
|
|||
/* Change DAC state */ |
|||
hdac->State = HAL_DAC_STATE_READY; |
|||
|
|||
/* Process unlocked */ |
|||
__HAL_UNLOCK(hdac); |
|||
|
|||
/* Return function status */ |
|||
return HAL_OK; |
|||
} |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
/**
|
|||
* @brief Set the specified data holding register value for dual DAC channel. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @param Alignment Specifies the data alignment for dual channel DAC. |
|||
* This parameter can be one of the following values: |
|||
* DAC_ALIGN_8B_R: 8bit right data alignment selected |
|||
* DAC_ALIGN_12B_L: 12bit left data alignment selected |
|||
* DAC_ALIGN_12B_R: 12bit right data alignment selected |
|||
* @param Data1 Data for DAC Channel1 to be loaded in the selected data holding register. |
|||
* @param Data2 Data for DAC Channel2 to be loaded in the selected data holding register. |
|||
* @note In dual mode, a unique register access is required to write in both |
|||
* DAC channels at the same time. |
|||
* @retval HAL status |
|||
*/ |
|||
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2) |
|||
{ |
|||
uint32_t data; |
|||
uint32_t tmp; |
|||
|
|||
/* Check the parameters */ |
|||
assert_param(IS_DAC_ALIGN(Alignment)); |
|||
assert_param(IS_DAC_DATA(Data1)); |
|||
assert_param(IS_DAC_DATA(Data2)); |
|||
|
|||
/* Calculate and set dual DAC data holding register value */ |
|||
if (Alignment == DAC_ALIGN_8B_R) |
|||
{ |
|||
data = ((uint32_t)Data2 << 8U) | Data1; |
|||
} |
|||
else |
|||
{ |
|||
data = ((uint32_t)Data2 << 16U) | Data1; |
|||
} |
|||
|
|||
tmp = (uint32_t)hdac->Instance; |
|||
tmp += DAC_DHR12RD_ALIGNMENT(Alignment); |
|||
|
|||
/* Set the dual DAC selected data holding register */ |
|||
*(__IO uint32_t *)tmp = data; |
|||
|
|||
/* Return function status */ |
|||
return HAL_OK; |
|||
} |
|||
|
|||
/**
|
|||
* @brief Conversion complete callback in non-blocking mode for Channel2. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @retval None |
|||
*/ |
|||
__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac) |
|||
{ |
|||
/* Prevent unused argument(s) compilation warning */ |
|||
UNUSED(hdac); |
|||
|
|||
/* NOTE : This function should not be modified, when the callback is needed,
|
|||
the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file |
|||
*/ |
|||
} |
|||
|
|||
/**
|
|||
* @brief Conversion half DMA transfer callback in non-blocking mode for Channel2. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @retval None |
|||
*/ |
|||
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac) |
|||
{ |
|||
/* Prevent unused argument(s) compilation warning */ |
|||
UNUSED(hdac); |
|||
|
|||
/* NOTE : This function should not be modified, when the callback is needed,
|
|||
the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file |
|||
*/ |
|||
} |
|||
|
|||
/**
|
|||
* @brief Error DAC callback for Channel2. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @retval None |
|||
*/ |
|||
__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac) |
|||
{ |
|||
/* Prevent unused argument(s) compilation warning */ |
|||
UNUSED(hdac); |
|||
|
|||
/* NOTE : This function should not be modified, when the callback is needed,
|
|||
the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file |
|||
*/ |
|||
} |
|||
|
|||
/**
|
|||
* @brief DMA underrun DAC callback for Channel2. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @retval None |
|||
*/ |
|||
__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac) |
|||
{ |
|||
/* Prevent unused argument(s) compilation warning */ |
|||
UNUSED(hdac); |
|||
|
|||
/* NOTE : This function should not be modified, when the callback is needed,
|
|||
the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file |
|||
*/ |
|||
} |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
|
|||
* @brief Extended Peripheral Control functions |
|||
* |
|||
@verbatim |
|||
============================================================================== |
|||
##### Peripheral Control functions ##### |
|||
============================================================================== |
|||
[..] This section provides functions allowing to: |
|||
(+) Set the specified data holding register value for DAC channel. |
|||
|
|||
@endverbatim |
|||
* @{ |
|||
*/ |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
/**
|
|||
* @brief Return the last data output value of the selected DAC channel. |
|||
* @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DAC. |
|||
* @retval The selected DAC channel data output value. |
|||
*/ |
|||
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef *hdac) |
|||
{ |
|||
uint32_t tmp = 0UL; |
|||
|
|||
tmp |= hdac->Instance->DOR1; |
|||
|
|||
tmp |= hdac->Instance->DOR2 << 16UL; |
|||
|
|||
/* Returns the DAC channel data output register value */ |
|||
return tmp; |
|||
} |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/* Private functions ---------------------------------------------------------*/ |
|||
/** @defgroup DACEx_Private_Functions DACEx private functions
|
|||
* @brief Extended private functions |
|||
* @{ |
|||
*/ |
|||
|
|||
#if defined(DAC_CHANNEL2_SUPPORT) |
|||
/**
|
|||
* @brief DMA conversion complete callback. |
|||
* @param hdma pointer to a DMA_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DMA module. |
|||
* @retval None |
|||
*/ |
|||
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma) |
|||
{ |
|||
DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|||
|
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
hdac->ConvCpltCallbackCh2(hdac); |
|||
#else |
|||
HAL_DACEx_ConvCpltCallbackCh2(hdac); |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
|
|||
hdac->State = HAL_DAC_STATE_READY; |
|||
} |
|||
|
|||
/**
|
|||
* @brief DMA half transfer complete callback. |
|||
* @param hdma pointer to a DMA_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DMA module. |
|||
* @retval None |
|||
*/ |
|||
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma) |
|||
{ |
|||
DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|||
/* Conversion complete callback */ |
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
hdac->ConvHalfCpltCallbackCh2(hdac); |
|||
#else |
|||
HAL_DACEx_ConvHalfCpltCallbackCh2(hdac); |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
} |
|||
|
|||
/**
|
|||
* @brief DMA error callback. |
|||
* @param hdma pointer to a DMA_HandleTypeDef structure that contains |
|||
* the configuration information for the specified DMA module. |
|||
* @retval None |
|||
*/ |
|||
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma) |
|||
{ |
|||
DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|||
|
|||
/* Set DAC error code to DMA error */ |
|||
hdac->ErrorCode |= HAL_DAC_ERROR_DMA; |
|||
|
|||
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|||
hdac->ErrorCallbackCh2(hdac); |
|||
#else |
|||
HAL_DACEx_ErrorCallbackCh2(hdac); |
|||
#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|||
|
|||
hdac->State = HAL_DAC_STATE_READY; |
|||
} |
|||
#endif /* DAC_CHANNEL2_SUPPORT */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
|||
#endif /* DAC */ |
|||
|
|||
#endif /* HAL_DAC_MODULE_ENABLED */ |
|||
|
|||
/**
|
|||
* @} |
|||
*/ |
|||
|
Loading…
Reference in new issue