Mercurial > pub > halpp
comparison l476rg/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr.h @ 0:32a3b1785697
a rough draft of Hardware Abstraction Layer for C++
STM32L476RG drivers
author | cin |
---|---|
date | Thu, 12 Jan 2017 02:45:43 +0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:32a3b1785697 |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32l4xx_hal_pwr.h | |
4 * @author MCD Application Team | |
5 * @version V1.6.0 | |
6 * @date 28-October-2016 | |
7 * @brief Header file of PWR HAL module. | |
8 ****************************************************************************** | |
9 * @attention | |
10 * | |
11 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> | |
12 * | |
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. | |
23 * | |
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. | |
34 * | |
35 ****************************************************************************** | |
36 */ | |
37 | |
38 /* Define to prevent recursive inclusion -------------------------------------*/ | |
39 #ifndef __STM32L4xx_HAL_PWR_H | |
40 #define __STM32L4xx_HAL_PWR_H | |
41 | |
42 #ifdef __cplusplus | |
43 extern "C" { | |
44 #endif | |
45 | |
46 /* Includes ------------------------------------------------------------------*/ | |
47 #include "stm32l4xx_hal_def.h" | |
48 | |
49 /** @addtogroup STM32L4xx_HAL_Driver | |
50 * @{ | |
51 */ | |
52 | |
53 /** @addtogroup PWR | |
54 * @{ | |
55 */ | |
56 | |
57 /* Exported types ------------------------------------------------------------*/ | |
58 | |
59 /** @defgroup PWR_Exported_Types PWR Exported Types | |
60 * @{ | |
61 */ | |
62 | |
63 /** | |
64 * @brief PWR PVD configuration structure definition | |
65 */ | |
66 typedef struct | |
67 { | |
68 uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level. | |
69 This parameter can be a value of @ref PWR_PVD_detection_level. */ | |
70 | |
71 uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins. | |
72 This parameter can be a value of @ref PWR_PVD_Mode. */ | |
73 }PWR_PVDTypeDef; | |
74 | |
75 | |
76 /** | |
77 * @} | |
78 */ | |
79 | |
80 /* Exported constants --------------------------------------------------------*/ | |
81 | |
82 /** @defgroup PWR_Exported_Constants PWR Exported Constants | |
83 * @{ | |
84 */ | |
85 | |
86 | |
87 /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels | |
88 * @{ | |
89 */ | |
90 #define PWR_PVDLEVEL_0 PWR_CR2_PLS_LEV0 /*!< PVD threshold around 2.0 V */ | |
91 #define PWR_PVDLEVEL_1 PWR_CR2_PLS_LEV1 /*!< PVD threshold around 2.2 V */ | |
92 #define PWR_PVDLEVEL_2 PWR_CR2_PLS_LEV2 /*!< PVD threshold around 2.4 V */ | |
93 #define PWR_PVDLEVEL_3 PWR_CR2_PLS_LEV3 /*!< PVD threshold around 2.5 V */ | |
94 #define PWR_PVDLEVEL_4 PWR_CR2_PLS_LEV4 /*!< PVD threshold around 2.6 V */ | |
95 #define PWR_PVDLEVEL_5 PWR_CR2_PLS_LEV5 /*!< PVD threshold around 2.8 V */ | |
96 #define PWR_PVDLEVEL_6 PWR_CR2_PLS_LEV6 /*!< PVD threshold around 2.9 V */ | |
97 #define PWR_PVDLEVEL_7 PWR_CR2_PLS_LEV7 /*!< External input analog voltage (compared internally to VREFINT) */ | |
98 /** | |
99 * @} | |
100 */ | |
101 | |
102 /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode | |
103 * @{ | |
104 */ | |
105 #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< Basic mode is used */ | |
106 #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */ | |
107 #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */ | |
108 #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ | |
109 #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */ | |
110 #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */ | |
111 #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */ | |
112 /** | |
113 * @} | |
114 */ | |
115 | |
116 | |
117 | |
118 | |
119 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode | |
120 * @{ | |
121 */ | |
122 #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) /*!< Regulator in main mode */ | |
123 #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */ | |
124 /** | |
125 * @} | |
126 */ | |
127 | |
128 /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry | |
129 * @{ | |
130 */ | |
131 #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Sleep mode */ | |
132 #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Sleep mode */ | |
133 /** | |
134 * @} | |
135 */ | |
136 | |
137 /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry | |
138 * @{ | |
139 */ | |
140 #define PWR_STOPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Stop mode */ | |
141 #define PWR_STOPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Stop mode */ | |
142 /** | |
143 * @} | |
144 */ | |
145 | |
146 | |
147 /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line | |
148 * @{ | |
149 */ | |
150 #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */ | |
151 /** | |
152 * @} | |
153 */ | |
154 | |
155 /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line | |
156 * @{ | |
157 */ | |
158 #define PWR_EVENT_LINE_PVD ((uint32_t)0x00010000) /*!< Event line 16 Connected to the PVD Event Line */ | |
159 /** | |
160 * @} | |
161 */ | |
162 | |
163 /** | |
164 * @} | |
165 */ | |
166 | |
167 /* Exported macros -----------------------------------------------------------*/ | |
168 /** @defgroup PWR_Exported_Macros PWR Exported Macros | |
169 * @{ | |
170 */ | |
171 | |
172 /** @brief Check whether or not a specific PWR flag is set. | |
173 * @param __FLAG__: specifies the flag to check. | |
174 * This parameter can be one of the following values: | |
175 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event | |
176 * was received from the WKUP pin 1. | |
177 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event | |
178 * was received from the WKUP pin 2. | |
179 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event | |
180 * was received from the WKUP pin 3. | |
181 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event | |
182 * was received from the WKUP pin 4. | |
183 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event | |
184 * was received from the WKUP pin 5. | |
185 * @arg @ref PWR_FLAG_SB StandBy Flag. Indicates that the system | |
186 * entered StandBy mode. | |
187 * @arg @ref PWR_FLAG_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on | |
188 * the internal wakeup line. | |
189 * @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the | |
190 * low-power regulator is ready. | |
191 * @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the | |
192 * regulator is ready in main mode or is in low-power mode. | |
193 * @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready | |
194 * in the selected voltage range or is still changing to the required voltage level. | |
195 * @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is | |
196 * below or above the selected PVD threshold. | |
197 * @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is | |
198 * is below or above PVM1 threshold (applicable when USB feature is supported). | |
199 @if STM32L486xx | |
200 * @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is | |
201 * is below or above PVM2 threshold (applicable when VDDIO2 is present on device). | |
202 @endif | |
203 * @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is | |
204 * is below or above PVM3 threshold. | |
205 * @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is | |
206 * is below or above PVM4 threshold. | |
207 * | |
208 * @retval The new state of __FLAG__ (TRUE or FALSE). | |
209 */ | |
210 #define __HAL_PWR_GET_FLAG(__FLAG__) ( ((((uint8_t)(__FLAG__)) >> 5U) == 1) ?\ | |
211 (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\ | |
212 (PWR->SR2 & (1U << ((__FLAG__) & 31U))) ) | |
213 | |
214 /** @brief Clear a specific PWR flag. | |
215 * @param __FLAG__: specifies the flag to clear. | |
216 * This parameter can be one of the following values: | |
217 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event | |
218 * was received from the WKUP pin 1. | |
219 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event | |
220 * was received from the WKUP pin 2. | |
221 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event | |
222 * was received from the WKUP pin 3. | |
223 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event | |
224 * was received from the WKUP pin 4. | |
225 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event | |
226 * was received from the WKUP pin 5. | |
227 * @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags. | |
228 * @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system | |
229 * entered Standby mode. | |
230 * @retval None | |
231 */ | |
232 #define __HAL_PWR_CLEAR_FLAG(__FLAG__) ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\ | |
233 (PWR->SCR = (__FLAG__)) :\ | |
234 (PWR->SCR = (1U << ((__FLAG__) & 31U))) ) | |
235 /** | |
236 * @brief Enable the PVD Extended Interrupt Line. | |
237 * @retval None | |
238 */ | |
239 #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD) | |
240 | |
241 /** | |
242 * @brief Disable the PVD Extended Interrupt Line. | |
243 * @retval None | |
244 */ | |
245 #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD) | |
246 | |
247 /** | |
248 * @brief Enable the PVD Event Line. | |
249 * @retval None | |
250 */ | |
251 #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD) | |
252 | |
253 /** | |
254 * @brief Disable the PVD Event Line. | |
255 * @retval None | |
256 */ | |
257 #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD) | |
258 | |
259 /** | |
260 * @brief Enable the PVD Extended Interrupt Rising Trigger. | |
261 * @retval None | |
262 */ | |
263 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD) | |
264 | |
265 /** | |
266 * @brief Disable the PVD Extended Interrupt Rising Trigger. | |
267 * @retval None | |
268 */ | |
269 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD) | |
270 | |
271 /** | |
272 * @brief Enable the PVD Extended Interrupt Falling Trigger. | |
273 * @retval None | |
274 */ | |
275 #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD) | |
276 | |
277 | |
278 /** | |
279 * @brief Disable the PVD Extended Interrupt Falling Trigger. | |
280 * @retval None | |
281 */ | |
282 #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD) | |
283 | |
284 | |
285 /** | |
286 * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger. | |
287 * @retval None | |
288 */ | |
289 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \ | |
290 do { \ | |
291 __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \ | |
292 __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \ | |
293 } while(0) | |
294 | |
295 /** | |
296 * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger. | |
297 * @retval None | |
298 */ | |
299 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \ | |
300 do { \ | |
301 __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \ | |
302 __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \ | |
303 } while(0) | |
304 | |
305 /** | |
306 * @brief Generate a Software interrupt on selected EXTI line. | |
307 * @retval None | |
308 */ | |
309 #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD) | |
310 | |
311 /** | |
312 * @brief Check whether or not the PVD EXTI interrupt flag is set. | |
313 * @retval EXTI PVD Line Status. | |
314 */ | |
315 #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR1 & PWR_EXTI_LINE_PVD) | |
316 | |
317 /** | |
318 * @brief Clear the PVD EXTI interrupt flag. | |
319 * @retval None | |
320 */ | |
321 #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD) | |
322 | |
323 /** | |
324 * @} | |
325 */ | |
326 | |
327 | |
328 /* Private macros --------------------------------------------------------*/ | |
329 /** @addtogroup PWR_Private_Macros PWR Private Macros | |
330 * @{ | |
331 */ | |
332 | |
333 #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \ | |
334 ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \ | |
335 ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \ | |
336 ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7)) | |
337 | |
338 #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) ||\ | |
339 ((MODE) == PWR_PVD_MODE_IT_RISING) ||\ | |
340 ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\ | |
341 ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\ | |
342 ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\ | |
343 ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\ | |
344 ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING)) | |
345 | |
346 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ | |
347 ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) | |
348 | |
349 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) | |
350 | |
351 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) ) | |
352 | |
353 /** | |
354 * @} | |
355 */ | |
356 | |
357 /* Include PWR HAL Extended module */ | |
358 #include "stm32l4xx_hal_pwr_ex.h" | |
359 | |
360 /* Exported functions --------------------------------------------------------*/ | |
361 | |
362 /** @addtogroup PWR_Exported_Functions PWR Exported Functions | |
363 * @{ | |
364 */ | |
365 | |
366 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions | |
367 * @{ | |
368 */ | |
369 | |
370 /* Initialization and de-initialization functions *******************************/ | |
371 void HAL_PWR_DeInit(void); | |
372 void HAL_PWR_EnableBkUpAccess(void); | |
373 void HAL_PWR_DisableBkUpAccess(void); | |
374 | |
375 /** | |
376 * @} | |
377 */ | |
378 | |
379 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions | |
380 * @{ | |
381 */ | |
382 | |
383 /* Peripheral Control functions ************************************************/ | |
384 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD); | |
385 void HAL_PWR_EnablePVD(void); | |
386 void HAL_PWR_DisablePVD(void); | |
387 | |
388 | |
389 /* WakeUp pins configuration functions ****************************************/ | |
390 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity); | |
391 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); | |
392 | |
393 /* Low Power modes configuration functions ************************************/ | |
394 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); | |
395 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); | |
396 void HAL_PWR_EnterSTANDBYMode(void); | |
397 | |
398 void HAL_PWR_EnableSleepOnExit(void); | |
399 void HAL_PWR_DisableSleepOnExit(void); | |
400 void HAL_PWR_EnableSEVOnPend(void); | |
401 void HAL_PWR_DisableSEVOnPend(void); | |
402 | |
403 void HAL_PWR_PVDCallback(void); | |
404 | |
405 | |
406 /** | |
407 * @} | |
408 */ | |
409 | |
410 /** | |
411 * @} | |
412 */ | |
413 | |
414 /** | |
415 * @} | |
416 */ | |
417 | |
418 /** | |
419 * @} | |
420 */ | |
421 | |
422 #ifdef __cplusplus | |
423 } | |
424 #endif | |
425 | |
426 | |
427 #endif /* __STM32L4xx_HAL_PWR_H */ | |
428 | |
429 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |