From 0c5fd55c166a78cd7ee4f0e68f2ec8ca89fc182b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 13 Oct 2022 20:09:48 -0500 Subject: [PATCH] picow: Turn off wifi co-processor regulator when entering deep sleep This reduces power consumption during true deep sleep. In my measurements with ppk2 and a program that _irrevocably_ entered deep sleep (no time alarm or pin alarm), power usage as measured on a ppk2 decreased from ~10mA to ~1mA. --- ports/raspberrypi/bindings/cyw43/__init__.c | 6 ++++++ ports/raspberrypi/bindings/cyw43/__init__.h | 1 + ports/raspberrypi/common-hal/alarm/__init__.c | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/ports/raspberrypi/bindings/cyw43/__init__.c b/ports/raspberrypi/bindings/cyw43/__init__.c index 66cc5fa1c4..bf0cbc2e67 100644 --- a/ports/raspberrypi/bindings/cyw43/__init__.c +++ b/ports/raspberrypi/bindings/cyw43/__init__.c @@ -35,6 +35,12 @@ static int power_management_value = PM_DISABLED; +void cyw43_enter_deep_sleep(void) { +#define WL_REG_ON 23 + gpio_set_dir(WL_REG_ON, GPIO_OUT); + gpio_put(WL_REG_ON, false); +} + void bindings_cyw43_wifi_enforce_pm() { cyw43_wifi_pm(&cyw43_state, power_management_value); } diff --git a/ports/raspberrypi/bindings/cyw43/__init__.h b/ports/raspberrypi/bindings/cyw43/__init__.h index c543f7b9e1..2520c6c2d1 100644 --- a/ports/raspberrypi/bindings/cyw43/__init__.h +++ b/ports/raspberrypi/bindings/cyw43/__init__.h @@ -51,3 +51,4 @@ const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj); #define PM_DISABLED CONSTANT_CYW43_PM_VALUE(CYW43_NO_POWERSAVE_MODE, 200, 1, 1, 10) extern void bindings_cyw43_wifi_enforce_pm(void); +void cyw43_enter_deep_sleep(void); diff --git a/ports/raspberrypi/common-hal/alarm/__init__.c b/ports/raspberrypi/common-hal/alarm/__init__.c index 31fa58aab3..9cfa390116 100644 --- a/ports/raspberrypi/common-hal/alarm/__init__.c +++ b/ports/raspberrypi/common-hal/alarm/__init__.c @@ -38,6 +38,10 @@ #include "shared-bindings/microcontroller/__init__.h" +#if CIRCUITPY_CYW43 +#include "bindings/cyw43/__init__.h" +#endif + #include "supervisor/port.h" #include "supervisor/shared/workflow.h" @@ -204,6 +208,10 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala void NORETURN common_hal_alarm_enter_deep_sleep(void) { bool timealarm_set = alarm_time_timealarm_is_set(); + #if CIRCUITPY_CYW43 + cyw43_enter_deep_sleep(); + #endif + // If there's a timealarm, just enter a very deep light sleep if (timealarm_set) { // Prune the clock for sleep