1 /**
2  * @file    lp.h
3  * @brief   Low Power(LP) function prototypes and data types.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32680_LP_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32680_LP_H_
29 
30 /* **** Includes **** */
31 #include <stdint.h>
32 #include "pwrseq_regs.h"
33 #include "mcr_regs.h"
34 #include "gcr_regs.h"
35 #include "gpio.h"
36 #include "tmr.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**
43  * @defgroup pwrseq Low Power (LP)
44  * @ingroup periphlibs
45  * @{
46  */
47 
48 /**
49  * @brief   Enumeration type for voltage selection
50  *
51  */
52 typedef enum { MXC_LP_V0_9 = 0, MXC_LP_V1_0, MXC_LP_V1_1 } mxc_lp_ovr_t;
53 
54 /**
55  * @brief   Enumeration type for PM Mode
56  *
57  */
58 typedef enum {
59     MXC_LP_IPO = MXC_F_GCR_PM_IPO_PD,
60     MXC_LP_IBRO = MXC_F_GCR_PM_IBRO_PD,
61 } mxc_lp_cfg_ds_pd_t;
62 
63 /**
64  * @brief      Places the device into SLEEP mode.  This function returns once an RTC or external interrupt occur.
65  */
66 void MXC_LP_EnterSleepMode(void);
67 
68 /**
69  * @brief      Places the device into Low Power mode.  This function returns once an RTC or external interrupt occur.
70  */
71 void MXC_LP_EnterLowPowerMode(void);
72 
73 /**
74  * @brief      Places the device into Micro Power mode.  This function returns once an RTC or external interrupt occur.
75  */
76 void MXC_LP_EnterMicroPowerMode(void);
77 
78 /**
79  * @brief      Places the device into Standby mode.  This function returns once an RTC or external interrupt occur.
80  */
81 void MXC_LP_EnterStandbyMode(void);
82 
83 /**
84  * @brief      Places the device into BACKUP mode.  CPU state is not maintained in this mode, so this function never returns.
85  *             Instead, the device will restart once an RTC or external interrupt occur.
86  */
87 void MXC_LP_EnterBackupMode(void);
88 
89 /**
90  * @brief      Places the device into Shutdown mode.  CPU state is not maintained in this mode, so this function never returns.
91  *             Instead, the device will restart once an RTC, USB wakeup, or external interrupt occur.
92  */
93 void MXC_LP_EnterPowerDownMode(void);
94 
95 /**
96  * @brief      Set ovr bits to set the voltage the micro will run at.
97  *
98  * @param[in]  ovr   The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t
99  */
100 void MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
101 
102 /**
103  * @brief      Turn bandgap on
104  */
105 void MXC_LP_BandgapOn(void);
106 
107 /**
108  * @brief      Turn bandgap off
109  */
110 void MXC_LP_BandgapOff(void);
111 
112 /**
113  * @brief      Is the bandgap on or off
114  *
115  * @return     1 = bandgap on , 0 = bandgap off
116  */
117 int MXC_LP_BandgapIsOn(void);
118 
119 /**
120  * @brief      clear all wake up status
121  */
122 void MXC_LP_ClearWakeStatus(void);
123 
124 /**
125  * @brief      Enables the selected GPIO port and its selected pins to wake up the device from any low power mode.
126  *             Call this function multiple times to enable pins on multiple ports.  This function does not configure
127  *             the GPIO pins nor does it setup their interrupt functionality.
128  * @param      wu_pins      The port and pins to configure as wakeup sources.  Only the gpio and mask fields of the
129  *                          structure are used.  The func and pad fields are ignored.
130  */
131 
132 void MXC_LP_EnableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
133 
134 /**
135  * @brief      Disables the selected GPIO port and its selected pins as a wake up source.
136  *             Call this function multiple times to disable pins on multiple ports.
137  * @param      wu_pins      The port and pins to disable as wakeup sources.  Only the gpio and mask fields of the
138  *                          structure are used.  The func and pad fields are ignored.
139  */
140 void MXC_LP_DisableGPIOWakeup(mxc_gpio_cfg_t *wu_pins);
141 
142 /**
143  * @brief      Enables the RTC alarm to wake up the device from any low power mode.
144  */
145 void MXC_LP_EnableRTCAlarmWakeup(void);
146 
147 /**
148  * @brief      Disables the RTC alarm from waking up the device.
149  */
150 void MXC_LP_DisableRTCAlarmWakeup(void);
151 
152 /**
153  * @brief      Enables Timer to wakeup from any low power mode.
154  *
155  * @param      tmr  Pointer to timer module.
156  */
157 void MXC_LP_EnableTimerWakeup(mxc_tmr_regs_t *tmr);
158 
159 /**
160  * @brief      Disables Timer from waking up device.
161  *
162  * @param      tmr  Pointer to timer module.
163  */
164 void MXC_LP_DisableTimerWakeup(mxc_tmr_regs_t *tmr);
165 
166 /**
167  * @brief      Enables the USB to wake up the device from any low power mode.
168  */
169 void MXC_LP_EnableUSBWakeup(void);
170 
171 /**
172  * @brief      Disables the USB from waking up the device.
173  */
174 void MXC_LP_DisableUSBWakeup(void);
175 
176 /**
177  * @brief      Enables the WUT alarm to wake up the device from any low power mode.
178  */
179 void MXC_LP_EnableWUTAlarmWakeup(void);
180 
181 /**
182  * @brief      Disables the WUT alarm from waking up the device.
183  */
184 void MXC_LP_DisableWUTAlarmWakeup(void);
185 
186 /**
187  * @brief      Enables the HA0 to wake up the device from any low power mode.
188  */
189 void MXC_LP_EnableHA0Wakeup(void);
190 
191 /**
192  * @brief      Disables the HA)0 from waking up the device.
193  */
194 void MXC_LP_DisableHA0Wakeup(void);
195 /**
196  * @brief      Enables the HA1 to wake up the device from any low power mode.
197  */
198 void MXC_LP_EnableHA1Wakeup(void);
199 
200 /**
201  * @brief      Disables the HA1 from waking up the device.
202  */
203 void MXC_LP_DisableHA1Wakeup(void);
204 
205 /**
206  * @brief      Configure which clocks are powered down at deep sleep and which are not affected.
207  *
208  * @note       Need to configure all clocks at once any clock not passed in the mask will be unaffected by Deepsleep.  This will
209  *             always overwrite the previous settings of ALL clocks.
210  *
211  * @param[in]  mask  The mask of the clocks to power down when part goes into deepsleep
212  *
213  * @return     #E_NO_ERROR or error based on /ref MXC_Error_Codes
214  */
215 int MXC_LP_ConfigDeepSleepClocks(uint32_t mask);
216 
217 /**
218  * @brief      Enable NFC Oscilator Bypass
219  */
220 void MXC_LP_NFCOscBypassEnable(void);
221 
222 /**
223  * @brief      Disable NFC Oscilator Bypass
224  */
225 void MXC_LP_NFCOscBypassDisable(void);
226 
227 /**
228  * @brief      Is NFC Oscilator Bypass Enabled
229  *
230  * @return     1 = enabled, 0 = disabled
231  */
232 int MXC_LP_NFCOscBypassIsEnabled(void);
233 
234 /**@} end of group pwrseq */
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32680_LP_H_
241