summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-03-23 21:33:57 +0100
committerUros Majstorovic <majstor@majstor.org>2021-03-23 21:33:57 +0100
commit8c61343677d2ed8f929372863016524707b8ab93 (patch)
tree59f2c65f006bcf20c0b9a6a73c53a100d08775a2 /fw/fe310/eos/eve
parent98941cdc89d93f5387bb98a443f06408321acc8f (diff)
form scroll completed
Diffstat (limited to 'fw/fe310/eos/eve')
-rw-r--r--fw/fe310/eos/eve/Makefile2
-rw-r--r--fw/fe310/eos/eve/eve.h1
-rw-r--r--fw/fe310/eos/eve/eve_kbd.c15
-rw-r--r--fw/fe310/eos/eve/eve_kbd.h2
-rw-r--r--fw/fe310/eos/eve/eve_phy.c77
-rw-r--r--fw/fe310/eos/eve/eve_phy.h28
-rw-r--r--fw/fe310/eos/eve/eve_text.c11
-rw-r--r--fw/fe310/eos/eve/eve_text.h2
-rw-r--r--fw/fe310/eos/eve/eve_touch.c272
-rw-r--r--fw/fe310/eos/eve/eve_touch.h97
-rw-r--r--fw/fe310/eos/eve/eve_vtrack.c111
-rw-r--r--fw/fe310/eos/eve/eve_vtrack.h39
-rw-r--r--fw/fe310/eos/eve/screen/form.c117
-rw-r--r--fw/fe310/eos/eve/screen/form.h11
-rw-r--r--fw/fe310/eos/eve/screen/page.h4
-rw-r--r--fw/fe310/eos/eve/screen/screen.c23
-rw-r--r--fw/fe310/eos/eve/screen/screen.h2
-rw-r--r--fw/fe310/eos/eve/screen/view.h2
18 files changed, 461 insertions, 355 deletions
diff --git a/fw/fe310/eos/eve/Makefile b/fw/fe310/eos/eve/Makefile
index 43470d8..e55ef7a 100644
--- a/fw/fe310/eos/eve/Makefile
+++ b/fw/fe310/eos/eve/Makefile
@@ -2,7 +2,7 @@ include ../../common.mk
CFLAGS += -I.. -I../../bsp/include
-obj = eve.o eve_platform.o eve_touch.o eve_vtrack.o eve_kbd.o eve_text.o eve_font.o clipb.o
+obj = eve.o eve_platform.o eve_touch.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.h b/fw/fe310/eos/eve/eve.h
index 4056dd3..d813dce 100644
--- a/fw/fe310/eos/eve/eve.h
+++ b/fw/fe310/eos/eve/eve.h
@@ -2,6 +2,7 @@
#include "eve_def.h"
#include "eve_touch.h"
+#include "eve_phy.h"
#include "eve_vtrack.h"
#include "eve_platform.h"
diff --git a/fw/fe310/eos/eve/eve_kbd.c b/fw/fe310/eos/eve/eve_kbd.c
index 5dd4d5a..a664ef2 100644
--- a/fw/fe310/eos/eve/eve_kbd.c
+++ b/fw/fe310/eos/eve/eve_kbd.c
@@ -73,17 +73,15 @@ void eve_kbd_set_handler(EVEKbd *kbd, eve_kbd_input_handler_t putc, void *param)
kbd->param = param;
}
-int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx) {
- EVETouch *t;
- uint16_t evt;
+int eve_kbd_touch(EVEKbd *kbd, EVETouch *touch, uint16_t evt, uint8_t tag0) {
int ret;
- t = eve_touch_evt(tag0, touch_idx, 1, 126, &evt);
- if (t && evt) {
- ret = 1;
+ evt = eve_touch_evt(touch, evt, tag0, 1, 126);
+ if (touch && evt) {
+ int8_t touch_idx = eve_touch_get_idx(touch);
if (evt & EVE_TOUCH_ETYPE_TAG) {
- uint8_t _tag = t->tag;
+ uint8_t _tag = touch->tag;
if (_tag >= TAG_SHIFT && _tag <= TAG_FN) {
if (touch_idx == 0) {
@@ -113,7 +111,7 @@ int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx) {
}
}
if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
- uint8_t _tag = t->tag_up;
+ uint8_t _tag = touch->tag_up;
if (_tag >= TAG_SHIFT && _tag <= TAG_FN) {
if (touch_idx == 0) {
@@ -132,6 +130,7 @@ int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx) {
}
}
}
+ ret = 1;
} else {
ret = 0;
}
diff --git a/fw/fe310/eos/eve/eve_kbd.h b/fw/fe310/eos/eve/eve_kbd.h
index 7746472..b4f9874 100644
--- a/fw/fe310/eos/eve/eve_kbd.h
+++ b/fw/fe310/eos/eve/eve_kbd.h
@@ -19,5 +19,5 @@ typedef struct EVEKbd {
void eve_kbd_init(EVEKbd *kbd, EVERect *g, uint32_t mem_addr, uint32_t *mem_next);
void eve_kbd_close(EVEKbd *kbd);
void eve_kbd_set_handler(EVEKbd *kbd, eve_kbd_input_handler_t putc, void *param);
-int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx);
+int eve_kbd_touch(EVEKbd *kbd, EVETouch *touch, uint16_t evt, uint8_t tag0);
uint8_t eve_kbd_draw(EVEKbd *kbd);
diff --git a/fw/fe310/eos/eve/eve_phy.c b/fw/fe310/eos/eve/eve_phy.c
new file mode 100644
index 0000000..1e255fe
--- /dev/null
+++ b/fw/fe310/eos/eve/eve_phy.c
@@ -0,0 +1,77 @@
+#include <stdlib.h>
+#include <math.h>
+
+#include "eve_platform.h"
+#include "eve_phy.h"
+
+/* Constant accelerator */
+void eve_phy_acc_init(EVEPhyAcc *param, int a) {
+ param->a = a;
+}
+
+void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y) {
+ double v0 = sqrt(v0x * v0x + v0y * v0y);
+
+ param->x0 = x0;
+ param->y0 = y0;
+ param->v0x = v0x;
+ param->v0y = v0y;
+ param->k = 2 * v0 / param->a * EVE_RTC_FREQ;
+}
+
+int eve_phy_acc_tick(EVEPhyAcc *param, int 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 more = 1;
+
+ 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);
+
+ return more;
+}
+
+/* Linear harmonic oscillator */
+void eve_phy_lho_init(EVEPhyLHO *param, int x, int y, uint32_t T, double d, uint32_t t_max) {
+ double f0 = 2 * M_PI / (T * EVE_RTC_FREQ / 1000);
+
+ if (d < 0) d = 0;
+ if (d > 1) d = 1;
+ param->x = x;
+ param->y = y;
+ param->f = f0 * sqrt(1 - d * d);
+ param->a = -d * f0;
+ param->t_max = t_max * EVE_RTC_FREQ / 1000;
+}
+
+int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0) {
+ param->x0 = x0;
+ param->y0 = y0;
+}
+
+int eve_phy_lho_tick(EVEPhyLHO *param, int dt, int *x, int *y) {
+ int ax = param->x0 - param->x;
+ int ay = param->y0 - param->y;
+ int more = 1;
+
+ if (param->t_max && (dt >= param->t_max)) {
+ dt = param->t_max;
+ more = 0;
+ }
+ if (param->a) {
+ double e = exp(param->a * dt);
+ ax = ax * e;
+ ay = ay * e;
+ if ((ax == 0) && (ay == 0)) more = 0;
+ }
+ if (x) *x = param->x + ax * cos(param->f * dt);
+ if (y) *y = param->y + ay * cos(param->f * dt);
+
+ return more;
+}
diff --git a/fw/fe310/eos/eve/eve_phy.h b/fw/fe310/eos/eve/eve_phy.h
new file mode 100644
index 0000000..1be5fd0
--- /dev/null
+++ b/fw/fe310/eos/eve/eve_phy.h
@@ -0,0 +1,28 @@
+#include <stdint.h>
+
+typedef struct EVEPhyAcc {
+ int a;
+ int k;
+ int x0;
+ int y0;
+ int v0x;
+ int v0y;
+} 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);
+
+typedef struct EVEPhyLHO {
+ int x;
+ int y;
+ double f;
+ double a;
+ uint32_t t_max;
+ int x0;
+ int y0;
+} 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
diff --git a/fw/fe310/eos/eve/eve_text.c b/fw/fe310/eos/eve/eve_text.c
index d23d012..eecfa0a 100644
--- a/fw/fe310/eos/eve/eve_text.c
+++ b/fw/fe310/eos/eve/eve_text.c
@@ -119,18 +119,15 @@ void eve_text_scroll0(EVEText *box) {
}
}
-int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx) {
- EVETouch *t;
- uint16_t evt;
-
- t = eve_touch_evt(tag0, touch_idx, box->tag, 1, &evt);
- if (t && evt) {
+int eve_text_touch(EVEText *box, EVETouch *touch, uint16_t evt, uint8_t tag0) {
+ evt = eve_touch_evt(touch, evt, tag0, box->tag, 1);
+ if (touch && evt) {
if ((evt & EVE_TOUCH_ETYPE_TRACK_START) && (box->line_top < 0)) {
box->line_top = box->line0;
box->line_top0 = box->line0;
}
if ((evt & EVE_TOUCH_ETYPE_TRACK) && (box->line_top0 >=0)) {
- int line = LINE_IDX_ADD(box->line_top0, (t->y0 - t->y) / box->ch_h, box->line_size);
+ int line = LINE_IDX_ADD(box->line_top0, (touch->y0 - touch->y) / box->ch_h, box->line_size);
if (LINE_IDX_LTE(line, box->line0, box->line_size, box->h)) {
box->line_top = line;
eve_text_update(box);
diff --git a/fw/fe310/eos/eve/eve_text.h b/fw/fe310/eos/eve/eve_text.h
index 8f1ed71..3b282c9 100644
--- a/fw/fe310/eos/eve/eve_text.h
+++ b/fw/fe310/eos/eve/eve_text.h
@@ -23,7 +23,7 @@ void eve_text_init(EVEText *box, EVERect *g, uint16_t w, uint16_t h, uint16_t li
void eve_text_update(EVEText *box);
void eve_text_scroll0(EVEText *box);
-int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx);
+int eve_text_touch(EVEText *box, EVETouch *touch, uint16_t evt, uint8_t tag0);
uint8_t eve_text_draw(EVEText *box, uint8_t tag);
void eve_text_putc(EVEText *box, int c);
diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c
index 334dfa3..b5ca7fd 100644
--- a/fw/fe310/eos/eve/eve_touch.c
+++ b/fw/fe310/eos/eve/eve_touch.c
@@ -4,14 +4,6 @@
#include "eve.h"
-#define EVE_THRESHOLD_X 5
-#define EVE_THRESHOLD_Y 5
-#define EVE_TRAVG 3
-
-#define EVE_NOTOUCH 0x80000000
-
-#define EVE_MAX_TOUCH 5
-
static int _intr_mask = EVE_INT_TAG | EVE_INT_TOUCH;
static int _multitouch;
static uint8_t _tag0;
@@ -50,7 +42,6 @@ void eve_handle_touch(void) {
int i;
char touch_ex = 0;
char int_ccomplete = 0;
- uint8_t touch_last = 0;
uint8_t flags;
eve_spi_start();
@@ -61,44 +52,54 @@ void eve_handle_touch(void) {
uint8_t touch_tag;
uint32_t touch_xy;
uint64_t now = 0;
+ uint16_t touch_evt = 0;
EVETouch *touch = &_touch[i];
- touch->evt = 0;
touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y));
- if (touch_xy != 0x80008000) {
+ 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->x == EVE_NOTOUCH) {
+ if (touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH) {
uint16_t _evt = 0;
uint16_t _eevt = 0;
- uint16_t _ttevt = eve_touch_timer_evt(i);
+ uint16_t _ttevt = eve_touch_timer_get_evt(touch);
if (_ttevt) {
- EVEVTrack *vtrack = eve_vtrack_get();
+ touch->eevt &= ~EVE_TOUCH_EETYPE_NOTOUCH;
- if (_ttevt & EVE_TOUCH_ETYPE_TAP1) {
+ if (_ttevt & 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_THRESHOLD_X) || (dy > EVE_THRESHOLD_Y)) {
- touch->evt |= EVE_TOUCH_ETYPE_TAP1;
+ 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;
}
- } else {
- touch->evt |= _ttevt;
+ }
+ 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);
}
- if (_touch_handler && touch->evt) {
- _touch_handler(_touch_handler_param, _touch_timer.tag0, i);
+ if (_ttevt & EVE_TOUCH_ETYPE_TIMER) {
+ _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT;
+ touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT;
+ }
+
+ eve_touch_timer_clear(touch);
+ if (_touch_handler && touch_evt) {
+ _touch_handler(_touch_timer.touch, touch_evt, _touch_timer.tag0, _touch_handler_param);
}
- eve_touch_timer_clear();
}
- touch->evt = EVE_TOUCH_ETYPE_POINT | _evt;
+ touch_evt = EVE_TOUCH_ETYPE_POINT | _evt;
touch->eevt = _eevt;
touch->tag0 = 0;
touch->tag = 0;
@@ -115,8 +116,8 @@ void eve_handle_touch(void) {
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_TRAVG) / (EVE_TRAVG + 1) : vx;
- touch->vy = touch->vy ? (vy + touch->vy * EVE_TRAVG) / (EVE_TRAVG + 1) : vy;
+ 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;
@@ -129,27 +130,27 @@ void eve_handle_touch(void) {
touch_ex = 1;
} else {
touch_tag = 0;
- if (touch->x != EVE_NOTOUCH) {
- touch->evt |= EVE_TOUCH_ETYPE_POINT_UP;
- if (eve_touch_timer_evt(i)) {
- _touch_timer.evt &= ~EVE_TOUCH_ETYPE_LPRESS;
- if (!_touch_timer.evt) eve_touch_timer_clear();
+ 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 = _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 (!_touch_timer.evt && track_ext) {
+ if (!eve_touch_timer_get_evt(NULL) && track_ext) {
EVEVTrack *vtrack = eve_vtrack_get();
- eve_touch_timer_set(_tag0, i, EVE_TOUCH_ETYPE_TRACK, EVE_TOUCH_TIMEOUT_TRACK);
+ eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, _tag0, EVE_TOUCH_TIMEOUT_TRACK);
if (vtrack->start) vtrack->start(touch, vtrack->param);
} else {
- touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
+ touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
}
}
- touch->x = EVE_NOTOUCH;
- touch->y = EVE_NOTOUCH;
}
}
if (touch_tag != touch->tag) {
@@ -157,83 +158,79 @@ void eve_handle_touch(void) {
if (!_tag0) _tag0 = touch_tag;
if (!touch->tag0) {
touch->tag0 = touch_tag;
- if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_TRACK_MASK) {
+ if (_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) {
touch->tracker.tag = touch_tag;
}
if (touch->tracker.tag && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) {
+ touch_evt |= EVE_TOUCH_ETYPE_TRACK_START;
touch->tracker.track = 1;
- touch->evt |= EVE_TOUCH_ETYPE_TRACK_START;
touch->t = now;
}
- if (!_touch_timer.evt && (_tag_opt[touch_tag] & EVE_TOUCH_OPT_TIMER_MASK)) {
+ if (!eve_touch_timer_get_evt(NULL) && (_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) {
uint16_t _evt = 0;
if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS;
- if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_DTAP) _evt |= EVE_TOUCH_ETYPE_TAP1;
- eve_touch_timer_set(_tag0, i, _evt, EVE_TOUCH_TIMEOUT_TAP);
+ if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2;
+ eve_touch_timer_set(touch, _evt, _tag0, EVE_TOUCH_TIMEOUT_TAP);
}
}
}
touch->tag_up = touch->tag;
- if (touch->tag_up) touch->evt |= EVE_TOUCH_ETYPE_TAG_UP;
+ 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->tag) touch_evt |= EVE_TOUCH_ETYPE_TAG;
}
- if (touch_xy != 0x80008000) {
+ if (touch_xy != EVE_NOTOUCH) {
+ uint16_t _ttevt = eve_touch_timer_get_evt(touch);
int _track = touch->tracker.tag && !touch->tracker.track;
- int _timer = eve_touch_timer_evt(i) & EVE_TOUCH_ETYPE_TIMER_MASK;
+ 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_THRESHOLD_X) && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) {
+ if ((dx > EVE_TOUCH_THRESHOLD_X) && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) {
touch->tracker.tag = 0;
}
- if ((dy > EVE_THRESHOLD_Y) && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) {
+ if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) {
touch->tracker.tag = 0;
}
- if (touch->tracker.tag && ((dx > EVE_THRESHOLD_X) || (dy > EVE_THRESHOLD_Y))) {
- if (dx > EVE_THRESHOLD_X) {
+ 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_THRESHOLD_Y) {
+ 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->evt |= EVE_TOUCH_ETYPE_TRACK_START;
touch->t = now;
}
}
- if (_timer && ((dx > EVE_THRESHOLD_X) || (dy > EVE_THRESHOLD_Y))) {
+ 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_timer.evt &= ~EVE_TOUCH_ETYPE_TIMER_MASK;
- if (!_touch_timer.evt) eve_touch_timer_clear();
}
}
if (touch->tracker.tag && touch->tracker.track) {
- touch->evt |= _tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_MASK;
+ if (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK;
+ if (_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) {
+ 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;
+ touch_evt &= ~EVE_TOUCH_ETYPE_TRACK_REG;
}
}
if (touch->tracker.tag || _timer) int_ccomplete = 1;
}
- if (touch->evt) touch_last = i + 1;
- if (!_multitouch) break;
- }
-
- for (i=0; i<touch_last; i++) {
- EVETouch *touch = &_touch[i];
- if (_touch_handler && touch->evt) {
- _touch_handler(_touch_handler_param, _tag0, i);
+ if (_touch_handler && touch_evt) {
+ _touch_handler(touch, touch_evt, _tag0, _touch_handler_param);
}
+ if (!_multitouch) break;
}
if (!touch_ex) {
@@ -256,41 +253,51 @@ void eve_handle_touch(void) {
}
void eve_handle_time(void) {
- EVETouch *touch = &_touch[_touch_timer.idx];
-
- if ((_touch_timer.evt & EVE_TOUCH_ETYPE_TAP1) && (touch->x != EVE_NOTOUCH)) _touch_timer.evt &= ~EVE_TOUCH_ETYPE_TAP1;
+ EVETouch *touch = _touch_timer.touch;
if (_touch_timer.evt) {
int more = 0;
- int _x = touch->x;
- int _y = touch->y;
- EVEVTrack *vtrack = eve_vtrack_get();
+ uint16_t touch_evt = 0;
eve_spi_start();
- touch->evt = _touch_timer.evt;
- if (touch->evt & EVE_TOUCH_ETYPE_LPRESS) {
- touch->eevt |= EVE_TOUCH_EETYPE_LPRESS;
- } else {
- if (vtrack->tick) more = vtrack->tick(touch, vtrack->param);
- if (more) {
- eve_timer_set(EVE_TOUCH_TIMEOUT_TRACK);
- } else if (vtrack->stop) {
- vtrack->stop(touch, vtrack->param);
+ if (_touch_timer.evt & EVE_TOUCH_ETYPE_LPRESS) {
+ touch_evt |= EVE_TOUCH_ETYPE_LPRESS;
+ if (touch) touch->eevt |= EVE_TOUCH_EETYPE_LPRESS;
+ }
+ if (_touch_timer.evt & EVE_TOUCH_ETYPE_TAP2) {
+ touch_evt |= EVE_TOUCH_ETYPE_TAP1;
+ if (touch) touch->eevt |= EVE_TOUCH_EETYPE_TAP1;
+ }
+ if (_touch_timer.evt & EVE_TOUCH_ETYPE_TRACK) {
+ EVEVTrack *vtrack = eve_vtrack_get();
+
+ if (vtrack->tick) {
+ touch_evt |= EVE_TOUCH_ETYPE_TRACK;
+ more = vtrack->tick(touch, vtrack->param);
}
+ if (!more) {
+ touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
+ if (vtrack->stop) vtrack->stop(touch, vtrack->param);
+ }
+ }
+ if (_touch_timer.evt & EVE_TOUCH_ETYPE_TIMER) {
+ touch_evt |= EVE_TOUCH_ETYPE_TIMER;
+ more = 1;
}
- if (_touch_handler) _touch_handler(_touch_handler_param, _touch_timer.tag0, _touch_timer.idx);
+ if (more) {
+ eve_timer_set(_touch_timer.to);
+ } else {
+ _touch_timer.evt = 0;
+ }
- eve_spi_stop();
+ if (_touch_handler && touch_evt) {
+ _touch_handler(touch, touch_evt, _touch_timer.tag0, _touch_handler_param);
+ }
- if (!more) eve_touch_timer_clear();
- touch->x = _x;
- touch->y = _y;
- } else {
- eve_touch_timer_clear();
+ eve_spi_stop();
}
-
}
void eve_touch_init(void) {
@@ -300,9 +307,9 @@ void eve_touch_init(void) {
for (i=0; i<EVE_MAX_TOUCH; i++) {
EVETouch *touch = &_touch[i];
- touch->x = EVE_NOTOUCH;
- touch->y = EVE_NOTOUCH;
+ touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH;
}
+
eve_write8(REG_INT_MASK, _intr_mask);
eve_write8(REG_INT_EN, 0x01);
while(eve_read8(REG_INT_FLAGS));
@@ -317,42 +324,43 @@ EVETouch *eve_touch_get(int i) {
return &_touch[i];
}
-EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_n, uint16_t *evt) {
+int8_t eve_touch_get_idx(EVETouch *touch) {
+ if (touch == NULL) return -1;
+ return touch - _touch;
+}
+
+uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_min, uint8_t tag_n) {
int tag_max;
uint8_t _tag;
uint16_t _evt;
- EVETouch *ret = NULL;
- *evt = 0;
-
- if ((touch_idx < 0) || (touch_idx > 4)) return ret;
- if (tag_min == EVE_TAG_NOTAG) return ret;
+ if (tag_min == EVE_TAG_NOTAG) return 0;
tag_max = tag_min + tag_n;
- if ((tag0 < tag_min) || (tag0 >= tag_max)) return ret;
+ if ((tag0 < tag_min) || (tag0 >= tag_max)) return 0;
- ret = &_touch[touch_idx];
- _evt = ret->evt;
+ _evt = evt & (EVE_TOUCH_ETYPE_TIMER_MASK | EVE_TOUCH_ETYPE_USR_MASK);
+ if (touch == NULL) return _evt;
- *evt |= _evt & EVE_TOUCH_ETYPE_POINT_MASK;
- if (_evt & EVE_TOUCH_ETYPE_TAG) {
- _tag = ret->tag;
- if ((_tag >= tag_min) && (_tag < tag_max)) *evt |= EVE_TOUCH_ETYPE_TAG;
+ _evt |= evt & EVE_TOUCH_ETYPE_POINT_MASK;
+ if (evt & EVE_TOUCH_ETYPE_TAG) {
+ _tag = touch->tag;
+ if ((_tag >= tag_min) && (_tag < tag_max)) _evt |= EVE_TOUCH_ETYPE_TAG;
}
- if (_evt & EVE_TOUCH_ETYPE_TAG_UP) {
- _tag = ret->tag_up;
- if ((_tag >= tag_min) && (_tag < tag_max)) *evt |= EVE_TOUCH_ETYPE_TAG_UP;
+ if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ _tag = touch->tag_up;
+ if ((_tag >= tag_min) && (_tag < tag_max)) _evt |= EVE_TOUCH_ETYPE_TAG_UP;
}
- if (_evt & EVE_TOUCH_ETYPE_TRACK_MASK) {
- _tag = ret->tracker.tag;
- if ((_tag >= tag_min) && (_tag < tag_max)) *evt |= _evt & EVE_TOUCH_ETYPE_TRACK_MASK;
+ if (evt & EVE_TOUCH_ETYPE_TRACK_MASK) {
+ _tag = touch->tracker.tag;
+ if ((_tag >= tag_min) && (_tag < tag_max)) _evt |= evt & EVE_TOUCH_ETYPE_TRACK_MASK;
}
- if (_evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2)) {
- _tag = ret->tag0;
- if ((_tag >= tag_min) && (_tag < tag_max)) *evt |= _evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2);
+ if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2)) {
+ _tag = touch->tag0;
+ if ((_tag >= tag_min) && (_tag < tag_max)) _evt |= evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2);
}
- return ret;
+ return _evt;
}
void eve_touch_set_opt(uint8_t tag, uint8_t opt) {
@@ -367,20 +375,44 @@ void eve_touch_clear_opt(void) {
memset(_tag_opt, 0, sizeof(_tag_opt));
}
-void eve_touch_timer_set(uint8_t tag0, int i, uint16_t evt, uint32_t to) {
- _touch_timer.tag0 = tag0;
- _touch_timer.idx = i;
+void eve_touch_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);
}
-void eve_touch_timer_clear(void) {
- eve_timer_clear();
- _touch_timer.evt = 0;
+void eve_touch_timer_clear(EVETouch *touch) {
+ eve_touch_timer_set_evt(touch, 0);
+}
+
+uint16_t eve_touch_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;
+ }
+ 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();
+}
+
+void eve_touch_timer_start(uint8_t tag0, uint32_t to) {
+ eve_touch_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to);
}
-uint16_t eve_touch_timer_evt(int i) {
- return (i == _touch_timer.idx) ? _touch_timer.evt : 0;
+void eve_touch_timer_stop(void) {
+ eve_touch_timer_clear(NULL);
}
EVETouchTimer *eve_touch_timer_get(void) {
diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h
index 80d7f61..d4de196 100644
--- a/fw/fe310/eos/eve/eve_touch.h
+++ b/fw/fe310/eos/eve/eve_touch.h
@@ -3,54 +3,72 @@
#define EVE_TOUCH_TIMEOUT_TAP 1000
#define EVE_TOUCH_TIMEOUT_TRACK 20
+#define EVE_TOUCH_THRESHOLD_X 5
+#define EVE_TOUCH_THRESHOLD_Y 5
+#define EVE_TOUCH_TRAVG 3
+
+#define EVE_NOTOUCH 0x80008000
+#define EVE_MAX_TOUCH 5
+
/* events */
-#define EVE_TOUCH_ETYPE_TRACK 0x0001
-#define EVE_TOUCH_ETYPE_TRACK_REG 0x0002
-#define EVE_TOUCH_ETYPE_TRACK_START 0x0004
-#define EVE_TOUCH_ETYPE_TRACK_STOP 0x0008
-#define EVE_TOUCH_ETYPE_TAG 0x0010
-#define EVE_TOUCH_ETYPE_TAG_UP 0x0020
-#define EVE_TOUCH_ETYPE_POINT 0x0040
-#define EVE_TOUCH_ETYPE_POINT_UP 0x0080
-#define EVE_TOUCH_ETYPE_LPRESS 0x0100
-#define EVE_TOUCH_ETYPE_TAP1 0x0200
-#define EVE_TOUCH_ETYPE_TAP2 0x0400
-
-#define EVE_TOUCH_ETYPE_TAG_MASK (EVE_TOUCH_ETYPE_TAG | EVE_TOUCH_ETYPE_TAG_UP)
-#define EVE_TOUCH_ETYPE_TAP_MASK (EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2)
-#define EVE_TOUCH_ETYPE_TRACK_MASK (EVE_TOUCH_ETYPE_TRACK | EVE_TOUCH_ETYPE_TRACK_START | EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_REG)
+#define EVE_TOUCH_ETYPE_TAG 0x0001
+#define EVE_TOUCH_ETYPE_TAG_UP 0x0002
+#define EVE_TOUCH_ETYPE_POINT 0x0004
+#define EVE_TOUCH_ETYPE_POINT_UP 0x0008
+#define EVE_TOUCH_ETYPE_TRACK 0x0010
+#define EVE_TOUCH_ETYPE_TRACK_START 0x0020
+#define EVE_TOUCH_ETYPE_TRACK_STOP 0x0040
+#define EVE_TOUCH_ETYPE_TRACK_ABORT 0x0080
+#define EVE_TOUCH_ETYPE_TIMER 0x0100
+#define EVE_TOUCH_ETYPE_TIMER_ABORT 0x0200
+#define EVE_TOUCH_ETYPE_TRACK_REG 0x0400
+#define EVE_TOUCH_ETYPE_LPRESS 0x0800
+#define EVE_TOUCH_ETYPE_TAP1 0x1000
+#define EVE_TOUCH_ETYPE_TAP2 0x2000
+#define EVE_TOUCH_ETYPE_USR 0x4000
+#define EVE_TOUCH_ETYPE_USR1 0x8000
+
+#define EVE_TOUCH_ETYPE_TRACK_MASK (EVE_TOUCH_ETYPE_TRACK | EVE_TOUCH_ETYPE_TRACK_START | EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_ABORT | EVE_TOUCH_ETYPE_TRACK_REG)
+#define EVE_TOUCH_ETYPE_TIMER_MASK (EVE_TOUCH_ETYPE_TIMER | EVE_TOUCH_ETYPE_TIMER_ABORT)
#define EVE_TOUCH_ETYPE_POINT_MASK (EVE_TOUCH_ETYPE_POINT | EVE_TOUCH_ETYPE_POINT_UP)
-#define EVE_TOUCH_ETYPE_TIMER_MASK (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_DTAP)
+#define EVE_TOUCH_ETYPE_USR_MASK (EVE_TOUCH_ETYPE_USR | EVE_TOUCH_ETYPE_USR1)
/* extended events */
-#define EVE_TOUCH_EETYPE_LPRESS 0x0001
-#define EVE_TOUCH_EETYPE_TAP2 0x0002
+#define EVE_TOUCH_EETYPE_NOTOUCH 0x0001
+#define EVE_TOUCH_EETYPE_LPRESS 0x0002
+#define EVE_TOUCH_EETYPE_TAP1 0x0004
+#define EVE_TOUCH_EETYPE_TAP2 0x0008
-#define EVE_TOUCH_EETYPE_TRACK_LEFT 0x1000
-#define EVE_TOUCH_EETYPE_TRACK_RIGHT 0x2000
-#define EVE_TOUCH_EETYPE_TRACK_UP 0x4000
-#define EVE_TOUCH_EETYPE_TRACK_DOWN 0x8000
+#define EVE_TOUCH_EETYPE_TRACK_LEFT 0x0010
+#define EVE_TOUCH_EETYPE_TRACK_RIGHT 0x0020
+#define EVE_TOUCH_EETYPE_TRACK_UP 0x0040
+#define EVE_TOUCH_EETYPE_TRACK_DOWN 0x0080
+
+#define EVE_TOUCH_EETYPE_TRACK_ABORT 0x0100
+#define EVE_TOUCH_EETYPE_TIMER_ABORT 0x0200
+
+#define EVE_TOUCH_EETYPE_USR 0x1000
+#define EVE_TOUCH_EETYPE_USR1 0x2000
+#define EVE_TOUCH_EETYPE_USR2 0x4000
+#define EVE_TOUCH_EETYPE_USR3 0x8000
#define EVE_TOUCH_EETYPE_TRACK_X (EVE_TOUCH_EETYPE_TRACK_LEFT | EVE_TOUCH_EETYPE_TRACK_RIGHT)
#define EVE_TOUCH_EETYPE_TRACK_Y (EVE_TOUCH_EETYPE_TRACK_UP | EVE_TOUCH_EETYPE_TRACK_DOWN)
#define EVE_TOUCH_EETYPE_TRACK_XY (EVE_TOUCH_EETYPE_TRACK_X | EVE_TOUCH_EETYPE_TRACK_Y)
+#define EVE_TOUCH_EETYPE_ABORT (EVE_TOUCH_EETYPE_TRACK_ABORT | EVE_TOUCH_EETYPE_TIMER_ABORT)
/* tag options */
-#define EVE_TOUCH_OPT_TRACK EVE_TOUCH_ETYPE_TRACK
-#define EVE_TOUCH_OPT_TRACK_REG EVE_TOUCH_ETYPE_TRACK_REG
+#define EVE_TOUCH_OPT_TRACK 0x01
+#define EVE_TOUCH_OPT_TRACK_REG 0x02
#define EVE_TOUCH_OPT_TRACK_X 0x04
#define EVE_TOUCH_OPT_TRACK_Y 0x08
#define EVE_TOUCH_OPT_TRACK_EXT_X 0x10
#define EVE_TOUCH_OPT_TRACK_EXT_Y 0x20
#define EVE_TOUCH_OPT_LPRESS 0x40
-#define EVE_TOUCH_OPT_DTAP 0x80
+#define EVE_TOUCH_OPT_TAP2 0x80
#define EVE_TOUCH_OPT_TRACK_XY (EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_Y)
#define EVE_TOUCH_OPT_TRACK_EXT_XY (EVE_TOUCH_OPT_TRACK_EXT_X | EVE_TOUCH_OPT_TRACK_EXT_Y)
-#define EVE_TOUCH_OPT_TRACK_MASK (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)
-#define EVE_TOUCH_OPT_TIMER_MASK (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_DTAP)
-
-typedef void (*eve_touch_handler_t) (void *, uint8_t, int);
typedef struct EVETouch {
int x;
@@ -60,7 +78,6 @@ typedef struct EVETouch {
int x0;
int y0;
uint64_t t;
- uint16_t evt;
uint16_t eevt;
uint8_t tag0;
uint8_t tag;
@@ -73,24 +90,32 @@ typedef struct EVETouch {
} EVETouch;
typedef struct EVETouchTimer {
- uint8_t tag0;
- uint8_t idx;
+ EVETouch *touch;
+ uint32_t to;
uint16_t evt;
+ uint8_t tag0;
} EVETouchTimer;
+typedef void (*eve_touch_handler_t) (EVETouch *, uint16_t, uint8_t, void *);
+
void eve_handle_touch(void);
void eve_handle_time(void);
void eve_touch_init(void);
void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param);
EVETouch *eve_touch_get(int i);
-EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_n, uint16_t *evt);
+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);
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(uint8_t tag0, int i, uint16_t evt, uint32_t to);
-void eve_touch_timer_clear(void);
-uint16_t eve_touch_timer_evt(int i);
+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);
+
EVETouchTimer *eve_touch_timer_get(void);
diff --git a/fw/fe310/eos/eve/eve_vtrack.c b/fw/fe310/eos/eve/eve_vtrack.c
index bf65ec8..dfa8ba8 100644
--- a/fw/fe310/eos/eve/eve_vtrack.c
+++ b/fw/fe310/eos/eve/eve_vtrack.c
@@ -4,11 +4,11 @@
#include "eve.h"
static EVEVTrack _vtrack;
-static EVEVTrackInert _vtrack_inert;
+static EVEPhyAcc _vtrack_acc;
void eve_vtrack_init(void) {
- eve_vtrack_inert_init(&_vtrack_inert, EVE_VTRACK_FRICTION);
- eve_vtrack_set(eve_vtrack_inert_start, eve_vtrack_inert_tick, eve_vtrack_inert_stop, &_vtrack_inert);
+ eve_phy_acc_init(&_vtrack_acc, -EVE_VTRACK_ACC_A);
+ eve_vtrack_reset();
}
EVEVTrack *eve_vtrack_get(void) {
@@ -23,110 +23,43 @@ void eve_vtrack_set(eve_vtrack_start_t start, eve_vtrack_tick_t tick, eve_vtrack
}
void eve_vtrack_reset(void) {
- eve_vtrack_set(eve_vtrack_inert_start, eve_vtrack_inert_tick, eve_vtrack_inert_stop, &_vtrack_inert);
+ eve_vtrack_set(eve_vtrack_acc_start, eve_vtrack_acc_tick, NULL, &_vtrack_acc);
}
-void eve_vtrack_start(uint8_t tag0, int i) {
- EVETouch *touch = eve_touch_get(i);
-
- eve_touch_timer_set(tag0, i, EVE_TOUCH_ETYPE_TRACK, EVE_TOUCH_TIMEOUT_TRACK);
+void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) {
+ eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to);
if (_vtrack.start) _vtrack.start(touch, _vtrack.param);
}
-void eve_vtrack_stop(void) {
- eve_touch_timer_clear();
+void eve_vtrack_stop(EVETouch *touch) {
+ eve_touch_timer_clear(touch);
eve_vtrack_reset();
}
-
-EVEVTrackInert *eve_vtrack_inert_get_param(void) {
- return &_vtrack_inert;
-}
-
-void eve_vtrack_inert_init(EVEVTrackInert *param, int fc) {
- param->fc = fc;
+void eve_vtrack_acc_start(EVETouch *touch, void *p) {
+ EVEPhyAcc *param = (EVEPhyAcc *)p;
+ eve_phy_acc_start(param, touch->x, touch->y, touch->vx, touch->vy);
}
-void eve_vtrack_inert_start(EVETouch *touch, void *p) {
- EVEVTrackInert *param = (EVEVTrackInert *)p;
- double d = sqrt(touch->vx * touch->vx + touch->vy * touch->vy);
+int eve_vtrack_acc_tick(EVETouch *touch, void *p) {
+ EVEPhyAcc *param = (EVEPhyAcc *)p;
- param->x0 = touch->x;
- param->y0 = touch->y;
- param->f = (double)(EVE_RTC_FREQ) * d / param->fc;
+ return eve_phy_acc_tick(param, eve_time_get_tick() - touch->t, &touch->x, &touch->y);
}
-int eve_vtrack_inert_tick(EVETouch *touch, void *p) {
- EVEVTrackInert *param = (EVEVTrackInert *)p;
- int dt = eve_time_get_tick() - touch->t;
- int f = param->f;
- int more = 1;
+void eve_vtrack_lho_start(EVETouch *touch, void *p) {
+ EVEPhyLHO *param = (EVEPhyLHO *)p;
- if (dt >= f / 2) {
- dt = f / 2;
- more = 0;
- }
- touch->x = param->x0 + (touch->vx * dt - touch->vx * dt / f * dt) / (int)(EVE_RTC_FREQ);
- touch->y = param->y0 + (touch->vy * dt - touch->vy * dt / f * dt) / (int)(EVE_RTC_FREQ);
-
- return more;
-}
-
-void eve_vtrack_inert_stop(EVETouch *touch, void *p) {
- touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
+ eve_phy_lho_start(param, touch->x, touch->y);
}
+int eve_vtrack_lho_tick(EVETouch *touch, void *p) {
+ EVEPhyLHO *param = (EVEPhyLHO *)p;
-static EVEVTrackOsc _vtrack_osc;
-
-EVEVTrackOsc *eve_vtrack_osc_get_param(void) {
- return &_vtrack_osc;
+ return eve_phy_lho_tick(param, eve_time_get_tick() - touch->t, &touch->x, &touch->y);
}
-void eve_vtrack_osc_init(EVEVTrackOsc *param, int x, int y, uint32_t T, double d, uint32_t t_max) {
- double f0 = 2 * M_PI / (T * EVE_RTC_FREQ / 1000);
-
- if (d < 0) d = 0;
- if (d > 1) d = 1;
- param->x = x;
- param->y = y;
- param->f = d ? f0 * sqrt(1 - d * d) : f0;
- param->d = d;
- param->a = -d * f0;
- param->t_max = t_max;
-}
-
-void eve_vtrack_osc_start(EVETouch *touch, void *p) {
- EVEVTrackOsc *param = (EVEVTrackOsc *)p;
-
- param->x0 = touch->x;
- param->y0 = touch->y;
-}
-
-int eve_vtrack_osc_tick(EVETouch *touch, void *p) {
- EVEVTrackOsc *param = (EVEVTrackOsc *)p;
- int dt = eve_time_get_tick() - touch->t;
- int ax = param->x0 - param->x;
- int ay = param->y0 - param->y;
- int more = 1;
-
- if (param->t_max && (dt >= param->t_max)) {
- dt = param->t_max;
- more = 0;
- }
- if (param->d) {
- double e = exp(param->a * dt);
- ax = ax * e;
- ay = ay * e;
- if ((ax == 0) && (ay == 0)) more = 0;
- }
- touch->x = param->x + ax * cos(param->f * dt);
- touch->y = param->y + ay * cos(param->f * dt);
-
- return more;
-}
-
-void eve_vtrack_osc_stop(EVETouch *touch, void *p) {
- touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
+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 6bf8fa5..b75f673 100644
--- a/fw/fe310/eos/eve/eve_vtrack.h
+++ b/fw/fe310/eos/eve/eve_vtrack.h
@@ -1,6 +1,6 @@
#include <stdint.h>
-#define EVE_VTRACK_FRICTION 500
+#define EVE_VTRACK_ACC_A 1000
typedef void (*eve_vtrack_start_t) (EVETouch *, void *);
typedef int (*eve_vtrack_tick_t) (EVETouch *, void *);
@@ -17,35 +17,12 @@ void eve_vtrack_init(void);
EVEVTrack *eve_vtrack_get(void);
void eve_vtrack_set(eve_vtrack_start_t start, eve_vtrack_tick_t tick, eve_vtrack_stop_t stop, void *param);
void eve_vtrack_reset(void);
-void eve_vtrack_start(uint8_t tag0, int i);
-void eve_vtrack_stop(void);
+void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to);
+void eve_vtrack_stop(EVETouch *touch);
-typedef struct EVEVTrackInert {
- int fc;
- int f;
- int x0;
- int y0;
-} EVEVTrackInert;
+void eve_vtrack_acc_start(EVETouch *touch, void *p);
+int eve_vtrack_acc_tick(EVETouch *touch, void *p);
-EVEVTrackInert *eve_vtrack_inert_get_param(void);
-void eve_vtrack_inert_init(EVEVTrackInert *param, int fc);
-void eve_vtrack_inert_start(EVETouch *touch, void *p);
-int eve_vtrack_inert_tick(EVETouch *touch, void *p);
-void eve_vtrack_inert_stop(EVETouch *touch, void *p);
-
-typedef struct EVEVTrackOsc {
- int x;
- int y;
- double f;
- double d;
- double a;
- uint32_t t_max;
- int x0;
- int y0;
-} EVEVTrackOsc;
-
-EVEVTrackOsc *eve_vtrack_osc_get_param(void);
-void eve_vtrack_osc_init(EVEVTrackOsc *param, int x, int y, uint32_t T, double d, uint32_t t_max);
-void eve_vtrack_osc_start(EVETouch *touch, void *p);
-int eve_vtrack_osc_tick(EVETouch *touch, void *p);
-void eve_vtrack_osc_stop(EVETouch *touch, void *p);
+void eve_vtrack_lho_start(EVETouch *touch, void *p);
+int eve_vtrack_lho_tick(EVETouch *touch, void *p);
+void eve_vtrack_lho_stop(EVETouch *touch, void *p);
diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c
index 32227c9..5d71d80 100644
--- a/fw/fe310/eos/eve/screen/form.c
+++ b/fw/fe310/eos/eve/screen/form.c
@@ -41,6 +41,7 @@ static void form_update_g(EVEForm *form, EVEWidget *_widget) {
}
widget->g.x = w;
widget->g.y = h;
+ form->h = widget->g.y + widget->g.h;
w += widget->g.w;
_h = MAX(_h, widget->g.h);
@@ -49,35 +50,72 @@ static void form_update_g(EVEForm *form, EVEWidget *_widget) {
}
}
-static int form_handle_evt(EVEForm *form, EVEWidget *widget, EVETouch *touch, uint16_t evt) {
- if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
- form->win_x0 = form->p.win_x;
- form->win_y0 = form->p.win_y;
- form->evt_lock = 1;
+static int form_handle_evt(EVEForm *form, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0) {
+ int ret = 0;
+ EVEPage *page = &form->p;
+
+ if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & (EVE_TOUCH_EETYPE_TRACK_XY | EVE_TOUCH_EETYPE_ABORT))) {
+ if (page->widget_f) eve_page_set_focus(page, NULL, NULL);
+ ret = 1;
}
- if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
- form->evt_lock = 0;
+
+ /* Scroll start */
+ if ((evt & EVE_TOUCH_ETYPE_TRACK_START) && !(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) {
+ form->evt_lock = 1;
}
- if ((evt & EVE_TOUCH_ETYPE_TRACK) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)) {
- form->p.win_y = form->win_y0 + touch->y0 - touch->y;
- return 1;
+
+ /* Scroll stop */
+ if (((evt & EVE_TOUCH_ETYPE_TRACK_STOP) && !(evt & EVE_TOUCH_ETYPE_TRACK_ABORT)) ||
+ ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_ABORT) && !(touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY))) {
+ int wmax_y;
+ EVERect vg;
+
+ eve_window_visible_g(page->v.window, &vg);
+ wmax_y = form->h > vg.h ? form->h - vg.h : 0;
+ if ((page->win_y < 0) || (page->win_y > wmax_y)) {
+ EVEPhyLHO *lho = &form->lho;
+ eve_phy_lho_init(lho, 0, page->win_y < 0 ? 0 : wmax_y, 1000, 0.5, 0);
+ eve_phy_lho_start(lho, 0, page->win_y);
+ form->lho_t0 = eve_time_get_tick();
+ eve_touch_timer_start(tag0, 20);
+ } else {
+ form->evt_lock = 0;
+ if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
+ if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) {
+ eve_page_close((EVEPage *)form);
+ return 1;
+ }
+ if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) {
+ if (form->action) form->action(form);
+ return 1;
+ }
+ }
+ }
}
- if (evt & EVE_TOUCH_ETYPE_POINT_UP) {
- if ((touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY) == 0) {
- if (form->p.widget_f) eve_page_set_focus(&form->p, NULL, NULL);
- return 1;
+
+ if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
+ if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y) {
+ form->win_y0 = page->win_y;
}
- if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) {
- eve_page_close((EVEPage *)form);
- return 1;
+ }
+ if (evt & EVE_TOUCH_ETYPE_TRACK) {
+ if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y) {
+ page->win_y = form->win_y0 + touch->y0 - touch->y;
}
- if (touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) {
- form->action(form);
- return 1;
+ ret = 1;
+ }
+ if (evt & EVE_TOUCH_ETYPE_TIMER) {
+ EVEPhyLHO *lho = &form->lho;
+ int more = eve_phy_lho_tick(lho, eve_time_get_tick() - form->lho_t0, NULL, &page->win_y);
+
+ if (!more) {
+ form->evt_lock = 0;
+ eve_touch_timer_stop();
}
+ ret = 1;
}
- return 0;
+ return ret;
}
int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor) {
@@ -90,31 +128,29 @@ int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidg
form_update_g(form, NULL);
}
-int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx) {
- EVEForm *form = (EVEForm *)v;
+int eve_form_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
+ EVEForm *form = (EVEForm *)view;
EVEWidget *widget = form->widget;
- EVETouch *t;
- uint16_t evt;
- int i, ret = 0;
+ int8_t touch_idx = eve_touch_get_idx(touch);
+ uint16_t _evt;
+ int i, ret;
if (touch_idx > 0) return 0;
- t = eve_touch_evt(tag0, touch_idx, form->p.v.window->tag, 1, &evt);
- if (t && evt) {
- ret = form_handle_evt(form, NULL, t, evt);
+ _evt = eve_touch_evt(touch, evt, tag0, form->p.v.window->tag, 1);
+ if (_evt) {
+ ret = form_handle_evt(form, NULL, touch, _evt, tag0);
if (ret) return 1;
}
for (i=0; i<form->widget_size; i++) {
- if (eve_page_rect_visible(&form->p, &widget->g)) {
- t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt);
- if (t && evt) {
- if (!form->evt_lock) {
- ret = widget->touch(widget, &form->p, t, evt);
- if (ret) return 1;
- }
- ret = form_handle_evt(form, widget, t, evt);
+ _evt = eve_touch_evt(touch, evt, tag0, widget->tag0, widget->tagN - widget->tag0);
+ if (_evt) {
+ if (!form->evt_lock) {
+ ret = widget->touch(widget, &form->p, touch, _evt);
if (ret) return 1;
}
+ ret = form_handle_evt(form, widget, touch, _evt, tag0);
+ if (ret) return 1;
}
widget = eve_widget_next(widget);
}
@@ -122,8 +158,8 @@ int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx) {
return 0;
}
-uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
- EVEForm *form = (EVEForm *)v;
+uint8_t eve_form_draw(EVEView *view, uint8_t tag0) {
+ EVEForm *form = (EVEForm *)view;
EVEWidget *widget = form->widget;
int i;
uint8_t tagN = tag0;
@@ -133,7 +169,6 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
eve_cmd_dl(VERTEX_FORMAT(0));
eve_cmd_dl(VERTEX_TRANSLATE_X(eve_page_scr_x(&form->p, 0) * 16));
eve_cmd_dl(VERTEX_TRANSLATE_Y(eve_page_scr_y(&form->p, 0) * 16));
-
for (i=0; i<form->widget_size; i++) {
if (widget->label && eve_page_rect_visible(&form->p, &widget->label->g)) {
eve_cmd_dl(TAG_MASK(0));
@@ -153,7 +188,7 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
for (i=tag0; i<tagN; i++) {
eve_touch_set_opt(i, eve_touch_get_opt(i) | tag_opt);
}
- if (v->window->tag != EVE_TAG_NOTAG) eve_touch_set_opt(v->window->tag, eve_touch_get_opt(v->window->tag) | tag_opt);
+ if (view->window->tag != EVE_TAG_NOTAG) eve_touch_set_opt(view->window->tag, eve_touch_get_opt(view->window->tag) | tag_opt);
return tagN;
}
diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h
index 68dfdca..51b56b0 100644
--- a/fw/fe310/eos/eve/screen/form.h
+++ b/fw/fe310/eos/eve/screen/form.h
@@ -11,15 +11,18 @@ typedef struct EVEForm {
struct EVEWidget *widget;
uint16_t widget_size;
eve_form_action_t action;
- int16_t win_x0;
- int16_t win_y0;
+ int win_x0;
+ int win_y0;
+ uint16_t h;
uint8_t evt_lock;
+ EVEPhyLHO lho;
+ uint64_t lho_t0;
} EVEForm;
int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor);
-int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx);
-uint8_t eve_form_draw(EVEView *v, uint8_t tag0);
+int eve_form_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0);
+uint8_t eve_form_draw(EVEView *view, uint8_t tag0);
void eve_form_update_g(EVEForm *form, struct EVEWidget *widget);
int eve_form_handle_evt(EVEForm *form, struct EVEWidget *widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h
index ed558ba..c198d94 100644
--- a/fw/fe310/eos/eve/screen/page.h
+++ b/fw/fe310/eos/eve/screen/page.h
@@ -7,8 +7,8 @@ typedef void (*eve_page_destructor_t) (struct EVEPage *);
typedef struct EVEPage {
EVEView v;
- int16_t win_x;
- int16_t win_y;
+ int win_x;
+ int win_y;
eve_page_destructor_t destructor;
EVEViewStack *stack;
struct EVEWidget *widget_f;
diff --git a/fw/fe310/eos/eve/screen/screen.c b/fw/fe310/eos/eve/screen/screen.c
index 1099515..25a1a76 100644
--- a/fw/fe310/eos/eve/screen/screen.c
+++ b/fw/fe310/eos/eve/screen/screen.c
@@ -88,23 +88,22 @@ void eve_screen_draw(EVEScreen *screen) {
eve_cmd_exec(1);
}
-void eve_screen_handle_touch(void *s, uint8_t tag0, int touch_idx) {
+void eve_screen_handle_touch(EVETouch *touch, uint16_t evt, uint8_t tag0, void *s) {
EVEScreen *screen = s;
EVEWindow *win;
int h = 0;
- eve_touch_clear_opt();
-
- if (touch_idx >= 0) {
- win = screen->win_tail;
- while (win) {
- if (eve_window_visible(win)) {
- h = win->view->touch(win->view, tag0, touch_idx);
- if (h) break;
- }
- win = win->prev;
+ win = screen->win_tail;
+ while (win) {
+ if (eve_window_visible(win)) {
+ h = win->view->touch(win->view, touch, evt, tag0);
+ if (h) break;
}
+ win = win->prev;
}
- if (h) eve_screen_draw(screen);
+ if (h) {
+ eve_touch_clear_opt();
+ eve_screen_draw(screen);
+ }
}
diff --git a/fw/fe310/eos/eve/screen/screen.h b/fw/fe310/eos/eve/screen/screen.h
index a9745ad..2f3f3ac 100644
--- a/fw/fe310/eos/eve/screen/screen.h
+++ b/fw/fe310/eos/eve/screen/screen.h
@@ -18,4 +18,4 @@ void eve_screen_show_kbd(EVEScreen *screen);
void eve_screen_hide_kbd(EVEScreen *screen);
void eve_screen_draw(EVEScreen *screen);
-void eve_screen_handle_touch(void *s, uint8_t tag0, int touch_idx);
+void eve_screen_handle_touch(EVETouch *touch, uint16_t evt, uint8_t tag0, void *s);
diff --git a/fw/fe310/eos/eve/screen/view.h b/fw/fe310/eos/eve/screen/view.h
index 3b635ef..6164a88 100644
--- a/fw/fe310/eos/eve/screen/view.h
+++ b/fw/fe310/eos/eve/screen/view.h
@@ -5,7 +5,7 @@
struct EVEView;
struct EVEViewStack;
-typedef int (*eve_view_touch_t) (struct EVEView *, uint8_t, int);
+typedef int (*eve_view_touch_t) (struct EVEView *, EVETouch *, uint16_t, uint8_t);
typedef uint8_t (*eve_view_draw_t) (struct EVEView *, uint8_t);
typedef void (*eve_view_constructor_t) (EVEWindow *window, struct EVEViewStack *);