From 9ccb4db8d59ec9dab33ee8617d462f21a8bb4fa8 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 13 May 2022 12:26:19 +0200 Subject: touch controller/eve fixes --- fw/fe310/eos/Makefile | 2 +- fw/fe310/eos/eos.c | 30 ++- fw/fe310/eos/eos.h | 4 +- fw/fe310/eos/eve/Makefile | 2 +- fw/fe310/eos/eve/eve.c | 42 ++-- fw/fe310/eos/eve/eve.h | 12 +- fw/fe310/eos/eve/eve_config.h | 16 +- fw/fe310/eos/eve/eve_def.h | 4 + fw/fe310/eos/eve/eve_eos.c | 104 --------- fw/fe310/eos/eve/eve_eos.h | 6 - fw/fe310/eos/eve/eve_phy.c | 15 +- fw/fe310/eos/eve/eve_phy.h | 4 +- fw/fe310/eos/eve/eve_platform.c | 14 +- fw/fe310/eos/eve/eve_platform.h | 8 +- fw/fe310/eos/eve/eve_touch.c | 483 +++++++++++++++++----------------------- fw/fe310/eos/eve/eve_touch.h | 25 +-- fw/fe310/eos/eve/eve_vtrack.c | 9 +- fw/fe310/eos/eve/eve_vtrack.h | 2 +- fw/fe310/eos/eve/screen/page.c | 10 +- fw/fe310/eos/eve/screen/page.h | 2 +- fw/fe310/eos/eve/widget/strw.c | 2 +- fw/fe310/eos/eve_eos.c | 149 +++++++++++++ fw/fe310/eos/eve_eos.h | 7 + fw/fe310/eos/event.c | 28 ++- fw/fe310/eos/event.h | 1 + fw/fe310/eos/evt_def.h | 3 +- fw/fe310/eos/i2c/Makefile | 3 +- fw/fe310/eos/i2c/bq25895.c | 2 +- fw/fe310/eos/irq_def.h | 3 +- fw/fe310/eos/lcd.c | 70 ++++-- fw/fe310/eos/net.c | 1 + fw/fe310/eos/pwr.c | 2 +- fw/fe310/eos/sdc_crypto.c | 2 +- fw/fe310/eos/sdcard.c | 26 +-- fw/fe310/eos/timer.c | 19 +- fw/fe310/eos/timer.h | 6 +- fw/fe310/test/Makefile | 4 +- fw/fe310/test/app/app_root.c | 4 +- fw/fe310/test/app/app_root.h | 2 +- fw/fe310/test/fs.c | 25 +++ fw/fe310/test/main.c | 22 +- 41 files changed, 613 insertions(+), 562 deletions(-) delete mode 100644 fw/fe310/eos/eve/eve_eos.c delete mode 100644 fw/fe310/eos/eve/eve_eos.h create mode 100644 fw/fe310/eos/eve_eos.c create mode 100644 fw/fe310/eos/eve_eos.h diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile index a52b5db..7861810 100644 --- a/fw/fe310/eos/Makefile +++ b/fw/fe310/eos/Makefile @@ -1,7 +1,7 @@ include ../common.mk CFLAGS += -I. -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto -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 rng.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 eve_eos.o sdcard.o sdc_crypto.o cam.o net.o rng.o wifi.o cell.o sock.o unicode.o %.o: %.c %.h diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c index b52ed93..0260073 100644 --- a/fw/fe310/eos/eos.c +++ b/fw/fe310/eos/eos.c @@ -15,17 +15,19 @@ #include "wifi.h" #include "cell.h" #include "sock.h" +#include "eve_eos.h" + +#include "eve/eve.h" +#include "i2c/gt911.h" #include "i2c/bq25895.h" -#include "eve/eve_eos.h" #include "board.h" - #include "eos.h" +extern const uint32_t _eos_touch_matrix[6]; + void eos_init(void) { uint8_t wakeup_cause = eos_pwr_wakeup_cause(); - uint32_t touch_matrix[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0}; - int touch_calibrate = 0; int rv; eos_evtq_init(wakeup_cause); @@ -55,16 +57,16 @@ void eos_init(void) { eos_i2c_stop(); if (rv) printf("BQ25895 INIT ERR:%d\n", rv); - rv = eos_eve_init(wakeup_cause, EVE_GPIO_DIR, touch_calibrate, touch_matrix); + rv = eos_eve_init(wakeup_cause, EVE_GPIO_DIR, _eos_touch_matrix); if (rv) printf("EVE INIT ERR:%d\n", rv); rv = eos_lcd_init(wakeup_cause); + if (rv == EOS_ERR_ABSENT) eve_lcd_absent(); 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]); - } + rv = eos_gt911_init(wakeup_cause); + if (rv) printf("CTP INIT ERR:%d\n", rv); + eos_run(wakeup_cause); } @@ -81,3 +83,13 @@ void eos_run(uint8_t wakeup_cause) { rv = eos_net_run(wakeup_cause); if (rv) printf("NET RUN ERR:%d\n", rv); } + +void eos_run_once(void) { + eos_i2c_start(); + eos_gt911_cfg_print(); + eos_gt911_set_threshold(); + eos_gt911_cfg_print(); + eos_i2c_stop(); + + eos_eve_calibrate(); +} diff --git a/fw/fe310/eos/eos.h b/fw/fe310/eos/eos.h index 87a7e27..f3caf6b 100644 --- a/fw/fe310/eos/eos.h +++ b/fw/fe310/eos/eos.h @@ -9,8 +9,10 @@ #define EOS_ERR_FULL -11 #define EOS_ERR_EMPTY -12 #define EOS_ERR_NOTFOUND -13 +#define EOS_ERR_ABSENT -14 #define EOS_ERR_NET -20 void eos_init(void); -void eos_run(uint8_t wakeup_cause); \ No newline at end of file +void eos_run(uint8_t wakeup_cause); +void eos_run_once(void); \ No newline at end of file diff --git a/fw/fe310/eos/eve/Makefile b/fw/fe310/eos/eve/Makefile index 323a132..462891c 100644 --- a/fw/fe310/eos/eve/Makefile +++ b/fw/fe310/eos/eve/Makefile @@ -1,7 +1,7 @@ include ../../common.mk CFLAGS += -I$(bsp_dir)/include -obj = eve.o eve_eos.o eve_platform.o eve_touch.o eve_phy.o eve_vtrack.o eve_font.o eve_kbd.o eve_text.o clipb.o +obj = eve.o eve_platform.o eve_touch.o eve_touch_engine.o eve_phy.o eve_vtrack.o eve_font.o eve_kbd.o eve_text.o clipb.o %.o: %.c %.h diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c index e1191fc..02e0cae 100644 --- a/fw/fe310/eos/eve/eve.c +++ b/fw/fe310/eos/eve/eve.c @@ -13,6 +13,7 @@ static char dl_burst; static uint32_t dl_addr; static uint8_t power_state; +static int lcd_absent = 0; void eve_command(uint8_t command, uint8_t parameter) { eve_spi_cs_set(); @@ -289,6 +290,7 @@ int eve_cmd_exec(int w) { void eve_cmd_burst_start(void) { uint32_t addr = EVE_RAM_CMD + cmd_offset; + eve_spi_lock(); eve_spi_cs_set(); eve_spi_xchg24(addr | EVE_MEM_WRITE, EVE_SPI_FLAG_TX); @@ -306,10 +308,10 @@ void eve_handle_intr(void) { uint16_t intr_flags; intr_flags = eve_read16(REG_INT_FLAGS); - eve_handle_touch(intr_flags); + if (intr_flags & (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)) eve_handle_touch(intr_flags); } -int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { +int eve_init(uint8_t gpio_dir) { uint8_t chipid = 0; uint8_t reset = 0x07; uint16_t timeout; @@ -319,11 +321,11 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { 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(4); + eve_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 */ - eve_time_sleep(1); + eve_sleep(1); chipid = eve_read8(REG_ID); timeout++; if (timeout > 400) return EVE_ERR; @@ -331,7 +333,7 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { timeout = 0; while (reset != 0x00) { /* check if EVE is in working status */ - eve_time_sleep(1); + eve_sleep(1); reset = eve_read8(REG_CPURESET) & 0x07; timeout++; if(timeout > 50) return EVE_ERR; @@ -381,21 +383,16 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { #endif /* nothing is being displayed yet... the pixel clock is still 0x00 */ - eve_touch_init(touch_calibrate, touch_matrix); return EVE_OK; } void eve_start(void) { - eve_touch_start(); - /* enable interrupts */ eve_write8(REG_INT_EN, 0x01); while(eve_read8(REG_INT_FLAGS)); } void eve_stop(void) { - eve_touch_stop(); - /* disable interrupts */ eve_write8(REG_INT_EN, 0x00); while(eve_read8(REG_INT_FLAGS)); @@ -417,12 +414,12 @@ void eve_stop_clk(void) { eve_write8(REG_PCLK, 0); } -void eve_active(void) { +void eve_activate(void) { eve_command(EVE_ACTIVE, 0); - eve_time_sleep(40); + eve_sleep(40); } -void eve_standby(void) { +void eve_pwr_standby(void) { if (power_state != EVE_PSTATE_ACTIVE) return; eve_command(EVE_STANDBY, 0); @@ -430,7 +427,7 @@ void eve_standby(void) { power_state = EVE_PSTATE_STANDBY; } -void eve_sleep(void) { +void eve_pwr_sleep(void) { if (power_state != EVE_PSTATE_ACTIVE) return; eve_stop_clk(); @@ -441,8 +438,8 @@ void eve_sleep(void) { power_state = EVE_PSTATE_SLEEP; } -void eve_wake(void) { - eve_active(); +void eve_pwr_wake(void) { + eve_activate(); if (power_state == EVE_PSTATE_SLEEP) { eve_start(); @@ -452,10 +449,6 @@ void eve_wake(void) { power_state = EVE_PSTATE_ACTIVE; } -void eve_brightness(uint8_t b) { - eve_write8(REG_PWM_DUTY, b); -} - int eve_gpio_get(int gpio) { uint16_t reg = eve_read16(REG_GPIOX); @@ -483,3 +476,12 @@ void eve_gpio_set_dir(uint8_t dir) { reg |= dir & 0x0f; eve_write16(REG_GPIOX_DIR, reg); } + +void eve_brightness(uint8_t b) { + if (lcd_absent) b = 0; + eve_write8(REG_PWM_DUTY, b); +} + +void eve_lcd_absent(void) { + lcd_absent = 1; +} diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h index 02fa697..6b31818 100644 --- a/fw/fe310/eos/eve/eve.h +++ b/fw/fe310/eos/eve/eve.h @@ -58,19 +58,21 @@ void eve_cmd_burst_end(void); void eve_handle_intr(void); -int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix); +int eve_init(uint8_t gpio_dir); void eve_start(void); void eve_stop(void); void eve_start_clk(void); void eve_stop_clk(void); -void eve_active(void); -void eve_standby(void); -void eve_sleep(void); -void eve_wake(void); +void eve_activate(void); +void eve_pwr_standby(void); +void eve_pwr_sleep(void); +void eve_pwr_wake(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_brightness(uint8_t b); +void eve_lcd_absent(void); \ No newline at end of file diff --git a/fw/fe310/eos/eve/eve_config.h b/fw/fe310/eos/eve/eve_config.h index 1126277..b151c63 100755 --- a/fw/fe310/eos/eve/eve_config.h +++ b/fw/fe310/eos/eve/eve_config.h @@ -3,20 +3,19 @@ /* FocusLCDs E50RG84885LWAM520-CA */ -#define EVE_HLPW 6 /* horizontal low pulse width */ -#define EVE_HBP 6 /* horizontal back porch */ -#define EVE_HFP 6 /* horizontal front porch */ +#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 6 /* vertical low pulse width */ -#define EVE_VBP 6 /* vertical back porch */ -#define EVE_VFP 6 /* vertical front porch */ +#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) */ @@ -33,8 +32,7 @@ #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 1 /* Clock from EVE_PCLK_FREQ */ -#define EVE_PCLK_FREQ 27000000 +#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 2f7e0b7..b7110b9 100755 --- a/fw/fe310/eos/eve/eve_def.h +++ b/fw/fe310/eos/eve/eve_def.h @@ -697,6 +697,10 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #define REG_PLAY_CONTROL 0x30914eUL #define REG_COPRO_PATCH_PTR 0x309162UL +#define REG_EHOST_TOUCH_X 0x30210cUL +#define REG_EHOST_TOUCH_Y 0x302118UL +#define REG_EHOST_TOUCH_ID 0x302114UL +#define REG_EHOST_TOUCH_ACK 0x302170UL /* BT81x graphics engine specific macros */ #define BITMAP_EXT_FORMAT(format) ((46UL<<24)|(((format)&65535UL)<<0)) diff --git a/fw/fe310/eos/eve/eve_eos.c b/fw/fe310/eos/eve/eve_eos.c deleted file mode 100644 index 2e13cd2..0000000 --- a/fw/fe310/eos/eve/eve_eos.c +++ /dev/null @@ -1,104 +0,0 @@ -#include - -#include "platform.h" - -#include "eos.h" -#include "interrupt.h" -#include "event.h" -#include "pwr.h" - -#include "board.h" - -#include "eve.h" -#include "eve_eos.h" - -static int _run; - -static void handle_time(unsigned char type) { - if (_run) { - eve_spi_start(); - eve_handle_time(); - eve_spi_stop(); - } -} - -static void handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { - if (_run) { - eve_spi_start(); - eve_handle_intr(); - eve_spi_stop(); - - GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR); - } -} - -static void handle_intr(void) { - GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR); - GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INTR); - 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 = EVE_OK; - - eve_spi_start(); - if (rst) { - rv = eve_init(gpio_dir, touch_calibrate, touch_matrix); - } 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); - eos_intr_set(INT_GPIO_BASE + EVE_PIN_INTR, IRQ_PRIORITY_UI, handle_intr); - eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR); - - return EOS_OK; -} - -int eos_eve_run(uint8_t wakeup_cause) { - eve_spi_start(); - _start(); - eve_start_clk(); - eve_spi_stop(); - - return EOS_OK; -} - -void eos_eve_start(void) { - eve_spi_start(); - _start(); - eve_spi_stop(); -} - -void eos_eve_stop(void) { - eve_spi_start(); - _stop(); - eve_spi_stop(); -} diff --git a/fw/fe310/eos/eve/eve_eos.h b/fw/fe310/eos/eve/eve_eos.h deleted file mode 100644 index 80eea86..0000000 --- a/fw/fe310/eos/eve/eve_eos.h +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix); -int eos_eve_run(uint8_t wakeup_cause); -void eos_eve_start(void); -void eos_eve_stop(void); diff --git a/fw/fe310/eos/eve/eve_phy.c b/fw/fe310/eos/eve/eve_phy.c index 1e255fe..09a86c6 100644 --- a/fw/fe310/eos/eve/eve_phy.c +++ b/fw/fe310/eos/eve/eve_phy.c @@ -19,20 +19,27 @@ void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y) { param->k = 2 * v0 / param->a * EVE_RTC_FREQ; } -int eve_phy_acc_tick(EVEPhyAcc *param, int dt, int *x, int *y) { +int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y) { int k = param->k; int x0 = param->x0; int y0 = param->y0; int v0x = param->v0x; int v0y = param->v0y; + int _dt = dt; int more = 1; + if (k == 0) { + if (x) *x = x0; + if (y) *y = y0; + return 0; + } + if ((k < 0) && (dt >= -k / 2)) { dt = -k / 2; more = 0; } - if (x) *x = x0 + (v0x * dt + v0x * dt / k * dt) / (int)(EVE_RTC_FREQ); - if (y) *y = y0 + (v0y * dt + v0y * dt / k * dt) / (int)(EVE_RTC_FREQ); + if (x) *x = x0 + (v0x * _dt + v0x * _dt / k * _dt) / EVE_RTC_FREQ; + if (y) *y = y0 + (v0y * _dt + v0y * _dt / k * _dt) / EVE_RTC_FREQ; return more; } @@ -55,7 +62,7 @@ int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0) { param->y0 = y0; } -int eve_phy_lho_tick(EVEPhyLHO *param, int dt, int *x, int *y) { +int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y) { int ax = param->x0 - param->x; int ay = param->y0 - param->y; int more = 1; diff --git a/fw/fe310/eos/eve/eve_phy.h b/fw/fe310/eos/eve/eve_phy.h index 1be5fd0..37d0221 100644 --- a/fw/fe310/eos/eve/eve_phy.h +++ b/fw/fe310/eos/eve/eve_phy.h @@ -11,7 +11,7 @@ typedef struct EVEPhyAcc { void eve_phy_acc_init(EVEPhyAcc *param, int a); void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y); -int eve_phy_acc_tick(EVEPhyAcc *param, int dt, int *x, int *y); +int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y); typedef struct EVEPhyLHO { int x; @@ -25,4 +25,4 @@ typedef struct EVEPhyLHO { void eve_phy_lho_init(EVEPhyLHO *param, int x, int y, uint32_t T, double d, uint32_t t_max); int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0); -int eve_phy_lho_tick(EVEPhyLHO *param, int dt, int *x, int *y); \ No newline at end of file +int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y); \ No newline at end of file diff --git a/fw/fe310/eos/eve/eve_platform.c b/fw/fe310/eos/eve/eve_platform.c index 4450412..f0fc399 100644 --- a/fw/fe310/eos/eve/eve_platform.c +++ b/fw/fe310/eos/eve/eve_platform.c @@ -17,19 +17,19 @@ void eve_free(void *p) { free(p); } -void eve_timer_set(uint32_t ms) { - eos_timer_set(ms, EOS_TIMER_ETYPE_UI); +void eve_sleep(uint32_t ms) { + eos_time_sleep(ms); } -void eve_time_sleep(uint32_t ms) { - eos_time_sleep(ms); +uint32_t eve_get_tick(void) { + return (uint32_t)eos_time_get_tick(); } -uint64_t eve_time_get_tick(void) { - return eos_time_get_tick(); +void eve_sys_timer_set(uint32_t ms) { + eos_timer_set(EOS_TIMER_ETYPE_UI, ms); } -void eve_timer_clear(void) { +void eve_sys_timer_clear(void) { eos_timer_clear(EOS_TIMER_ETYPE_UI); } diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h index 77afffc..9d472b5 100644 --- a/fw/fe310/eos/eve/eve_platform.h +++ b/fw/fe310/eos/eve/eve_platform.h @@ -31,7 +31,7 @@ void eve_spi_stop(void); #define eve_spi_lock eos_spi_lock #define eve_spi_unlock eos_spi_unlock -void eve_time_sleep(uint32_t ms); -uint64_t eve_time_get_tick(void); -void eve_timer_set(uint32_t ms); -void eve_timer_clear(void); +void eve_sleep(uint32_t ms); +uint32_t eve_get_tick(void); +void eve_sys_timer_set(uint32_t ms); +void eve_sys_timer_clear(void); diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c index 7c06f81..0dc8b31 100644 --- a/fw/fe310/eos/eve/eve_touch.c +++ b/fw/fe310/eos/eve/eve_touch.c @@ -1,10 +1,9 @@ #include #include -#include #include "eve.h" +#include "eve_touch_engine.h" -static int touch_multi; static uint8_t touch_tag0; static EVETouch touch_obj[EVE_MAX_TOUCH]; @@ -14,235 +13,210 @@ static eve_touch_handler_t touch_handler; static void *touch_handler_param; static uint8_t touch_tag_opt[256]; -static const uint32_t _reg_touch[] = { - REG_CTOUCH_TOUCH0_XY, - REG_CTOUCH_TOUCH1_XY, - REG_CTOUCH_TOUCH2_XY, - REG_CTOUCH_TOUCH3_XY -}; - -static const uint32_t _reg_tag[] = { - REG_TOUCH_TAG, - REG_TOUCH_TAG1, - REG_TOUCH_TAG2, - REG_TOUCH_TAG3, - REG_TOUCH_TAG4 -}; - -static const uint32_t _reg_track[] = { - REG_TRACKER, - REG_TRACKER_1, - REG_TRACKER_2, - REG_TRACKER_3, - REG_TRACKER_4 -}; - -void eve_handle_touch(uint16_t intr_flags) { +void eve_touch_init(void) { int i; - char touch_ex = 0; - char int_ccomplete = 0; - uint16_t intr_mask; - - intr_mask = eve_read16(REG_INT_MASK); - if (!touch_multi && (intr_flags & EVE_INT_TOUCH)) touch_multi = 1; + touch_tag0 = 0; + memset(&touch_timer, 0, sizeof(touch_timer)); for (i=0; ieevt |= EVE_TOUCH_EETYPE_NOTOUCH; + } + eve_vtrack_init(); +} - if (touch_xy != EVE_NOTOUCH) { - int16_t touch_x = touch_xy >> 16; - int16_t touch_y = touch_xy & 0xffff; - now = eve_time_get_tick(); - if (touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH) { - uint16_t _evt = 0; - uint16_t _eevt = 0; - uint16_t _ttevt = eve_touch_timer_get_evt(touch); +void eve_handle_touch(uint16_t intr_flags) { + int i; - if (_ttevt) { - touch->eevt &= ~EVE_TOUCH_EETYPE_NOTOUCH; + for (i=0; ix0; - int dy = touch_y - touch->y0; + now = eve_get_tick(); + + if (intr_flags & EVE_INT_CONVCOMPLETE) { + uint32_t touch_xy = eve_touch_reg_xy(i); + uint16_t timer_evt; + + if (touch_xy != EVE_NOTOUCH) { + int16_t touch_x = touch_xy >> 16; + int16_t touch_y = touch_xy & 0xffff; + int check_track, check_timer; + + if (touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH) { + uint16_t _evt = 0; + uint16_t _eevt = 0; + + timer_evt = eve_timer_get_evt(touch); + if (timer_evt) { + uint16_t _touch_evt = 0; + + touch->eevt &= ~EVE_TOUCH_EETYPE_NOTOUCH; + if (timer_evt & EVE_TOUCH_ETYPE_TAP2) { + int dx = touch_x - touch->x0; + int dy = touch_y - touch->y0; + + dx = dx < 0 ? -dx : dx; + dy = dy < 0 ? -dy : dy; + if ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y)) { + _touch_evt |= EVE_TOUCH_ETYPE_TAP1; + } else { + _evt |= EVE_TOUCH_ETYPE_TAP2; + _eevt |= EVE_TOUCH_EETYPE_TAP2; + } + } + if (timer_evt & EVE_TOUCH_ETYPE_TRACK) { + EVEVTrack *vtrack = eve_vtrack_get(); - dx = dx < 0 ? -dx : dx; - dy = dy < 0 ? -dy : dy; - if ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y)) { - touch_evt |= EVE_TOUCH_ETYPE_TAP1; - } else { - _evt |= EVE_TOUCH_ETYPE_TAP2; - _eevt |= EVE_TOUCH_EETYPE_TAP2; + _eevt |= EVE_TOUCH_EETYPE_TRACK_ABORT; + _touch_evt |= (EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_ABORT); + if (vtrack->stop) vtrack->stop(touch, vtrack->param); + } + if (timer_evt & EVE_TOUCH_ETYPE_TIMER) { + _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT; + _touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT; } - } - if (_ttevt & EVE_TOUCH_ETYPE_TRACK) { - EVEVTrack *vtrack = eve_vtrack_get(); - _eevt |= EVE_TOUCH_EETYPE_TRACK_ABORT; - touch_evt |= (EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_ABORT); - if (vtrack->stop) vtrack->stop(touch, vtrack->param); + eve_timer_clear(touch); + if (touch_handler && _touch_evt) { + touch_handler(touch_timer.touch, _touch_evt, touch_timer.tag0, touch_handler_param); + } } - if (_ttevt & EVE_TOUCH_ETYPE_TIMER) { - _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT; - touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT; + touch_evt |= EVE_TOUCH_ETYPE_POINT | _evt; + touch->eevt = _eevt; + touch->tag0 = 0; + touch->tag = 0; + touch->tag_up = 0; + touch->tracker.tag = 0; + touch->tracker.track = 0; + touch->tracker.val = 0; + touch->t = 0; + touch->vx = 0; + touch->vy = 0; + touch->x0 = touch_x; + touch->y0 = touch_y; + } else if (touch->tracker.track) { + uint32_t dt = now - touch->t; + int vx = ((int)touch_x - touch->x) * EVE_RTC_FREQ / (int)dt; + int vy = ((int)touch_y - touch->y) * EVE_RTC_FREQ / (int)dt; + + touch->vx = vx; + touch->vy = vy; + touch->t = now; + } + touch->x = touch_x; + touch->y = touch_y; + + timer_evt = eve_timer_get_evt(touch); + check_track = touch->tracker.tag && !touch->tracker.track; + check_timer = timer_evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2); + + if (check_track || check_timer) { + int dx = touch->x - touch->x0; + int dy = touch->y - touch->y0; + + dx = dx < 0 ? -dx : dx; + dy = dy < 0 ? -dy : dy; + if (check_track) { + if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) { + touch->tracker.tag = 0; + } + if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) { + touch->tracker.tag = 0; + } + if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { + if (dx > EVE_TOUCH_THRESHOLD_X) { + touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; + } + if (dy > EVE_TOUCH_THRESHOLD_Y) { + touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP; + } + touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; + touch->tracker.track = 1; + touch->t = now; + } } - - eve_touch_timer_clear(touch); - if (touch_handler && touch_evt) { - touch_handler(touch_timer.touch, touch_evt, touch_timer.tag0, touch_handler_param); + if (check_timer && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { + eve_timer_set_evt(touch, timer_evt & ~(EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2)); } } - touch_evt = EVE_TOUCH_ETYPE_POINT | _evt; - touch->eevt = _eevt; - touch->tag0 = 0; - touch->tag = 0; - touch->tag_up = 0; - touch->tracker.tag = 0; - touch->tracker.track = 0; - touch->tracker.val = 0; - touch->t = 0; - touch->vx = 0; - touch->vy = 0; - touch->x0 = touch_x; - touch->y0 = touch_y; - } else if (touch->t) { - int dt = now - touch->t; - int vx = ((int)touch_x - touch->x) * (int)(EVE_RTC_FREQ) / dt; - int vy = ((int)touch_y - touch->y) * (int)(EVE_RTC_FREQ) / dt; - touch->vx = touch->vx ? (vx + touch->vx * EVE_TOUCH_TRAVG) / (EVE_TOUCH_TRAVG + 1) : vx; - touch->vy = touch->vy ? (vy + touch->vy * EVE_TOUCH_TRAVG) / (EVE_TOUCH_TRAVG + 1) : vy; - touch->t = now; - } - touch->x = touch_x; - touch->y = touch_y; - if (touch_multi || (intr_flags & EVE_INT_TAG)) { - touch_tag = eve_read8(_reg_tag[i]); - } else { - touch_tag = touch->tag; - } - touch_ex = 1; - } else { - touch_tag = 0; - if (!(touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH)) { - uint16_t _ttevt = eve_touch_timer_get_evt(touch); - - touch_evt = EVE_TOUCH_ETYPE_POINT_UP; - touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; - if (_ttevt & EVE_TOUCH_ETYPE_LPRESS) { - eve_touch_timer_set_evt(touch, _ttevt & ~EVE_TOUCH_ETYPE_LPRESS); - } if (touch->tracker.tag && touch->tracker.track) { - uint8_t opt = touch_tag_opt[touch->tracker.tag]; - char track_ext = ((opt & EVE_TOUCH_OPT_TRACK_EXT_X) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X)) || - ((opt & EVE_TOUCH_OPT_TRACK_EXT_Y) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)); - if (!eve_touch_timer_get_evt(NULL) && track_ext) { - EVEVTrack *vtrack = eve_vtrack_get(); - - eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK); - if (vtrack->start) vtrack->start(touch, vtrack->param); + if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK; + if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG; + } + if (touch_evt & EVE_TOUCH_ETYPE_TRACK_REG) { + uint32_t touch_track = eve_touch_reg_track(i); + + if (touch->tracker.tag == (touch_track & 0xff)) { + touch->tracker.val = touch_track >> 16; } else { - touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP; + touch_evt &= ~EVE_TOUCH_ETYPE_TRACK_REG; } } - } - } - if (touch_tag != touch->tag) { - if (touch_tag) { - if (!touch_tag0) touch_tag0 = touch_tag; - if (!touch->tag0) { - touch->tag0 = touch_tag; - if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) { - touch->tracker.tag = touch_tag; - } - if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { - touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; - touch->tracker.track = 1; - touch->t = now; - } - if (!eve_touch_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) { - uint16_t _evt = 0; + } else { + if (!(touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH)) { + touch_evt |= EVE_TOUCH_ETYPE_POINT_UP; + touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; - if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS; - if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2; - eve_touch_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP); + timer_evt = eve_timer_get_evt(touch); + if (timer_evt & EVE_TOUCH_ETYPE_LPRESS) { + eve_timer_set_evt(touch, timer_evt & ~EVE_TOUCH_ETYPE_LPRESS); + } + if (touch->tracker.tag && touch->tracker.track) { + uint8_t opt = touch_tag_opt[touch->tracker.tag]; + uint8_t track_ext = ((opt & EVE_TOUCH_OPT_TRACK_EXT_X) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X)) || + ((opt & EVE_TOUCH_OPT_TRACK_EXT_Y) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)); + if (!eve_timer_get_evt(NULL) && track_ext) { + EVEVTrack *vtrack = eve_vtrack_get(); + + eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK); + if (vtrack->start) vtrack->start(touch, vtrack->param); + } else { + touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP; + } } } } - touch->tag_up = touch->tag; - if (touch->tag_up) touch_evt |= EVE_TOUCH_ETYPE_TAG_UP; - touch->tag = touch_tag; - if (touch->tag) touch_evt |= EVE_TOUCH_ETYPE_TAG; } - if (touch_xy != EVE_NOTOUCH) { - uint16_t _ttevt = eve_touch_timer_get_evt(touch); - int _track = touch->tracker.tag && !touch->tracker.track; - int _timer = _ttevt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2); - if (_track || _timer) { - int dx = touch->x - touch->x0; - int dy = touch->y - touch->y0; - dx = dx < 0 ? -dx : dx; - dy = dy < 0 ? -dy : dy; - if (_track) { - if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) { - touch->tracker.tag = 0; - } - if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) { - touch->tracker.tag = 0; - } - if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { - if (dx > EVE_TOUCH_THRESHOLD_X) { - touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; + + if (intr_flags & EVE_INT_TAG) { + uint8_t touch_tag = eve_touch_reg_tag(i); + + if (touch_tag != touch->tag) { + if (touch_tag) { + if (!touch_tag0) touch_tag0 = touch_tag; + if (!touch->tag0) { + touch->tag0 = touch_tag; + if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) { + touch->tracker.tag = touch_tag; } - if (dy > EVE_TOUCH_THRESHOLD_Y) { - touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP; + if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { + touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; + touch->tracker.track = 1; + touch->t = now; + } + if (!eve_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) { + uint16_t _evt = 0; + + if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS; + if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2; + eve_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP); } - touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; - touch->tracker.track = 1; - touch->t = now; } } - if (_timer && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { - eve_touch_timer_set_evt(touch, _ttevt & ~(EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2)); - _timer = 0; - } + touch->tag_up = touch->tag; + if (touch->tag_up) touch_evt |= EVE_TOUCH_ETYPE_TAG_UP; + touch->tag = touch_tag; + if (touch->tag) touch_evt |= EVE_TOUCH_ETYPE_TAG; } - if (touch->tracker.tag && touch->tracker.track) { - if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK; - if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG; - } - if (touch_evt & EVE_TOUCH_ETYPE_TRACK_REG) { - uint32_t touch_track = eve_read32(_reg_track[i]); - if (touch->tracker.tag == (touch_track & 0xff)) { - touch->tracker.val = touch_track >> 16; - } else { - touch_evt &= ~EVE_TOUCH_ETYPE_TRACK_REG; - } - } - if (touch->tracker.tag || _timer) int_ccomplete = 1; } + if (touch_handler && touch_evt) { touch_handler(touch, touch_evt, touch_tag0, touch_handler_param); } - if (!touch_multi) break; - } - - if (!touch_ex) { - touch_tag0 = 0; - touch_multi = 0; - } - - if (touch_multi) int_ccomplete = 1; - - if (int_ccomplete && !(intr_mask & EVE_INT_CONVCOMPLETE)) { - eve_write16(REG_INT_MASK, intr_mask | EVE_INT_CONVCOMPLETE); - } - if (!int_ccomplete && (intr_mask & EVE_INT_CONVCOMPLETE)) { - eve_write16(REG_INT_MASK, intr_mask & ~EVE_INT_CONVCOMPLETE); } } @@ -278,7 +252,7 @@ void eve_handle_time(void) { } if (more) { - eve_timer_set(touch_timer.to); + eve_sys_timer_set(touch_timer.to); } else { touch_timer.evt = 0; } @@ -289,74 +263,12 @@ void eve_handle_time(void) { } } -void eve_touch_init(int touch_calibrate, uint32_t *touch_matrix) { - /* configure 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(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_exec(1); - eve_write8(REG_PWM_DUTY, 0); - - touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A); - touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B); - touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C); - touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D); - touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E); - touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F); - } else { - eve_write32(REG_TOUCH_TRANSFORM_A, touch_matrix[0]); - eve_write32(REG_TOUCH_TRANSFORM_B, touch_matrix[1]); - eve_write32(REG_TOUCH_TRANSFORM_C, touch_matrix[2]); - eve_write32(REG_TOUCH_TRANSFORM_D, touch_matrix[3]); - eve_write32(REG_TOUCH_TRANSFORM_E, touch_matrix[4]); - eve_write32(REG_TOUCH_TRANSFORM_F, touch_matrix[5]); - } - - eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */ -} - -void eve_touch_start(void) { - uint16_t intr_mask; - int i; - - touch_multi = 0; - touch_tag0 = 0; - memset(&touch_timer, 0, sizeof(touch_timer)); - for (i=0; ieevt |= EVE_TOUCH_EETYPE_NOTOUCH; - } - eve_vtrack_init(); - - intr_mask = eve_read16(REG_INT_MASK); - eve_write16(REG_INT_MASK, intr_mask | EVE_INT_TAG | EVE_INT_TOUCH); - - eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); -} - -void eve_touch_stop(void) { - uint16_t intr_mask; - - intr_mask = eve_read16(REG_INT_MASK); - eve_write16(REG_INT_MASK, intr_mask & ~(EVE_INT_TAG | EVE_INT_TOUCH | EVE_INT_CONVCOMPLETE)); - eve_touch_timer_clear(touch_timer.touch); - - 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; } -EVETouch *eve_touch_get(int i) { +EVETouch *eve_touch_get_obj(int i) { return &touch_obj[i]; } @@ -411,46 +323,55 @@ void eve_touch_clear_opt(void) { memset(touch_tag_opt, 0, sizeof(touch_tag_opt)); } -void eve_touch_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) { +void eve_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) { touch_timer.touch = touch; touch_timer.evt = evt; touch_timer.tag0 = tag0; touch_timer.to = to; - eve_timer_set(to); + eve_sys_timer_set(to); } -void eve_touch_timer_clear(EVETouch *touch) { - eve_touch_timer_set_evt(touch, 0); +void eve_timer_clear(EVETouch *touch) { + eve_timer_set_evt(touch, 0); } -uint16_t eve_touch_timer_get_evt(EVETouch *touch) { +void eve_timer_set_evt(EVETouch *touch, uint16_t evt) { + if ((touch == NULL) || (touch == touch_timer.touch)) { + touch_timer.evt = evt; + } else if (touch_timer.touch == NULL) { + touch_timer.evt = evt; + } + if (!touch_timer.evt) { + eve_sys_timer_clear(); + touch_timer.touch = NULL; + touch_timer.tag0 = 0; + touch_timer.to = 0; + } +} + +uint16_t eve_timer_get_evt(EVETouch *touch) { uint16_t ret = 0; if ((touch == NULL) || (touch_timer.touch == touch)) { ret = touch_timer.evt; } else if (touch_timer.touch == NULL) { - ret = touch_timer.evt & EVE_TOUCH_ETYPE_TIMER; + ret = touch_timer.evt; } return ret; } -void eve_touch_timer_set_evt(EVETouch *touch, uint16_t evt) { - if (touch == touch_timer.touch) { - touch_timer.evt = evt; - } else if (touch_timer.touch == NULL) { - touch_timer.evt = evt & EVE_TOUCH_ETYPE_TIMER; - } - if (!touch_timer.evt) eve_timer_clear(); +EVETouchTimer *eve_timer_get_obj(void) { + return &touch_timer; } -void eve_touch_timer_start(uint8_t tag0, uint32_t to) { - eve_touch_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to); +void eve_timer_start(uint8_t tag0, uint32_t to) { + if (!touch_timer.evt) eve_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to); } -void eve_touch_timer_stop(void) { - eve_touch_timer_clear(NULL); +void eve_timer_stop(void) { + if (touch_timer.touch == NULL) eve_timer_clear(NULL); } -EVETouchTimer *eve_touch_timer_get(void) { - return &touch_timer; +void eve_touch_clear_tag0(void) { + touch_tag0 = 0; } diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h index b10fde2..e3e92b0 100644 --- a/fw/fe310/eos/eve/eve_touch.h +++ b/fw/fe310/eos/eve/eve_touch.h @@ -5,7 +5,6 @@ #define EVE_TOUCH_THRESHOLD_X 5 #define EVE_TOUCH_THRESHOLD_Y 5 -#define EVE_TOUCH_TRAVG 3 #define EVE_NOTAG 0 #define EVE_NOTOUCH 0x80008000 @@ -77,7 +76,7 @@ typedef struct EVETouch { int vy; int x0; int y0; - uint64_t t; + uint32_t t; uint16_t eevt; uint8_t tag0; uint8_t tag; @@ -98,15 +97,12 @@ typedef struct EVETouchTimer { typedef void (*eve_touch_handler_t) (EVETouch *, uint16_t, uint8_t, void *); +void eve_touch_init(void); void eve_handle_touch(uint16_t intr_flags); void eve_handle_time(void); -void eve_touch_init(int touch_calibrate, uint32_t *touch_matrix); -void eve_touch_start(void); -void eve_touch_stop(void); - void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param); -EVETouch *eve_touch_get(int i); +EVETouch *eve_touch_get_obj(int i); int8_t eve_touch_get_idx(EVETouch *touch); uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_min, uint8_t tag_n); @@ -114,11 +110,12 @@ void eve_touch_set_opt(uint8_t tag, uint8_t opt); uint8_t eve_touch_get_opt(uint8_t tag); void eve_touch_clear_opt(void); -void eve_touch_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to); -void eve_touch_timer_clear(EVETouch *touch); -uint16_t eve_touch_timer_get_evt(EVETouch *touch); -void eve_touch_timer_set_evt(EVETouch *touch, uint16_t evt); -void eve_touch_timer_start(uint8_t tag0, uint32_t to); -void eve_touch_timer_stop(void); +void eve_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to); +void eve_timer_clear(EVETouch *touch); +void eve_timer_set_evt(EVETouch *touch, uint16_t evt); +uint16_t eve_timer_get_evt(EVETouch *touch); +EVETouchTimer *eve_timer_get_obj(void); -EVETouchTimer *eve_touch_timer_get(void); +void eve_timer_start(uint8_t tag0, uint32_t to); +void eve_timer_stop(void); +void eve_touch_clear_tag0(void); diff --git a/fw/fe310/eos/eve/eve_vtrack.c b/fw/fe310/eos/eve/eve_vtrack.c index b9f28af..bd9158b 100644 --- a/fw/fe310/eos/eve/eve_vtrack.c +++ b/fw/fe310/eos/eve/eve_vtrack.c @@ -27,12 +27,12 @@ void eve_vtrack_reset(void) { } void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) { - eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to); + eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to); if (vtrack.start) vtrack.start(touch, vtrack.param); } void eve_vtrack_stop(EVETouch *touch) { - eve_touch_timer_clear(touch); + eve_timer_clear(touch); eve_vtrack_reset(); } @@ -44,7 +44,7 @@ void eve_vtrack_acc_start(EVETouch *touch, void *p) { int eve_vtrack_acc_tick(EVETouch *touch, void *p) { EVEPhyAcc *param = (EVEPhyAcc *)p; - return eve_phy_acc_tick(param, eve_time_get_tick() - touch->t, &touch->x, &touch->y); + return eve_phy_acc_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y); } void eve_vtrack_lho_start(EVETouch *touch, void *p) { @@ -56,10 +56,9 @@ void eve_vtrack_lho_start(EVETouch *touch, void *p) { int eve_vtrack_lho_tick(EVETouch *touch, void *p) { EVEPhyLHO *param = (EVEPhyLHO *)p; - return eve_phy_lho_tick(param, eve_time_get_tick() - touch->t, &touch->x, &touch->y); + return eve_phy_lho_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y); } void eve_vtrack_lho_stop(EVETouch *touch, void *p) { eve_vtrack_reset(); } - diff --git a/fw/fe310/eos/eve/eve_vtrack.h b/fw/fe310/eos/eve/eve_vtrack.h index b75f673..fa7e7b7 100644 --- a/fw/fe310/eos/eve/eve_vtrack.h +++ b/fw/fe310/eos/eve/eve_vtrack.h @@ -1,6 +1,6 @@ #include -#define EVE_VTRACK_ACC_A 1000 +#define EVE_VTRACK_ACC_A 10000 typedef void (*eve_vtrack_start_t) (EVETouch *, void *); typedef int (*eve_vtrack_tick_t) (EVETouch *, void *); diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c index 65dd534..28526ca 100644 --- a/fw/fe310/eos/eve/screen/page.c +++ b/fw/fe310/eos/eve/screen/page.c @@ -47,7 +47,7 @@ void eve_page_close(EVEPage *page) { if (page->lho_t0) { page->lho_t0 = 0; - eve_touch_timer_stop(); + eve_timer_stop(); } if (eve_window_scroll(window->root, NULL) == window) { eve_window_scroll_stop(window); @@ -213,8 +213,8 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0 eve_phy_lho_init(lho, lho_x, lho_y, 1000, 0.5, 0); eve_phy_lho_start(lho, page->g.x, page->g.y); - page->lho_t0 = eve_time_get_tick(); - eve_touch_timer_start(_tag, 20); + page->lho_t0 = eve_get_tick(); + eve_timer_start(_tag, 20); } } @@ -256,14 +256,14 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0 EVEPhyLHO *lho = &page->lho; int x, y, more; - more = eve_phy_lho_tick(lho, eve_time_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL); + more = eve_phy_lho_tick(lho, eve_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL); if (scroll_x) page->g.x = x; if (scroll_y) page->g.y = y; if (!more) { int _ret = 0; page->lho_t0 = 0; - eve_touch_timer_stop(); + eve_timer_stop(); page->track_mode = PAGE_TMODE_NONE; eve_window_scroll_stop(window); _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0); diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h index 26c33c5..0fc9809 100644 --- a/fw/fe310/eos/eve/screen/page.h +++ b/fw/fe310/eos/eve/screen/page.h @@ -26,7 +26,7 @@ typedef struct EVEPage { uint16_t widget_size; struct EVEWidget *widget_f; EVEPhyLHO lho; - uint64_t lho_t0; + uint32_t lho_t0; uint8_t track_mode; uint8_t opt; } EVEPage; diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c index e78cf46..55eeca4 100644 --- a/fw/fe310/eos/eve/widget/strw.c +++ b/fw/fe310/eos/eve/widget/strw.c @@ -71,6 +71,7 @@ int eve_strw_update(EVEStrWidget *widget) { widget->str[str_len] = '\0'; } widget->str_len = str_len; + widget->str_g.w = eve_font_str_w(widget->font, widget->str); return (rv == UTF_OK) ? EVE_OK : EVE_ERR; } @@ -305,7 +306,6 @@ void eve_strw_putc(void *w, int c) { int ins_c = 0, del_c = 0; int ins_w = 0, del_w = 0; - if (c == EVE_PAGE_KBDCH_CLOSE) { if (cursor1->on) eve_strw_cursor_clear(widget, cursor1); if (cursor2->on) eve_strw_cursor_clear(widget, cursor2); diff --git a/fw/fe310/eos/eve_eos.c b/fw/fe310/eos/eve_eos.c new file mode 100644 index 0000000..351cd79 --- /dev/null +++ b/fw/fe310/eos/eve_eos.c @@ -0,0 +1,149 @@ +#include +#include + +#include "platform.h" + +#include "eos.h" +#include "interrupt.h" +#include "event.h" +#include "pwr.h" + +#include "board.h" + +#include "eve/eve.h" +#include "eve/eve_touch_engine.h" + +#include "eve_eos.h" + +static int _run; + +static void handle_time(unsigned char type) { + if (_run) { + eve_spi_start(); + eve_handle_time(); + eve_spi_stop(); + } +} + +static void handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + if (_run) { + eve_spi_start(); + eve_handle_intr(); + eve_spi_stop(); + + GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR); + } +} + +static void handle_intr(void) { + GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR); + GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INTR); + eos_evtq_push_isr(EOS_EVT_EVE | EVE_ETYPE_INTR, NULL, 0); +} + + +static void _start(void) { + eve_touch_start(); + 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_touch_stop(); + eve_stop(); +} + +int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, const uint32_t *touch_matrix) { + int rst = (wakeup_cause == EOS_PWR_WAKE_RST); + int rv = EVE_OK; + + eve_spi_start(); + if (rst) { + rv = eve_init(gpio_dir); + if (!rv) eve_touch_init_engine(touch_matrix); + } else { + eve_activate(); + } + eve_spi_stop(); + + if (rv) return EOS_ERR; + + eve_touch_init(); + + eos_evtq_set_handler(EOS_EVT_EVE, handle_evt); + eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time); + eos_intr_set_handler(INT_GPIO_BASE + EVE_PIN_INTR, handle_intr); + eos_intr_set_priority(INT_GPIO_BASE + EVE_PIN_INTR, IRQ_PRIORITY_EVE); + + return EOS_OK; +} + +void eos_eve_calibrate(void) { + uint32_t touch_matrix[6]; + int r; + + eve_spi_start(); + + eve_brightness(0x40); + eve_touch_set_extended(0); + + 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_exec(0); + + do { + r = eve_cmd_done(); + if (r < 0) break; + eve_spi_stop(); + eos_evtq_exec(); + eve_spi_start(); + } while (!r); + + eve_touch_set_extended(1); + eve_brightness(0); + + touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A); + touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B); + touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C); + touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D); + touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E); + touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F); + + eve_spi_stop(); + + 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]); +} + +int eos_eve_run(uint8_t wakeup_cause) { + eve_spi_start(); + _start(); + eve_start_clk(); + eve_spi_stop(); + + return EOS_OK; +} + +void eos_eve_start(void) { + eve_spi_start(); + _start(); + eve_spi_stop(); +} + +void eos_eve_stop(void) { + eve_spi_start(); + _stop(); + eve_spi_stop(); +} diff --git a/fw/fe310/eos/eve_eos.h b/fw/fe310/eos/eve_eos.h new file mode 100644 index 0000000..47b326e --- /dev/null +++ b/fw/fe310/eos/eve_eos.h @@ -0,0 +1,7 @@ +#include + +int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, const uint32_t *touch_matrix); +void eos_eve_calibrate(void); +int eos_eve_run(uint8_t wakeup_cause); +void eos_eve_start(void); +void eos_eve_stop(void); diff --git a/fw/fe310/eos/event.c b/fw/fe310/eos/event.c index 753cdb4..f76384a 100644 --- a/fw/fe310/eos/event.c +++ b/fw/fe310/eos/event.c @@ -121,22 +121,28 @@ void eos_evtq_flush_isr(void) { } void eos_evtq_loop(void) { + int foo = 1; + + while(foo) { + eos_evtq_exec(); + } +} + +void eos_evtq_exec(void) { unsigned char type; unsigned char *buffer; uint16_t len; - int foo = 1; - while(foo) { - clear_csr(mstatus, MSTATUS_MIE); - eos_msgq_pop(&_eos_event_q, &type, &buffer, &len); - if (type) { - set_csr(mstatus, MSTATUS_MIE); - evt_handler[0](type, buffer, len); - } else { - asm volatile ("wfi"); - set_csr(mstatus, MSTATUS_MIE); - } + clear_csr(mstatus, MSTATUS_MIE); + eos_msgq_pop(&_eos_event_q, &type, &buffer, &len); + if (type) { + set_csr(mstatus, MSTATUS_MIE); + evt_handler[0](type, buffer, len); + } else { + asm volatile ("wfi"); + set_csr(mstatus, MSTATUS_MIE); } + } void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len) { diff --git a/fw/fe310/eos/event.h b/fw/fe310/eos/event.h index 82043f4..9501a15 100644 --- a/fw/fe310/eos/event.h +++ b/fw/fe310/eos/event.h @@ -15,6 +15,7 @@ void eos_evtq_wait(unsigned char type, unsigned char *selector, uint16_t sel_len void eos_evtq_flush(void); void eos_evtq_flush_isr(void); void eos_evtq_loop(void); +void eos_evtq_exec(void); void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len); void eos_evtq_set_handler(unsigned char type, eos_evt_handler_t handler); diff --git a/fw/fe310/eos/evt_def.h b/fw/fe310/eos/evt_def.h index 16c4255..e34b2d2 100644 --- a/fw/fe310/eos/evt_def.h +++ b/fw/fe310/eos/evt_def.h @@ -3,7 +3,8 @@ #define EOS_EVT_NET 0x30 #define EOS_EVT_SPI 0x40 #define EOS_EVT_UART 0x50 -#define EOS_EVT_UI 0x60 +#define EOS_EVT_EVE 0x60 +#define EOS_EVT_CTP 0x70 #define EOS_EVT_USER 0x80 #define EOS_EVT_MAX_EVT 8 diff --git a/fw/fe310/eos/i2c/Makefile b/fw/fe310/eos/i2c/Makefile index 97e4f12..83cb1f5 100644 --- a/fw/fe310/eos/i2c/Makefile +++ b/fw/fe310/eos/i2c/Makefile @@ -1,6 +1,7 @@ include ../../common.mk +CFLAGS += -I$(bsp_dir)/include -obj = bq25895.o ov2640.o +obj = bq25895.o ov2640.o gt911.o %.o: %.c %.h diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c index 570e9a0..b290926 100644 --- a/fw/fe310/eos/i2c/bq25895.c +++ b/fw/fe310/eos/i2c/bq25895.c @@ -5,7 +5,7 @@ #include "eos.h" #include "pwr.h" #include "i2c.h" -#include "i2c/bq25895.h" +#include "bq25895.h" static int reg_read(uint8_t reg, uint8_t *data) { return eos_i2c_read8(BQ25895_ADDR, reg, data, 1); diff --git a/fw/fe310/eos/irq_def.h b/fw/fe310/eos/irq_def.h index 5d9fb1e..ea3e7a8 100644 --- a/fw/fe310/eos/irq_def.h +++ b/fw/fe310/eos/irq_def.h @@ -8,4 +8,5 @@ #define IRQ_PRIORITY_UART 1 -#define IRQ_PRIORITY_UI 5 +#define IRQ_PRIORITY_EVE 5 +#define IRQ_PRIORITY_CTP 5 diff --git a/fw/fe310/eos/lcd.c b/fw/fe310/eos/lcd.c index cf09018..3080a13 100644 --- a/fw/fe310/eos/lcd.c +++ b/fw/fe310/eos/lcd.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include "encoding.h" #include "platform.h" @@ -91,62 +93,84 @@ void eos_lcd_read(uint8_t *data) { static int _init(void) { int rv; + uint8_t chip_id[3]; 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(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(0, 0x08); // Output SDA // eos_lcd_write(1, 0x10); - eos_lcd_write(0, 0x20); // set DE/VSYNC mode + eos_lcd_write(0, 0xFE); // enable read + eos_lcd_write(1, 0x81); + + eos_lcd_write(0, 0x00); // RDID4 + eos_lcd_read(&chip_id[0]); + + eos_lcd_write(0, 0x01); + eos_lcd_read(&chip_id[1]); + + eos_lcd_write(0, 0x02); + eos_lcd_read(&chip_id[2]); + + printf("LCD CHIP ID: %.2x%.2x%.2x\n", chip_id[0], chip_id[1], chip_id[2]); + + eos_lcd_write(0, 0xFE); // disable read + eos_lcd_write(1, 0x00); + + if (memcmp(chip_id, "\x98\x06\x04", sizeof(chip_id))) { + return EOS_ERR_ABSENT; + } + + 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(0, 0x21); // DE = 1 Active eos_lcd_write(1, 0x01); - eos_lcd_write(0, 0x30); // resolution setting 480 X 854 + 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(0, 0x31); // inversion setting 2-dot eos_lcd_write(1, 0x00); - eos_lcd_write(0, 0x40); // BT AVDD,AVDD + 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(1, 0x33); // 22 eos_lcd_write(0, 0x42); - eos_lcd_write(1, 0x03); // VGL=DDVDH+VCIP-DDVDL, VGH=2DDVDL-VCIP + 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(1, 0x09); // set VGH clamp level eos_lcd_write(0, 0x44); - eos_lcd_write(1, 0x06); // set VGL clamp level + eos_lcd_write(1, 0x06); // set VGL clamp level - eos_lcd_write(0, 0x50); // VREG1 + eos_lcd_write(0, 0x50); // VREG1 eos_lcd_write(1, 0x88); - eos_lcd_write(0, 0x51); // VREG2 + eos_lcd_write(0, 0x51); // VREG2 eos_lcd_write(1, 0x88); - eos_lcd_write(0, 0x52); // flicker MSB + 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, 0x53); // flicker LSB + eos_lcd_write(1, 0x49); // VCOM - eos_lcd_write(0, 0x55); // flicker + eos_lcd_write(0, 0x55); // flicker eos_lcd_write(1, 0x49); eos_lcd_write(0, 0x60); @@ -162,7 +186,7 @@ static int _init(void) { eos_lcd_write(1, 0x00); /* Gamma Setting */ - eos_lcd_write(0, 0xA0); // positive Gamma + eos_lcd_write(0, 0xA0); // positive Gamma eos_lcd_write(1, 0x00); eos_lcd_write(0, 0xA1); @@ -210,7 +234,7 @@ static int _init(void) { eos_lcd_write(0, 0xAF); eos_lcd_write(1, 0x00); - eos_lcd_write(0, 0xC0); // negative Gamma + eos_lcd_write(0, 0xC0); // negative Gamma eos_lcd_write(1, 0x00); eos_lcd_write(0, 0xC1); @@ -258,7 +282,7 @@ static int _init(void) { 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(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); @@ -430,7 +454,7 @@ static int _init(void) { 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(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); @@ -446,7 +470,7 @@ static int _init(void) { 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(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); @@ -454,7 +478,7 @@ static int _init(void) { eos_lcd_write(1, 0x00); eos_lcd_write(0, 0x3A); - eos_lcd_write(1, 0x70); // 24BIT + eos_lcd_write(1, 0x70); // 24BIT eos_lcd_write(0, 0x11); eos_time_sleep(120); diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c index e10414c..33b71c2 100644 --- a/fw/fe310/eos/net.c +++ b/fw/fe310/eos/net.c @@ -213,6 +213,7 @@ static void net_handle_cts(void) { static void net_handle_rts(void) { uint32_t rts_offset = (1 << NET_PIN_RTS); + if (GPIO_REG(GPIO_RISE_IP) & rts_offset) { GPIO_REG(GPIO_RISE_IP) = rts_offset; net_state_flags |= NET_STATE_FLAG_RTS; diff --git a/fw/fe310/eos/pwr.c b/fw/fe310/eos/pwr.c index f42249d..802e593 100644 --- a/fw/fe310/eos/pwr.c +++ b/fw/fe310/eos/pwr.c @@ -48,7 +48,7 @@ int eos_pwr_sleep(void) { if (rv) return rv; eos_spi_select(EOS_SPI_DEV_EVE); - eve_sleep(); + eve_pwr_sleep(); eos_spi_deselect(); rv = eos_net_sleep(1000); diff --git a/fw/fe310/eos/sdc_crypto.c b/fw/fe310/eos/sdc_crypto.c index c094468..f0e935d 100644 --- a/fw/fe310/eos/sdc_crypto.c +++ b/fw/fe310/eos/sdc_crypto.c @@ -48,4 +48,4 @@ void eos_sdcc_decrypt(uint32_t sect, uint8_t *buffer) { memcpy(iv, §, sizeof(sect)); sdc_crypto->enc_essiv(sdc_crypto->ctx_essiv, iv); sdc_crypto->dec(sdc_crypto->ctx, iv, buffer, 512); -} \ No newline at end of file +} diff --git a/fw/fe310/eos/sdcard.c b/fw/fe310/eos/sdcard.c index 6f5488d..d081388 100644 --- a/fw/fe310/eos/sdcard.c +++ b/fw/fe310/eos/sdcard.c @@ -94,8 +94,8 @@ static uint16_t sdc_crc16(uint16_t crc, uint8_t b) { return crc; } -static uint32_t sdc_nto(uint64_t start, uint32_t timeout) { - uint32_t d = eos_time_since(start); +static uint32_t sdc_nto(uint32_t start, uint32_t timeout) { + uint32_t d = eos_time_delta_ms(start); return (d > timeout) ? 0 : timeout - d; } @@ -167,12 +167,12 @@ static int sdc_xchg_cmd(uint8_t cmd, uint32_t arg, uint8_t flags) { static int sdc_ready(uint32_t timeout) { uint8_t d = 0; - uint64_t start; + uint32_t start; if (timeout == 0) return EOS_ERR_BUSY; start = eos_time_get_tick(); do { - if (eos_time_since(start) > timeout) break; + if (eos_time_delta_ms(start) > timeout) break; d = sdc_xchg8(0xff); } while (d != 0xff); if (d != 0xff) return EOS_ERR_BUSY; @@ -182,12 +182,12 @@ static int sdc_ready(uint32_t timeout) { static int sdc_block_read(uint8_t *buffer, uint16_t len, uint32_t timeout) { uint8_t token = 0xff; - uint64_t start; + uint32_t start; if (timeout == 0) return EOS_ERR_BUSY; start = eos_time_get_tick(); do { - if (eos_time_since(start) > timeout) break; + if (eos_time_delta_ms(start) > timeout) break; token = sdc_xchg8(0xff); } while (token == 0xff); if (token == 0xff) return EOS_ERR_BUSY; @@ -236,7 +236,7 @@ static int sdc_cmd(uint8_t cmd, uint32_t arg, uint8_t flags, uint32_t timeout) { static int sdc_acmd(uint8_t cmd, uint32_t arg, uint8_t flags, uint32_t timeout) { int rv; - uint64_t start; + uint32_t start; start = eos_time_get_tick(); rv = sdc_cmd(APP_CMD, 0, flags, timeout); @@ -253,7 +253,7 @@ static int sdc_init(uint32_t timeout) { int rv, i; uint8_t _type; uint8_t ocr[4]; - uint64_t start; + uint32_t start; start = eos_time_get_tick(); eos_time_sleep(100); @@ -378,7 +378,7 @@ uint8_t eos_sdc_cap(void) { int eos_sdc_get_sect_count(uint32_t timeout, uint32_t *sectors) { int rv; uint8_t csd[16]; - uint64_t start = eos_time_get_tick(); + uint32_t start = eos_time_get_tick(); sdc_select(); rv = sdc_cmd(SEND_CSD, 0, SDC_CMD_FLAG_NOCS, timeout); @@ -404,7 +404,7 @@ int eos_sdc_get_sect_count(uint32_t timeout, uint32_t *sectors) { int eos_sdc_get_blk_size(uint32_t timeout, uint32_t *size) { int rv; uint8_t rbl[64]; /* SD Status or CSD register */ - uint64_t start = eos_time_get_tick(); + uint32_t start = eos_time_get_tick(); sdc_select(); if (sdc_type & EOS_SDC_TYPE_SDC2) { @@ -444,7 +444,7 @@ int eos_sdc_sync(uint32_t timeout) { int eos_sdc_erase(uint32_t blk_start, uint32_t blk_end, uint32_t timeout) { int rv; - uint64_t start; + uint32_t start; if (!(sdc_type & EOS_SDC_TYPE_SDC)) return EOS_ERR; if (!(sdc_type & EOS_SDC_CAP_ERASE_EN)) return EOS_ERR; @@ -468,11 +468,9 @@ int eos_sdc_erase(uint32_t blk_start, uint32_t blk_end, uint32_t timeout) { int eos_sdc_sect_read(uint32_t sect, unsigned int count, uint8_t *buffer) { int rv; - uint64_t start; uint8_t cmd = ((count == 1) ? READ_SINGLE_BLOCK : READ_MULTIPLE_BLOCK); if (!(sdc_type & EOS_SDC_CAP_BLK)) sect *= 512; - start = eos_time_get_tick(); sdc_select(); rv = sdc_cmd(cmd, sect, SDC_CMD_FLAG_NOCS, SDC_TIMEOUT_CMD); @@ -498,10 +496,8 @@ int eos_sdc_sect_read(uint32_t sect, unsigned int count, uint8_t *buffer) { int eos_sdc_sect_write(uint32_t sect, unsigned int count, uint8_t *buffer) { int rv; - uint64_t start; if (!(sdc_type & EOS_SDC_CAP_BLK)) sect *= 512; - start = eos_time_get_tick(); if (count == 1) { sdc_select(); diff --git a/fw/fe310/eos/timer.c b/fw/fe310/eos/timer.c index 5ae58da..91861a3 100644 --- a/fw/fe310/eos/timer.c +++ b/fw/fe310/eos/timer.c @@ -32,7 +32,7 @@ void _eos_timer_handle(void) { uint64_t now = *mtime; uint64_t next = 0; - for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) { + for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) { if (timer_next[i] && (timer_next[i] <= now)) { timer_next[i] = 0; if (i == 0) { @@ -88,7 +88,7 @@ uint32_t eos_timer_get(unsigned char evt) { return ret; } -void eos_timer_set(uint32_t msec, unsigned char evt) { +void eos_timer_set(unsigned char evt, uint32_t msec) { int i; volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME); uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP); @@ -97,7 +97,7 @@ void eos_timer_set(uint32_t msec, unsigned char evt) { if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP); timer_next[evt] = tick; - for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) { + for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) { next = next && timer_next[i] ? MIN(next, timer_next[i]) : (next ? next : timer_next[i]); } *mtimecmp = next; @@ -112,7 +112,7 @@ void eos_timer_clear(unsigned char evt) { if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP); if (timer_next[evt]) { timer_next[evt] = 0; - for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) { + for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) { next = next && timer_next[i] ? MIN(next, timer_next[i]) : (next ? next : timer_next[i]); } *mtimecmp = next; @@ -120,12 +120,11 @@ void eos_timer_clear(unsigned char evt) { if (*mtimecmp != 0) set_csr(mie, MIP_MTIP); } - void eos_time_sleep(uint32_t msec) { volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME); - uint64_t now_ms = *mtime * 1000 / EOS_TIMER_RTC_FREQ; + uint64_t mtime0 = *mtime; - while (*mtime * 1000 / EOS_TIMER_RTC_FREQ < now_ms + msec); + while ((*mtime - mtime0) < (msec * EOS_TIMER_RTC_FREQ / 1000 + 1)); } uint64_t eos_time_get_tick(void) { @@ -133,6 +132,6 @@ uint64_t eos_time_get_tick(void) { return *mtime; } -uint32_t eos_time_since(uint32_t start) { - return (eos_time_get_tick() - start) * 1000 / EOS_TIMER_RTC_FREQ; - } +uint32_t eos_time_delta_ms(uint32_t tick) { + return ((uint32_t)eos_time_get_tick() - tick) * 1000 / EOS_TIMER_RTC_FREQ; +} diff --git a/fw/fe310/eos/timer.h b/fw/fe310/eos/timer.h index e479483..0309454 100644 --- a/fw/fe310/eos/timer.h +++ b/fw/fe310/eos/timer.h @@ -6,7 +6,7 @@ #define EOS_TIMER_MAX_ETYPE 4 -#define EOS_TIMER_NONE 0xffffffff +#define EOS_TIMER_NONE -1 #define EOS_TIMER_RTC_FREQ 32768 typedef void (*eos_timer_handler_t) (unsigned char); @@ -15,9 +15,9 @@ int eos_timer_init(uint8_t wakeup_cause); void eos_timer_set_handler(unsigned char evt, eos_timer_handler_t handler); uint32_t eos_timer_get(unsigned char evt); -void eos_timer_set(uint32_t msec, unsigned char evt); +void eos_timer_set(unsigned char evt, uint32_t msec); void eos_timer_clear(unsigned char evt); void eos_time_sleep(uint32_t msec); uint64_t eos_time_get_tick(void); -uint32_t eos_time_since(uint32_t start); +uint32_t eos_time_delta_ms(uint32_t tick); diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile index 236217f..323bce0 100644 --- a/fw/fe310/test/Makefile +++ b/fw/fe310/test/Makefile @@ -1,9 +1,9 @@ include ../common.mk -CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto -I$(ext_dir)/fsfat -I$(ecp_dir)/src -I$(ecp_dir)/src/platform/fe310 -I.. +CFLAGS += -DECP_WITH_VCONN=1 -DECP_WITH_DIR=1 -DECP_DEBUG=1 -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto -I$(ext_dir)/fsfat -I$(ecp_dir)/src -I$(ecp_dir)/src/platform/fe310 -I.. LDFLAGS = app/*.o $(CFLAGS) -L.. -L$(ecp_dir)/build-fe310 -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -lecp -lecpcr -lecptr -lecptm -lecpdir -lecpvconn -Wl,--end-group -T../bsp/default.lds DEPS = main.o mem.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o cam.o fs.o test.o -# DEPS += ecp.o ecp_init.o audio.o +# DEPS += ecp2.o ecp_init.o audio.o TARGET = phone diff --git a/fw/fe310/test/app/app_root.c b/fw/fe310/test/app/app_root.c index 7dda3c7..e6de2d1 100644 --- a/fw/fe310/test/app/app_root.c +++ b/fw/fe310/test/app/app_root.c @@ -16,7 +16,7 @@ #include "app_root.h" #define KBD_X 0 -#define KBD_Y 575 +#define KBD_Y 629 #define KBD_W 480 #define KBD_H 225 @@ -84,5 +84,5 @@ void app_root_init(eve_view_constructor_t home_page, int b) { eve_spi_stop(); - eos_net_acquire_for_evt(EOS_EVT_UI | EVE_ETYPE_INTR, 1); + eos_net_acquire_for_evt(EOS_EVT_EVE | EVE_ETYPE_INTR, 1); } diff --git a/fw/fe310/test/app/app_root.h b/fw/fe310/test/app/app_root.h index b085344..35f889f 100644 --- a/fw/fe310/test/app/app_root.h +++ b/fw/fe310/test/app/app_root.h @@ -1,7 +1,7 @@ #include #define APP_SCREEN_W 480 -#define APP_SCREEN_H 800 +#define APP_SCREEN_H 854 #define APP_STATUS_H 60 #define APP_FONT_HANDLE 31 diff --git a/fw/fe310/test/fs.c b/fw/fe310/test/fs.c index 222833b..1dce3af 100644 --- a/fw/fe310/test/fs.c +++ b/fw/fe310/test/fs.c @@ -100,5 +100,30 @@ void app_fs_init(void) { rv = f_mount(&fs, "", 1); printf("f_mount:%d\n", rv); } + + if (rv == FR_OK) { + FIL f; + UINT w; + char *msg = "PERA JE CAR!"; + + rv = f_open(&f, TEXT_FN, FA_READ); + printf("f_open:%d\n", rv); + if (!rv) { + UINT r; + char _msg[TEXT_SIZE]; + + memset(_msg, 0, sizeof(_msg)); + rv = f_read(&f, _msg, sizeof(_msg), &r); + printf("f_read:%d %u %s\n", rv, r, _msg); + f_close(&f); + } else { + rv = f_open(&f, TEXT_FN, FA_WRITE | FA_CREATE_ALWAYS); + printf("f_open:%d\n", rv); + rv = f_write(&f, msg, strlen(msg), &w); + printf("f_write:%d\n", rv); + } + f_close(&f); + + } eos_spi_deselect(); } \ No newline at end of file diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c index 52d281b..36ad5b8 100644 --- a/fw/fe310/test/main.c +++ b/fw/fe310/test/main.c @@ -32,6 +32,8 @@ #include "ecp.h" #include "test.h" +const uint32_t _eos_touch_matrix[6] = {0xf7ac,0x440,0x3e704,0xfffff718,0x108a3,0xfff76d42}; + void app_home_page(EVEWindow *window, EVEViewStack *stack) { EVEWidgetSpec spec[] = { /* @@ -65,13 +67,13 @@ 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, @@ -80,22 +82,26 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) { }, }; - EVEForm *form = eve_form_create(window, stack, spec, 1, NULL, NULL, NULL); + EVEForm *form = eve_form_create(window, stack, spec, 2, NULL, NULL, NULL); } void print_mem(void); int main() { eos_init(); + // eos_run_once(); + printf("FREQ:%lu\n", PRCI_get_cpu_freq()); printf("\nREADY.\n"); - app_root_init(app_home_page, 0x20); - // app_phone_init(); - // app_wifi_init(); - // app_cell_dev_init(); - // app_cell_pdp_init(); - // app_fs_init(); + app_root_init(app_home_page, 0x10); + app_phone_init(); + app_wifi_init(); + app_cell_dev_init(); + app_cell_pdp_init(); + app_fs_init(); + // audio_start(); + // app_ecp_init(); eos_evtq_loop(); } -- cgit v1.2.3