STM32F103xB HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_ll_dac.c 00004 * @author MCD Application Team 00005 * @brief DAC LL module driver 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 #if defined(USE_FULL_LL_DRIVER) 00020 00021 /* Includes ------------------------------------------------------------------*/ 00022 #include "stm32f1xx_ll_dac.h" 00023 #include "stm32f1xx_ll_bus.h" 00024 00025 #ifdef USE_FULL_ASSERT 00026 #include "stm32_assert.h" 00027 #else 00028 #define assert_param(expr) ((void)0U) 00029 #endif /* USE_FULL_ASSERT */ 00030 00031 /** @addtogroup STM32F1xx_LL_Driver 00032 * @{ 00033 */ 00034 00035 #if defined(DAC) 00036 00037 /** @addtogroup DAC_LL DAC 00038 * @{ 00039 */ 00040 00041 /* Private types -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 /* Private constants ---------------------------------------------------------*/ 00044 /* Private macros ------------------------------------------------------------*/ 00045 00046 /** @addtogroup DAC_LL_Private_Macros 00047 * @{ 00048 */ 00049 #define IS_LL_DAC_CHANNEL(__DAC_CHANNEL__) \ 00050 ( ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \ 00051 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \ 00052 ) 00053 00054 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \ 00055 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \ 00056 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \ 00057 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \ 00058 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \ 00059 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \ 00060 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \ 00061 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \ 00062 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \ 00063 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \ 00064 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \ 00065 ) 00066 00067 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \ 00068 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \ 00069 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \ 00070 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \ 00071 ) 00072 00073 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_MODE__, __WAVE_AUTO_GENERATION_CONFIG__) \ 00074 ( (((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \ 00075 && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \ 00076 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \ 00077 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \ 00078 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \ 00079 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \ 00080 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \ 00081 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \ 00082 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \ 00083 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \ 00084 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \ 00085 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \ 00086 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0)) \ 00087 ) \ 00088 ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \ 00089 && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \ 00090 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \ 00091 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \ 00092 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \ 00093 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \ 00094 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \ 00095 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \ 00096 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \ 00097 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \ 00098 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \ 00099 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \ 00100 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095)) \ 00101 ) \ 00102 ) 00103 00104 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \ 00105 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \ 00106 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \ 00107 ) 00108 00109 /** 00110 * @} 00111 */ 00112 00113 00114 /* Private function prototypes -----------------------------------------------*/ 00115 00116 /* Exported functions --------------------------------------------------------*/ 00117 /** @addtogroup DAC_LL_Exported_Functions 00118 * @{ 00119 */ 00120 00121 /** @addtogroup DAC_LL_EF_Init 00122 * @{ 00123 */ 00124 00125 /** 00126 * @brief De-initialize registers of the selected DAC instance 00127 * to their default reset values. 00128 * @param DACx DAC instance 00129 * @retval An ErrorStatus enumeration value: 00130 * - SUCCESS: DAC registers are de-initialized 00131 * - ERROR: not applicable 00132 */ 00133 ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx) 00134 { 00135 /* Check the parameters */ 00136 assert_param(IS_DAC_ALL_INSTANCE(DACx)); 00137 00138 /* Force reset of DAC clock */ 00139 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1); 00140 00141 /* Release reset of DAC clock */ 00142 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1); 00143 00144 return SUCCESS; 00145 } 00146 00147 /** 00148 * @brief Initialize some features of DAC channel. 00149 * @note @ref LL_DAC_Init() aims to ease basic configuration of a DAC channel. 00150 * Leaving it ready to be enabled and output: 00151 * a level by calling one of 00152 * @ref LL_DAC_ConvertData12RightAligned 00153 * @ref LL_DAC_ConvertData12LeftAligned 00154 * @ref LL_DAC_ConvertData8RightAligned 00155 * or one of the supported autogenerated wave. 00156 * @note This function allows configuration of: 00157 * - Output mode 00158 * - Trigger 00159 * - Wave generation 00160 * @note The setting of these parameters by function @ref LL_DAC_Init() 00161 * is conditioned to DAC state: 00162 * DAC channel must be disabled. 00163 * @param DACx DAC instance 00164 * @param DAC_Channel This parameter can be one of the following values: 00165 * @arg @ref LL_DAC_CHANNEL_1 00166 * @arg @ref LL_DAC_CHANNEL_2 00167 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure 00168 * @retval An ErrorStatus enumeration value: 00169 * - SUCCESS: DAC registers are initialized 00170 * - ERROR: DAC registers are not initialized 00171 */ 00172 ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct) 00173 { 00174 ErrorStatus status = SUCCESS; 00175 00176 /* Check the parameters */ 00177 assert_param(IS_DAC_ALL_INSTANCE(DACx)); 00178 assert_param(IS_LL_DAC_CHANNEL(DAC_Channel)); 00179 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource)); 00180 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer)); 00181 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration)); 00182 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) 00183 { 00184 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGeneration, 00185 DAC_InitStruct->WaveAutoGenerationConfig)); 00186 } 00187 00188 /* Note: Hardware constraint (refer to description of this function) */ 00189 /* DAC instance must be disabled. */ 00190 if (LL_DAC_IsEnabled(DACx, DAC_Channel) == 0UL) 00191 { 00192 /* Configuration of DAC channel: */ 00193 /* - TriggerSource */ 00194 /* - WaveAutoGeneration */ 00195 /* - OutputBuffer */ 00196 /* - OutputMode */ 00197 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) 00198 { 00199 MODIFY_REG(DACx->CR, 00200 (DAC_CR_TSEL1 00201 | DAC_CR_WAVE1 00202 | DAC_CR_MAMP1 00203 | DAC_CR_BOFF1 00204 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00205 , 00206 (DAC_InitStruct->TriggerSource 00207 | DAC_InitStruct->WaveAutoGeneration 00208 | DAC_InitStruct->WaveAutoGenerationConfig 00209 | DAC_InitStruct->OutputBuffer 00210 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00211 ); 00212 } 00213 else 00214 { 00215 MODIFY_REG(DACx->CR, 00216 (DAC_CR_TSEL1 00217 | DAC_CR_WAVE1 00218 | DAC_CR_BOFF1 00219 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00220 , 00221 (DAC_InitStruct->TriggerSource 00222 | LL_DAC_WAVE_AUTO_GENERATION_NONE 00223 | DAC_InitStruct->OutputBuffer 00224 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00225 ); 00226 } 00227 } 00228 else 00229 { 00230 /* Initialization error: DAC instance is not disabled. */ 00231 status = ERROR; 00232 } 00233 return status; 00234 } 00235 00236 /** 00237 * @brief Set each @ref LL_DAC_InitTypeDef field to default value. 00238 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure 00239 * whose fields will be set to default values. 00240 * @retval None 00241 */ 00242 void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct) 00243 { 00244 /* Set DAC_InitStruct fields to default values */ 00245 DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE; 00246 DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE; 00247 /* Note: Parameter discarded if wave auto generation is disabled, */ 00248 /* set anyway to its default value. */ 00249 DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0; 00250 DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE; 00251 } 00252 00253 /** 00254 * @} 00255 */ 00256 00257 /** 00258 * @} 00259 */ 00260 00261 /** 00262 * @} 00263 */ 00264 00265 #endif /* DAC */ 00266 00267 /** 00268 * @} 00269 */ 00270 00271 #endif /* USE_FULL_LL_DRIVER */ 00272 00273 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/