From 51453315e18632c00e4a43407ec63a4b69b17e80 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 17 May 2020 04:48:51 +0200 Subject: power management fix --- code/fe310/eos/power.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'code/fe310/eos/power.c') diff --git a/code/fe310/eos/power.c b/code/fe310/eos/power.c index 9a96689..3cc3462 100644 --- a/code/fe310/eos/power.c +++ b/code/fe310/eos/power.c @@ -16,6 +16,7 @@ #define PWR_RTC_SFREQ (EOS_TIMER_RTC_FREQ >> PWR_RTC_SCALE) static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE]; +static unsigned char power_btn_down; static void power_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { if ((buffer == NULL) || (len < 1)) { @@ -32,8 +33,16 @@ static void power_handle_evt(unsigned char type, unsigned char *buffer, uint16_t } static void power_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) { - // Do nothing + unsigned char level = buffer[1]; + eos_net_free(buffer, 0); + if (!level) { + power_btn_down = 1; + return; + } + if (!power_btn_down) return; + + eos_power_sleep(); } void eos_power_init(void) { @@ -63,6 +72,11 @@ uint8_t eos_power_cause_rst(void) { } void eos_power_sleep(void) { + eos_spi_dev_start(EOS_DEV_DISP); + eve_sleep(); + eos_spi_dev_stop(); + eos_net_sleep(1000); + AON_REG(AON_PMUKEY) = 0x51F15E; AON_REG(AON_PMUSLEEP) = 1; } -- cgit v1.2.3