From 7d03a941be6e9226e71cb5f5b4f7949e06bbfb02 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Thu, 9 Dec 2021 23:50:58 +0100 Subject: improved init process --- fw/fe310/bsp/metal/metal.c | 9 --- fw/fe310/eos/Makefile | 2 +- fw/fe310/eos/cell.c | 2 +- fw/fe310/eos/cell.h | 2 +- fw/fe310/eos/eos.c | 35 ++++++------ fw/fe310/eos/eve/eve.c | 1 - fw/fe310/eos/eve/eve_eos.c | 58 ++++++++++++------- fw/fe310/eos/eve/eve_touch.c | 1 - fw/fe310/eos/i2c.c | 11 ++-- fw/fe310/eos/i2c.h | 3 +- fw/fe310/eos/i2c/bq25895.c | 5 +- fw/fe310/eos/i2s.c | 49 ++++++++-------- fw/fe310/eos/i2s.h | 1 + fw/fe310/eos/lcd.c | 10 +++- fw/fe310/eos/net.c | 6 +- fw/fe310/eos/power.c | 131 ------------------------------------------ fw/fe310/eos/power.h | 23 -------- fw/fe310/eos/pwr.c | 133 +++++++++++++++++++++++++++++++++++++++++++ fw/fe310/eos/pwr.h | 25 ++++++++ fw/fe310/eos/sock.c | 2 +- fw/fe310/eos/sock.h | 2 +- fw/fe310/eos/spi.c | 10 +--- fw/fe310/eos/spi_dev.c | 2 - fw/fe310/eos/trap_entry.S | 2 +- fw/fe310/eos/uart.c | 20 +++++++ fw/fe310/eos/uart.h | 6 ++ fw/fe310/eos/wifi.c | 2 +- fw/fe310/eos/wifi.h | 2 +- fw/fe310/test/Makefile | 3 +- fw/fe310/test/cam.c | 4 +- fw/fe310/test/main.c | 20 +++---- fw/fe310/test/test.c | 6 +- 32 files changed, 302 insertions(+), 286 deletions(-) delete mode 100644 fw/fe310/eos/power.c delete mode 100644 fw/fe310/eos/power.h create mode 100644 fw/fe310/eos/pwr.c create mode 100644 fw/fe310/eos/pwr.h (limited to 'fw') diff --git a/fw/fe310/bsp/metal/metal.c b/fw/fe310/bsp/metal/metal.c index 00849b9..9e1bb3f 100644 --- a/fw/fe310/bsp/metal/metal.c +++ b/fw/fe310/bsp/metal/metal.c @@ -6,21 +6,12 @@ extern void eos_trap_entry(); -static void uart_init(size_t baud_rate) { - GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_UART0_MASK; - GPIO_REG(GPIO_IOF_EN) |= IOF0_UART0_MASK; - UART0_REG(UART_REG_DIV) = PRCI_get_cpu_freq() / baud_rate - 1; - UART0_REG(UART_REG_TXCTRL) |= UART_TXEN; - UART0_REG(UART_REG_RXCTRL) |= UART_RXEN; -} - __attribute__((constructor)) void metal_init(void) { SPI0_REG(SPI_REG_SCKDIV) = 8; PRCI_use_default_clocks(); PRCI_use_pll(PLL_REFSEL_HFXOSC, 0, 1, 31, 1, -1, -1, -1); - uart_init(115200); write_csr(mtvec, &eos_trap_entry); if (read_csr(misa) & (1 << ('F' - 'A'))) { // if F extension is present diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile index 899fea3..2bf285f 100644 --- a/fw/fe310/eos/Makefile +++ b/fw/fe310/eos/Makefile @@ -4,7 +4,7 @@ CRYPTO_DIR = ../../../crypto CFLAGS += -I. -I../bsp/include -I../bsp/drivers -I$(CRYPTO_DIR) -obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.o i2s.o i2c.o uart.o spi.o spi_dev.o lcd.o sdcard.o sdc_crypto.o cam.o net.o wifi.o cell.o sock.o unicode.o +obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o pwr.o i2s.o i2c.o uart.o spi.o spi_dev.o lcd.o sdcard.o sdc_crypto.o cam.o net.o wifi.o cell.o sock.o unicode.o %.o: %.c %.h diff --git a/fw/fe310/eos/cell.c b/fw/fe310/eos/cell.c index 2886041..20a9f42 100644 --- a/fw/fe310/eos/cell.c +++ b/fw/fe310/eos/cell.c @@ -28,7 +28,7 @@ static void cell_handle_msg(unsigned char type, unsigned char *buffer, uint16_t } } -void eos_cell_init(void) { +void eos_cell_netinit(void) { int i; for (i=0; i #include -#include "power.h" #include "eve.h" #define EVE_MEM_WRITE 0x800000 diff --git a/fw/fe310/eos/eve/eve_eos.c b/fw/fe310/eos/eve/eve_eos.c index 35c237e..283aa6a 100644 --- a/fw/fe310/eos/eve/eve_eos.c +++ b/fw/fe310/eos/eve/eve_eos.c @@ -5,7 +5,7 @@ #include "eos.h" #include "interrupt.h" #include "event.h" -#include "power.h" +#include "pwr.h" #include "board.h" @@ -38,16 +38,41 @@ static void handle_intr(void) { eos_evtq_push_isr(EOS_EVT_UI | EVE_ETYPE_INTR, NULL, 0); } + +static void _start(void) { + eve_start(); + + GPIO_REG(GPIO_INPUT_EN) |= (1 << EVE_PIN_INTR); + GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << EVE_PIN_INTR); + + GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR); + + eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR); + _run = 1; +} + +static void _stop(void) { + _run = 0; + eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR); + + GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR); + + eve_stop(); +} + int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { int rst = (wakeup_cause == EOS_PWR_WAKE_RST); - int rv; + int rv = EVE_OK; + eve_spi_start(); if (rst) { rv = eve_init(gpio_dir, touch_calibrate, touch_matrix); - if (rv) return EOS_ERR; } else { eve_active(); } + eve_spi_stop(); + + if (rv) return EOS_ERR; eos_evtq_set_handler(EOS_EVT_UI, handle_evt); eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time); @@ -58,31 +83,22 @@ int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, ui } int eos_eve_run(uint8_t wakeup_cause) { - eos_eve_start(); + eve_spi_start(); + _start(); eve_start_clk(); + eve_spi_stop(); return EOS_OK; } void eos_eve_start(void) { - eve_start(); - - GPIO_REG(GPIO_INPUT_EN) |= (1 << EVE_PIN_INTR); - GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << EVE_PIN_INTR); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << EVE_PIN_INTR); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << EVE_PIN_INTR); - - GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR); - - eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR); - _run = 1; + eve_spi_start(); + _start(); + eve_spi_stop(); } void eos_eve_stop(void) { - _run = 0; - eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR); - - GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR); - - eve_stop(); + eve_spi_start(); + _stop(); + eve_spi_stop(); } \ No newline at end of file diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c index 4f8a543..7c06f81 100644 --- a/fw/fe310/eos/eve/eve_touch.c +++ b/fw/fe310/eos/eve/eve_touch.c @@ -2,7 +2,6 @@ #include #include -#include "power.h" #include "eve.h" static int touch_multi; diff --git a/fw/fe310/eos/i2c.c b/fw/fe310/eos/i2c.c index 63dd7e6..a507af1 100644 --- a/fw/fe310/eos/i2c.c +++ b/fw/fe310/eos/i2c.c @@ -10,19 +10,16 @@ #include "i2c.h" int eos_i2c_init(uint8_t wakeup_cause) { - eos_i2c_stop(); eos_i2c_speed(EOS_I2C_SPEED); + // eos_i2c_start(); return EOS_OK; } -int eos_i2c_start(void) { - if (eos_i2s_running()) return EOS_ERR_BUSY; - - GPIO_REG(GPIO_IOF_EN) |= IOF0_I2C0_MASK; +void eos_i2c_start(void) { I2C0_REGB(I2C_CONTROL) |= I2C_CONTROL_EN; - - return EOS_OK; + GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_I2C0_MASK; + GPIO_REG(GPIO_IOF_EN) |= IOF0_I2C0_MASK; } void eos_i2c_stop(void) { diff --git a/fw/fe310/eos/i2c.h b/fw/fe310/eos/i2c.h index b407f8d..20d3dc7 100644 --- a/fw/fe310/eos/i2c.h +++ b/fw/fe310/eos/i2c.h @@ -3,7 +3,8 @@ #define EOS_I2C_SPEED 100000 int eos_i2c_init(uint8_t wakeup_cause); -int eos_i2c_start(void); +int eos_i2c_run(uint8_t wakeup_cause); +void eos_i2c_start(void); void eos_i2c_stop(void); void eos_i2c_speed(uint32_t baud_rate); int eos_i2c_read8(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t len); diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c index f8923c6..570e9a0 100644 --- a/fw/fe310/eos/i2c/bq25895.c +++ b/fw/fe310/eos/i2c/bq25895.c @@ -3,7 +3,7 @@ #include #include "eos.h" -#include "power.h" +#include "pwr.h" #include "i2c.h" #include "i2c/bq25895.h" @@ -20,8 +20,6 @@ int eos_bq25895_init(uint8_t wakeup_cause) { int i, rv = EOS_OK; uint8_t data = 0; - rv = eos_i2c_start(); - if (rv) return rv; if (rst) { rv = reg_write(0x14, 0x80); // reset if (rv) printf("I2C ERROR 0x14\n"); @@ -40,7 +38,6 @@ int eos_bq25895_init(uint8_t wakeup_cause) { rv = reg_read(i, &data); if (!rv) printf("REG%02x: %02x\n", i, data); } - eos_i2c_stop(); return EOS_OK; } diff --git a/fw/fe310/eos/i2s.c b/fw/fe310/eos/i2s.c index 5623add..5e5eaa7 100644 --- a/fw/fe310/eos/i2s.c +++ b/fw/fe310/eos/i2s.c @@ -140,53 +140,48 @@ extern void _eos_i2s_start_pwm(void); int eos_i2s_init(uint8_t wakeup_cause) { eos_evtq_set_handler(EOS_EVT_I2S, i2s_handle_evt); - GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW); - GPIO_REG(GPIO_OUTPUT_VAL) &= ~((1 << I2S_PIN_CK) | (1 << I2S_PIN_CK_SR) | (1 << I2S_PIN_WS_MIC) | (1 << I2S_PIN_WS_SPK)); + eos_i2s_init_mux(); - GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK); - GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK); + GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW); + GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << I2S_PIN_CK_SR); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK_SW); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK_SW); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK_SW); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK_SW); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK_SR); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK_SR); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK_SR); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK_SR); + + return EOS_OK; +} + +void eos_i2s_init_mux(void) { + GPIO_REG(GPIO_OUTPUT_VAL) &= ~((1 << I2S_PIN_CK) | (1 << I2S_PIN_WS_MIC) | (1 << I2S_PIN_WS_SPK)); + + GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK); + GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_WS_MIC); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_WS_MIC); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_WS_MIC); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_MIC); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_WS_SPK); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_WS_SPK); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_WS_SPK); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK); GPIO_REG(GPIO_INPUT_EN) |= (1 << I2S_PIN_SD_IN); GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_IN); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_SD_IN); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_SD_IN); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_SD_OUT); GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_OUT); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_SD_OUT); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_SD_OUT); - - GPIO_REG(GPIO_IOF_EN) &= ~I2S_PIN_PWM; - GPIO_REG(GPIO_IOF_SEL) |= I2S_PIN_PWM; - - return EOS_OK; } void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) { i2s_clk_period = ((PRCI_get_cpu_freq() / (sample_rate * 64)) & ~I2S_PWM_SCALE_CK_MASK) + 1; + GPIO_REG(GPIO_INPUT_EN) |= (1 << I2S_PIN_SD_IN); + GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_IN); + + GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_SD_OUT); + GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_OUT); + I2S_REG_CK(PWM_CMP0) = i2s_clk_period >> I2S_PWM_SCALE_CK; I2S_REG_CK(PWM_CMP1) = I2S_REG_CK(PWM_CMP0) / 2; I2S_REG_CK(PWM_CMP2) = 0; @@ -219,8 +214,9 @@ void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) { I2S_REG_WS_SPK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP1GANG; */ - GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SR); - GPIO_REG(GPIO_IOF_EN) |= I2S_PIN_PWM; + GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SR); + GPIO_REG(GPIO_IOF_SEL) |= I2S_PIN_PWM; + GPIO_REG(GPIO_IOF_EN) |= I2S_PIN_PWM; } void eos_i2s_stop(void) { @@ -238,7 +234,10 @@ void eos_i2s_stop(void) { eos_intr_disable(I2S_IRQ_WS_ID); eos_intr_disable(I2S_IRQ_SD_ID); + GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW); GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << I2S_PIN_CK_SR); + + GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK); GPIO_REG(GPIO_IOF_EN) &= ~I2S_PIN_PWM; } diff --git a/fw/fe310/eos/i2s.h b/fw/fe310/eos/i2s.h index 1cc10e0..f53e183 100644 --- a/fw/fe310/eos/i2s.h +++ b/fw/fe310/eos/i2s.h @@ -12,6 +12,7 @@ typedef struct EOSABuf { typedef void (*eos_i2s_handler_t) (unsigned char); int eos_i2s_init(uint8_t wakeup_cause); +void eos_i2s_init_mux(void); void eos_i2s_start(uint32_t sample_rate, unsigned char fmt); void eos_i2s_stop(void); int eos_i2s_running(void); diff --git a/fw/fe310/eos/lcd.c b/fw/fe310/eos/lcd.c index 86dd1e9..cf09018 100644 --- a/fw/fe310/eos/lcd.c +++ b/fw/fe310/eos/lcd.c @@ -5,7 +5,6 @@ #include "platform.h" #include "eos.h" -#include "power.h" #include "timer.h" #include "i2s.h" #include "net.h" @@ -33,13 +32,18 @@ int eos_lcd_select(void) { if (eos_spi_dev() != EOS_SPI_DEV_NET) return EOS_ERR_BUSY; eos_net_stop(); - GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK; + + GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << LCD_PIN_CS); + + GPIO_REG(GPIO_INPUT_EN) &= ~(1 << LCD_PIN_CS); + GPIO_REG(GPIO_OUTPUT_EN) |= (1 << LCD_PIN_CS); + + GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK; return EOS_OK; } void eos_lcd_deselect(void) { - GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_MOSI); GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK; eos_net_start(); } diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c index 4d9aadf..e65bcd2 100644 --- a/fw/fe310/eos/net.c +++ b/fw/fe310/eos/net.c @@ -9,7 +9,7 @@ #include "interrupt.h" #include "event.h" #include "timer.h" -#include "power.h" +#include "pwr.h" #include "board.h" @@ -332,16 +332,12 @@ int eos_net_init(uint8_t wakeup_cause) { GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_CTS); GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_CTS); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << NET_PIN_CTS); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << NET_PIN_CTS); GPIO_REG(GPIO_RISE_IE) |= (1 << NET_PIN_CTS); eos_intr_set(INT_GPIO_BASE + NET_PIN_CTS, IRQ_PRIORITY_NET_CTS, net_handle_cts); GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_RTS); GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_RTS); - GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << NET_PIN_RTS); - GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << NET_PIN_RTS); GPIO_REG(GPIO_RISE_IE) |= (1 << NET_PIN_RTS); GPIO_REG(GPIO_FALL_IE) |= (1 << NET_PIN_RTS); diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/power.c deleted file mode 100644 index 0d6ab0c..0000000 --- a/fw/fe310/eos/power.c +++ /dev/null @@ -1,131 +0,0 @@ -#include -#include - -#include "encoding.h" -#include "platform.h" - -#include "eos.h" -#include "event.h" -#include "timer.h" -#include "spi.h" -#include "spi_dev.h" -#include "net.h" -#include "lcd.h" -#include "eve/eve.h" - -#include "power.h" - -#define PWR_RTC_SCALE 15 -#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_msg(unsigned char type, unsigned char *buffer, uint16_t len) { - unsigned char mtype; - - if ((buffer == NULL) || (len < 1)) { - eos_net_bad_handler(type, buffer, len); - return; - } - - mtype = buffer[0]; - if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) { - evt_handler[mtype](mtype, buffer, len); - } else { - eos_net_bad_handler(type, buffer, len); - } -} - -static void power_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) { - 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(); -} - -int eos_power_init(uint8_t wakeup_cause) { - int i; - - for (i=0; i> 8) & 0xff; -} - -int eos_power_sleep(void) { - int rv; - - rv = eos_lcd_sleep(); - if (rv) return rv; - - eos_spi_select(EOS_SPI_DEV_EVE); - eve_sleep(); - eos_spi_deselect(); - - rv = eos_net_sleep(1000); - if (rv) return rv; - - AON_REG(AON_PMUKEY) = 0x51F15E; - AON_REG(AON_PMUSLEEP) = 1; - - return EOS_OK; -} - -void eos_power_wake_at(uint32_t msec) { - uint32_t pmuie; - - AON_REG(AON_RTCCFG) |= AON_RTCCFG_ENALWAYS; - AON_REG(AON_RTCCMP) = msec * PWR_RTC_SFREQ / 1000; - - pmuie = AON_REG(AON_PMUIE) | 0x2; - AON_REG(AON_PMUKEY) = 0x51F15E; - AON_REG(AON_PMUIE) = pmuie; -} - -void eos_power_wake_disable(void) { - uint32_t pmuie; - - AON_REG(AON_RTCCMP) = 0xFFFFFFFF; - AON_REG(AON_RTCCFG) &= ~AON_RTCCFG_ENALWAYS; - AON_REG(AON_RTCHI) = 0; - AON_REG(AON_RTCLO) = 0; - - pmuie = AON_REG(AON_PMUIE) & ~0x2; - AON_REG(AON_PMUKEY) = 0x51F15E; - AON_REG(AON_PMUIE) = pmuie; -} - -void eos_power_set_handler(unsigned char mtype, eos_evt_handler_t handler) { - if (mtype < EOS_PWR_MAX_MTYPE) evt_handler[mtype] = handler; -} - -eos_evt_handler_t eos_power_get_handler(unsigned char mtype) { - if (mtype < EOS_PWR_MAX_MTYPE) return evt_handler[mtype]; - return NULL; -} diff --git a/fw/fe310/eos/power.h b/fw/fe310/eos/power.h deleted file mode 100644 index 76b57a8..0000000 --- a/fw/fe310/eos/power.h +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "event.h" - -#define EOS_PWR_MTYPE_BUTTON 1 - -#define EOS_PWR_MAX_MTYPE 2 - -#define EOS_PWR_WAKE_RST 0 -#define EOS_PWR_WAKE_RTC 1 -#define EOS_PWR_WAKE_BTN 2 - -#define EOS_PWR_RST_PWRON 0 -#define EOS_PWR_RST_EXT 1 -#define EOS_PWR_RST_WDOG 2 - -int eos_power_init(uint8_t wakeup_cause); -uint8_t eos_power_wakeup_cause(void); -uint8_t eos_power_reset_cause(void); -int eos_power_sleep(void); -void eos_power_wake_at(uint32_t msec); -void eos_power_wake_disable(void); -void eos_power_set_handler(unsigned char mtype, eos_evt_handler_t handler); -eos_evt_handler_t eos_power_get_handler(unsigned char mtype); \ No newline at end of file diff --git a/fw/fe310/eos/pwr.c b/fw/fe310/eos/pwr.c new file mode 100644 index 0000000..f42249d --- /dev/null +++ b/fw/fe310/eos/pwr.c @@ -0,0 +1,133 @@ +#include +#include + +#include "encoding.h" +#include "platform.h" + +#include "eos.h" +#include "event.h" +#include "timer.h" +#include "spi.h" +#include "spi_dev.h" +#include "net.h" +#include "lcd.h" +#include "eve/eve.h" + +#include "pwr.h" + +#define PWR_RTC_SCALE 15 +#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; + +int eos_pwr_init(uint8_t wakeup_cause) { + AON_REG(AON_PMUKEY) = 0x51F15E; + AON_REG(AON_PMUIE) = 0x5; + + AON_REG(AON_RTCCMP) = 0xFFFFFFFF; + AON_REG(AON_RTCCFG) = PWR_RTC_SCALE; + AON_REG(AON_RTCHI) = 0; + AON_REG(AON_RTCLO) = 0; + + return EOS_OK; +} + +uint8_t eos_pwr_wakeup_cause(void) { + return AON_REG(AON_PMUCAUSE) & 0xff; +} + +uint8_t eos_pwr_reset_cause(void) { + return (AON_REG(AON_PMUCAUSE) >> 8) & 0xff; +} + +int eos_pwr_sleep(void) { + int rv; + + rv = eos_lcd_sleep(); + if (rv) return rv; + + eos_spi_select(EOS_SPI_DEV_EVE); + eve_sleep(); + eos_spi_deselect(); + + rv = eos_net_sleep(1000); + if (rv) return rv; + + AON_REG(AON_PMUKEY) = 0x51F15E; + AON_REG(AON_PMUSLEEP) = 1; + + return EOS_OK; +} + +void eos_pwr_wake_at(uint32_t msec) { + uint32_t pmuie; + + AON_REG(AON_RTCCFG) |= AON_RTCCFG_ENALWAYS; + AON_REG(AON_RTCCMP) = msec * PWR_RTC_SFREQ / 1000; + + pmuie = AON_REG(AON_PMUIE) | 0x2; + AON_REG(AON_PMUKEY) = 0x51F15E; + AON_REG(AON_PMUIE) = pmuie; +} + +void eos_pwr_wake_disable(void) { + uint32_t pmuie; + + AON_REG(AON_RTCCMP) = 0xFFFFFFFF; + AON_REG(AON_RTCCFG) &= ~AON_RTCCFG_ENALWAYS; + AON_REG(AON_RTCHI) = 0; + AON_REG(AON_RTCLO) = 0; + + pmuie = AON_REG(AON_PMUIE) & ~0x2; + AON_REG(AON_PMUKEY) = 0x51F15E; + AON_REG(AON_PMUIE) = pmuie; +} + +static void pwr_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) { + unsigned char mtype; + + if ((buffer == NULL) || (len < 1)) { + eos_net_bad_handler(type, buffer, len); + return; + } + + mtype = buffer[0]; + if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) { + evt_handler[mtype](mtype, buffer, len); + } else { + eos_net_bad_handler(type, buffer, len); + } +} + +static void pwr_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) { + unsigned char level = buffer[1]; + + eos_net_free(buffer, 0); + if (!level) { + power_btn_down = 1; + return; + } + if (!power_btn_down) return; + + eos_pwr_sleep(); +} + +void eos_pwr_netinit(void) { + int i; + + for (i=0; i +#include "event.h" + +#define EOS_PWR_MTYPE_BUTTON 1 + +#define EOS_PWR_MAX_MTYPE 2 + +#define EOS_PWR_WAKE_RST 0 +#define EOS_PWR_WAKE_RTC 1 +#define EOS_PWR_WAKE_BTN 2 + +#define EOS_PWR_RST_PWRON 0 +#define EOS_PWR_RST_EXT 1 +#define EOS_PWR_RST_WDOG 2 + +int eos_pwr_init(uint8_t wakeup_cause); +uint8_t eos_pwr_wakeup_cause(void); +uint8_t eos_pwr_reset_cause(void); +int eos_pwr_sleep(void); +void eos_pwr_wake_at(uint32_t msec); +void eos_pwr_wake_disable(void); + +void eos_pwr_netinit(void); +void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler); +eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype); \ No newline at end of file diff --git a/fw/fe310/eos/sock.c b/fw/fe310/eos/sock.c index a2e30e3..ef043d1 100644 --- a/fw/fe310/eos/sock.c +++ b/fw/fe310/eos/sock.c @@ -34,7 +34,7 @@ static void sock_handle_msg(unsigned char type, unsigned char *buffer, uint16_t } } -void eos_sock_init(void) { +void eos_sock_netinit(void) { int i; for (i=0; i #include -#include +#include #include #include @@ -28,7 +28,8 @@ #include "modem.h" #include "wifi.h" #include "cam.h" -#include "fs.h" +// #include "fs.h" +#include "audio.h" #include "test.h" void app_home_page(EVEWindow *window, EVEViewStack *stack) { @@ -63,12 +64,14 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) { .widget.spec.page.title = "Camera", .widget.spec.page.constructor = app_cam }, + /* { .widget.type = EVE_WIDGET_TYPE_PAGE, .widget.g.w = APP_SCREEN_W, .widget.spec.page.title = "File system", .widget.spec.page.constructor = app_fs }, + */ { .widget.type = EVE_WIDGET_TYPE_PAGE, .widget.g.w = APP_SCREEN_W, @@ -77,17 +80,13 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) { }, }; - EVEForm *form = eve_form_create(window, stack, spec, 7, NULL, NULL, NULL); + EVEForm *form = eve_form_create(window, stack, spec, 6, NULL, NULL, NULL); } int main() { - uint8_t wakeup_cause = eos_power_wakeup_cause(); - int rst = (wakeup_cause == EOS_PWR_WAKE_RST); - - printf("\nREADY.\n"); - printf("FREQ:%lu\n", PRCI_get_cpu_freq()); - eos_init(); + printf("FREQ:%lu\n", PRCI_get_cpu_freq()); + printf("\nREADY.\n"); app_root_init(app_home_page, 0x20); app_status_init(); @@ -95,6 +94,7 @@ int main() { app_wifi_init(); app_cell_dev_init(); app_cell_pdp_init(); - app_fs_init(); + // app_fs_init(); + audio_start(); eos_evtq_loop(); } diff --git a/fw/fe310/test/test.c b/fw/fe310/test/test.c index 87c1e2b..9cf7605 100644 --- a/fw/fe310/test/test.c +++ b/fw/fe310/test/test.c @@ -40,11 +40,7 @@ int app_test_uievt(EVEForm *form, uint16_t evt, void *param) { case EVE_UIEVT_PAGE_TOUCH: printf("PAGE TOUCH\n"); printf("BQ25895:\n"); - rv = eos_i2c_start(); - if (rv) { - printf("I2C BUSY\n"); - return 0; - } + eos_i2c_start(); for (i=0; i<0x15; i++) { rv = reg_read(i, &data); if (!rv) printf("REG%02x: %02x\n", i, data); -- cgit v1.2.3