From acce7d8e05ac38776d6340342f6a7868df4f7f28 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 28 Nov 2021 23:53:05 +0100 Subject: lcd driver added; fixed startup code; --- fw/fe310/eos/Makefile | 2 +- fw/fe310/eos/board.h | 4 +- fw/fe310/eos/display.c | 71 ------ fw/fe310/eos/display.h | 8 - fw/fe310/eos/eos.c | 63 +++-- fw/fe310/eos/eve/eve.c | 209 ++++++++-------- fw/fe310/eos/eve/eve.h | 9 +- fw/fe310/eos/eve/eve_config.h | 63 ++--- fw/fe310/eos/eve/eve_def.h | 2 +- fw/fe310/eos/eve/eve_platform.h | 5 + fw/fe310/eos/eve/eve_touch.c | 30 +-- fw/fe310/eos/eve/eve_touch.h | 5 +- fw/fe310/eos/event.c | 5 +- fw/fe310/eos/event.h | 2 +- fw/fe310/eos/i2c.c | 4 +- fw/fe310/eos/i2c.h | 2 +- fw/fe310/eos/i2c/bq25895.c | 11 +- fw/fe310/eos/i2c/bq25895.h | 2 +- fw/fe310/eos/i2s.c | 4 +- fw/fe310/eos/i2s.h | 2 +- fw/fe310/eos/interrupt.c | 5 +- fw/fe310/eos/interrupt.h | 2 +- fw/fe310/eos/lcd.c | 518 ++++++++++++++++++++++++++++++++++++++++ fw/fe310/eos/lcd.h | 12 + fw/fe310/eos/net.c | 8 +- fw/fe310/eos/net.h | 2 +- fw/fe310/eos/power.c | 18 +- fw/fe310/eos/power.h | 9 +- fw/fe310/eos/sdcard.c | 4 +- fw/fe310/eos/sdcard.h | 2 +- fw/fe310/eos/spi.c | 3 +- fw/fe310/eos/spi.h | 2 +- fw/fe310/eos/spi_dev.c | 4 +- fw/fe310/eos/spi_dev.h | 2 +- fw/fe310/eos/timer.c | 5 +- fw/fe310/eos/timer.h | 2 +- fw/fe310/eos/uart.c | 4 +- fw/fe310/eos/uart.h | 2 +- 38 files changed, 820 insertions(+), 287 deletions(-) delete mode 100644 fw/fe310/eos/display.c delete mode 100644 fw/fe310/eos/display.h create mode 100644 fw/fe310/eos/lcd.c create mode 100644 fw/fe310/eos/lcd.h (limited to 'fw/fe310/eos') diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile index ebba204..899fea3 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 display.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 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 %.o: %.c %.h diff --git a/fw/fe310/eos/board.h b/fw/fe310/eos/board.h index 79465b0..62111a9 100644 --- a/fw/fe310/eos/board.h +++ b/fw/fe310/eos/board.h @@ -18,7 +18,7 @@ #define NET_PIN_RTS 20 #define NET_PIN_CTS 22 -#define DISP_PIN_CS 11 +#define LCD_PIN_CS 11 #define EVE_PIN_INTR 23 @@ -42,6 +42,6 @@ #define EVE_GPIO_DIR 0xf #define EVE_GPIO_CAM 0 -#define EVE_GPIO_DISP_EN 1 +#define EVE_GPIO_LCD_EN 1 #define EVE_GPIO_GAIN_SEL 2 #define EVE_GPIO_HAPT 3 diff --git a/fw/fe310/eos/display.c b/fw/fe310/eos/display.c deleted file mode 100644 index bc181cb..0000000 --- a/fw/fe310/eos/display.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include - -#include "encoding.h" -#include "platform.h" - -#include "eos.h" - -#include "board.h" - -#include "i2s.h" -#include "net.h" -#include "spi_dev.h" -#include "display.h" - -#define BIT_PUT(b, pin) if (b) GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << (pin)); else GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << (pin)); -#define BIT_GET(pin) ((GPIO_REG(GPIO_INPUT_VAL) & (1 << (pin))) >> (pin)) - -int eos_disp_select(void) { - if (eos_i2s_running()) return EOS_ERR_BUSY; - if (eos_spi_dev() != EOS_SPI_DEV_NET) return EOS_ERR_BUSY; - - eos_net_stop(); - GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK; -} - -void eos_disp_deselect(void) { - GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_MOSI); - GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK; - eos_net_start(0); -} - -void eos_disp_cs_set(void) { - GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << DISP_PIN_CS); -} - -void eos_disp_cs_clear(void) { - GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << DISP_PIN_CS); -} - -void eos_disp_write(uint8_t dc, uint8_t data) { - int i; - - BIT_PUT(dc, IOF_SPI1_MOSI); - // sleep - BIT_PUT(1, IOF_SPI1_SCK); - for (i=0; i<8; i++) { - // sleep - BIT_PUT(0, IOF_SPI1_SCK); - BIT_PUT(data & 0x80, IOF_SPI1_MOSI); - // sleep - BIT_PUT(1, IOF_SPI1_SCK); - data = data << 1; - } - // sleep - BIT_PUT(0, IOF_SPI1_SCK); -} - -void eos_disp_read(uint8_t *data) { - int i; - - *data = 0; - for (i=0; i<8; i++) { - // sleep - BIT_PUT(1, IOF_SPI1_SCK); - *data = *data << 1; - *data |= BIT_GET(IOF_SPI1_MISO); - // sleep - BIT_PUT(0, IOF_SPI1_SCK); - } -} diff --git a/fw/fe310/eos/display.h b/fw/fe310/eos/display.h deleted file mode 100644 index 61effca..0000000 --- a/fw/fe310/eos/display.h +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int eos_disp_select(void); -void eos_disp_deselect(void); -void eos_disp_cs_set(void); -void eos_disp_cs_clear(void); -void eos_disp_write(uint8_t dc, uint8_t data); -void eos_disp_read(uint8_t *data); \ No newline at end of file diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c index 96fc298..0b6228b 100644 --- a/fw/fe310/eos/eos.c +++ b/fw/fe310/eos/eos.c @@ -9,6 +9,7 @@ #include "uart.h" #include "spi.h" #include "spi_dev.h" +#include "lcd.h" #include "sdcard.h" #include "net.h" #include "wifi.h" @@ -22,28 +23,46 @@ #include "eos.h" void eos_init(void) { - uint8_t wakeup_cause = eos_power_wakeup_cause(); + uint8_t wakeup_cause = eos_power_wakeup_cause() | EOS_PWR_INIT; uint32_t touch_matrix[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0}; int touch_calibrate = 0; - int rst = (wakeup_cause == EOS_PWR_WAKE_RST); - - printf("WAKE:%d\n", wakeup_cause); - - eos_evtq_init(wakeup_cause); - eos_intr_init(wakeup_cause); - eos_timer_init(wakeup_cause); - eos_i2s_init(wakeup_cause); - eos_i2c_init(wakeup_cause); - eos_uart_init(wakeup_cause); - eos_spi_init(wakeup_cause); - eos_spi_dev_init(wakeup_cause); - eos_sdc_init(wakeup_cause); - eos_net_init(wakeup_cause); - eos_power_init(wakeup_cause); - eos_bq25895_init(wakeup_cause); - int rv = eve_init(wakeup_cause, touch_calibrate, touch_matrix, EVE_GPIO_DIR); - - printf("EVE INIT: %d\n", rv); + int rv; + + printf("INIT:%d\n", wakeup_cause & ~EOS_PWR_INIT); + + rv = eos_evtq_init(wakeup_cause); + if (rv) printf("EVTQ INIT ERR:%d\n", rv); + rv = eos_intr_init(wakeup_cause); + if (rv) printf("INTR INIT ERR:%d\n", rv); + rv = eos_timer_init(wakeup_cause); + if (rv) printf("TIMER INIT ERR:%d\n", rv); + rv = eos_i2s_init(wakeup_cause); + if (rv) printf("I2S INIT ERR:%d\n", rv); + rv = eos_i2c_init(wakeup_cause); + if (rv) printf("I2C INIT ERR:%d\n", rv); + rv = eos_uart_init(wakeup_cause); + if (rv) printf("UART INIT ERR:%d\n", rv); + rv = eos_spi_init(wakeup_cause); + if (rv) printf("SPI INIT ERR:%d\n", rv); + rv = eos_spi_dev_init(wakeup_cause); + if (rv) printf("SPI DEV INIT ERR:%d\n", rv); + rv = eos_sdc_init(wakeup_cause); + if (rv) printf("SDC INIT ERR:%d\n", rv); + rv = eos_net_init(wakeup_cause); + if (rv) printf("NET INIT ERR:%d\n", rv); + rv = eos_power_init(wakeup_cause); + if (rv) printf("POWER INIT ERR:%d\n", rv); + rv = eos_bq25895_init(wakeup_cause); + if (rv) printf("BQ25895 INIT ERR:%d\n", rv); + + eos_spi_select(EOS_SPI_DEV_EVE); + rv = eve_init(wakeup_cause, touch_calibrate, touch_matrix, EVE_GPIO_DIR); + eos_spi_deselect(); + if (rv) printf("EVE INIT ERR:%d\n", rv); + + rv = eos_lcd_init(wakeup_cause); + if (rv) printf("LCD INIT ERR:%d\n", rv); + if (touch_calibrate) { printf("TOUCH MATRIX:\n"); printf("uint32_t touch_matrix[6] = {0x%x,0x%x,0x%x,0x%x,0x%x,0x%x}\n", touch_matrix[0], touch_matrix[1], touch_matrix[2], touch_matrix[3], touch_matrix[4], touch_matrix[5]); @@ -52,6 +71,10 @@ void eos_init(void) { } void eos_start(uint8_t wakeup_cause) { + eos_spi_select(EOS_SPI_DEV_EVE); + eve_start(wakeup_cause); + eos_spi_deselect(); + eos_wifi_init(); eos_cell_init(); eos_sock_init(); diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c index 3447d6b..8cca34b 100644 --- a/fw/fe310/eos/eve/eve.c +++ b/fw/fe310/eos/eve/eve.c @@ -254,15 +254,23 @@ void eve_cmd_dl(uint32_t dl) { int eve_cmd_done(void) { uint16_t r = eve_read16(REG_CMD_READ); + if (r == 0xfff) { + uint16_t ptr; + cmd_offset = 0; + ptr = eve_read16(REG_COPRO_PATCH_PTR); eve_write8(REG_CPURESET, 1); eve_write16(REG_CMD_READ, 0); eve_write16(REG_CMD_WRITE, 0); eve_write16(REG_CMD_DL, 0); eve_write8(REG_CPURESET, 0); - return -1; + eve_write16(REG_COPRO_PATCH_PTR, ptr); + eve_write8(REG_PCLK, EVE_PCLK); + + return EVE_ERR; } + return (r == cmd_offset); } @@ -270,8 +278,10 @@ int eve_cmd_exec(int w) { eve_write16(REG_CMD_WRITE, cmd_offset); if (w) { int r; + do { r = eve_cmd_done(); + if (r < 0) break; } while (!r); if (r < 0) return EVE_ERR; } @@ -293,92 +303,17 @@ 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) { - uint16_t gpiox; - - eve_command(EVE_ACTIVE, 0); - - if (power_state == EVE_PSTATE_SLEEP) { - eve_time_sleep(40); - eve_touch_active(); - } - - gpiox = eve_read16(REG_GPIOX) | 0x8000; - eve_write16(REG_GPIOX, gpiox); - - power_state = EVE_PSTATE_ACTIVE; -} - -void eve_standby(void) { - uint16_t gpiox; - - if (power_state != EVE_PSTATE_ACTIVE) return; - - gpiox = eve_read16(REG_GPIOX) & ~0x8000; - eve_write16(REG_GPIOX, gpiox); - - eve_command(EVE_STANDBY, 0); - - power_state = EVE_PSTATE_STANDBY; -} - -void eve_sleep(void) { - uint16_t gpiox; - - if (power_state != EVE_PSTATE_ACTIVE) return; - - gpiox = eve_read16(REG_GPIOX) & ~0x8000; - eve_write16(REG_GPIOX, gpiox); - - eve_touch_sleep(); - - eve_command(EVE_SLEEP, 0); - - power_state = EVE_PSTATE_SLEEP; -} - -void eve_brightness(uint8_t b) { - eve_write8(REG_PWM_DUTY, b); -} - -static int _init(int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) { +static int _init(uint8_t gpio_dir) { uint8_t chipid = 0; uint8_t reset = 0x07; uint16_t timeout; - eve_command(EVE_CORERST, 0); + eve_command(EVE_CORERST, 0); /* reset */ + eve_command(EVE_CLKEXT, 0); eve_command(EVE_CLKSEL, 0x46); /* set clock to 72 MHz */ eve_command(EVE_ACTIVE, 0); /* start EVE */ - eve_time_sleep(40); + eve_time_sleep(4); timeout = 0; while (chipid != 0x7c) { /* if chipid is not 0x7c, continue to read it until it is, EVE needs a moment for it's power on self-test and configuration */ @@ -399,23 +334,23 @@ static int _init(int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) eve_write32(REG_FREQUENCY, 72000000); /* tell EVE that we changed the frequency from default to 72MHz for BT8xx */ eve_write8(REG_PWM_DUTY, 0x00); + eve_write16(REG_GPIOX, 0x0000); eve_write16(REG_GPIOX_DIR, 0x8000 | (gpio_dir & 0x0f)); - eve_write16(REG_GPIOX, 0x8000); /* initialize display */ eve_write16(REG_HCYCLE, EVE_HCYCLE); /* total number of clocks per line, incl front/back porch */ eve_write16(REG_HOFFSET, EVE_HOFFSET); /* start of active line */ eve_write16(REG_HSYNC0, EVE_HSYNC0); /* start of horizontal sync pulse */ eve_write16(REG_HSYNC1, EVE_HSYNC1); /* end of horizontal sync pulse */ + eve_write16(REG_HSIZE, EVE_HSIZE); /* active display width */ eve_write16(REG_VCYCLE, EVE_VCYCLE); /* total number of lines per screen, including pre/post */ eve_write16(REG_VOFFSET, EVE_VOFFSET); /* start of active screen */ eve_write16(REG_VSYNC0, EVE_VSYNC0); /* start of vertical sync pulse */ eve_write16(REG_VSYNC1, EVE_VSYNC1); /* end of vertical sync pulse */ + eve_write16(REG_VSIZE, EVE_VSIZE); /* active display height */ eve_write8(REG_SWIZZLE, EVE_SWIZZLE); /* FT8xx output to LCD - pin order */ eve_write8(REG_PCLK_POL, EVE_PCLKPOL); /* LCD data is clocked in on this PCLK edge */ eve_write8(REG_CSPREAD, EVE_CSPREAD); /* helps with noise, when set to 1 fewer signals are changed simultaneously, reset-default: 1 */ - eve_write16(REG_HSIZE, EVE_HSIZE); /* active display width */ - eve_write16(REG_VSIZE, EVE_VSIZE); /* active display height */ /* do not set PCLK yet - wait for just after the first display list */ @@ -431,33 +366,115 @@ static int _init(int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) eve_dl_write(DISPLAY()); eve_dl_swap(); - /* nothing is being displayed yet... the pixel clock is still 0x00 */ - eve_write16(REG_GPIOX, 0x8000); /* enable the DISP signal to the LCD panel, it is set to output in REG_GPIOX_DIR by default */ - eve_write8(REG_PCLK, EVE_PCLK); /* now start clocking data to the LCD panel */ - - eve_cmd(CMD_SETROTATE, "w", 2); +#ifdef EVE_PCLK_FREQ + eve_cmd(CMD_PCLKFREQ, "www", EVE_PCLK_FREQ, 0, 0); eve_cmd_exec(1); +#endif + /* nothing is being displayed yet... the pixel clock is still 0x00 */ return EVE_OK; } int eve_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) { - int rst = (wakeup_cause == EOS_PWR_WAKE_RST); - - eve_spi_start(); + int rst = (wakeup_cause == EVE_INIT_RST); if (rst) { - int rv = _init(touch_calibrate, touch_matrix, gpio_dir); + int rv = _init(gpio_dir); if (rv) return rv; } else { - power_state = EVE_PSTATE_SLEEP; - eve_active(); + eve_command(EVE_ACTIVE, 0); + eve_time_sleep(40); } eve_touch_init(wakeup_cause, touch_calibrate, touch_matrix); eve_platform_init(); - eve_spi_stop(); - return EVE_OK; } + +void eve_start(uint8_t wakeup_cause) { + uint16_t gpiox; + + gpiox = eve_read16(REG_GPIOX) | 0x8000; + eve_write16(REG_GPIOX, gpiox); /* enable the DISP signal to the LCD panel, it is set to output in REG_GPIOX_DIR by default */ + eve_write8(REG_PCLK, EVE_PCLK); /* now start clocking data to the LCD panel */ + + eve_touch_start(wakeup_cause); +} + +void eve_stop(void) { + uint16_t gpiox; + + eve_touch_stop(); + + gpiox = eve_read16(REG_GPIOX) & ~0x8000; + eve_write16(REG_GPIOX, gpiox); + eve_write8(REG_PCLK, 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_standby(void) { + uint16_t gpiox; + + if (power_state != EVE_PSTATE_ACTIVE) return; + + eve_command(EVE_STANDBY, 0); + + power_state = EVE_PSTATE_STANDBY; +} + +void eve_sleep(void) { + uint16_t gpiox; + + if (power_state != EVE_PSTATE_ACTIVE) return; + + eve_stop(); + + eve_command(EVE_SLEEP, 0); + + power_state = EVE_PSTATE_SLEEP; +} + +void eve_active(void) { + uint16_t gpiox; + + eve_command(EVE_ACTIVE, 0); + + if (power_state == EVE_PSTATE_SLEEP) { + eve_time_sleep(40); + eve_start(0); + } + + power_state = EVE_PSTATE_ACTIVE; +} + +void eve_brightness(uint8_t b) { + eve_write8(REG_PWM_DUTY, b); +} diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h index 11d59cd..363905c 100644 --- a/fw/fe310/eos/eve/eve.h +++ b/fw/fe310/eos/eve/eve.h @@ -56,15 +56,16 @@ int eve_cmd_exec(int w); void eve_cmd_burst_start(void); void eve_cmd_burst_end(void); +int eve_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir); +void eve_start(uint8_t wakeup_cause); +void eve_stop(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); -void eve_wake(void); +void eve_active(void); void eve_brightness(uint8_t b); - -int eve_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir); diff --git a/fw/fe310/eos/eve/eve_config.h b/fw/fe310/eos/eve/eve_config.h index b0dd1a4..b151c63 100755 --- a/fw/fe310/eos/eve/eve_config.h +++ b/fw/fe310/eos/eve/eve_config.h @@ -1,37 +1,38 @@ #ifndef EVE_CONFIG_H_ #define EVE_CONFIG_H_ -/* my display */ - -#define EVE_TH 1200L -#define EVE_THD 800L -#define EVE_THF 210L -#define EVE_THP 20L -#define EVE_THB 46L - -#define EVE_TV 650L -#define EVE_TVD 480L -#define EVE_TVF 22L -#define EVE_TVP 12L -#define EVE_TVB 23L - - -#define EVE_HSIZE (EVE_THD) /* Thd Length of visible part of line (in PCLKs) - display width */ -#define EVE_HSYNC0 (EVE_THF) /* Thf Horizontal Front Porch */ -#define EVE_HSYNC1 (EVE_THF + EVE_THP) /* Thf + Thp Horizontal Front Porch plus Hsync Pulse width */ -#define EVE_HOFFSET (EVE_THF + EVE_THP + EVE_THB) /* Thf + Thp + Thb Length of non-visible part of line (in PCLK cycles) */ -#define EVE_HCYCLE (EVE_TH) /* Th Total length of line (visible and non-visible) (in PCLKs) */ - -#define EVE_VSIZE (EVE_TVD) /* Tvd Number of visible lines (in lines) - display height */ -#define EVE_VSYNC0 (EVE_TVF) /* Tvf Vertical Front Porch */ -#define EVE_VSYNC1 (EVE_TVF + EVE_TVP) /* Tvf + Tvp Vertical Front Porch plus Vsync Pulse width */ -#define EVE_VOFFSET (EVE_TVF + EVE_TVP + EVE_TVB) /* Tvf + Tvp + Tvb Number of non-visible lines (in lines) */ -#define EVE_VCYCLE (EVE_TV) /* Tv Total number of lines (visible and non-visible) (in lines) */ - -#define EVE_PCLKPOL (1L) /* PCLK polarity (0 = rising edge, 1 = falling edge) */ -#define EVE_SWIZZLE (0L) /* Defines the arrangement of the RGB pins of the FT800 */ -#define EVE_PCLK (1L) /* 60MHz / REG_PCLK = PCLK frequency - 30 MHz */ -#define EVE_CSPREAD (0L) /* helps with noise, when set to 1 fewer signals are changed simultaneously, reset-default: 1 */ +/* FocusLCDs E50RG84885LWAM520-CA */ + +#define EVE_HLPW 20 /* horizontal low pulse width */ +#define EVE_HBP 60 /* horizontal back porch */ +#define EVE_HFP 40 /* horizontal front porch */ +#define EVE_HACT 480 /* horizontal active pixels */ +#define EVE_HTOT (EVE_HLPW + EVE_HBP + EVE_HFP + EVE_HACT + 10) + + +#define EVE_VLPW 26 /* vertical low pulse width */ +#define EVE_VBP 50 /* vertical back porch */ +#define EVE_VFP 30 /* vertical front porch */ +#define EVE_VACT 854 /* vertical active pixels */ +#define EVE_VTOT (EVE_VLPW + EVE_VBP + EVE_VFP + EVE_VACT + 10) + +#define EVE_HCYCLE (EVE_HTOT) /* Th Total length of line (visible and non-visible) (in PCLKs) */ +#define EVE_HSIZE (EVE_HACT) /* Length of visible part of line (in PCLKs) - display width */ +#define EVE_HOFFSET (EVE_HFP + EVE_HLPW + EVE_HBP) /* Length of non-visible part of line (in PCLK cycles) */ +#define EVE_HSYNC0 (EVE_HFP) /* Horizontal Front Porch */ +#define EVE_HSYNC1 (EVE_HFP + EVE_HLPW) /* Horizontal Front Porch plus Hsync Pulse width */ + +#define EVE_VCYCLE (EVE_VTOT) /* Total number of lines (visible and non-visible) (in lines) */ +#define EVE_VSIZE (EVE_VACT) /* Number of visible lines (in lines) - display height */ +#define EVE_VOFFSET (EVE_VFP + EVE_VLPW + EVE_VBP) /* Number of non-visible lines (in lines) */ +#define EVE_VSYNC0 (EVE_VFP) /* Vertical Front Porch */ +#define EVE_VSYNC1 (EVE_VFP + EVE_VLPW) /* Vertical Front Porch plus Vsync Pulse width */ + +#define EVE_PCLKPOL 1 /* PCLK polarity (0 = rising edge, 1 = falling edge) */ +#define EVE_SWIZZLE 0 /* Defines the arrangement of the RGB pins */ +#define EVE_CSPREAD 0 /* helps with noise, when set to 1 fewer signals are changed simultaneously, reset-default: 1 */ + +#define EVE_PCLK 2 /* 36 MHz */ #define EVE_GEN 4 diff --git a/fw/fe310/eos/eve/eve_def.h b/fw/fe310/eos/eve/eve_def.h index e607320..2f7e0b7 100755 --- a/fw/fe310/eos/eve/eve_def.h +++ b/fw/fe310/eos/eve/eve_def.h @@ -695,7 +695,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #define REG_FLASH_STATUS 0x3025f0UL #define REG_FLASH_SIZE 0x309024UL #define REG_PLAY_CONTROL 0x30914eUL -#define REG_COPRO_PATCH_DTR 0x309162UL +#define REG_COPRO_PATCH_PTR 0x309162UL /* BT81x graphics engine specific macros */ diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h index 83c1799..587e1cf 100644 --- a/fw/fe310/eos/eve/eve_platform.h +++ b/fw/fe310/eos/eve/eve_platform.h @@ -2,6 +2,7 @@ #include "spi.h" #include "spi_dev.h" +#include "power.h" #include "timer.h" #define EVE_ETYPE_INTR 1 @@ -11,6 +12,10 @@ #define EVE_SPI_FLAG_BSWAP EOS_SPI_FLAG_BSWAP #define EVE_SPI_FLAG_TX EOS_SPI_FLAG_TX +#define EVE_INIT_RST EOS_INIT_RST +#define EVE_INIT_RTC EOS_INIT_RTC +#define EVE_INIT_BTN EOS_INIT_BTN + void *eve_malloc(size_t); void eve_free(void *); diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c index 035e122..fc9d040 100644 --- a/fw/fe310/eos/eve/eve_touch.c +++ b/fw/fe310/eos/eve/eve_touch.c @@ -300,28 +300,16 @@ void eve_handle_time(void) { } } -void eve_touch_active(void) { - eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); -} - -void eve_touch_sleep(void) { - eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF); -} - static void _init(int touch_calibrate, uint32_t *touch_matrix) { /* configure touch */ - eve_write16(REG_TOUCH_CONFIG, 0x381); /* default */ - eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); /* enable touch */ + eve_write8(REG_CPURESET, 2); /* touch engine reset */ + eve_write16(REG_TOUCH_CONFIG, 0x4000); /* host mode multi touch */ + eve_write8(REG_CPURESET, 0); /* clear reset */ if (touch_calibrate) { eve_write8(REG_PWM_DUTY, 0x40); - eve_cmd_dl(CMD_DLSTART); - eve_cmd_dl(CLEAR_COLOR_RGB(0,0,0)); - eve_cmd_dl(CLEAR(1,1,1)); eve_cmd(CMD_TEXT, "hhhhs", EVE_HSIZE/2, EVE_VSIZE/2, 27, EVE_OPT_CENTER, "Please tap on the dot."); eve_cmd(CMD_CALIBRATE, "w", 0); - eve_cmd_dl(DISPLAY()); - eve_cmd_dl(CMD_SWAP); eve_cmd_exec(1); eve_write8(REG_PWM_DUTY, 0); @@ -340,7 +328,7 @@ static void _init(int touch_calibrate, uint32_t *touch_matrix) { eve_write32(REG_TOUCH_TRANSFORM_F, touch_matrix[5]); } - eve_write8(REG_CTOUCH_EXTENDED, 0x00); + eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */ /* configure interrupts */ eve_write8(REG_INT_MASK, touch_intr_mask); @@ -349,7 +337,7 @@ static void _init(int touch_calibrate, uint32_t *touch_matrix) { } void eve_touch_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix) { - int rst = (wakeup_cause == EOS_PWR_WAKE_RST); + int rst = (wakeup_cause == EVE_INIT_RST); int i; eve_vtrack_init(); @@ -362,6 +350,14 @@ void eve_touch_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_m if (rst) _init(touch_calibrate, touch_matrix); } +void eve_touch_start(uint8_t wakeup_cause) { + eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); +} + +void eve_touch_stop(void) { + eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF); +} + void eve_touch_set_handler(eve_touch_handler_t handler, void *param) { touch_handler = handler; touch_handler_param = param; diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h index 074d37a..b6ca6d9 100644 --- a/fw/fe310/eos/eve/eve_touch.h +++ b/fw/fe310/eos/eve/eve_touch.h @@ -101,9 +101,10 @@ typedef void (*eve_touch_handler_t) (EVETouch *, uint16_t, uint8_t, void *); void eve_handle_touch(void); void eve_handle_time(void); -void eve_touch_active(void); -void eve_touch_sleep(void); void eve_touch_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix); +void eve_touch_start(uint8_t wakeup_cause); +void eve_touch_stop(void); + void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param); EVETouch *eve_touch_get(int i); int8_t eve_touch_get_idx(EVETouch *touch); diff --git a/fw/fe310/eos/event.c b/fw/fe310/eos/event.c index 1b08acc..4a6493f 100644 --- a/fw/fe310/eos/event.c +++ b/fw/fe310/eos/event.c @@ -6,6 +6,7 @@ #include "encoding.h" #include "platform.h" +#include "eos.h" #include "msgq.h" #include "event.h" @@ -24,7 +25,7 @@ static void evtq_handler(unsigned char type, unsigned char *buffer, uint16_t len } } -void eos_evtq_init(uint8_t wakeup_cause) { +int eos_evtq_init(uint8_t wakeup_cause) { int i; evt_handler[0] = evtq_handler; @@ -32,6 +33,8 @@ void eos_evtq_init(uint8_t wakeup_cause) { evt_handler[i + 1] = eos_evtq_bad_handler; } eos_msgq_init(&_eos_event_q, event_q_array, EOS_EVT_SIZE_Q); + + return EOS_OK; } int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len) { diff --git a/fw/fe310/eos/event.h b/fw/fe310/eos/event.h index 02250a5..82043f4 100644 --- a/fw/fe310/eos/event.h +++ b/fw/fe310/eos/event.h @@ -4,7 +4,7 @@ typedef void (*eos_evt_handler_t) (unsigned char, unsigned char *, uint16_t); -void eos_evtq_init(uint8_t wakeup_cause); +int eos_evtq_init(uint8_t wakeup_cause); int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len); int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len); void eos_evtq_pop(unsigned char *type, unsigned char **buffer, uint16_t *len); diff --git a/fw/fe310/eos/i2c.c b/fw/fe310/eos/i2c.c index f296bc7..37c5cf8 100644 --- a/fw/fe310/eos/i2c.c +++ b/fw/fe310/eos/i2c.c @@ -9,8 +9,10 @@ #include "i2s.h" #include "i2c.h" -void eos_i2c_init(uint8_t wakeup_cause) { +int eos_i2c_init(uint8_t wakeup_cause) { GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_I2C0_MASK; + + return EOS_OK; } int eos_i2c_start(uint32_t baud_rate) { diff --git a/fw/fe310/eos/i2c.h b/fw/fe310/eos/i2c.h index 260e680..2da0517 100644 --- a/fw/fe310/eos/i2c.h +++ b/fw/fe310/eos/i2c.h @@ -1,6 +1,6 @@ #include -void eos_i2c_init(uint8_t wakeup_cause); +int eos_i2c_init(uint8_t wakeup_cause); int eos_i2c_start(uint32_t baud_rate); void eos_i2c_stop(void); void eos_i2c_set_baud_rate(uint32_t baud_rate); diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c index db4a6ab..b619fe3 100644 --- a/fw/fe310/eos/i2c/bq25895.c +++ b/fw/fe310/eos/i2c/bq25895.c @@ -7,16 +7,13 @@ #include "i2c.h" #include "i2c/bq25895.h" -void eos_bq25895_init(uint8_t wakeup_cause) { - int rst = (wakeup_cause == EOS_PWR_WAKE_RST); +int eos_bq25895_init(uint8_t wakeup_cause) { + int rst = (wakeup_cause == EOS_INIT_RST); int i, rv = EOS_OK; uint8_t data = 0; rv = eos_i2c_start(100000); - if (rv) { - printf("I2C BUSY\n"); - return; - } + if (rv) return rv; if (rst) { rv = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x80); // reset if (rv) printf("I2C ERROR 0x14\n"); @@ -36,4 +33,6 @@ void eos_bq25895_init(uint8_t wakeup_cause) { if (!rv) printf("REG%02x: %02x\n", i, data); } eos_i2c_stop(); + + return EOS_OK; } diff --git a/fw/fe310/eos/i2c/bq25895.h b/fw/fe310/eos/i2c/bq25895.h index 39c6b68..cbef36e 100644 --- a/fw/fe310/eos/i2c/bq25895.h +++ b/fw/fe310/eos/i2c/bq25895.h @@ -2,4 +2,4 @@ #define BQ25895_ADDR 0x6A -void eos_bq25895_init(uint8_t wakeup_cause); +int eos_bq25895_init(uint8_t wakeup_cause); diff --git a/fw/fe310/eos/i2s.c b/fw/fe310/eos/i2s.c index 0a2742b..5623add 100644 --- a/fw/fe310/eos/i2s.c +++ b/fw/fe310/eos/i2s.c @@ -137,7 +137,7 @@ static void _spk_vol_set(uint8_t vol) { extern void _eos_i2s_start_pwm(void); -void eos_i2s_init(uint8_t wakeup_cause) { +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); @@ -180,6 +180,8 @@ void eos_i2s_init(uint8_t wakeup_cause) { 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) { diff --git a/fw/fe310/eos/i2s.h b/fw/fe310/eos/i2s.h index 1339d0f..1cc10e0 100644 --- a/fw/fe310/eos/i2s.h +++ b/fw/fe310/eos/i2s.h @@ -11,7 +11,7 @@ typedef struct EOSABuf { typedef void (*eos_i2s_handler_t) (unsigned char); -void eos_i2s_init(uint8_t wakeup_cause); +int eos_i2s_init(uint8_t wakeup_cause); 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/interrupt.c b/fw/fe310/eos/interrupt.c index 5eeace8..8af492b 100644 --- a/fw/fe310/eos/interrupt.c +++ b/fw/fe310/eos/interrupt.c @@ -7,6 +7,7 @@ #include "platform.h" #include "plic_driver.h" +#include "eos.h" #include "interrupt.h" // Global Instance data for the PLIC @@ -25,7 +26,7 @@ uintptr_t eos_intr_handle(uintptr_t int_num) { return int_num; } -void eos_intr_init(uint8_t wakeup_cause) { +int eos_intr_init(uint8_t wakeup_cause) { for (int i = 0; i < PLIC_NUM_INTERRUPTS; i++){ ext_interrupt_handler[i] = NULL; } @@ -43,6 +44,8 @@ void eos_intr_init(uint8_t wakeup_cause) { // Enable all interrupts set_csr(mstatus, MSTATUS_MIE); + + return EOS_OK; } void eos_intr_set(uint8_t int_num, uint8_t priority, eos_intr_handler_t handler) { diff --git a/fw/fe310/eos/interrupt.h b/fw/fe310/eos/interrupt.h index 603f0e1..a239934 100644 --- a/fw/fe310/eos/interrupt.h +++ b/fw/fe310/eos/interrupt.h @@ -4,7 +4,7 @@ typedef void (*eos_intr_handler_t) (void); -void eos_intr_init(uint8_t wakeup_cause); +int eos_intr_init(uint8_t wakeup_cause); void eos_intr_set(uint8_t int_num, uint8_t priority, eos_intr_handler_t handler); void eos_intr_set_handler(uint8_t int_num, eos_intr_handler_t handler); void eos_intr_set_priority(uint8_t int_num, uint8_t priority); diff --git a/fw/fe310/eos/lcd.c b/fw/fe310/eos/lcd.c new file mode 100644 index 0000000..8a77651 --- /dev/null +++ b/fw/fe310/eos/lcd.c @@ -0,0 +1,518 @@ +#include +#include + +#include "encoding.h" +#include "platform.h" + +#include "eos.h" +#include "power.h" +#include "timer.h" +#include "i2s.h" +#include "net.h" +#include "spi_dev.h" +#include "eve/eve.h" + +#include "board.h" + +#include "lcd.h" + +#define BIT_PUT(b, pin) if (b) GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << (pin)); else GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << (pin)); +#define BIT_GET(pin) ((GPIO_REG(GPIO_INPUT_VAL) & (1 << (pin))) >> (pin)) + +#define SCK_UP { GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_SCK); } +#define SCK_DN { GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << IOF_SPI1_SCK); } + +static inline void _sleep(int n) { + volatile int x = n; + + while(x) x--; +} + +int eos_lcd_select(void) { + if (eos_i2s_running()) return EOS_ERR_BUSY; + if (eos_spi_dev() != EOS_SPI_DEV_NET) return EOS_ERR_BUSY; + + eos_net_stop(); + 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(0); +} + +void eos_lcd_cs_set(void) { + GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << LCD_PIN_CS); +} + +void eos_lcd_cs_clear(void) { + GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << LCD_PIN_CS); +} + +/* sck frequency for r/w operations is 0.8Mhz */ +void eos_lcd_write(uint8_t dc, uint8_t data) { + int i; + + BIT_PUT(dc, IOF_SPI1_MOSI); + _sleep(10); + SCK_UP; + for (i=0; i<8; i++) { + _sleep(10); + SCK_DN; + BIT_PUT(data & 0x80, IOF_SPI1_MOSI); + _sleep(10); + SCK_UP; + data = data << 1; + } + _sleep(10); + SCK_DN; +} + +void eos_lcd_read(uint8_t *data) { + int i; + + *data = 0; + for (i=0; i<8; i++) { + _sleep(10); + *data = *data << 1; + *data |= BIT_GET(IOF_SPI1_MISO); + SCK_UP; + _sleep(10); + SCK_DN; + } +} + +static int _init(void) { + int rv; + + rv = eos_lcd_select(); + if (rv) return rv; + eos_lcd_cs_set(); + + /* LCD Setting */ + eos_lcd_write(0, 0xFF); // change to Page 1 CMD + eos_lcd_write(1, 0xFF); + eos_lcd_write(1, 0x98); + eos_lcd_write(1, 0x06); + eos_lcd_write(1, 0x04); + eos_lcd_write(1, 0x01); + + // eos_lcd_write(0, 0x08); //Output SDA + // eos_lcd_write(1, 0x10); + + eos_lcd_write(0, 0x20); // set DE/VSYNC mode + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x21); // DE = 1 Active + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x30); // resolution setting 480 X 854 + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x31); // inversion setting 2-dot + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x40); // BT AVDD,AVDD + eos_lcd_write(1, 0x16); + + eos_lcd_write(0, 0x41); + eos_lcd_write(1, 0x33); // 22 + + eos_lcd_write(0, 0x42); + eos_lcd_write(1, 0x03); // VGL=DDVDH+VCIP-DDVDL, VGH=2DDVDL-VCIP + + eos_lcd_write(0, 0x43); + eos_lcd_write(1, 0x09); // set VGH clamp level + + eos_lcd_write(0, 0x44); + eos_lcd_write(1, 0x06); // set VGL clamp level + + eos_lcd_write(0, 0x50); // VREG1 + eos_lcd_write(1, 0x88); + + eos_lcd_write(0, 0x51); // VREG2 + eos_lcd_write(1, 0x88); + + eos_lcd_write(0, 0x52); // flicker MSB + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x53); // flicker LSB + eos_lcd_write(1, 0x49); // VCOM + + eos_lcd_write(0, 0x55); // flicker + eos_lcd_write(1, 0x49); + + eos_lcd_write(0, 0x60); + eos_lcd_write(1, 0x07); + + eos_lcd_write(0, 0x61); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x62); + eos_lcd_write(1, 0x07); + + eos_lcd_write(0, 0x63); + eos_lcd_write(1, 0x00); + + /* Gamma Setting */ + eos_lcd_write(0, 0xA0); // positive Gamma + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0xA1); + eos_lcd_write(1, 0x09); + + eos_lcd_write(0, 0xA2); + eos_lcd_write(1, 0x11); + + eos_lcd_write(0, 0xA3); + eos_lcd_write(1, 0x0B); + + eos_lcd_write(0, 0xA4); + eos_lcd_write(1, 0x05); + + eos_lcd_write(0, 0xA5); + eos_lcd_write(1, 0x08); + + eos_lcd_write(0, 0xA6); + eos_lcd_write(1, 0x06); + + eos_lcd_write(0, 0xA7); + eos_lcd_write(1, 0x04); + + eos_lcd_write(0, 0xA8); + eos_lcd_write(1, 0x09); + + eos_lcd_write(0, 0xA9); + eos_lcd_write(1, 0x0C); + + eos_lcd_write(0, 0xAA); + eos_lcd_write(1, 0x15); + + eos_lcd_write(0, 0xAB); + eos_lcd_write(1, 0x08); + + eos_lcd_write(0, 0xAC); + eos_lcd_write(1, 0x0F); + + eos_lcd_write(0, 0xAD); + eos_lcd_write(1, 0x12); + + eos_lcd_write(0, 0xAE); + eos_lcd_write(1, 0x09); + + eos_lcd_write(0, 0xAF); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0xC0); // negative Gamma + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0xC1); + eos_lcd_write(1, 0x09); + + eos_lcd_write(0, 0xC2); + eos_lcd_write(1, 0x10); + + eos_lcd_write(0, 0xC3); + eos_lcd_write(1, 0x0C); + + eos_lcd_write(0, 0xC4); + eos_lcd_write(1, 0x05); + + eos_lcd_write(0, 0xC5); + eos_lcd_write(1, 0x08); + + eos_lcd_write(0, 0xC6); + eos_lcd_write(1, 0x06); + + eos_lcd_write(0, 0xC7); + eos_lcd_write(1, 0x04); + + eos_lcd_write(0, 0xC8); + eos_lcd_write(1, 0x08); + + eos_lcd_write(0, 0xC9); + eos_lcd_write(1, 0x0C); + + eos_lcd_write(0, 0xCA); + eos_lcd_write(1, 0x14); + + eos_lcd_write(0, 0xCB); + eos_lcd_write(1, 0x08); + + eos_lcd_write(0, 0xCC); + eos_lcd_write(1, 0x0F); + + eos_lcd_write(0, 0xCD); + eos_lcd_write(1, 0x11); + + eos_lcd_write(0, 0xCE); + eos_lcd_write(1, 0x09); + + eos_lcd_write(0, 0xCF); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0xFF); // change to Page 6 CMD for GIP timing + eos_lcd_write(1, 0xFF); + eos_lcd_write(1, 0x98); + eos_lcd_write(1, 0x06); + eos_lcd_write(1, 0x04); + eos_lcd_write(1, 0x06); + + eos_lcd_write(0, 0x00); + eos_lcd_write(1, 0x20); + + eos_lcd_write(0, 0x01); + eos_lcd_write(1, 0x0A); + + eos_lcd_write(0, 0x02); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x03); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x04); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x05); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x06); + eos_lcd_write(1, 0x98); + + eos_lcd_write(0, 0x07); + eos_lcd_write(1, 0x06); + + eos_lcd_write(0, 0x08); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x09); + eos_lcd_write(1, 0x80); + + eos_lcd_write(0, 0x0A); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x0B); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x0C); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x0D); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x0E); + eos_lcd_write(1, 0x05); + + eos_lcd_write(0, 0x0F); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x10); + eos_lcd_write(1, 0xF0); + + eos_lcd_write(0, 0x11); + eos_lcd_write(1, 0xF4); + + eos_lcd_write(0, 0x12); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x13); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x14); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x15); + eos_lcd_write(1, 0xC0); + + eos_lcd_write(0, 0x16); + eos_lcd_write(1, 0x08); + + eos_lcd_write(0, 0x17); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x18); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x19); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x1A); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x1B); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x1C); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x1D); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x20); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x21); + eos_lcd_write(1, 0x23); + + eos_lcd_write(0, 0x22); + eos_lcd_write(1, 0x45); + + eos_lcd_write(0, 0x23); + eos_lcd_write(1, 0x67); + + eos_lcd_write(0, 0x24); + eos_lcd_write(1, 0x01); + + eos_lcd_write(0, 0x25); + eos_lcd_write(1, 0x23); + + eos_lcd_write(0, 0x26); + eos_lcd_write(1, 0x45); + + eos_lcd_write(0, 0x27); + eos_lcd_write(1, 0x67); + + eos_lcd_write(0, 0x30); + eos_lcd_write(1, 0x11); + + eos_lcd_write(0, 0x31); + eos_lcd_write(1, 0x11); + + eos_lcd_write(0, 0x32); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x33); + eos_lcd_write(1, 0xEE); + + eos_lcd_write(0, 0x34); + eos_lcd_write(1, 0xFF); + + eos_lcd_write(0, 0x35); + eos_lcd_write(1, 0xBB); + + eos_lcd_write(0, 0x36); + eos_lcd_write(1, 0xAA); + + eos_lcd_write(0, 0x37); + eos_lcd_write(1, 0xDD); + + eos_lcd_write(0, 0x38); + eos_lcd_write(1, 0xCC); + + eos_lcd_write(0, 0x39); + eos_lcd_write(1, 0x66); + + eos_lcd_write(0, 0x3A); + eos_lcd_write(1, 0x77); + + eos_lcd_write(0, 0x3B); + eos_lcd_write(1, 0x22); + + eos_lcd_write(0, 0x3C); + eos_lcd_write(1, 0x22); + + eos_lcd_write(0, 0x3D); + eos_lcd_write(1, 0x22); + + eos_lcd_write(0, 0x3E); + eos_lcd_write(1, 0x22); + + eos_lcd_write(0, 0x3F); + eos_lcd_write(1, 0x22); + + eos_lcd_write(0, 0x40); + eos_lcd_write(1, 0x22); + + eos_lcd_write(0, 0xFF); // change to Page 7 CMD for GIP timing + eos_lcd_write(1, 0xFF); + eos_lcd_write(1, 0x98); + eos_lcd_write(1, 0x06); + eos_lcd_write(1, 0x04); + eos_lcd_write(1, 0x07); + + eos_lcd_write(0, 0x17); + eos_lcd_write(1, 0x22); + + eos_lcd_write(0, 0x02); + eos_lcd_write(1, 0x77); + + eos_lcd_write(0, 0x26); + eos_lcd_write(1, 0xB2); + + eos_lcd_write(0, 0xFF); // change to Page 0 CMD for normal command + eos_lcd_write(1, 0xFF); + eos_lcd_write(1, 0x98); + eos_lcd_write(1, 0x06); + eos_lcd_write(1, 0x04); + eos_lcd_write(1, 0x00); + + eos_lcd_write(0, 0x3A); + eos_lcd_write(1, 0x70); // 24BIT + + eos_lcd_write(0, 0x11); + eos_time_sleep(120); + eos_lcd_write(0, 0x29); + eos_time_sleep(25); + + eos_lcd_cs_clear(); + eos_lcd_deselect(); + + return EOS_OK; +} + +int eos_lcd_init(uint8_t wakeup_cause) { + eos_spi_select(EOS_SPI_DEV_EVE); + eve_gpio_set(EVE_GPIO_LCD_EN, 1); + eos_spi_deselect(); + eos_time_sleep(200); + + return _init(); +} + +int eos_lcd_sleep(void) { + int rv; + + rv = eos_lcd_select(); + if (rv) return rv; + + eos_lcd_cs_set(); + + eos_lcd_write(0, 0x28); + eos_time_sleep(10); + eos_lcd_write(0, 0x10); + + eos_lcd_cs_clear(); + eos_lcd_deselect(); + + eos_spi_select(EOS_SPI_DEV_EVE); + eve_gpio_set(EVE_GPIO_LCD_EN, 0); + eos_spi_deselect(); + + return EOS_OK; +} + +int eos_lcd_wake(void) { + int rv; + + eos_spi_select(EOS_SPI_DEV_EVE); + eve_gpio_set(EVE_GPIO_LCD_EN, 1); + eos_spi_deselect(); + eos_time_sleep(200); + + rv = eos_lcd_select(); + if (rv) return rv; + + eos_lcd_cs_set(); + + eos_lcd_write(0, 0x11); + eos_time_sleep(120); + eos_lcd_write(0, 0x29); + + eos_lcd_cs_clear(); + eos_lcd_deselect(); + + return EOS_OK; +} diff --git a/fw/fe310/eos/lcd.h b/fw/fe310/eos/lcd.h new file mode 100644 index 0000000..1bcb2cd --- /dev/null +++ b/fw/fe310/eos/lcd.h @@ -0,0 +1,12 @@ +#include + +int eos_lcd_init(uint8_t wakeup_cause); +int eos_lcd_select(void); +void eos_lcd_deselect(void); +void eos_lcd_cs_set(void); +void eos_lcd_cs_clear(void); +void eos_lcd_write(uint8_t dc, uint8_t data); +void eos_lcd_read(uint8_t *data); + +int eos_lcd_sleep(void); +int eos_lcd_wake(void); \ No newline at end of file diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c index 5caac38..dffbc31 100644 --- a/fw/fe310/eos/net.c +++ b/fw/fe310/eos/net.c @@ -305,7 +305,7 @@ static void net_resume(void) { } } -void eos_net_init(uint8_t wakeup_cause) { +int eos_net_init(uint8_t wakeup_cause) { int i; eos_msgq_init(&net_send_q, net_sndq_array, EOS_NET_SIZE_BUFQ); @@ -342,6 +342,8 @@ void eos_net_init(uint8_t wakeup_cause) { if (GPIO_REG(GPIO_INPUT_VAL) & (1 << NET_PIN_CTS)) net_state_flags |= NET_STATE_FLAG_CTS; if (GPIO_REG(GPIO_INPUT_VAL) & (1 << NET_PIN_RTS)) net_state_flags |= NET_STATE_FLAG_RTS; set_csr(mstatus, MSTATUS_MIE); + + return EOS_OK; } void eos_net_start(uint8_t wakeup_cause) { @@ -350,8 +352,8 @@ void eos_net_start(uint8_t wakeup_cause) { SPI1_REG(SPI_REG_CSID) = eos_spi_csid(EOS_SPI_DEV_NET); clear_csr(mstatus, MSTATUS_MIE); - if (wakeup_cause) { - if (wakeup_cause != EOS_PWR_WAKE_BTN) { + if ((wakeup_cause & EOS_PWR_INIT) && (wakeup_cause != EOS_INIT_RST)) { + if (wakeup_cause != EOS_INIT_BTN) { net_xchg_wake(); } if (!(net_state_flags & NET_STATE_FLAG_CTS)) { diff --git a/fw/fe310/eos/net.h b/fw/fe310/eos/net.h index c26706e..6cb4cf0 100644 --- a/fw/fe310/eos/net.h +++ b/fw/fe310/eos/net.h @@ -22,7 +22,7 @@ /* fe310 specific */ #define EOS_NET_SIZE_BUFQ 2 -void eos_net_init(uint8_t wakeup_cause); +int eos_net_init(uint8_t wakeup_cause); void eos_net_start(uint8_t wakeup_cause); void eos_net_stop(void); int eos_net_sleep(uint32_t timeout); diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/power.c index 539749b..0d6ab0c 100644 --- a/fw/fe310/eos/power.c +++ b/fw/fe310/eos/power.c @@ -10,6 +10,7 @@ #include "spi.h" #include "spi_dev.h" #include "net.h" +#include "lcd.h" #include "eve/eve.h" #include "power.h" @@ -49,7 +50,7 @@ static void power_handle_btn(unsigned char type, unsigned char *buffer, uint16_t eos_power_sleep(); } -void eos_power_init(uint8_t wakeup_cause) { +int eos_power_init(uint8_t wakeup_cause) { int i; for (i=0; i> 8) & 0xff; } -void eos_power_sleep(void) { +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(); - eos_net_sleep(1000); + + 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) { diff --git a/fw/fe310/eos/power.h b/fw/fe310/eos/power.h index 9f6729c..241ee07 100644 --- a/fw/fe310/eos/power.h +++ b/fw/fe310/eos/power.h @@ -8,15 +8,20 @@ #define EOS_PWR_WAKE_RST 0 #define EOS_PWR_WAKE_RTC 1 #define EOS_PWR_WAKE_BTN 2 +#define EOS_PWR_INIT 0x80 #define EOS_PWR_RST_PWRON 0 #define EOS_PWR_RST_EXT 1 #define EOS_PWR_RST_WDOG 2 -void eos_power_init(uint8_t wakeup_cause); +#define EOS_INIT_RST (EOS_PWR_WAKE_RST | EOS_PWR_INIT) +#define EOS_INIT_RTC (EOS_PWR_WAKE_RTC | EOS_PWR_INIT) +#define EOS_INIT_BTN (EOS_PWR_WAKE_BTN | EOS_PWR_INIT) + +int eos_power_init(uint8_t wakeup_cause); uint8_t eos_power_wakeup_cause(void); uint8_t eos_power_reset_cause(void); -void eos_power_sleep(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); diff --git a/fw/fe310/eos/sdcard.c b/fw/fe310/eos/sdcard.c index 82b679b..6f5488d 100644 --- a/fw/fe310/eos/sdcard.c +++ b/fw/fe310/eos/sdcard.c @@ -352,7 +352,7 @@ static int sdc_init(uint32_t timeout) { return EOS_OK; } -void eos_sdc_init(uint8_t wakeup_cause) { +int eos_sdc_init(uint8_t wakeup_cause) { int rv; eos_spi_select(EOS_SPI_DEV_SDC); @@ -363,6 +363,8 @@ void eos_sdc_init(uint8_t wakeup_cause) { printf("SDC OK:%x\n", sdc_type); } eos_spi_deselect(); + + return EOS_OK; } uint8_t eos_sdc_type(void) { diff --git a/fw/fe310/eos/sdcard.h b/fw/fe310/eos/sdcard.h index 1204508..910a6e0 100644 --- a/fw/fe310/eos/sdcard.h +++ b/fw/fe310/eos/sdcard.h @@ -11,7 +11,7 @@ #define EOS_SDC_CAP_ERASE_EN 0x20 #define EOS_SDC_CAP_MASK 0xf0 -void eos_sdc_init(uint8_t wakeup_cause); +int eos_sdc_init(uint8_t wakeup_cause); uint8_t eos_sdc_type(void); uint8_t eos_sdc_cap(void); int eos_sdc_get_sect_count(uint32_t timeout, uint32_t *sectors); diff --git a/fw/fe310/eos/spi.c b/fw/fe310/eos/spi.c index 234bff6..a4b164e 100644 --- a/fw/fe310/eos/spi.c +++ b/fw/fe310/eos/spi.c @@ -45,7 +45,7 @@ static void spi_handle_evt(unsigned char type, unsigned char *buffer, uint16_t l } } -void eos_spi_init(uint8_t wakeup_cause) { +int eos_spi_init(uint8_t wakeup_cause) { int i; for (i=0; i