2 ******************************************************************************
3 * @file stm32f7xx_ll_lptim.c
4 * @author MCD Application Team
5 * @brief LPTIM LL module driver.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32f7xx_ll_lptim.h"
23 #include "stm32f7xx_ll_bus.h"
25 #ifdef USE_FULL_ASSERT
26 #include "stm32_assert.h"
28 #define assert_param(expr) ((void)0U)
31 /** @addtogroup STM32F7xx_LL_Driver
35 #if defined (LPTIM1) || defined (LPTIM2)
37 /** @addtogroup LPTIM_LL
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /* Private macros ------------------------------------------------------------*/
45 /** @addtogroup LPTIM_LL_Private_Macros
48 #define IS_LL_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
49 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
51 #define IS_LL_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
52 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
53 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
54 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
55 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
56 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
57 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
58 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
60 #define IS_LL_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \
61 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
63 #define IS_LL_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \
64 || ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
70 /* Private function prototypes -----------------------------------------------*/
71 /* Exported functions --------------------------------------------------------*/
72 /** @addtogroup LPTIM_LL_Exported_Functions
76 /** @addtogroup LPTIM_LL_EF_Init
81 * @brief Set LPTIMx registers to their reset values.
82 * @param LPTIMx LP Timer instance
83 * @retval An ErrorStatus enumeration value:
84 * - SUCCESS: LPTIMx registers are de-initialized
85 * - ERROR: invalid LPTIMx instance
87 ErrorStatus
LL_LPTIM_DeInit(LPTIM_TypeDef
* LPTIMx
)
89 ErrorStatus result
= SUCCESS
;
91 /* Check the parameters */
92 assert_param(IS_LPTIM_INSTANCE(LPTIMx
));
96 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1
);
97 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1
);
100 else if (LPTIMx
== LPTIM2
)
102 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2
);
103 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2
);
115 * @brief Set each fields of the LPTIM_InitStruct structure to its default
117 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
120 void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef
* LPTIM_InitStruct
)
122 /* Set the default configuration */
123 LPTIM_InitStruct
->ClockSource
= LL_LPTIM_CLK_SOURCE_INTERNAL
;
124 LPTIM_InitStruct
->Prescaler
= LL_LPTIM_PRESCALER_DIV1
;
125 LPTIM_InitStruct
->Waveform
= LL_LPTIM_OUTPUT_WAVEFORM_PWM
;
126 LPTIM_InitStruct
->Polarity
= LL_LPTIM_OUTPUT_POLARITY_REGULAR
;
130 * @brief Configure the LPTIMx peripheral according to the specified parameters.
131 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
132 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
133 * @param LPTIMx LP Timer Instance
134 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
135 * @retval An ErrorStatus enumeration value:
136 * - SUCCESS: LPTIMx instance has been initialized
137 * - ERROR: LPTIMx instance hasn't been initialized
139 ErrorStatus
LL_LPTIM_Init(LPTIM_TypeDef
* LPTIMx
, LL_LPTIM_InitTypeDef
* LPTIM_InitStruct
)
141 ErrorStatus result
= SUCCESS
;
143 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
144 (ENABLE bit is reset to 0).
146 if (LL_LPTIM_IsEnabled(LPTIMx
))
152 /* Check the parameters */
153 assert_param(IS_LPTIM_INSTANCE(LPTIMx
));
154 assert_param(IS_LL_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct
->ClockSource
));
155 assert_param(IS_LL_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct
->Prescaler
));
156 assert_param(IS_LL_LPTIM_WAVEFORM(LPTIM_InitStruct
->Waveform
));
157 assert_param(IS_LL_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct
->Polarity
));
159 /* Set CKSEL bitfield according to ClockSource value */
160 /* Set PRESC bitfield according to Prescaler value */
161 /* Set WAVE bitfield according to Waveform value */
162 /* Set WAVEPOL bitfield according to Polarity value */
163 MODIFY_REG(LPTIMx
->CFGR
,
164 (LPTIM_CFGR_CKSEL
| LPTIM_CFGR_PRESC
| LPTIM_CFGR_WAVE
| LPTIM_CFGR_WAVPOL
),
165 LPTIM_InitStruct
->ClockSource
| \
166 LPTIM_InitStruct
->Prescaler
| \
167 LPTIM_InitStruct
->Waveform
| \
168 LPTIM_InitStruct
->Polarity
);
186 #endif /* defined (LPTIM1) || defined (LPTIM2) */
192 #endif /* USE_FULL_LL_DRIVER */
194 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/