From 15bddabc5cbe0e751fadcaaa7f7c7c36bca61331 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 28 Jan 2020 19:25:20 +0100 Subject: eve logng press event added --- code/fe310/eos/eve.c | 96 +++++++++++++++++++++++++++++++++++--------------- code/fe310/eos/eve.h | 1 + code/fe310/eos/event.c | 14 +++++--- code/fe310/eos/event.h | 4 +-- code/fe310/eos/i2s.c | 6 ++-- code/fe310/eos/net.c | 6 ++-- code/fe310/eos/net.h | 2 +- code/fe310/eos/spi.c | 4 +-- code/fe310/eos/timer.c | 8 +++-- code/fe310/eos/timer.h | 6 ++-- code/fe310/eos/uart.c | 4 +-- 11 files changed, 103 insertions(+), 48 deletions(-) (limited to 'code/fe310/eos') diff --git a/code/fe310/eos/eve.c b/code/fe310/eos/eve.c index 3766355..22af7d7 100644 --- a/code/fe310/eos/eve.c +++ b/code/fe310/eos/eve.c @@ -20,6 +20,9 @@ #define EVE_ETYPE_INT 1 +#define EVE_MOVE_THRESHOLD 10 +#define EVE_LPRESS_TIMEOUT 1000 + static char eve_cmd_burst; static uint16_t eve_cmd_offset; static uint32_t eve_dl_addr; @@ -28,6 +31,8 @@ static int eve_int_mask = EVE_INT_TAG | EVE_INT_TOUCH; static int eve_multitouch = 0; static uint8_t eve_tag0; static EOSTouch eve_touch[5]; +static uint64_t eve_touch_timer_t0; +static uint8_t eve_touch_timer_tag; static uint8_t eve_tag_evt[256]; static eos_eve_fptr_t eve_renderer; @@ -283,31 +288,12 @@ void eos_eve_cmd_burst_end(void) { eve_cmd_burst = 0; } -static void eve_handler_int(void) { - GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INT); - eos_evtq_push_isr(EOS_EVT_UI | EVE_ETYPE_INT, NULL, 0); - return; -} - -static void eve_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { +static void eve_handle_touch(uint8_t flags) { int i; - uint8_t flags; uint8_t tag0 = eve_tag0; uint8_t touch_last = 0; char touch_ex = 0; char int_ccomplete = 0; - - eos_spi_dev_start(EOS_SPI_DEV_DISP); - flags = eos_eve_read8(REG_INT_FLAGS) & eve_int_mask; - /* - if (flags == 0) { - GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INT); - GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INT); - eos_spi_dev_stop(); - return; - } - */ - if (!eve_multitouch && (flags & EVE_INT_TOUCH)) eve_multitouch = 1; for (i=0; ievt &= EOS_TOUCH_ETYPE_TRACK_MASK; + touch->evt &= (EOS_TOUCH_ETYPE_LPRESS | EOS_TOUCH_ETYPE_TRACK_MASK); touch_xy = i < 4 ? eos_eve_read32(_reg_touch[i]) : (((uint32_t)eos_eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eos_eve_read16(REG_CTOUCH_TOUCH4_Y)); @@ -343,14 +329,20 @@ static void eve_handler_evt(unsigned char type, unsigned char *buffer, uint16_t if (touch_tag) { if (!eve_tag0) tag0 = eve_tag0 = touch_tag; if (!touch->tag0) { - printf("TAG0:%x\n", touch_tag); touch->tag0 = touch_tag; - touch->evt |= eve_tag_evt[touch->tag0] & EOS_TOUCH_ETYPE_TRACK_MASK; + touch->evt |= eve_tag_evt[touch_tag] & EOS_TOUCH_ETYPE_TRACK_MASK; if (touch->evt & EOS_TOUCH_ETYPE_TRACK_MASK) { - touch->tracker.tag = touch_tag; + if (touch->evt & EOS_TOUCH_ETYPE_TRACK) touch->tracker.tag = touch_tag; } else { touch->evt |= eve_tag_evt[0xff] & EOS_TOUCH_ETYPE_TRACK_MASK; - if (touch->evt & EOS_TOUCH_ETYPE_TRACK_MASK) touch->tracker.tag = 0xff; + if (touch->evt & EOS_TOUCH_ETYPE_TRACK) touch->tracker.tag = 0xff; + } + if (((eve_tag_evt[touch_tag] | eve_tag_evt[0xff]) & EOS_TOUCH_ETYPE_LPRESS) && (i == 0)) { + volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME); + + eve_touch_timer_t0 = *mtime; + eve_touch_timer_tag = eve_tag_evt[touch_tag] & EOS_TOUCH_ETYPE_LPRESS ? touch_tag : 0xff; + eos_timer_set(EVE_LPRESS_TIMEOUT, EOS_TIMER_ETYPE_UI, 0); } } } @@ -364,6 +356,15 @@ static void eve_handler_evt(unsigned char type, unsigned char *buffer, uint16_t touch->tracker.tag = touch_track & 0xffff; touch->tracker.val = touch_track >> 16; } + if (eve_touch_timer_tag && (i == 0)) { + uint16_t dx = touch->x > touch->x0 ? touch->x - touch->x0 : touch->x0 - touch->x; + uint16_t dy = touch->y > touch->y0 ? touch->y - touch->y0 : touch->y0 - touch->y; + if ((dx > EVE_MOVE_THRESHOLD) || (dy > EVE_MOVE_THRESHOLD)) { + eos_timer_clear(EOS_TIMER_ETYPE_UI); + eve_touch_timer_t0 = 0; + eve_touch_timer_tag = 0; + } + } if (touch->evt) { touch_last = i + 1; if (touch->evt & EOS_TOUCH_ETYPE_TRACK_MASK) int_ccomplete = 1; @@ -400,13 +401,44 @@ static void eve_handler_evt(unsigned char type, unsigned char *buffer, uint16_t touch->tag_down = 0; touch->tracker.tag = 0; touch->tracker.val = 0; + if (eve_touch_timer_tag && (i == 0)) { + eos_timer_clear(EOS_TIMER_ETYPE_UI); + eve_touch_timer_t0 = 0; + eve_touch_timer_tag = 0; + } } } } +} + +static void eve_handler_time(unsigned char type) { + eve_touch[0].evt |= EOS_TOUCH_ETYPE_LPRESS; + + eos_spi_dev_start(EOS_SPI_DEV_DISP); + eve_handle_touch(0); + eos_spi_dev_stop(); + + eve_touch[0].evt &= ~EOS_TOUCH_ETYPE_LPRESS; + eve_touch_timer_t0 = 0; + eve_touch_timer_tag = 0; +} + +static void eve_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) { + uint8_t flags; + + eos_spi_dev_start(EOS_SPI_DEV_DISP); + flags = eos_eve_read8(REG_INT_FLAGS) & eve_int_mask; + eve_handle_touch(flags); + eos_spi_dev_stop(); GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INT); GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INT); - eos_spi_dev_stop(); +} + +static void eve_handler_int(void) { + GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INT); + eos_evtq_push_isr(EOS_EVT_UI | EVE_ETYPE_INT, NULL, 0); + return; } int eos_eve_init(void) { @@ -508,7 +540,8 @@ int eos_eve_init(void) { touch->x = 0x8000; touch->y = 0x8000; } - eos_evtq_set_handler(EOS_EVT_UI, eve_handler_evt); + eos_evtq_set_handler(EOS_EVT_UI, eve_handler_evt, 0); + eos_timer_set_handler(EOS_TIMER_ETYPE_UI, eve_handler_time, 0); GPIO_REG(GPIO_INPUT_EN) |= (1 << EVE_PIN_INT); GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << EVE_PIN_INT); @@ -523,7 +556,8 @@ int eos_eve_init(void) { void eos_eve_set_renderer(eos_eve_fptr_t renderer, uint8_t flags) { eve_renderer = renderer; - eos_evtq_set_flags(EOS_EVT_UI | EVE_ETYPE_INT, flags); + eos_evtq_set_hflags(EOS_EVT_UI | EVE_ETYPE_INT, flags); + eos_timer_set_hflags(EOS_TIMER_ETYPE_UI, flags); } EOSTouch *eos_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_max, uint8_t *evt) { @@ -538,6 +572,8 @@ EOSTouch *eos_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t ta if ((tag0 < tag_min) || (tag0 > tag_max)) return ret; _evt = ret->evt; + if (tag0 == 0xff) *evt |= _evt & EOS_TOUCH_ETYPE_POINT_MASK; + if (_evt & EOS_TOUCH_ETYPE_TAG_UP) { _tag = ret->tag_up; if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EOS_TOUCH_ETYPE_TAG_UP; @@ -554,6 +590,10 @@ EOSTouch *eos_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t ta _tag = ret->tracker.tag; if ((_tag >= tag_min) && (_tag <= tag_max) && (_tag == ret->tag0)) *evt |= EOS_TOUCH_ETYPE_TRACK_REG; } + if (_evt & EOS_TOUCH_ETYPE_LPRESS) { + _tag = eve_touch_timer_tag; + if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EOS_TOUCH_ETYPE_LPRESS; + } return ret; } diff --git a/code/fe310/eos/eve.h b/code/fe310/eos/eve.h index 3e76b92..71435e7 100644 --- a/code/fe310/eos/eve.h +++ b/code/fe310/eos/eve.h @@ -4,6 +4,7 @@ #define EOS_TOUCH_ETYPE_TRACK 0x01 #define EOS_TOUCH_ETYPE_TRACK_REG 0x02 +#define EOS_TOUCH_ETYPE_LPRESS 0x04 #define EOS_TOUCH_ETYPE_POINT_UP 0x10 #define EOS_TOUCH_ETYPE_POINT_DOWN 0x20 #define EOS_TOUCH_ETYPE_TAG_UP 0x40 diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c index df75ad4..bf11729 100644 --- a/code/fe310/eos/event.c +++ b/code/fe310/eos/event.c @@ -78,17 +78,23 @@ static void evtq_handler(unsigned char type, unsigned char *buffer, uint16_t len } } -void eos_evtq_set_handler(unsigned char type, eos_evt_fptr_t handler) { +void eos_evtq_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags) { unsigned char idx = ((type & EOS_EVT_MASK) >> 4) - 1; - if (idx < EOS_EVT_MAX_EVT) evt_handler[idx] = handler; + if (idx < EOS_EVT_MAX_EVT) { + evt_handler[idx] = handler; + eos_evtq_set_hflags(type, flags); + } } -void eos_evtq_set_flags(unsigned char type, uint8_t flags) { +void eos_evtq_set_hflags(unsigned char type, uint8_t flags) { unsigned char idx = ((type & EOS_EVT_MASK) >> 4) - 1; uint16_t flag = type & ~EOS_EVT_MASK ? (uint16_t)1 << ((type & ~EOS_EVT_MASK) - 1) : 0xFFFF; - if ((idx < EOS_EVT_MAX_EVT) && (flags & EOS_NET_FLAG_BACQ)) evt_handler_flags_buf_acq[idx] |= flag; + if (idx < EOS_EVT_MAX_EVT) { + evt_handler_flags_buf_acq[idx] &= ~flag; + if (flags & EOS_NET_FLAG_BACQ) evt_handler_flags_buf_acq[idx] |= flag; + } } void eos_evtq_get(unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len) { diff --git a/code/fe310/eos/event.h b/code/fe310/eos/event.h index 6beb263..a706412 100644 --- a/code/fe310/eos/event.h +++ b/code/fe310/eos/event.h @@ -9,8 +9,8 @@ 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); void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len); -void eos_evtq_set_handler(unsigned char type, eos_evt_fptr_t handler); -void eos_evtq_set_flags(unsigned char type, uint8_t flags); +void eos_evtq_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags); +void eos_evtq_set_hflags(unsigned char type, uint8_t flags); void eos_evtq_get(unsigned char type, unsigned char *selector, uint16_t sel_len, unsigned char **buffer, uint16_t *len); void eos_evtq_loop(void); diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c index 8b878b3..5b8d2cb 100644 --- a/code/fe310/eos/i2s.c +++ b/code/fe310/eos/i2s.c @@ -136,7 +136,7 @@ static void _spk_vol_set(uint8_t vol) { extern void _eos_i2s_start_pwm(void); void eos_i2s_init(void) { - eos_evtq_set_handler(EOS_EVT_AUDIO, i2s_handler_evt); + eos_evtq_set_handler(EOS_EVT_AUDIO, i2s_handler_evt, 0); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK); @@ -272,7 +272,7 @@ void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags) { i2s_mic_handler = wm_handler; set_csr(mstatus, MSTATUS_MIE); - if (flags) eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_MIC, flags); + eos_evtq_set_hflags(EOS_EVT_AUDIO | I2S_ETYPE_MIC, flags); } void eos_i2s_mic_set_wm(uint16_t wm) { @@ -348,7 +348,7 @@ void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags) { i2s_spk_handler = wm_handler; set_csr(mstatus, MSTATUS_MIE); - if (flags) eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_SPK, flags); + eos_evtq_set_hflags(EOS_EVT_AUDIO | I2S_ETYPE_SPK, flags); } void eos_i2s_spk_set_wm(uint16_t wm) { diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c index 2285ef7..36695bc 100644 --- a/code/fe310/eos/net.c +++ b/code/fe310/eos/net.c @@ -204,7 +204,7 @@ void eos_net_init(void) { for (i=0; i -#define EOS_TIMER_ETYPE_ECP 1 -#define EOS_TIMER_ETYPE_USER 2 +#define EOS_TIMER_ETYPE_UI 1 +#define EOS_TIMER_ETYPE_ECP 2 +#define EOS_TIMER_ETYPE_USER 4 #define EOS_TIMER_MAX_ETYPE 4 @@ -9,6 +10,7 @@ typedef void (*eos_timer_fptr_t) (unsigned char); void eos_timer_init(void); void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t flags); +void eos_timer_set_hflags(unsigned char evt, uint8_t flags); uint64_t eos_timer_get(unsigned char evt); void eos_timer_set(uint32_t msec, unsigned char evt, unsigned char b); diff --git a/code/fe310/eos/uart.c b/code/fe310/eos/uart.c index 88931ab..95c9057 100644 --- a/code/fe310/eos/uart.c +++ b/code/fe310/eos/uart.c @@ -41,7 +41,7 @@ void eos_uart_init(void) { for (i=0; i