According to guide `gpio_stay_*_map` are specifically there to prevent pulling pins to a specific level and let them float during deep sleep. https://docs.bekencorp.com/sdk_3.0.x/bk7238/build/en/latest/developer-guide/power_save/sleep_test.html This allows any external low-power circuitry to change a pin level, as required, to trigger the wake up This requires changes in BDK and was implemented via fixup. Also, exposed `gpio_stay_lo_map` parameter via `lt_deep_sleep_keep_floating_gpio` to manage this configuration for pins in range P0-P31.
48 lines
1.3 KiB
C
48 lines
1.3 KiB
C
/* Copyright (c) Peter Sarkozi 2023-06-17. */
|
|
|
|
#include <libretiny.h>
|
|
#include <sdk_private.h>
|
|
|
|
static PS_DEEP_CTRL_PARAM deep_sleep_param;
|
|
|
|
void lt_deep_sleep_config_gpio(uint32_t gpio_index_map, bool on_high) {
|
|
deep_sleep_param.wake_up_way |= PS_DEEP_WAKEUP_GPIO;
|
|
deep_sleep_param.gpio_index_map |= gpio_index_map;
|
|
if (on_high) {
|
|
deep_sleep_param.gpio_edge_map |= gpio_index_map;
|
|
} else {
|
|
deep_sleep_param.gpio_edge_map &= (~gpio_index_map);
|
|
}
|
|
}
|
|
|
|
void lt_deep_sleep_unset_gpio(uint32_t gpio_index_map) {
|
|
deep_sleep_param.gpio_index_map &= (~gpio_index_map);
|
|
}
|
|
|
|
void lt_deep_sleep_keep_floating_gpio(uint32_t gpio_index_map, bool enabled) {
|
|
if (enabled) {
|
|
deep_sleep_param.gpio_stay_lo_map |= gpio_index_map;
|
|
} else {
|
|
deep_sleep_param.gpio_stay_lo_map &= (~gpio_index_map);
|
|
}
|
|
}
|
|
|
|
void lt_deep_sleep_config_timer(uint32_t sleep_duration_ms) {
|
|
deep_sleep_param.wake_up_way |= PS_DEEP_WAKEUP_RTC;
|
|
uint64_t sleep_ticks = 32.768 * sleep_duration_ms;
|
|
if (sleep_ticks >= 0xFFFFFFFF) {
|
|
deep_sleep_param.sleep_time = 0xFFFFFFFE;
|
|
} else {
|
|
deep_sleep_param.sleep_time = sleep_ticks & 0xFFFFFFFF;
|
|
}
|
|
}
|
|
|
|
void lt_deep_sleep_enter() {
|
|
bk_misc_update_set_type(RESET_SOURCE_DEEPPS_GPIO);
|
|
GLOBAL_INT_DECLARATION();
|
|
GLOBAL_INT_DISABLE();
|
|
sctrl_enter_rtos_deep_sleep_fix((PS_DEEP_CTRL_PARAM *)&deep_sleep_param);
|
|
ps_delay(500);
|
|
GLOBAL_INT_RESTORE();
|
|
}
|