summaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-01-28 19:25:20 +0100
committerUros Majstorovic <majstor@majstor.org>2020-01-28 19:25:20 +0100
commit15bddabc5cbe0e751fadcaaa7f7c7c36bca61331 (patch)
treef1c1351a9ed0acb426914ee92cd7b2b917fd9ee4 /code
parent445d72abf487dc325ccbde1e3a12d1c4cf695a6a (diff)
eve logng press event added
Diffstat (limited to 'code')
-rw-r--r--code/fe310/eos/eve.c96
-rw-r--r--code/fe310/eos/eve.h1
-rw-r--r--code/fe310/eos/event.c14
-rw-r--r--code/fe310/eos/event.h4
-rw-r--r--code/fe310/eos/i2s.c6
-rw-r--r--code/fe310/eos/net.c6
-rw-r--r--code/fe310/eos/net.h2
-rw-r--r--code/fe310/eos/spi.c4
-rw-r--r--code/fe310/eos/timer.c8
-rw-r--r--code/fe310/eos/timer.h6
-rw-r--r--code/fe310/eos/uart.c4
11 files changed, 103 insertions, 48 deletions
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; i<EVE_MAX_TOUCH; i++) {
@@ -315,7 +301,7 @@ static void eve_handler_evt(unsigned char type, unsigned char *buffer, uint16_t
uint32_t touch_xy;
EOSTouch *touch = &eve_touch[i];
- touch->evt &= 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<EOS_NET_MAX_MTYPE; i++) {
evt_handler[i] = eos_evtq_bad_handler;
}
- eos_evtq_set_handler(EOS_EVT_NET, net_handler_evt);
+ eos_evtq_set_handler(EOS_EVT_NET, net_handler_evt, 0);
GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_CTS);
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_CTS);
@@ -266,9 +266,11 @@ void _eos_net_handle(unsigned char type, unsigned char *buffer, uint16_t len, un
if (buf_free && buf_acq) eos_net_release();
}
-void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint16_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq) {
+void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint8_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq) {
if (flags) {
uint16_t flag = (uint16_t)1 << idx;
+ *flags_buf_free &= ~flag;
+ *flags_buf_acq &= ~flag;
if (flags & EOS_NET_FLAG_BFREE) *flags_buf_free |= flag;
if (flags & EOS_NET_FLAG_BACQ) *flags_buf_acq |= flag;
}
diff --git a/code/fe310/eos/net.h b/code/fe310/eos/net.h
index 982ee1b..59cc6eb 100644
--- a/code/fe310/eos/net.h
+++ b/code/fe310/eos/net.h
@@ -23,7 +23,7 @@ void eos_net_init(void);
void eos_net_start(void);
void eos_net_stop(void);
void _eos_net_handle(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char idx, eos_evt_fptr_t handlers[], uint16_t *flags_buf_free, uint16_t *flags_buf_acq);
-void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint16_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq);
+void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint8_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq);
void eos_net_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags);
int _eos_net_acquire(unsigned char reserved);
diff --git a/code/fe310/eos/spi.c b/code/fe310/eos/spi.c
index d752bfb..ae12f40 100644
--- a/code/fe310/eos/spi.c
+++ b/code/fe310/eos/spi.c
@@ -63,7 +63,7 @@ void eos_spi_init(void) {
for (i=0; i<EOS_SPI_MAX_DEV; i++) {
evt_handler[i] = eos_evtq_bad_handler;
}
- eos_evtq_set_handler(EOS_EVT_SPI, spi_handler_evt);
+ eos_evtq_set_handler(EOS_EVT_SPI, spi_handler_evt, 0);
eos_intr_set(INT_SPI1_BASE, IRQ_PRIORITY_SPI_XCHG, NULL);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << SPI_CS_PIN_CAM);
@@ -127,7 +127,7 @@ void eos_spi_set_handler(unsigned char dev, eos_evt_fptr_t handler, uint8_t flag
}
evt_handler[dev] = handler;
- if (flags) eos_evtq_set_flags(EOS_EVT_SPI | dev + 1, flags);
+ eos_evtq_set_hflags(EOS_EVT_SPI | dev + 1, flags);
}
void eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags) {
diff --git a/code/fe310/eos/timer.c b/code/fe310/eos/timer.c
index 9fd8d23..c629866 100644
--- a/code/fe310/eos/timer.c
+++ b/code/fe310/eos/timer.c
@@ -56,7 +56,7 @@ void eos_timer_init(void) {
timer_next[i] = 0;
timer_handler[i] = NULL;
}
- eos_evtq_set_handler(EOS_EVT_TIMER, timer_handler_evt);
+ eos_evtq_set_handler(EOS_EVT_TIMER, timer_handler_evt, 0);
}
void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t flags) {
@@ -74,7 +74,11 @@ void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t
timer_handler[evt] = handler;
if (*mtimecmp != 0) set_csr(mie, MIP_MTIP);
- if ((evt != EOS_TIMER_MAX_ETYPE) && flags) eos_evtq_set_flags(EOS_EVT_TIMER | evt + 1, flags);
+ if (evt != EOS_TIMER_MAX_ETYPE) eos_evtq_set_hflags(EOS_EVT_TIMER | evt + 1, flags);
+}
+
+void eos_timer_set_hflags(unsigned char evt, uint8_t flags) {
+ if (evt && (evt < EOS_TIMER_MAX_ETYPE)) eos_evtq_set_hflags(EOS_EVT_TIMER | evt, flags);
}
uint64_t eos_timer_get(unsigned char evt) {
diff --git a/code/fe310/eos/timer.h b/code/fe310/eos/timer.h
index e8416ab..52efc30 100644
--- a/code/fe310/eos/timer.h
+++ b/code/fe310/eos/timer.h
@@ -1,7 +1,8 @@
#include <stdint.h>
-#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<EOS_UART_MAX_ETYPE; i++) {
uart_handler[i] = NULL;
}
- eos_evtq_set_handler(EOS_EVT_UART, uart_handler_evt);
+ eos_evtq_set_handler(EOS_EVT_UART, uart_handler_evt, 0);
eos_intr_set(INT_UART0_BASE, IRQ_PRIORITY_UART, uart_handler_intr);
}
@@ -53,7 +53,7 @@ void eos_uart_set_handler(unsigned char type, eos_uart_fptr_t handler, uint8_t f
}
uart_handler[type] = handler;
- if (flags) eos_evtq_set_flags(EOS_EVT_UART | type + 1, flags);
+ eos_evtq_set_hflags(EOS_EVT_UART | type + 1, flags);
}
void eos_uart_txwm_set(uint8_t wm) {