comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_lptim.c @ 128:c78bcbd5deda FlipDisplay

Added current STM32 standandard libraries in version independend folder structure
author Ideenmodellierer
date Sun, 17 Feb 2019 21:12:22 +0100
parents
children
comparison
equal deleted inserted replaced
127:1369f8660eaa 128:c78bcbd5deda
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_ll_lptim.c
4 * @author MCD Application Team
5 * @brief LPTIM LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 ******************************************************************************
34 */
35 #if defined(USE_FULL_LL_DRIVER)
36
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx_ll_lptim.h"
39 #include "stm32f4xx_ll_bus.h"
40
41 #ifdef USE_FULL_ASSERT
42 #include "stm32_assert.h"
43 #else
44 #define assert_param(expr) ((void)0U)
45 #endif
46
47 /** @addtogroup STM32F4xx_LL_Driver
48 * @{
49 */
50
51 #if defined (LPTIM1) || defined (LPTIM2)
52
53 /** @addtogroup LPTIM_LL
54 * @{
55 */
56
57 /* Private types -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
59 /* Private constants ---------------------------------------------------------*/
60 /* Private macros ------------------------------------------------------------*/
61 /** @addtogroup LPTIM_LL_Private_Macros
62 * @{
63 */
64 #define IS_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
65 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
66
67 #define IS_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
68 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
69 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
70 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
71 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
72 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
73 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
74 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
75
76 #define IS_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \
77 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
78
79 #define IS_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \
80 || ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
81 /**
82 * @}
83 */
84
85
86 /* Private function prototypes -----------------------------------------------*/
87 /* Exported functions --------------------------------------------------------*/
88 /** @addtogroup LPTIM_LL_Exported_Functions
89 * @{
90 */
91
92 /** @addtogroup LPTIM_LL_EF_Init
93 * @{
94 */
95
96 /**
97 * @brief Set LPTIMx registers to their reset values.
98 * @param LPTIMx LP Timer instance
99 * @retval An ErrorStatus enumeration value:
100 * - SUCCESS: LPTIMx registers are de-initialized
101 * - ERROR: invalid LPTIMx instance
102 */
103 ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef* LPTIMx)
104 {
105 ErrorStatus result = SUCCESS;
106
107 /* Check the parameters */
108 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
109
110 if (LPTIMx == LPTIM1)
111 {
112 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1);
113 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1);
114 }
115 #if defined(LPTIM2)
116 else if (LPTIMx == LPTIM2)
117 {
118 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2);
119 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2);
120 }
121 #endif
122 else
123 {
124 result = ERROR;
125 }
126
127 return result;
128 }
129
130 /**
131 * @brief Set each fields of the LPTIM_InitStruct structure to its default
132 * value.
133 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
134 * @retval None
135 */
136 void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef* LPTIM_InitStruct)
137 {
138 /* Set the default configuration */
139 LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL;
140 LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1;
141 LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM;
142 LPTIM_InitStruct->Polarity = LL_LPTIM_OUTPUT_POLARITY_REGULAR;
143 }
144
145 /**
146 * @brief Configure the LPTIMx peripheral according to the specified parameters.
147 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
148 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
149 * @param LPTIMx LP Timer Instance
150 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
151 * @retval An ErrorStatus enumeration value:
152 * - SUCCESS: LPTIMx instance has been initialized
153 * - ERROR: LPTIMx instance hasn't been initialized
154 */
155 ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef * LPTIMx, LL_LPTIM_InitTypeDef* LPTIM_InitStruct)
156 {
157 ErrorStatus result = SUCCESS;
158
159 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
160 (ENABLE bit is reset to 0).
161 */
162 if (LL_LPTIM_IsEnabled(LPTIMx))
163 {
164 result = ERROR;
165 }
166 else
167 {
168 /* Check the parameters */
169 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
170 assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource));
171 assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler));
172 assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform));
173 assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity));
174
175 /* Set CKSEL bitfield according to ClockSource value */
176 /* Set PRESC bitfield according to Prescaler value */
177 /* Set WAVE bitfield according to Waveform value */
178 /* Set WAVEPOL bitfield according to Polarity value */
179 MODIFY_REG(LPTIMx->CFGR,
180 (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE| LPTIM_CFGR_WAVPOL),
181 LPTIM_InitStruct->ClockSource | \
182 LPTIM_InitStruct->Prescaler | \
183 LPTIM_InitStruct->Waveform | \
184 LPTIM_InitStruct->Polarity);
185 }
186
187 return result;
188 }
189
190 /**
191 * @}
192 */
193
194 /**
195 * @}
196 */
197
198 /**
199 * @}
200 */
201
202 #endif /* defined (LPTIM1) || defined (LPTIM2) */
203
204 /**
205 * @}
206 */
207
208 #endif /* USE_FULL_LL_DRIVER */
209
210 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/