2 ******************************************************************************
3 * @file stm32f7xx_ll_lptim.c
4 * @author MCD Application Team
7 * @brief LPTIM LL module driver.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
37 #if defined(USE_FULL_LL_DRIVER)
39 /* Includes ------------------------------------------------------------------*/
40 #include "stm32f7xx_ll_lptim.h"
41 #include "stm32f7xx_ll_bus.h"
43 #ifdef USE_FULL_ASSERT
44 #include "stm32_assert.h"
46 #define assert_param(expr) ((void)0U)
49 /** @addtogroup STM32F7xx_LL_Driver
53 #if defined (LPTIM1) || defined (LPTIM2)
55 /** @addtogroup LPTIM_LL
59 /* Private types -------------------------------------------------------------*/
60 /* Private variables ---------------------------------------------------------*/
61 /* Private constants ---------------------------------------------------------*/
62 /* Private macros ------------------------------------------------------------*/
63 /** @addtogroup LPTIM_LL_Private_Macros
66 #define IS_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
67 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
69 #define IS_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
70 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
71 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
72 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
73 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
74 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
75 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
76 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
78 #define IS_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \
79 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
81 #define IS_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \
82 || ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
88 /* Private function prototypes -----------------------------------------------*/
89 /* Exported functions --------------------------------------------------------*/
90 /** @addtogroup LPTIM_LL_Exported_Functions
94 /** @addtogroup LPTIM_LL_EF_Init
99 * @brief Set LPTIMx registers to their reset values.
100 * @param LPTIMx LP Timer instance
101 * @retval An ErrorStatus enumeration value:
102 * - SUCCESS: LPTIMx registers are de-initialized
103 * - ERROR: invalid LPTIMx instance
105 ErrorStatus
LL_LPTIM_DeInit(LPTIM_TypeDef
* LPTIMx
)
107 ErrorStatus result
= SUCCESS
;
109 /* Check the parameters */
110 assert_param(IS_LPTIM_INSTANCE(LPTIMx
));
112 if (LPTIMx
== LPTIM1
)
114 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1
);
115 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1
);
118 else if (LPTIMx
== LPTIM2
)
120 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2
);
121 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2
);
133 * @brief Set each fields of the LPTIM_InitStruct structure to its default
135 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
138 void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef
* LPTIM_InitStruct
)
140 /* Set the default configuration */
141 LPTIM_InitStruct
->ClockSource
= LL_LPTIM_CLK_SOURCE_INTERNAL
;
142 LPTIM_InitStruct
->Prescaler
= LL_LPTIM_PRESCALER_DIV1
;
143 LPTIM_InitStruct
->Waveform
= LL_LPTIM_OUTPUT_WAVEFORM_PWM
;
144 LPTIM_InitStruct
->Polarity
= LL_LPTIM_OUTPUT_POLARITY_REGULAR
;
148 * @brief Configure the LPTIMx peripheral according to the specified parameters.
149 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
150 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
151 * @param LPTIMx LP Timer Instance
152 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
153 * @retval An ErrorStatus enumeration value:
154 * - SUCCESS: LPTIMx instance has been initialized
155 * - ERROR: LPTIMx instance hasn't been initialized
157 ErrorStatus
LL_LPTIM_Init(LPTIM_TypeDef
* LPTIMx
, LL_LPTIM_InitTypeDef
* LPTIM_InitStruct
)
159 ErrorStatus result
= SUCCESS
;
161 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
162 (ENABLE bit is reset to 0).
164 if (LL_LPTIM_IsEnabled(LPTIMx
))
170 /* Check the parameters */
171 assert_param(IS_LPTIM_INSTANCE(LPTIMx
));
172 assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct
->ClockSource
));
173 assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct
->Prescaler
));
174 assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct
->Waveform
));
175 assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct
->Polarity
));
177 /* Set CKSEL bitfield according to ClockSource value */
178 /* Set PRESC bitfield according to Prescaler value */
179 /* Set WAVE bitfield according to Waveform value */
180 /* Set WAVEPOL bitfield according to Polarity value */
181 MODIFY_REG(LPTIMx
->CFGR
,
182 (LPTIM_CFGR_CKSEL
| LPTIM_CFGR_PRESC
| LPTIM_CFGR_WAVE
| LPTIM_CFGR_WAVPOL
),
183 LPTIM_InitStruct
->ClockSource
| \
184 LPTIM_InitStruct
->Prescaler
| \
185 LPTIM_InitStruct
->Waveform
| \
186 LPTIM_InitStruct
->Polarity
);
204 #endif /* defined (LPTIM1) || defined (LPTIM2) */
210 #endif /* USE_FULL_LL_DRIVER */
212 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/