summaryrefslogtreecommitdiff
path: root/code/fe310
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-05-17 04:48:51 +0200
committerUros Majstorovic <majstor@majstor.org>2020-05-17 04:48:51 +0200
commit51453315e18632c00e4a43407ec63a4b69b17e80 (patch)
tree6d9fceebd172a9c3d02d8806e5a749223fdbfdca /code/fe310
parentd4ceadf1afc2b3c8120d65ea1f03203df5714d7a (diff)
power management fix
Diffstat (limited to 'code/fe310')
-rw-r--r--code/fe310/eos/eos.c6
-rw-r--r--code/fe310/eos/eve/eve.c9
-rw-r--r--code/fe310/eos/eve/eve_track.c1
-rw-r--r--code/fe310/eos/power.c16
4 files changed, 22 insertions, 10 deletions
diff --git a/code/fe310/eos/eos.c b/code/fe310/eos/eos.c
index 292e3c6..1aae201 100644
--- a/code/fe310/eos/eos.c
+++ b/code/fe310/eos/eos.c
@@ -15,11 +15,8 @@
uint32_t eve_touch[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0};
-#include <stdio.h>
-
void eos_init(void) {
uint8_t wake_src = eos_power_cause_wake();
- printf("WAKE SRC:%d\n", wake_src);
eos_evtq_init();
eos_intr_init();
@@ -34,8 +31,7 @@ void eos_init(void) {
eos_sock_init();
eos_spi_dev_init();
- int rv = eos_net_wake(wake_src);
- printf("NET WAKE:%d\n", wake_src);
+ eos_net_wake(wake_src);
eve_set_touch_calibration(eve_touch);
eos_spi_dev_start(EOS_DEV_DISP);
diff --git a/code/fe310/eos/eve/eve.c b/code/fe310/eos/eve/eve.c
index 47b07c9..430b998 100644
--- a/code/fe310/eos/eve/eve.c
+++ b/code/fe310/eos/eve/eve.c
@@ -11,6 +11,7 @@ static uint16_t _cmd_offset;
static uint32_t _dl_addr;
static uint32_t *_touch_calib;
static uint8_t _brigtness;
+static char _sleep;
void eve_command(uint8_t command, uint8_t parameter) {
eve_spi_cs_set();
@@ -243,6 +244,9 @@ void eve_standby(void) {
}
void eve_sleep(void) {
+ if (_sleep) return;
+
+ _sleep = 1;
_brigtness = eve_read8(REG_PWM_DUTY);
eve_write8(REG_PWM_DUTY, 0x0);
@@ -261,6 +265,7 @@ void eve_wake(void) {
eve_write8(REG_CTOUCH_EXTENDED, 0x00);
eve_write8(REG_PWM_DUTY, _brigtness);
+ _sleep = 0;
}
void eve_brightness(uint8_t b) {
@@ -368,6 +373,7 @@ int eve_init(int pwr_on) {
int rv = _init();
if (rv) return rv;
} else {
+ _sleep = 1;
eve_wake();
}
@@ -375,8 +381,5 @@ int eve_init(int pwr_on) {
eve_init_track();
eve_init_platform();
- eve_time_sleep(500);
- eve_command(EVE_STANDBY, 0);
-
return EVE_OK;
}
diff --git a/code/fe310/eos/eve/eve_track.c b/code/fe310/eos/eve/eve_track.c
index 9f0fec8..dccedad 100644
--- a/code/fe310/eos/eve/eve_track.c
+++ b/code/fe310/eos/eve/eve_track.c
@@ -1,6 +1,5 @@
#include <stdlib.h>
#include <math.h>
-#include <stdio.h>
#include "eve.h"
#include "eve_platform.h"
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;
}