Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stm32l4xx_ll_dac.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_dac.c 00004 * @author MCD Application Team 00005 * @version V1.5.1 00006 * @date 31-May-2016 00007 * @brief DAC LL module driver 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 #if defined(USE_FULL_LL_DRIVER) 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 #include "stm32l4xx_ll_dac.h" 00041 #include "stm32l4xx_ll_bus.h" 00042 00043 #ifdef USE_FULL_ASSERT 00044 #include "stm32_assert.h" 00045 #else 00046 #define assert_param(expr) ((void)0U) 00047 #endif 00048 00049 /** @addtogroup STM32L4xx_LL_Driver 00050 * @{ 00051 */ 00052 00053 #if defined (DAC1) 00054 00055 /** @addtogroup DAC_LL DAC 00056 * @{ 00057 */ 00058 00059 /* Private types -------------------------------------------------------------*/ 00060 /* Private variables ---------------------------------------------------------*/ 00061 /* Private constants ---------------------------------------------------------*/ 00062 /* Private macros ------------------------------------------------------------*/ 00063 00064 /** @addtogroup DAC_LL_Private_Macros 00065 * @{ 00066 */ 00067 00068 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \ 00069 ( \ 00070 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \ 00071 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \ 00072 ) 00073 00074 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \ 00075 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \ 00076 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \ 00077 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \ 00078 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \ 00079 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \ 00080 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \ 00081 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \ 00082 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \ 00083 ) 00084 00085 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \ 00086 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \ 00087 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \ 00088 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \ 00089 ) 00090 00091 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_CONFIG__) \ 00092 ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \ 00093 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \ 00094 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \ 00095 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \ 00096 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \ 00097 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \ 00098 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \ 00099 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \ 00100 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \ 00101 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \ 00102 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \ 00103 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0) \ 00104 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \ 00105 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \ 00106 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \ 00107 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \ 00108 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \ 00109 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \ 00110 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \ 00111 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \ 00112 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \ 00113 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \ 00114 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \ 00115 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095) \ 00116 ) 00117 00118 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \ 00119 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \ 00120 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \ 00121 ) 00122 00123 #define IS_LL_DAC_OUTPUT_CONNECTION(__OUTPUT_CONNECTION__) \ 00124 ( ((__OUTPUT_CONNECTION__) == LL_DAC_OUTPUT_CONNECT_GPIO) \ 00125 || ((__OUTPUT_CONNECTION__) == LL_DAC_OUTPUT_CONNECT_INTERNAL) \ 00126 ) 00127 00128 #define IS_LL_DAC_OUTPUT_MODE(__OUTPUT_MODE__) \ 00129 ( ((__OUTPUT_MODE__) == LL_DAC_OUTPUT_MODE_NORMAL) \ 00130 || ((__OUTPUT_MODE__) == LL_DAC_OUTPUT_MODE_SAMPLE_AND_HOLD) \ 00131 ) 00132 00133 /** 00134 * @} 00135 */ 00136 00137 00138 /* Private function prototypes -----------------------------------------------*/ 00139 00140 /* Exported functions --------------------------------------------------------*/ 00141 /** @addtogroup DAC_LL_Exported_Functions 00142 * @{ 00143 */ 00144 00145 /** @addtogroup DAC_LL_EF_Init 00146 * @{ 00147 */ 00148 00149 /** 00150 * @brief De-initialize registers of the selected DAC instance 00151 * to their default reset values. 00152 * @param DACx DAC instance 00153 * @retval An ErrorStatus enumeration value: 00154 * - SUCCESS: DAC registers are de-initialized 00155 * - ERROR: not applicable 00156 */ 00157 ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx) 00158 { 00159 /* Check the parameters */ 00160 assert_param(IS_DAC_ALL_INSTANCE(DACx)); 00161 00162 /* Force reset of DAC clock */ 00163 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1); 00164 00165 /* Release reset of DAC clock */ 00166 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1); 00167 00168 return SUCCESS; 00169 } 00170 00171 /** 00172 * @brief Initialize some features of DAC instance. 00173 * @note The setting of these parameters by function @ref LL_DAC_Init() 00174 * is conditioned to DAC state: 00175 * DAC instance must be disabled. 00176 * @param DACx DAC instance 00177 * @param DAC_Channel This parameter can be one of the following values: 00178 * @arg @ref LL_DAC_CHANNEL_1 00179 * @arg @ref LL_DAC_CHANNEL_2 00180 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure 00181 * @retval An ErrorStatus enumeration value: 00182 * - SUCCESS: DAC registers are initialized 00183 * - ERROR: DAC registers are not initialized 00184 */ 00185 ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct) 00186 { 00187 ErrorStatus status = SUCCESS; 00188 00189 /* Check the parameters */ 00190 assert_param(IS_DAC_ALL_INSTANCE(DACx)); 00191 assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel)); 00192 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource )); 00193 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer )); 00194 assert_param(IS_LL_DAC_OUTPUT_CONNECTION(DAC_InitStruct->OutputConnection )); 00195 assert_param(IS_LL_DAC_OUTPUT_MODE(DAC_InitStruct->OutputMode )); 00196 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration )); 00197 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) 00198 { 00199 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGenerationConfig )); 00200 } 00201 00202 /* Note: Hardware constraint (refer to description of this function) */ 00203 /* DAC instance must be disabled. */ 00204 if(LL_DAC_IsEnabled(DACx, DAC_Channel) == 0U) 00205 { 00206 /* Configuration of DAC channel: */ 00207 /* - TriggerSource */ 00208 /* - WaveAutoGeneration */ 00209 /* - OutputBuffer */ 00210 /* - OutputConnection */ 00211 /* - OutputMode */ 00212 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) 00213 { 00214 MODIFY_REG(DACx->CR, 00215 ( DAC_CR_TSEL1 00216 | DAC_CR_WAVE1 00217 | DAC_CR_MAMP1 00218 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00219 , 00220 ( DAC_InitStruct->TriggerSource 00221 | DAC_InitStruct->WaveAutoGeneration 00222 | DAC_InitStruct->WaveAutoGenerationConfig 00223 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00224 ); 00225 } 00226 else 00227 { 00228 MODIFY_REG(DACx->CR, 00229 ( DAC_CR_TSEL1 00230 | DAC_CR_WAVE1 00231 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00232 , 00233 ( DAC_InitStruct->TriggerSource 00234 | LL_DAC_WAVE_AUTO_GENERATION_NONE 00235 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00236 ); 00237 } 00238 00239 MODIFY_REG(DACx->MCR, 00240 ( DAC_MCR_MODE1_1 00241 | DAC_MCR_MODE1_0 00242 | DAC_MCR_MODE1_2 00243 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00244 , 00245 ( DAC_InitStruct->OutputBuffer 00246 | DAC_InitStruct->OutputConnection 00247 | DAC_InitStruct->OutputMode 00248 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) 00249 ); 00250 } 00251 else 00252 { 00253 /* Initialization error: DAC instance is not disabled. */ 00254 status = ERROR; 00255 } 00256 return status; 00257 } 00258 00259 /** 00260 * @brief Set each @ref LL_DAC_InitTypeDef field to default value. 00261 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure 00262 * whose fields will be set to default values. 00263 * @retval None 00264 */ 00265 void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct) 00266 { 00267 /* Set DAC_InitStruct fields to default values */ 00268 DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE; 00269 DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE; 00270 /* Note: Parameter discarded if wave auto generation is disabled, */ 00271 /* set anyway to its default value. */ 00272 DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0; 00273 DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE; 00274 DAC_InitStruct->OutputConnection = LL_DAC_OUTPUT_CONNECT_GPIO; 00275 DAC_InitStruct->OutputMode = LL_DAC_OUTPUT_MODE_NORMAL; 00276 } 00277 00278 /** 00279 * @} 00280 */ 00281 00282 /** 00283 * @} 00284 */ 00285 00286 /** 00287 * @} 00288 */ 00289 00290 #endif /* DAC1 */ 00291 00292 /** 00293 * @} 00294 */ 00295 00296 #endif /* USE_FULL_LL_DRIVER */ 00297 00298 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 10:59:59 by
