diff options
Diffstat (limited to 'fw/fe310')
-rw-r--r-- | fw/fe310/eos/eos.c | 4 | ||||
-rw-r--r-- | fw/fe310/eos/eve/eve.c | 35 | ||||
-rw-r--r-- | fw/fe310/eos/eve/eve.h | 7 |
3 files changed, 41 insertions, 5 deletions
diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c index 87b414b..0909958 100644 --- a/fw/fe310/eos/eos.c +++ b/fw/fe310/eos/eos.c @@ -16,6 +16,8 @@ #include "i2c/bq25895.h" #include "eve/eve.h" +#include "board.h" + #include "eos.h" static uint32_t eve_touch[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0}; @@ -42,5 +44,5 @@ void eos_init(void) { eos_net_wake(wakeup_cause); eve_set_touch_calibration(eve_touch); - eve_init(wakeup_cause == EOS_PWR_WAKE_RST); + eve_init(wakeup_cause == EOS_PWR_WAKE_RST, EVE_GPIO_DIR); } diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c index 3b56e11..fb5aa28 100644 --- a/fw/fe310/eos/eve/eve.c +++ b/fw/fe310/eos/eve/eve.c @@ -281,6 +281,34 @@ void eve_cmd_burst_end(void) { cmd_burst = 0; } +int eve_gpio_get(int gpio) { + uint16_t reg = eve_read16(REG_GPIOX); + return !!(reg & (1 << gpio)); +} + +void eve_gpio_set(int gpio, int val) { + uint16_t reg = eve_read16(REG_GPIOX); + uint16_t reg_val = (1 << gpio); + if (val) { + reg |= reg_val; + } else { + reg &= ~reg_val; + } + eve_write16(REG_GPIOX, reg); +} + +uint8_t eve_gpio_get_dir(void) { + uint16_t reg = eve_read16(REG_GPIOX_DIR); + return reg & 0x000f; +} + +void eve_gpio_set_dir(uint8_t dir) { + uint16_t reg = eve_read16(REG_GPIOX_DIR); + reg &= 0xfff0; + reg |= dir & 0x0f; + eve_write16(REG_GPIOX_DIR, reg); +} + void eve_active(void) { eve_command(EVE_ACTIVE, 0); if (power_state == EVE_PSTATE_SLEEP) eve_time_sleep(40); @@ -326,7 +354,7 @@ void eve_set_touch_calibration(uint32_t *matrix) { touch_calib = matrix; } -static int _init(void) { +static int _init(uint8_t gpio_dir) { uint8_t chipid = 0; uint16_t timeout = 0; @@ -342,6 +370,7 @@ static int _init(void) { } eve_write8(REG_PWM_DUTY, 0); + eve_write16(REG_GPIOX_DIR, 0x8000 | (gpio_dir & 0x0f)); eve_write16(REG_GPIOX, 0); /* Initialize Display */ @@ -418,13 +447,13 @@ static int _init(void) { return EVE_OK; } -int eve_init(int pwr_on) { +int eve_init(int pwr_on, uint8_t gpio_dir) { eve_spi_start(); pwr_on = 1; // override this for now if (pwr_on) { - int rv = _init(); + int rv = _init(gpio_dir); if (rv) return rv; } else { power_state = EVE_PSTATE_SLEEP; diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h index e85ed76..b2c1141 100644 --- a/fw/fe310/eos/eve/eve.h +++ b/fw/fe310/eos/eve/eve.h @@ -54,6 +54,11 @@ int eve_cmd_exec(int w); void eve_cmd_burst_start(void); void eve_cmd_burst_end(void); +int eve_gpio_get(int gpio); +void eve_gpio_set(int gpio, int val); +uint8_t eve_gpio_get_dir(void); +void eve_gpio_set_dir(uint8_t dir); + void eve_active(void); void eve_standby(void); void eve_sleep(void); @@ -61,4 +66,4 @@ void eve_wake(void); void eve_brightness(uint8_t b); void eve_set_touch_calibration(uint32_t *matrix); -int eve_init(int pwr_on); +int eve_init(int pwr_on, uint8_t gpio_dir); |