Skip to content

Commit 5168276

Browse files
committed
revert back to old en0-mask if serial is connected
1 parent efd4b9c commit 5168276

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

ports/raspberrypi/common-hal/alarm/__init__.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ static inline void _sleep_run_from_lposc(void) {
9999
}
100100
#endif
101101

102+
#ifdef PICO_RP2040
103+
// Light sleep turns off nonvolatile Busio and other wake-only peripherals.
104+
// This does not save a considerable amount of current (~2mA), but
105+
// it is only used during fake (USB-connected) LightSleep anyway.
106+
const uint32_t RP_LIGHTSLEEP_EN0_MASK = ~(
107+
CLOCKS_SLEEP_EN0_CLK_SYS_SPI1_BITS |
108+
CLOCKS_SLEEP_EN0_CLK_PERI_SPI1_BITS |
109+
CLOCKS_SLEEP_EN0_CLK_SYS_SPI0_BITS |
110+
CLOCKS_SLEEP_EN0_CLK_PERI_SPI0_BITS |
111+
CLOCKS_SLEEP_EN0_CLK_SYS_PWM_BITS |
112+
CLOCKS_SLEEP_EN0_CLK_SYS_PIO1_BITS |
113+
CLOCKS_SLEEP_EN0_CLK_SYS_PIO0_BITS |
114+
CLOCKS_SLEEP_EN0_CLK_SYS_I2C1_BITS |
115+
CLOCKS_SLEEP_EN0_CLK_SYS_I2C0_BITS |
116+
CLOCKS_SLEEP_EN0_CLK_SYS_ADC_BITS |
117+
CLOCKS_SLEEP_EN0_CLK_ADC_ADC_BITS
118+
);
119+
#endif
120+
102121
static dormant_source_t _dormant_source;
103122

104123
// State of the serial connection
@@ -205,12 +224,13 @@ static void _sleep_goto_sleep_until(void) {
205224
DEBUG_PRINT("_sleep_goto_sleep_until");
206225
SLEEP(10);
207226

208-
clocks_hw->sleep_en0 = CLOCKS_SLEEP_EN0_CLK_RTC_RTC_BITS;
209227
if (_serial_connected) {
210-
DEBUG_PRINT("serial connected: using sleep_en1 = CLOCKS_SLEEP_EN1_RESET");
228+
DEBUG_PRINT("serial connected: using old clock-masks");
211229
SLEEP(10);
230+
clocks_hw->sleep_en0 &= RP_LIGHTSLEEP_EN0_MASK;
212231
clocks_hw->sleep_en1 = CLOCKS_SLEEP_EN1_RESET;
213232
} else {
233+
clocks_hw->sleep_en0 = CLOCKS_SLEEP_EN0_CLK_RTC_RTC_BITS;
214234
clocks_hw->sleep_en1 = 0x0;
215235
}
216236

0 commit comments

Comments
 (0)