summaryrefslogtreecommitdiff
path: root/code/fe310/eos
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-05-23 23:59:04 +0200
committerUros Majstorovic <majstor@majstor.org>2020-05-23 23:59:04 +0200
commit8cab5fea518d4bf6c680816f8ba8b7b7d9ee7401 (patch)
treefaa5c53a57aaf22e53892e22d29f013f79994c5c /code/fe310/eos
parent34da9599242ed7784c42f548e2d188d3d577c866 (diff)
eve power amanger fix
Diffstat (limited to 'code/fe310/eos')
-rw-r--r--code/fe310/eos/eos.c11
-rw-r--r--code/fe310/eos/eve/eve.c36
-rw-r--r--code/fe310/eos/eve/eve.h10
-rw-r--r--code/fe310/eos/power.c4
-rw-r--r--code/fe310/eos/power.h6
5 files changed, 39 insertions, 28 deletions
diff --git a/code/fe310/eos/eos.c b/code/fe310/eos/eos.c
index 1aae201..b02abed 100644
--- a/code/fe310/eos/eos.c
+++ b/code/fe310/eos/eos.c
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
#include "event.h"
#include "interrupt.h"
#include "timer.h"
@@ -13,10 +15,11 @@
#include "eos.h"
-uint32_t eve_touch[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0};
+static uint32_t eve_touch[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0};
void eos_init(void) {
- uint8_t wake_src = eos_power_cause_wake();
+ uint8_t wakeup_cause = eos_power_wakeup_cause();
+ printf("WAKE:%d\n", wakeup_cause);
eos_evtq_init();
eos_intr_init();
@@ -31,10 +34,10 @@ void eos_init(void) {
eos_sock_init();
eos_spi_dev_init();
- eos_net_wake(wake_src);
+ eos_net_wake(wakeup_cause);
eve_set_touch_calibration(eve_touch);
eos_spi_dev_start(EOS_DEV_DISP);
- eve_init(wake_src == EOS_PWR_WAKE_RESET);
+ eve_init(wakeup_cause == EOS_PWR_WAKE_RST);
eos_spi_dev_stop();
}
diff --git a/code/fe310/eos/eve/eve.c b/code/fe310/eos/eve/eve.c
index 430b998..8d8a15a 100644
--- a/code/fe310/eos/eve/eve.c
+++ b/code/fe310/eos/eve/eve.c
@@ -11,7 +11,7 @@ static uint16_t _cmd_offset;
static uint32_t _dl_addr;
static uint32_t *_touch_calib;
static uint8_t _brigtness;
-static char _sleep;
+static uint8_t _power_state;
void eve_command(uint8_t command, uint8_t parameter) {
eve_spi_cs_set();
@@ -235,18 +235,31 @@ void eve_cmd_burst_end(void) {
_cmd_burst = 0;
}
-void eve_active(void){
+void eve_active(void) {
eve_command(EVE_ACTIVE, 0);
+ if (_power_state == EVE_PSTATE_SLEEP) eve_time_sleep(40);
+
+ eve_write8(REG_PWM_DUTY, _brigtness);
+ if (_power_state != EVE_PSTATE_SLEEP) return;
+
+ eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS);
+ eve_write8(REG_CTOUCH_EXTENDED, 0x00);
+
+ _power_state = EVE_PSTATE_ACTIVE;
}
void eve_standby(void) {
+ if (_power_state != EVE_PSTATE_ACTIVE) return;
+
+ _brigtness = eve_read8(REG_PWM_DUTY);
eve_command(EVE_STANDBY, 0);
+
+ _power_state = EVE_PSTATE_STANDBY;
}
void eve_sleep(void) {
- if (_sleep) return;
+ if (_power_state != EVE_PSTATE_ACTIVE) return;
- _sleep = 1;
_brigtness = eve_read8(REG_PWM_DUTY);
eve_write8(REG_PWM_DUTY, 0x0);
@@ -255,17 +268,8 @@ void eve_sleep(void) {
eve_time_sleep(500);
eve_command(EVE_SLEEP, 0);
-}
-
-void eve_wake(void) {
- eve_command(EVE_ACTIVE, 0); /* start EVE */
- eve_time_sleep(40);
- eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS);
- eve_write8(REG_CTOUCH_EXTENDED, 0x00);
-
- eve_write8(REG_PWM_DUTY, _brigtness);
- _sleep = 0;
+ _power_state = EVE_PSTATE_SLEEP;
}
void eve_brightness(uint8_t b) {
@@ -373,8 +377,8 @@ int eve_init(int pwr_on) {
int rv = _init();
if (rv) return rv;
} else {
- _sleep = 1;
- eve_wake();
+ _power_state = EVE_PSTATE_SLEEP;
+ eve_active();
}
eve_init_touch();
diff --git a/code/fe310/eos/eve/eve.h b/code/fe310/eos/eve/eve.h
index 2fb2fb5..2ac93a2 100644
--- a/code/fe310/eos/eve/eve.h
+++ b/code/fe310/eos/eve/eve.h
@@ -5,9 +5,13 @@
#include "eve_track.h"
#include "eve_platform.h"
-#define EVE_OK 0
-#define EVE_ERR -1
-#define EVE_ERR_TEXT -100
+#define EVE_OK 0
+#define EVE_ERR -1
+#define EVE_ERR_TEXT -100
+
+#define EVE_PSTATE_ACTIVE 0
+#define EVE_PSTATE_STANDBY 1
+#define EVE_PSTATE_SLEEP 3
void eve_command(uint8_t command, uint8_t parameter);
diff --git a/code/fe310/eos/power.c b/code/fe310/eos/power.c
index 3cc3462..5c874e0 100644
--- a/code/fe310/eos/power.c
+++ b/code/fe310/eos/power.c
@@ -63,11 +63,11 @@ void eos_power_init(void) {
AON_REG(AON_RTCLO) = 0;
}
-uint8_t eos_power_cause_wake(void) {
+uint8_t eos_power_wakeup_cause(void) {
return AON_REG(AON_PMUCAUSE) & 0xff;
}
-uint8_t eos_power_cause_rst(void) {
+uint8_t eos_power_reset_cause(void) {
return (AON_REG(AON_PMUCAUSE) >> 8) & 0xff;
}
diff --git a/code/fe310/eos/power.h b/code/fe310/eos/power.h
index 7f579a5..466573f 100644
--- a/code/fe310/eos/power.h
+++ b/code/fe310/eos/power.h
@@ -5,7 +5,7 @@
#define EOS_PWR_MAX_MTYPE 2
-#define EOS_PWR_WAKE_RESET 0
+#define EOS_PWR_WAKE_RST 0
#define EOS_PWR_WAKE_RTC 1
#define EOS_PWR_WAKE_BTN 2
@@ -14,8 +14,8 @@
#define EOS_PWR_RST_WDOG 2
void eos_power_init(void);
-uint8_t eos_power_cause_wake(void);
-uint8_t eos_power_cause_rst(void);
+uint8_t eos_power_wakeup_cause(void);
+uint8_t eos_power_reset_cause(void);
void eos_power_sleep(void);
void eos_power_wake_at(uint32_t msec);
void eos_power_wake_disable(void);