diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-03-11 16:31:38 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-03-11 16:31:38 +0100 |
commit | 03925afaa3117243a7b29fa4327ea378c3e6eee6 (patch) | |
tree | 12357e194346213a3bded2654f7e3428c84d6aed /code/fe310 | |
parent | ab1006d27417cc831150877ec46fbc13ffeddb53 (diff) |
eve refactor: keyboard scale param; track extended; oscillator extended tracker
Diffstat (limited to 'code/fe310')
-rw-r--r-- | code/fe310/eos/eve/Makefile | 2 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve.c | 376 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve.h | 88 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_kbd.c | 78 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_kbd.h | 2 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_platform.c | 14 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_platform.h | 10 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_touch.c | 364 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_touch.h | 86 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_track.c | 99 | ||||
-rw-r--r-- | code/fe310/eos/eve/eve_track.h | 35 | ||||
-rw-r--r-- | code/fe310/eos/eve/screen/form.c | 4 |
12 files changed, 655 insertions, 503 deletions
diff --git a/code/fe310/eos/eve/Makefile b/code/fe310/eos/eve/Makefile index b5eef2d..0a737cc 100644 --- a/code/fe310/eos/eve/Makefile +++ b/code/fe310/eos/eve/Makefile @@ -2,7 +2,7 @@ include ../../common.mk CFLAGS += -I.. -I../../include -obj = eve.o eve_kbd.o eve_text.o eve_platform.o +obj = eve.o eve_touch.o eve_track.o eve_kbd.o eve_text.o eve_platform.o %.o: %.c %.h diff --git a/code/fe310/eos/eve/eve.c b/code/fe310/eos/eve/eve.c index adfe5f9..1a51891 100644 --- a/code/fe310/eos/eve/eve.c +++ b/code/fe310/eos/eve/eve.c @@ -1,64 +1,15 @@ #include <stdlib.h> -#include <string.h> #include <stdarg.h> #include <stdio.h> -#include <math.h> #include "eve.h" -#include "eve_platform.h" -#define EVE_THRESHOLD_X 5 -#define EVE_THRESHOLD_Y 5 -#define EVE_TIMEOUT_TAP 1000 -#define EVE_TIMEOUT_TRACK 20 -#define EVE_TRAVG 3 -#define EVE_FRICTION 500 - -#define EVE_NOTOUCH 0x80000000 #define EVE_MEM_WRITE 0x800000 -#define EVE_MAX_TOUCH 5 -#define EVE_TAG_SCREEN 0xff - static char _cmd_burst; static uint16_t _cmd_offset; static uint32_t _dl_addr; -static int _intr_mask = EVE_INT_TAG | EVE_INT_TOUCH; -static int _multitouch; -static uint8_t _tag0; - -static EVETouch _touch[EVE_MAX_TOUCH]; -static EVETouchTimer _touch_timer; - -static eve_touch_handler_t _touch_handler; -static void *_touch_handler_param; - -static uint8_t _tag_opt[255]; - -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_command(uint8_t command, uint8_t parameter) { eve_spi_cs_set(); eve_spi_xchg24(((uint32_t)command << 16) | ((uint32_t)parameter << 8), 0); @@ -289,257 +240,7 @@ void eve_cmd_burst_end(void) { _cmd_burst = 0; } -static void _touch_timer_clear(void) { - eve_timer_clear(); - _touch_timer.tag = 0; - _touch_timer.fc = 0; -} - -void eve_handle_touch(void) { - int i; - char touch_ex = 0; - char int_ccomplete = 0; - uint8_t tag0 = _tag0; - uint8_t touch_last = 0; - uint8_t flags = eve_read8(REG_INT_FLAGS) & _intr_mask; - - if (!_multitouch && (flags & EVE_INT_TOUCH)) _multitouch = 1; - for (i=0; i<EVE_MAX_TOUCH; i++) { - uint8_t touch_tag; - uint32_t touch_xy; - uint64_t now = 0; - EVETouch *touch = &_touch[i]; - - touch->evt &= ~EVE_TOUCH_EVT_MASK; - 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) { - int16_t touch_x = touch_xy >> 16; - int16_t touch_y = touch_xy & 0xffff; - now = eve_timer_get_tick(); - if (touch->x == EVE_NOTOUCH) { - if (!_tag0 && _touch_timer.tag) { - if (_touch_timer.evt & EVE_TOUCH_ETYPE_TAP1) { - 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; - } else { - touch->evt |= EVE_TOUCH_ETYPE_TAP2; - } - } - if (_touch_timer.evt & EVE_TOUCH_ETYPE_TRACK) { - touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP; - } - if (_touch_handler && (touch->evt & EVE_TOUCH_EVT_MASK)) { - _touch_handler(_touch_handler_param, _touch_timer.tag, i); - } - _touch_timer_clear(); - } - touch->evt = EVE_TOUCH_ETYPE_POINT; - 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_TRAVG) / (EVE_TRAVG + 1) : vx; - touch->vy = touch->vy ? (vy + touch->vy * EVE_TRAVG) / (EVE_TRAVG + 1) : vy; - touch->t = now; - } - touch->x = touch_x; - touch->y = touch_y; - if (_multitouch || (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->x != EVE_NOTOUCH) { - touch->evt |= EVE_TOUCH_ETYPE_POINT_UP; - if (_touch_timer.tag && (i == 0)) { - _touch_timer.evt &= ~EVE_TOUCH_ETYPE_LPRESS; - if (!_touch_timer.evt) { - _touch_timer_clear(); - } - } - if (touch->tracker.tag && touch->tracker.track) { - if (!_touch_timer.tag && (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_INERT)) { - _touch_timer.x0 = touch->x; - _touch_timer.y0 = touch->y; - _touch_timer.tag = touch->tracker.tag; - _touch_timer.idx = i; - _touch_timer.evt = EVE_TOUCH_ETYPE_TRACK; - eve_timer_set(EVE_TIMEOUT_TRACK); - } else { - touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP; - } - } - touch->x = EVE_NOTOUCH; - touch->y = EVE_NOTOUCH; - } - } - if (touch_tag != touch->tag) { - if (touch_tag) { - if (!touch->tag0) { - touch->tag0 = touch_tag; - if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_TRACK_MASK) { - touch->tracker.tag = touch_tag; - } else if (_tag_opt[EVE_TAG_SCREEN] & EVE_TOUCH_OPT_TRACK_MASK) { - touch->tracker.tag = EVE_TAG_SCREEN; - } - if (touch->tracker.tag && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { - touch->tracker.track = 1; - touch->evt |= EVE_TOUCH_ETYPE_TRACK_START; - touch->t = now; - } - if (!_tag0 && ((_tag_opt[touch_tag] | _tag_opt[EVE_TAG_SCREEN]) & EVE_TOUCH_OPT_TIMER_MASK)) { - _touch_timer.tag = _tag_opt[touch_tag] & EVE_TOUCH_OPT_TIMER_MASK ? touch_tag : EVE_TAG_SCREEN; - _touch_timer.idx = 0; - _touch_timer.evt = 0; - if (_tag_opt[_touch_timer.tag] & EVE_TOUCH_OPT_LPRESS) _touch_timer.evt |= EVE_TOUCH_ETYPE_LPRESS; - if (_tag_opt[_touch_timer.tag] & EVE_TOUCH_OPT_DTAP) _touch_timer.evt |= EVE_TOUCH_ETYPE_TAP1; - eve_timer_set(EVE_TIMEOUT_TAP); - } - } - if (!_tag0) _tag0 = tag0 = touch_tag; - } - 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 != 0x80008000) { - char _track = touch->tracker.tag && !touch->tracker.track; - if (_track || _touch_timer.tag) { - 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)) { - touch->tracker.tag = 0; - } - if ((dy > EVE_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) { - touch->evt |= touch->x > touch->x0 ? EVE_TOUCH_ETYPE_TRACK_RIGHT : EVE_TOUCH_ETYPE_TRACK_LEFT; - } - if (dy > EVE_THRESHOLD_Y) { - touch->evt |= touch->y > touch->y0 ? EVE_TOUCH_ETYPE_TRACK_DOWN : EVE_TOUCH_ETYPE_TRACK_UP; - } - touch->tracker.track = 1; - touch->evt |= EVE_TOUCH_ETYPE_TRACK_START; - touch->t = now; - } - } - if (_touch_timer.tag && ((dx > EVE_THRESHOLD_X) || (dy > EVE_THRESHOLD_Y))) { - _touch_timer_clear(); - } - } - if (touch->tracker.tag && touch->tracker.track) { - touch->evt |= _tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_MASK; - } - 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 || _touch_timer.tag) int_ccomplete = 1; - } - if (touch->evt & EVE_TOUCH_EVT_MASK) touch_last = i + 1; - if (!_multitouch) break; - if (_touch_timer.tag) { - _touch_timer_clear(); - } - } - - if (!touch_ex) { - _tag0 = 0; - _multitouch = 0; - } - - if (_multitouch) int_ccomplete = 1; - - if (int_ccomplete && !(_intr_mask & EVE_INT_CONVCOMPLETE)) { - _intr_mask |= EVE_INT_CONVCOMPLETE; - eve_write8(REG_INT_MASK, _intr_mask); - } - if (!int_ccomplete && (_intr_mask & EVE_INT_CONVCOMPLETE)) { - _intr_mask &= ~EVE_INT_CONVCOMPLETE; - eve_write8(REG_INT_MASK, _intr_mask); - } - - for (i=0; i<touch_last; i++) { - EVETouch *touch = &_touch[i]; - if (_touch_handler && (touch->evt & EVE_TOUCH_EVT_MASK)) { - _touch_handler(_touch_handler_param, tag0, i); - } - } -} - -void eve_handle_time(void) { - if (_touch_handler && _touch_timer.tag) { - 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; - - if (_touch_timer.evt) { - char more = 0; - int _x = touch->x; - int _y = touch->y; - - touch->evt &= ~EVE_TOUCH_EVT_MASK; - touch->evt |= _touch_timer.evt; - if (touch->evt & EVE_TOUCH_ETYPE_TRACK) { - int dt = eve_timer_get_tick() - touch->t; - - if (_touch_timer.fc == 0) { - double d = sqrt(touch->vx * touch->vx + touch->vy * touch->vy); - _touch_timer.fc = (double)(EVE_RTC_FREQ) * d / EVE_FRICTION; - } - - if (dt < _touch_timer.fc / 2) { - more = 1; - } else { - touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP; - dt = _touch_timer.fc / 2; - } - touch->x = _touch_timer.x0 + (touch->vx * dt - touch->vx * dt / _touch_timer.fc * dt ) / (int)(EVE_RTC_FREQ); - touch->y = _touch_timer.y0 + (touch->vy * dt - touch->vy * dt / _touch_timer.fc * dt ) / (int)(EVE_RTC_FREQ); - - if (more) eve_timer_set(EVE_TIMEOUT_TRACK); - } - - _touch_handler(_touch_handler_param, _touch_timer.tag, _touch_timer.idx); - - if (!more) _touch_timer_clear(); - touch->x = _x; - touch->y = _y; - } - } -} - int eve_init(uint32_t *touch_transform) { - int i; uint8_t chipid = 0; uint16_t timeout = 0; @@ -547,7 +248,7 @@ int eve_init(uint32_t *touch_transform) { eve_command(EVE_CLKEXT, 0); eve_command(EVE_ACTIVE, 0); /* start EVE */ - 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 */ + 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_sleep(1); chipid = eve_read8(REG_ID); timeout++; @@ -593,10 +294,6 @@ int eve_init(uint32_t *touch_transform) { eve_write8(REG_GPIO, 0x80); /* enable the DISP signal to the LCD panel, it is set to output in REG_GPIO_DIR by default */ eve_write8(REG_PCLK, EVE_PCLK); /* now start clocking data to the LCD panel */ - eve_write8(REG_INT_EN, 0x01); - eve_write8(REG_INT_MASK, _intr_mask); - while(eve_read8(REG_INT_FLAGS)); - if (touch_transform) { eve_write32(REG_TOUCH_TRANSFORM_A, touch_transform[0]); eve_write32(REG_TOUCH_TRANSFORM_B, touch_transform[1]); @@ -629,75 +326,12 @@ int eve_init(uint32_t *touch_transform) { eve_cmd(CMD_SETROTATE, "w", 2); eve_cmd_exec(1); + eve_init_touch(); + eve_init_track(); + eve_init_platform(); + eve_sleep(500); eve_command(EVE_STANDBY, 0); - for (i=0; i<EVE_MAX_TOUCH; i++) { - EVETouch *touch = &_touch[i]; - touch->x = EVE_NOTOUCH; - touch->y = EVE_NOTOUCH; - } - - eve_init_platform(); return EVE_OK; } - -void eve_touch_set_handler(eve_touch_handler_t handler, void *param) { - _touch_handler = handler; - _touch_handler_param = param; -} - -EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_max, uint16_t *evt) { - uint8_t _tag; - uint16_t _evt; - EVETouch *ret = NULL; - - *evt = 0; - if ((touch_idx < 0) || (touch_idx > 4)) return ret; - if ((tag_min == 0) || (tag_max == 0)) return ret; - if ((tag0 < tag_min) || (tag0 > tag_max)) return ret; - - ret = &_touch[touch_idx]; - _evt = ret->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; - } - 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_TRACK_REG) { - _tag = ret->tracker.tag; - if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EVE_TOUCH_ETYPE_TRACK_REG; - } - 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 | EVE_TOUCH_ETYPE_TRACK_XY); - } - if (_evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2)) { - _tag = _touch_timer.tag; - if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= _evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2); - } - - return ret; -} - -void eve_touch_set_opt(uint8_t tag, uint8_t opt) { - _tag_opt[tag] = opt; -} - -uint8_t eve_touch_get_opt(uint8_t tag) { - return _tag_opt[tag]; -} - -void eve_touch_clear_opt(void) { - memset(_tag_opt, 0, sizeof(_tag_opt)); -} - -EVETouchTimer *eve_touch_get_timer(void) { - return &_touch_timer; -} - diff --git a/code/fe310/eos/eve/eve.h b/code/fe310/eos/eve/eve.h index 41882c2..38310f6 100644 --- a/code/fe310/eos/eve/eve.h +++ b/code/fe310/eos/eve/eve.h @@ -1,85 +1,14 @@ #include <stdint.h> #include "eve_def.h" +#include "eve_touch.h" +#include "eve_track.h" +#include "eve_platform.h" -#define EVE_ETYPE_INTR 1 #define EVE_OK 0 #define EVE_ERR -1 #define EVE_ERR_TEXT -100 -/* 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_EVT_MASK 0x0fff - -#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) -#define EVE_TOUCH_ETYPE_POINT_MASK (EVE_TOUCH_ETYPE_POINT | EVE_TOUCH_ETYPE_POINT_UP) - -/* extended events */ -#define EVE_TOUCH_ETYPE_TRACK_LEFT 0x1000 -#define EVE_TOUCH_ETYPE_TRACK_RIGHT 0x2000 -#define EVE_TOUCH_ETYPE_TRACK_UP 0x4000 -#define EVE_TOUCH_ETYPE_TRACK_DOWN 0x8000 - -#define EVE_TOUCH_ETYPE_TRACK_X (EVE_TOUCH_ETYPE_TRACK_LEFT | EVE_TOUCH_ETYPE_TRACK_RIGHT) -#define EVE_TOUCH_ETYPE_TRACK_Y (EVE_TOUCH_ETYPE_TRACK_UP | EVE_TOUCH_ETYPE_TRACK_DOWN) -#define EVE_TOUCH_ETYPE_TRACK_XY (EVE_TOUCH_ETYPE_TRACK_X | EVE_TOUCH_ETYPE_TRACK_Y) - -/* 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_X 0x04 -#define EVE_TOUCH_OPT_TRACK_Y 0x08 -#define EVE_TOUCH_OPT_INERT 0x10 -#define EVE_TOUCH_OPT_LPRESS 0x40 -#define EVE_TOUCH_OPT_DTAP 0x80 - -#define EVE_TOUCH_OPT_TRACK_XY (EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_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 struct EVETouch { - int x; - int y; - int vx; - int vy; - int x0; - int y0; - uint64_t t; - uint16_t evt; - uint8_t tag0; - uint8_t tag; - uint8_t tag_up; - struct { - uint8_t tag; - uint8_t track; - uint16_t val; - } tracker; -} EVETouch; - -typedef struct EVETouchTimer { - uint8_t tag; - uint8_t idx; - uint16_t evt; - int x0; - int y0; - int fc; -} EVETouchTimer; - -typedef void (*eve_touch_handler_t) (void *, uint8_t, int); - void eve_command(uint8_t command, uint8_t parameter); uint8_t eve_read8(uint32_t addr); @@ -104,15 +33,4 @@ int eve_cmd_done(void); int eve_cmd_exec(int w); void eve_cmd_burst_start(void); void eve_cmd_burst_end(void); - -void eve_handle_touch(void); -void eve_handle_time(void); int eve_init(uint32_t *touch_transform); - -void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param); -EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_max, uint16_t *evt); -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); - -EVETouchTimer *eve_touch_get_timer(void);
\ No newline at end of file diff --git a/code/fe310/eos/eve/eve_kbd.c b/code/fe310/eos/eve/eve_kbd.c index 282cb37..26361cf 100644 --- a/code/fe310/eos/eve/eve_kbd.c +++ b/code/fe310/eos/eve/eve_kbd.c @@ -3,29 +3,35 @@ #include "eve.h" #include "eve_kbd.h" -#define FLAG_SHIFT 0x01 -#define FLAG_CTRL 0x02 -#define FLAG_FN 0x04 - -#define KEY_SHIFT 0x11 -#define KEY_CTRL 0x12 -#define KEY_FN 0x13 +#define KBD_X 0 +#define KBD_Y 575 +#define KBD_W 480 +#define KBD_H 225 -#define KEYS_Y 575 -#define KEYS_FSIZE 29 -#define KEYS_HEIGHT 40 -#define KEYS_RSIZE 45 +#define KEY_SPACERX 3 +#define KEY_SPACERY 5 +#define KEY_FONT 29 +#define MOD_FONT 21 #define KEY_BS 0x08 #define KEY_RET 0x0a +#define FLAG_SHIFT 0x01 +#define FLAG_CTRL 0x02 +#define FLAG_FN 0x04 + +#define TAG_SHIFT 0x11 +#define TAG_CTRL 0x12 +#define TAG_FN 0x13 + void eve_kbd_init(EVEKbd *kbd, uint32_t mem_addr, uint32_t *mem_next) { uint16_t mem_size; - kbd->w = 480; - kbd->h = 225; + kbd->x = KBD_X; + kbd->y = KBD_Y; + kbd->w = KBD_W; + kbd->h = KBD_H; kbd->mem_addr = mem_addr; - kbd->mem_size = mem_size; kbd->key_modifier = 0; kbd->key_count = 0; kbd->key_down = 0; @@ -39,6 +45,7 @@ void eve_kbd_init(EVEKbd *kbd, uint32_t mem_addr, uint32_t *mem_next) { eve_cmd(CMD_MEMCPY, "www", mem_addr, EVE_RAM_DL, mem_size); eve_cmd_exec(1); kbd->active = 0; + kbd->mem_size = mem_size; *mem_next = kbd->mem_addr + kbd->mem_size; } @@ -56,9 +63,9 @@ int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx, void *w) { if (evt & EVE_TOUCH_ETYPE_TAG) { uint8_t _tag = t->tag; - if (_tag >= KEY_SHIFT && _tag <= KEY_FN) { + if (_tag >= TAG_SHIFT && _tag <= TAG_FN) { if (touch_idx == 0) { - uint8_t f = (1 << (_tag - KEY_SHIFT)); + uint8_t f = (1 << (_tag - TAG_SHIFT)); kbd->key_modifier = f; kbd->key_modifier_sticky &= f; @@ -86,9 +93,9 @@ int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx, void *w) { if (evt & EVE_TOUCH_ETYPE_TAG_UP) { uint8_t _tag = t->tag_up; - if (_tag >= KEY_SHIFT && _tag <= KEY_FN) { + if (_tag >= TAG_SHIFT && _tag <= TAG_FN) { if (touch_idx == 0) { - uint8_t f = (1 << (_tag - KEY_SHIFT)); + uint8_t f = (1 << (_tag - TAG_SHIFT)); if (!((kbd->key_modifier_lock | kbd->key_modifier_sticky) & f)) { kbd->key_modifier &= ~f; @@ -112,23 +119,32 @@ int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx, void *w) { uint8_t eve_kbd_draw(EVEKbd *kbd) { if (kbd->active) { + int x = kbd->x; + int y = kbd->y; + int w = kbd->w; + int row_h = kbd->h / 5; + int key_w = (w - 9 * KEY_SPACERX) / 10 + 1; + int mod_w = key_w + key_w / 2; + int key_h = row_h - KEY_SPACERY; + + eve_cmd_dl(SAVE_CONTEXT()); - eve_cmd(CMD_KEYS, "hhhhhhs", 0, KEYS_Y + KEYS_RSIZE * 0, 480, KEYS_HEIGHT, KEYS_FSIZE, kbd->key_down, kbd->key_modifier & (FLAG_FN | FLAG_SHIFT) ? "!@#$%^&*()" : (kbd->key_modifier & FLAG_CTRL ? " @[\\]^_? " : "1234567890")); - eve_cmd(CMD_KEYS, "hhhhhhs", 0, KEYS_Y + KEYS_RSIZE * 1, 480, KEYS_HEIGHT, KEYS_FSIZE, kbd->key_down, kbd->key_modifier & FLAG_FN ? "-_=+[]{}\\|" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "QWERTYUIOP" : "qwertyuiop"); - eve_cmd(CMD_KEYS, "hhhhhhs", 24, KEYS_Y + KEYS_RSIZE * 2, 432, KEYS_HEIGHT, KEYS_FSIZE, kbd->key_down, kbd->key_modifier & FLAG_FN ? "`~ ;:'\"" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "ASDFGHJKL" : "asdfghjkl"); - eve_cmd(CMD_KEYS, "hhhhhhs", 72, KEYS_Y + KEYS_RSIZE * 3, 335, KEYS_HEIGHT, KEYS_FSIZE, kbd->key_down, kbd->key_modifier & FLAG_FN ? " ,.<>/?" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "ZXCVBNM" : "zxcvbnm"); - eve_cmd_dl(TAG(KEY_SHIFT)); - eve_cmd(CMD_BUTTON, "hhhhhhs", 0, KEYS_Y + KEYS_RSIZE * 3, 69, KEYS_HEIGHT, 21, kbd->key_modifier & FLAG_SHIFT ? EVE_OPT_FLAT : 0, "shift"); + eve_cmd(CMD_KEYS, "hhhhhhs", x, y + row_h * 0, w, key_h, KEY_FONT, kbd->key_down, kbd->key_modifier & (FLAG_FN | FLAG_SHIFT) ? "!@#$%^&*()" : (kbd->key_modifier & FLAG_CTRL ? " @[\\]^_? " : "1234567890")); + eve_cmd(CMD_KEYS, "hhhhhhs", x, y + row_h * 1, w, key_h, KEY_FONT, kbd->key_down, kbd->key_modifier & FLAG_FN ? "-_=+[]{}\\|" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "QWERTYUIOP" : "qwertyuiop"); + eve_cmd(CMD_KEYS, "hhhhhhs", x + key_w / 2, y + row_h * 2, w - key_w, key_h, KEY_FONT, kbd->key_down, kbd->key_modifier & FLAG_FN ? "`~ ;:'\"" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "ASDFGHJKL" : "asdfghjkl"); + eve_cmd(CMD_KEYS, "hhhhhhs", x + mod_w + KEY_SPACERX, y + row_h * 3, w - 2 * (mod_w + KEY_SPACERX), key_h, KEY_FONT, kbd->key_down, kbd->key_modifier & FLAG_FN ? " ,.<>/?" : kbd->key_modifier & (FLAG_SHIFT | FLAG_CTRL) ? "ZXCVBNM" : "zxcvbnm"); + eve_cmd_dl(TAG(TAG_SHIFT)); + eve_cmd(CMD_BUTTON, "hhhhhhs", x, y + row_h * 3, mod_w, key_h, MOD_FONT, kbd->key_modifier & FLAG_SHIFT ? EVE_OPT_FLAT : 0, "shift"); eve_cmd_dl(TAG(KEY_BS)); - eve_cmd(CMD_BUTTON, "hhhhhhs", 410, KEYS_Y + KEYS_RSIZE * 3, 70, KEYS_HEIGHT, 21, kbd->key_down == KEY_BS ? EVE_OPT_FLAT : 0, "del"); - eve_cmd_dl(TAG(KEY_FN)); - eve_cmd(CMD_BUTTON, "hhhhhhs", 0, KEYS_Y + KEYS_RSIZE * 4, 69, KEYS_HEIGHT, 21, kbd->key_modifier & FLAG_FN ? EVE_OPT_FLAT : 0, "fn"); - eve_cmd_dl(TAG(KEY_CTRL)); - eve_cmd(CMD_BUTTON, "hhhhhhs", 72, KEYS_Y + KEYS_RSIZE * 4, 69, KEYS_HEIGHT, 21, kbd->key_modifier & FLAG_CTRL ? EVE_OPT_FLAT : 0, "ctrl"); + eve_cmd(CMD_BUTTON, "hhhhhhs", x + w - mod_w, y + row_h * 3, mod_w, key_h, MOD_FONT, kbd->key_down == KEY_BS ? EVE_OPT_FLAT : 0, "del"); + eve_cmd_dl(TAG(TAG_FN)); + eve_cmd(CMD_BUTTON, "hhhhhhs", x, y + row_h * 4, mod_w, key_h, MOD_FONT, kbd->key_modifier & FLAG_FN ? EVE_OPT_FLAT : 0, "fn"); + eve_cmd_dl(TAG(TAG_CTRL)); + eve_cmd(CMD_BUTTON, "hhhhhhs", x + mod_w + KEY_SPACERX, y + row_h * 4, mod_w, key_h, MOD_FONT, kbd->key_modifier & FLAG_CTRL ? EVE_OPT_FLAT : 0, "ctrl"); eve_cmd_dl(TAG(' ')); - eve_cmd(CMD_BUTTON, "hhhhhhs", 144, KEYS_Y + KEYS_RSIZE * 4, 263, KEYS_HEIGHT, 21, kbd->key_down == ' ' ? EVE_OPT_FLAT : 0, ""); + eve_cmd(CMD_BUTTON, "hhhhhhs", x + 2 * (mod_w + KEY_SPACERX), y + row_h * 4, w - 3 * (mod_w + KEY_SPACERX), key_h, MOD_FONT, kbd->key_down == ' ' ? EVE_OPT_FLAT : 0, ""); eve_cmd_dl(TAG(KEY_RET)); - eve_cmd(CMD_BUTTON, "hhhhhhs", 410, KEYS_Y + KEYS_RSIZE * 4, 69, KEYS_HEIGHT, 21, kbd->key_down == KEY_RET ? EVE_OPT_FLAT : 0, "ret"); + eve_cmd(CMD_BUTTON, "hhhhhhs", x + w - mod_w, y + row_h * 4, mod_w, key_h, MOD_FONT, kbd->key_down == KEY_RET ? EVE_OPT_FLAT : 0, "ret"); eve_cmd_dl(RESTORE_CONTEXT()); } else { eve_cmd(CMD_APPEND, "ww", kbd->mem_addr, kbd->mem_size); diff --git a/code/fe310/eos/eve/eve_kbd.h b/code/fe310/eos/eve/eve_kbd.h index 01bd950..6529df1 100644 --- a/code/fe310/eos/eve/eve_kbd.h +++ b/code/fe310/eos/eve/eve_kbd.h @@ -3,6 +3,8 @@ typedef void (*eve_kbd_input_handler_t) (void *, int); typedef struct EVEKbd { + int16_t x; + int16_t y; uint16_t w; uint16_t h; uint32_t mem_addr; diff --git a/code/fe310/eos/eve/eve_platform.c b/code/fe310/eos/eve/eve_platform.c index 803b071..ab9157e 100644 --- a/code/fe310/eos/eve/eve_platform.c +++ b/code/fe310/eos/eve/eve_platform.c @@ -1,20 +1,15 @@ #include <stdlib.h> -#include "encoding.h" #include "platform.h" #include "eos.h" #include "interrupt.h" #include "event.h" -#include "timer.h" -#include "spi.h" #include "eve.h" #include "eve_platform.h" #include "irq_def.h" -#define EVE_PIN_INTR 0 - static void handle_time(unsigned char type) { eos_spi_dev_start(EOS_DEV_DISP); eve_handle_time(); @@ -37,20 +32,19 @@ static void handle_intr(void) { } void eve_sleep(uint32_t ms) { - eos_timer_sleep(ms); + eos_time_sleep(ms); } void eve_timer_set(uint32_t ms) { - eos_timer_set(ms, EOS_TIMER_ETYPE_UI, 0); + eos_timer_set(ms, EOS_TIMER_ETYPE_UI); } void eve_timer_clear(void) { eos_timer_clear(EOS_TIMER_ETYPE_UI); } -uint64_t eve_timer_get_tick(void) { - volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME); - return *mtime; +uint64_t eve_time_get_tick(void) { + return eos_time_get_tick(); } void eve_init_platform(void) { diff --git a/code/fe310/eos/eve/eve_platform.h b/code/fe310/eos/eve/eve_platform.h index 8ab43ea..baa48cd 100644 --- a/code/fe310/eos/eve/eve_platform.h +++ b/code/fe310/eos/eve/eve_platform.h @@ -1,8 +1,12 @@ #include <stdint.h> -#include "spi.h" +#include "../spi.h" +#include "../timer.h" -#define EVE_RTC_FREQ 32768 +#define EVE_ETYPE_INTR 1 +#define EVE_PIN_INTR 0 + +#define EVE_RTC_FREQ EOS_TIMER_RTC_FREQ #define EVE_SPI_FLAG_BSWAP EOS_SPI_FLAG_BSWAP #define EVE_SPI_FLAG_TX EOS_SPI_FLAG_TX @@ -18,6 +22,6 @@ void eve_sleep(uint32_t ms); void eve_timer_set(uint32_t ms); void eve_timer_clear(void); -uint64_t eve_timer_get_tick(void); +uint64_t eve_time_get_tick(void); void eve_init_platform(void);
\ No newline at end of file diff --git a/code/fe310/eos/eve/eve_touch.c b/code/fe310/eos/eve/eve_touch.c new file mode 100644 index 0000000..76fd526 --- /dev/null +++ b/code/fe310/eos/eve/eve_touch.c @@ -0,0 +1,364 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_platform.h" + +#define EVE_THRESHOLD_X 5 +#define EVE_THRESHOLD_Y 5 +#define EVE_TIMEOUT_TAP 1000 +#define EVE_TIMEOUT_TRACK 20 +#define EVE_TRAVG 3 + +#define EVE_NOTOUCH 0x80000000 + +#define EVE_MAX_TOUCH 5 +#define EVE_TAG_SCREEN 0xff + +static int _intr_mask = EVE_INT_TAG | EVE_INT_TOUCH; +static int _multitouch; +static uint8_t _tag0; + +static EVETouch _touch[EVE_MAX_TOUCH]; +static EVETouchTimer _touch_timer; + +static eve_touch_handler_t _touch_handler; +static void *_touch_handler_param; +static uint8_t _tag_opt[255]; + +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_init_touch(void) { + int i; + + for (i=0; i<EVE_MAX_TOUCH; i++) { + EVETouch *touch = &_touch[i]; + touch->x = EVE_NOTOUCH; + touch->y = EVE_NOTOUCH; + } + eve_write8(REG_INT_MASK, _intr_mask); + eve_write8(REG_INT_EN, 0x01); + while(eve_read8(REG_INT_FLAGS)); +} + +static void _touch_timer_set(uint8_t tag, uint8_t idx, uint16_t evt, int x0, int y0, uint32_t to) { + _touch_timer.tag = tag; + _touch_timer.idx = idx; + _touch_timer.evt = evt; + _touch_timer.x0 = x0; + _touch_timer.y0 = y0; + eve_timer_set(to); +} + +static void _touch_timer_clear(void) { + eve_timer_clear(); + _touch_timer.tag = 0; + _touch_timer.evt = 0; +} + +void eve_handle_touch(void) { + int i; + char touch_ex = 0; + char int_ccomplete = 0; + uint8_t tag0 = _tag0; + uint8_t touch_last = 0; + uint8_t flags = eve_read8(REG_INT_FLAGS) & _intr_mask; + + if (!_multitouch && (flags & EVE_INT_TOUCH)) _multitouch = 1; + for (i=0; i<EVE_MAX_TOUCH; i++) { + uint8_t touch_tag; + uint32_t touch_xy; + uint64_t now = 0; + EVETouch *touch = &_touch[i]; + + touch->evt &= ~EVE_TOUCH_EVT_MASK; + 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) { + 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 (!_tag0 && _touch_timer.tag) { + if (_touch_timer.evt & EVE_TOUCH_ETYPE_TAP1) { + 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; + } else { + touch->evt |= EVE_TOUCH_ETYPE_TAP2; + } + } + if (_touch_timer.evt & EVE_TOUCH_ETYPE_TRACK) { + EVETracker *tr= eve_track_get_tracker(); + if (tr->stop) tr->stop(&_touch_timer, touch); + } + if (_touch_handler && (touch->evt & EVE_TOUCH_EVT_MASK)) { + _touch_handler(_touch_handler_param, _touch_timer.tag, i); + } + _touch_timer_clear(); + } + touch->evt = EVE_TOUCH_ETYPE_POINT; + 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_TRAVG) / (EVE_TRAVG + 1) : vx; + touch->vy = touch->vy ? (vy + touch->vy * EVE_TRAVG) / (EVE_TRAVG + 1) : vy; + touch->t = now; + } + touch->x = touch_x; + touch->y = touch_y; + if (_multitouch || (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->x != EVE_NOTOUCH) { + touch->evt |= EVE_TOUCH_ETYPE_POINT_UP; + if (_touch_timer.tag && (i == 0)) { + _touch_timer.evt &= ~EVE_TOUCH_ETYPE_LPRESS; + if (!_touch_timer.evt) _touch_timer_clear(); + } + if (touch->tracker.tag && touch->tracker.track) { + if (!_touch_timer.tag && (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_EXT)) { + EVETracker *tr= eve_track_get_tracker(); + _touch_timer_set(touch->tracker.tag, i, EVE_TOUCH_ETYPE_TRACK, touch->x, touch->y, EVE_TIMEOUT_TRACK); + if (tr->init) tr->init(&_touch_timer, touch); + } else { + touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP; + } + } + touch->x = EVE_NOTOUCH; + touch->y = EVE_NOTOUCH; + } + } + if (touch_tag != touch->tag) { + if (touch_tag) { + if (!touch->tag0) { + touch->tag0 = touch_tag; + if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_TRACK_MASK) { + touch->tracker.tag = touch_tag; + } else if (_tag_opt[EVE_TAG_SCREEN] & EVE_TOUCH_OPT_TRACK_MASK) { + touch->tracker.tag = EVE_TAG_SCREEN; + } + if (touch->tracker.tag && !(_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { + touch->tracker.track = 1; + touch->evt |= EVE_TOUCH_ETYPE_TRACK_START; + touch->t = now; + } + if (!_tag0 && ((_tag_opt[touch_tag] | _tag_opt[EVE_TAG_SCREEN]) & EVE_TOUCH_OPT_TIMER_MASK)) { + uint8_t _tag = _tag_opt[touch_tag] & EVE_TOUCH_OPT_TIMER_MASK ? touch_tag : EVE_TAG_SCREEN; + uint16_t _evt = 0; + if (_tag_opt[_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS; + if (_tag_opt[_tag] & EVE_TOUCH_OPT_DTAP) _evt |= EVE_TOUCH_ETYPE_TAP1; + _touch_timer_set(_tag, 0, _evt, 0, 0, EVE_TIMEOUT_TAP); + } + } + if (!_tag0) _tag0 = tag0 = touch_tag; + } + 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 != 0x80008000) { + char _track = touch->tracker.tag && !touch->tracker.track; + char _timer = _touch_timer.tag && (_touch_timer.evt & EVE_TOUCH_ETYPE_TIMER_MASK) && (i == 0); + 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)) { + touch->tracker.tag = 0; + } + if ((dy > EVE_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) { + touch->evt |= touch->x > touch->x0 ? EVE_TOUCH_ETYPE_TRACK_RIGHT : EVE_TOUCH_ETYPE_TRACK_LEFT; + } + if (dy > EVE_THRESHOLD_Y) { + touch->evt |= touch->y > touch->y0 ? EVE_TOUCH_ETYPE_TRACK_DOWN : EVE_TOUCH_ETYPE_TRACK_UP; + } + touch->tracker.track = 1; + touch->evt |= EVE_TOUCH_ETYPE_TRACK_START; + touch->t = now; + } + } + if (_timer && ((dx > EVE_THRESHOLD_X) || (dy > EVE_THRESHOLD_Y))) { + _touch_timer.evt &= ~EVE_TOUCH_ETYPE_TIMER_MASK; + if (!_touch_timer.evt) _touch_timer_clear(); + } + } + if (touch->tracker.tag && touch->tracker.track) { + touch->evt |= _tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_MASK; + } + 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 || _touch_timer.tag) int_ccomplete = 1; + } + if (touch->evt & EVE_TOUCH_EVT_MASK) touch_last = i + 1; + if (!_multitouch) break; + } + + if (!touch_ex) { + _tag0 = 0; + _multitouch = 0; + } + + if (_multitouch) int_ccomplete = 1; + + if (int_ccomplete && !(_intr_mask & EVE_INT_CONVCOMPLETE)) { + _intr_mask |= EVE_INT_CONVCOMPLETE; + eve_write8(REG_INT_MASK, _intr_mask); + } + if (!int_ccomplete && (_intr_mask & EVE_INT_CONVCOMPLETE)) { + _intr_mask &= ~EVE_INT_CONVCOMPLETE; + eve_write8(REG_INT_MASK, _intr_mask); + } + + for (i=0; i<touch_last; i++) { + EVETouch *touch = &_touch[i]; + if (_touch_handler && (touch->evt & EVE_TOUCH_EVT_MASK)) { + _touch_handler(_touch_handler_param, tag0, i); + } + } +} + +void eve_handle_time(void) { + if (_touch_handler && _touch_timer.tag) { + 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; + + if (_touch_timer.evt) { + int more = 0; + int _x = touch->x; + int _y = touch->y; + + touch->evt &= ~EVE_TOUCH_EVT_MASK; + touch->evt |= _touch_timer.evt; + if (touch->evt & EVE_TOUCH_ETYPE_TRACK) { + EVETracker *tr= eve_track_get_tracker(); + if (tr->tick) more = tr->tick(&_touch_timer, touch); + if (more) { + eve_timer_set(EVE_TIMEOUT_TRACK); + } else if (tr->stop) { + tr->stop(&_touch_timer, touch); + } + } + + _touch_handler(_touch_handler_param, _touch_timer.tag, _touch_timer.idx); + + if (!more) _touch_timer_clear(); + touch->x = _x; + touch->y = _y; + } + } +} + +void eve_touch_set_handler(eve_touch_handler_t handler, void *param) { + _touch_handler = handler; + _touch_handler_param = param; +} + +EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_max, uint16_t *evt) { + uint8_t _tag; + uint16_t _evt; + EVETouch *ret = NULL; + + *evt = 0; + if ((touch_idx < 0) || (touch_idx > 4)) return ret; + if ((tag_min == 0) || (tag_max == 0)) return ret; + if ((tag0 < tag_min) || (tag0 > tag_max)) return ret; + + ret = &_touch[touch_idx]; + _evt = ret->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; + } + 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_TRACK_REG) { + _tag = ret->tracker.tag; + if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EVE_TOUCH_ETYPE_TRACK_REG; + } + 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 | EVE_TOUCH_ETYPE_TRACK_XY); + } + if (_evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2)) { + _tag = _touch_timer.tag; + if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= _evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2); + } + + return ret; +} + +void eve_touch_set_opt(uint8_t tag, uint8_t opt) { + _tag_opt[tag] = opt; +} + +uint8_t eve_touch_get_opt(uint8_t tag) { + return _tag_opt[tag]; +} + +void eve_touch_clear_opt(void) { + memset(_tag_opt, 0, sizeof(_tag_opt)); +} + +EVETouchTimer *eve_touch_get_timer(void) { + return &_touch_timer; +} diff --git a/code/fe310/eos/eve/eve_touch.h b/code/fe310/eos/eve/eve_touch.h new file mode 100644 index 0000000..1382ddc --- /dev/null +++ b/code/fe310/eos/eve/eve_touch.h @@ -0,0 +1,86 @@ +#include <stdint.h> + +/* 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_EVT_MASK 0x0fff + +#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) +#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) + +/* extended events */ +#define EVE_TOUCH_ETYPE_TRACK_LEFT 0x1000 +#define EVE_TOUCH_ETYPE_TRACK_RIGHT 0x2000 +#define EVE_TOUCH_ETYPE_TRACK_UP 0x4000 +#define EVE_TOUCH_ETYPE_TRACK_DOWN 0x8000 + +#define EVE_TOUCH_ETYPE_TRACK_X (EVE_TOUCH_ETYPE_TRACK_LEFT | EVE_TOUCH_ETYPE_TRACK_RIGHT) +#define EVE_TOUCH_ETYPE_TRACK_Y (EVE_TOUCH_ETYPE_TRACK_UP | EVE_TOUCH_ETYPE_TRACK_DOWN) +#define EVE_TOUCH_ETYPE_TRACK_XY (EVE_TOUCH_ETYPE_TRACK_X | EVE_TOUCH_ETYPE_TRACK_Y) + +/* 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_X 0x04 +#define EVE_TOUCH_OPT_TRACK_Y 0x08 +#define EVE_TOUCH_OPT_TRACK_EXT 0x10 +#define EVE_TOUCH_OPT_LPRESS 0x40 +#define EVE_TOUCH_OPT_DTAP 0x80 + +#define EVE_TOUCH_OPT_TRACK_XY (EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_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 struct EVETouch { + int x; + int y; + int vx; + int vy; + int x0; + int y0; + uint64_t t; + uint16_t evt; + uint8_t tag0; + uint8_t tag; + uint8_t tag_up; + struct { + uint8_t tag; + uint8_t track; + uint16_t val; + } tracker; +} EVETouch; + +typedef struct EVETouchTimer { + uint8_t tag; + uint8_t idx; + uint16_t evt; + int x0; + int y0; + void *p; +} EVETouchTimer; + +typedef void (*eve_touch_handler_t) (void *, uint8_t, int); + +void eve_init_touch(void); +void eve_handle_touch(void); +void eve_handle_time(void); + +void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param); +EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_max, uint16_t *evt); +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); +EVETouchTimer *eve_touch_get_timer(void); diff --git a/code/fe310/eos/eve/eve_track.c b/code/fe310/eos/eve/eve_track.c new file mode 100644 index 0000000..9f0fec8 --- /dev/null +++ b/code/fe310/eos/eve/eve_track.c @@ -0,0 +1,99 @@ +#include <stdlib.h> +#include <math.h> +#include <stdio.h> + +#include "eve.h" +#include "eve_platform.h" + +static EVETracker _tracker; + +void eve_init_track(void) { + eve_track_set_handler(eve_track_inert_init, eve_track_inert_tick, eve_track_stop, NULL); +} + +EVETracker *eve_track_get_tracker(void) { + return &_tracker; +} + +void eve_track_set_handler(eve_track_init_t init, eve_track_tick_t tick, eve_track_stop_t stop, void *param) { + if (stop == NULL) stop = eve_track_stop; + + _tracker.init = init; + _tracker.tick = tick; + _tracker.stop = stop; + eve_touch_get_timer()->p = param; +} + +void eve_track_set(uint8_t type, void *param) { + switch (type) { + case EVE_TRACK_TYPE_INERT: + eve_track_set_handler(eve_track_inert_init, eve_track_inert_tick, eve_track_stop, NULL); + break; + case EVE_TRACK_TYPE_OSC: + eve_track_set_handler(NULL, eve_track_osc_tick, eve_track_stop, param); + break; + default: + break; + } +} + +void eve_track_stop(EVETouchTimer *timer, EVETouch *touch) { + touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP; +} + + +void eve_track_inert_init(EVETouchTimer *timer, EVETouch *touch) { + double d = sqrt(touch->vx * touch->vx + touch->vy * touch->vy); + int fc = (double)(EVE_RTC_FREQ) * d / EVE_TRACK_FRICTION; + + timer->p = (void *)fc; +} + +int eve_track_inert_tick(EVETouchTimer *timer, EVETouch *touch) { + int dt = eve_time_get_tick() - touch->t; + int fc = (int)timer->p; + int more = 1; + + if (dt >= fc / 2) { + dt = fc / 2; + more = 0; + } + touch->x = timer->x0 + (touch->vx * dt - touch->vx * dt / fc * dt) / (int)(EVE_RTC_FREQ); + touch->y = timer->y0 + (touch->vy * dt - touch->vy * dt / fc * dt) / (int)(EVE_RTC_FREQ); + return more; +} + +int eve_track_osc_tick(EVETouchTimer *timer, EVETouch *touch) { + EVETrackOsc *p = (EVETrackOsc *)timer->p; + int dt = eve_time_get_tick() - touch->t; + int ax = timer->x0 - p->x; + int ay = timer->y0 - p->y; + int more = 1; + + if (p->t_max && (dt >= p->t_max)) { + dt = p->t_max; + more = 0; + } + if (p->d) { + double e = exp(p->a * dt); + ax = ax * e; + ay = ay * e; + if ((ax == 0) && (ay == 0)) more = 0; + } + touch->x = p->x + ax * cos(p->f * dt); + touch->y = p->y + ay * cos(p->f * dt); + return more; +} + +void eve_track_osc_init(EVETrackOsc *p, 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; + p->x = x; + p->y = y; + p->f = d ? f0 * sqrt(1 - d * d) : f0; + p->d = d; + p->a = -d * f0; + p->t_max = t_max; +} diff --git a/code/fe310/eos/eve/eve_track.h b/code/fe310/eos/eve/eve_track.h new file mode 100644 index 0000000..07ddb44 --- /dev/null +++ b/code/fe310/eos/eve/eve_track.h @@ -0,0 +1,35 @@ +#include <stdint.h> + +#define EVE_TRACK_TYPE_INERT 1 +#define EVE_TRACK_TYPE_OSC 2 +#define EVE_TRACK_FRICTION 500 + +typedef void (*eve_track_init_t) (EVETouchTimer *, EVETouch *); +typedef int (*eve_track_tick_t) (EVETouchTimer *, EVETouch *); +typedef void (*eve_track_stop_t) (EVETouchTimer *, EVETouch *); + +typedef struct EVETracker { + eve_track_init_t init; + eve_track_tick_t tick; + eve_track_stop_t stop; +} EVETracker; + +typedef struct EVETrackOsc { + int x; + int y; + double f; + double d; + double a; + uint32_t t_max; +} EVETrackOsc; + +void eve_init_track(void); +EVETracker *eve_track_get_tracker(void); +void eve_track_set_handler(eve_track_init_t init, eve_track_tick_t tick, eve_track_stop_t stop, void *param); +void eve_track_set(uint8_t type, void *param); +void eve_track_stop(EVETouchTimer *timer, EVETouch *touch); + +void eve_track_inert_init(EVETouchTimer *timer, EVETouch *touch); +int eve_track_inert_tick(EVETouchTimer *timer, EVETouch *touch); +int eve_track_osc_tick(EVETouchTimer *timer, EVETouch *touch); +void eve_track_osc_init(EVETrackOsc *p, int x, int y, uint32_t T, double d, uint32_t t_max); diff --git a/code/fe310/eos/eve/screen/form.c b/code/fe310/eos/eve/screen/form.c index b4e59b9..10f17ad 100644 --- a/code/fe310/eos/eve/screen/form.c +++ b/code/fe310/eos/eve/screen/form.c @@ -24,7 +24,7 @@ int eve_form_touch(EVECanvas *c, uint8_t tag0, int touch_idx) { EVEForm *form = (EVEForm *)c; EVEWidget *widget = form->widget; int a, i, ret = 0; - EVEPageFocus focus = { NULL, {0,0,0,0}}; + EVEPageFocus focus = {NULL, {0,0,0,0}}; for (i=0; i<form->widget_size; i++) { a = widget->touch(widget, &form->p, tag0, touch_idx, &focus); @@ -61,7 +61,7 @@ uint8_t eve_form_draw(EVECanvas *c, uint8_t tag0) { tagN = widget->draw(widget, &form->p, tag0); if (tagN) { for (j=tag0; j<=tagN; j++) { - eve_touch_set_opt(j, eve_touch_get_opt(j) | EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_INERT); + eve_touch_set_opt(j, eve_touch_get_opt(j) | EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT); } if (tagN < 0xfe) { tag0 = tagN + 1; |