source: trunk/firmware/Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_lptim.c

Last change on this file was 6, checked in by f.jahn, 8 months ago
File size: 6.5 KB
Line 
1/**
2 ******************************************************************************
3 * @file stm32g0xx_ll_lptim.c
4 * @author MCD Application Team
5 * @brief LPTIM LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
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
16 *
17 ******************************************************************************
18 */
19#if defined(USE_FULL_LL_DRIVER)
20
21/* Includes ------------------------------------------------------------------*/
22#include "stm32g0xx_ll_lptim.h"
23#include "stm32g0xx_ll_bus.h"
24
25#ifdef USE_FULL_ASSERT
26#include "stm32_assert.h"
27#else
28#define assert_param(expr) ((void)0U)
29#endif
30
31/** @addtogroup STM32G0xx_LL_Driver
32 * @{
33 */
34
35#if defined (LPTIM1) || defined (LPTIM2)
36
37/** @addtogroup LPTIM_LL
38 * @{
39 */
40
41/* Private types -------------------------------------------------------------*/
42/* Private variables ---------------------------------------------------------*/
43/* Private constants ---------------------------------------------------------*/
44/* Private macros ------------------------------------------------------------*/
45/** @addtogroup LPTIM_LL_Private_Macros
46 * @{
47 */
48#define IS_LL_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
49 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
50
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))
59
60#define IS_LL_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \
61 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
62
63#define IS_LL_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \
64 || ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
65/**
66 * @}
67 */
68
69
70/* Private function prototypes -----------------------------------------------*/
71/* Exported functions --------------------------------------------------------*/
72/** @addtogroup LPTIM_LL_Exported_Functions
73 * @{
74 */
75
76/** @addtogroup LPTIM_LL_EF_Init
77 * @{
78 */
79
80/**
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
86 */
87ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef *LPTIMx)
88{
89 ErrorStatus result = SUCCESS;
90
91 /* Check the parameters */
92 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
93
94 if (LPTIMx == LPTIM1)
95 {
96 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1);
97 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1);
98 }
99#if defined(LPTIM2)
100 else if (LPTIMx == LPTIM2)
101 {
102 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM2);
103 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM2);
104 }
105#endif /* LPTIM2 */
106 else
107 {
108 result = ERROR;
109 }
110
111 return result;
112}
113
114/**
115 * @brief Set each fields of the LPTIM_InitStruct structure to its default
116 * value.
117 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
118 * @retval None
119 */
120void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
121{
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;
127}
128
129/**
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
138 */
139ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, LL_LPTIM_InitTypeDef *LPTIM_InitStruct)
140{
141 ErrorStatus result = SUCCESS;
142 /* Check the parameters */
143 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
144 assert_param(IS_LL_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource));
145 assert_param(IS_LL_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler));
146 assert_param(IS_LL_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform));
147 assert_param(IS_LL_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity));
148
149 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
150 (ENABLE bit is reset to 0).
151 */
152 if (LL_LPTIM_IsEnabled(LPTIMx) == 1U)
153 {
154 result = ERROR;
155 }
156 else
157 {
158 /* Set CKSEL bitfield according to ClockSource value */
159 /* Set PRESC bitfield according to Prescaler value */
160 /* Set WAVE bitfield according to Waveform value */
161 /* Set WAVEPOL bitfield according to Polarity value */
162 MODIFY_REG(LPTIMx->CFGR,
163 (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE | LPTIM_CFGR_WAVPOL),
164 LPTIM_InitStruct->ClockSource | \
165 LPTIM_InitStruct->Prescaler | \
166 LPTIM_InitStruct->Waveform | \
167 LPTIM_InitStruct->Polarity);
168 }
169
170 return result;
171}
172
173/**
174 * @}
175 */
176
177/**
178 * @}
179 */
180
181/**
182 * @}
183 */
184
185#endif /* LPTIM1 || LPTIM2 */
186
187/**
188 * @}
189 */
190
191#endif /* USE_FULL_LL_DRIVER */
192
193/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.