1 /** 2 ****************************************************************************** 3 * @file stm32wbaxx_ll_lptim.c 4 * @author MCD Application Team 5 * @brief LPTIM LL module driver. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 #if defined(USE_FULL_LL_DRIVER) 19 20 /* Includes ------------------------------------------------------------------*/ 21 #include "stm32wbaxx_ll_lptim.h" 22 #include "stm32wbaxx_ll_bus.h" 23 #include "stm32wbaxx_ll_rcc.h" 24 25 26 #ifdef USE_FULL_ASSERT 27 #include "stm32_assert.h" 28 #else 29 #define assert_param(expr) ((void)0U) 30 #endif /* USE_FULL_ASSERT */ 31 32 /** @addtogroup STM32WBAxx_LL_Driver 33 * @{ 34 */ 35 36 #if defined (LPTIM1) || defined (LPTIM2) 37 38 /** @addtogroup LPTIM_LL 39 * @{ 40 */ 41 42 /* Private types -------------------------------------------------------------*/ 43 /* Private variables ---------------------------------------------------------*/ 44 /* Private constants ---------------------------------------------------------*/ 45 /* Private macros ------------------------------------------------------------*/ 46 /** @addtogroup LPTIM_LL_Private_Macros 47 * @{ 48 */ 49 #define IS_LL_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \ 50 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL)) 51 52 #define IS_LL_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \ 53 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \ 54 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \ 55 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \ 56 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \ 57 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \ 58 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \ 59 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128)) 60 61 #define IS_LL_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \ 62 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE)) 63 64 /** 65 * @} 66 */ 67 68 69 /* Private function prototypes -----------------------------------------------*/ 70 /* Private functions ---------------------------------------------------------*/ 71 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions 72 * @{ 73 */ 74 /** 75 * @} 76 */ 77 /* Exported functions --------------------------------------------------------*/ 78 /** @addtogroup LPTIM_LL_Exported_Functions 79 * @{ 80 */ 81 82 /** @addtogroup LPTIM_LL_EF_Init 83 * @{ 84 */ 85 86 /** 87 * @brief Set LPTIMx registers to their reset values. 88 * @param LPTIMx LP Timer instance 89 * @retval An ErrorStatus enumeration value: 90 * - SUCCESS: LPTIMx registers are de-initialized 91 * - ERROR: invalid LPTIMx instance 92 */ LL_LPTIM_DeInit(const LPTIM_TypeDef * LPTIMx)93ErrorStatus LL_LPTIM_DeInit(const LPTIM_TypeDef *LPTIMx) 94 { 95 ErrorStatus result = SUCCESS; 96 97 /* Check the parameters */ 98 assert_param(IS_LPTIM_INSTANCE(LPTIMx)); 99 100 if (LPTIMx == LPTIM1) 101 { 102 LL_APB7_GRP1_ForceReset(LL_APB7_GRP1_PERIPH_LPTIM1); 103 LL_APB7_GRP1_ReleaseReset(LL_APB7_GRP1_PERIPH_LPTIM1); 104 } 105 #if defined(LPTIM2) 106 else if (LPTIMx == LPTIM2) 107 { 108 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2); 109 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2); 110 } 111 #endif /* LPTIM2 */ 112 else 113 { 114 result = ERROR; 115 } 116 117 return result; 118 } 119 120 /** 121 * @brief Set each fields of the LPTIM_InitStruct structure to its default 122 * value. 123 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure 124 * @retval None 125 */ LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef * LPTIM_InitStruct)126void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct) 127 { 128 /* Set the default configuration */ 129 LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL; 130 LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1; 131 LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM; 132 } 133 134 /** 135 * @brief Configure the LPTIMx peripheral according to the specified parameters. 136 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled. 137 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable(). 138 * @param LPTIMx LP Timer Instance 139 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure 140 * @retval An ErrorStatus enumeration value: 141 * - SUCCESS: LPTIMx instance has been initialized 142 * - ERROR: LPTIMx instance hasn't been initialized 143 */ LL_LPTIM_Init(LPTIM_TypeDef * LPTIMx,const LL_LPTIM_InitTypeDef * LPTIM_InitStruct)144ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, const LL_LPTIM_InitTypeDef *LPTIM_InitStruct) 145 { 146 ErrorStatus result = SUCCESS; 147 /* Check the parameters */ 148 assert_param(IS_LPTIM_INSTANCE(LPTIMx)); 149 assert_param(IS_LL_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource)); 150 assert_param(IS_LL_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler)); 151 assert_param(IS_LL_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform)); 152 153 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled 154 (ENABLE bit is reset to 0). 155 */ 156 if (LL_LPTIM_IsEnabled(LPTIMx) == 1UL) 157 { 158 result = ERROR; 159 } 160 else 161 { 162 /* Set CKSEL bitfield according to ClockSource value */ 163 /* Set PRESC bitfield according to Prescaler value */ 164 /* Set WAVE bitfield according to Waveform value */ 165 MODIFY_REG(LPTIMx->CFGR, 166 (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE), 167 LPTIM_InitStruct->ClockSource | \ 168 LPTIM_InitStruct->Prescaler | \ 169 LPTIM_InitStruct->Waveform); 170 } 171 172 return result; 173 } 174 175 /** 176 * @} 177 */ 178 179 /** 180 * @} 181 */ 182 183 /** 184 * @} 185 */ 186 187 #endif /* LPTIM1 || LPTIM2 */ 188 189 /** 190 * @} 191 */ 192 193 #endif /* USE_FULL_LL_DRIVER */ 194