summaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
Diffstat (limited to 'code')
-rw-r--r--code/fe310/eos/eve.c80
-rw-r--r--code/fe310/eos/eve.h32
-rw-r--r--code/fe310/eos/eve_text.c16
3 files changed, 66 insertions, 62 deletions
diff --git a/code/fe310/eos/eve.c b/code/fe310/eos/eve.c
index ccc52e2..8de0362 100644
--- a/code/fe310/eos/eve.c
+++ b/code/fe310/eos/eve.c
@@ -17,7 +17,7 @@
#define EVE_PIN_INTR 0
#define EVE_MAX_TOUCH 5
-#define EVE_ETYPE_INTR 1
+#define EVE_TAG_SCREEN 0xff
#define EVE_THRESHOLD_X 5
#define EVE_THRESHOLD_Y 5
@@ -29,8 +29,6 @@
#define EVE_NOTOUCH 0x80000000
#define EVE_MEM_WRITE 0x800000
-// #define EOS_SPI_FLAG_TX 0
-
static char _cmd_burst;
static uint16_t _cmd_offset;
static uint32_t _dl_addr;
@@ -317,10 +315,10 @@ static void handle_touch(uint8_t flags) {
uint8_t touch_tag;
uint32_t touch_xy;
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
- uint64_t now = 0;
+ volatile uint64_t now = 0;
EVETouch *touch = &_touch[i];
- touch->evt &= 0xff00;
+ 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) {
@@ -335,10 +333,15 @@ static void handle_touch(uint8_t flags) {
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;
+ touch->evt |= EVE_TOUCH_ETYPE_TAP1;
} else {
- touch->evt = EVE_TOUCH_ETYPE_TAP2;
+ 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);
}
eos_timer_clear(EOS_TIMER_ETYPE_UI);
@@ -383,13 +386,17 @@ static void handle_touch(uint8_t flags) {
_touch_timer_clear();
}
}
- if (!_touch_timer.tag && touch->tracker.tag && touch->tracker.track && (_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;
- eos_timer_set(EVE_TIMEOUT_TRACK, EOS_TIMER_ETYPE_UI, 0);
+ 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;
+ eos_timer_set(EVE_TIMEOUT_TRACK, EOS_TIMER_ETYPE_UI, 0);
+ } else {
+ touch->evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
+ }
}
touch->x = EVE_NOTOUCH;
touch->y = EVE_NOTOUCH;
@@ -401,15 +408,16 @@ static void handle_touch(uint8_t flags) {
touch->tag0 = touch_tag;
if (_tag_opt[touch_tag] & EVE_TOUCH_OPT_TRACK_MASK) {
touch->tracker.tag = touch_tag;
- } else if (_tag_opt[0xff] & EVE_TOUCH_OPT_TRACK_MASK) {
- touch->tracker.tag = 0xff;
+ } 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;
if (!touch->t && (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_INERT)) touch->t = now;
}
- if (!_tag0 && ((_tag_opt[touch_tag] | _tag_opt[0xff]) & EVE_TOUCH_OPT_TIMER_MASK)) {
- _touch_timer.tag = _tag_opt[touch_tag] & EVE_TOUCH_OPT_TIMER_MASK ? touch_tag : 0xff;
+ 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;
@@ -417,7 +425,7 @@ static void handle_touch(uint8_t flags) {
eos_timer_set(EVE_TIMEOUT_TAP, EOS_TIMER_ETYPE_UI, 0);
}
}
- if (!_tag0) tag0 = _tag0 = touch_tag;
+ if (!_tag0) _tag0 = tag0 = touch_tag;
}
touch->tag_up = touch->tag;
if (touch->tag_up) touch->evt |= EVE_TOUCH_ETYPE_TAG_UP;
@@ -446,6 +454,7 @@ static void handle_touch(uint8_t flags) {
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;
if (!touch->t && (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_INERT)) touch->t = now;
}
}
@@ -455,7 +464,7 @@ static void handle_touch(uint8_t flags) {
}
}
if (touch->tracker.tag && touch->tracker.track) {
- touch->evt |= _tag_opt[touch->tracker.tag] & EVE_TOUCH_ETYPE_TRACK_MASK;
+ 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]);
@@ -467,7 +476,7 @@ static void handle_touch(uint8_t flags) {
}
if (touch->tracker.tag || _touch_timer.tag) int_ccomplete = 1;
}
- if (touch->evt & 0xff) touch_last = i + 1;
+ if (touch->evt & EVE_TOUCH_EVT_MASK) touch_last = i + 1;
if (!_multitouch) break;
if (_touch_timer.tag) {
eos_timer_clear(EOS_TIMER_ETYPE_UI);
@@ -493,14 +502,14 @@ static void handle_touch(uint8_t flags) {
for (i=0; i<touch_last; i++) {
EVETouch *touch = &_touch[i];
- if (touch->evt & 0xff) {
+ if (_touch_handler && (touch->evt & EVE_TOUCH_EVT_MASK)) {
_touch_handler(_touch_handler_param, tag0, i);
}
}
}
static void handle_time(unsigned char type) {
- if (_touch_timer.tag) {
+ 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;
@@ -509,9 +518,9 @@ static void handle_time(unsigned char type) {
char more = 0;
int _x = touch->x;
int _y = touch->y;
- uint16_t _evt = touch->evt;
- touch->evt = _touch_timer.evt;
+ touch->evt &= ~EVE_TOUCH_EVT_MASK;
+ touch->evt |= _touch_timer.evt;
if (touch->evt & EVE_TOUCH_ETYPE_TRACK) {
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
int dt = *mtime - touch->t;
@@ -524,7 +533,7 @@ static void handle_time(unsigned char type) {
if (dt < _touch_timer.fc / 2) {
more = 1;
} else {
- touch->evt |= EVE_TOUCH_ETYPE_TRACK_DONE;
+ 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)(RTC_FREQ);
@@ -539,7 +548,6 @@ static void handle_time(unsigned char type) {
eos_spi_dev_stop();
if (!more) _touch_timer_clear();
- touch->evt = _evt;
touch->x = _x;
touch->y = _y;
}
@@ -571,7 +579,7 @@ int eve_init(uint32_t *touch_transform) {
eve_command(EVE_RST_PULSE, 0);
eve_command(EVE_CLKEXT, 0);
- eve_command(EVE_ACTIVE, 0); /* start EVE */
+ 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 */
eos_timer_sleep(1);
@@ -680,10 +688,6 @@ int eve_init(uint32_t *touch_transform) {
void eve_touch_set_handler(eve_touch_handler_t handler, void *param) {
_touch_handler = handler;
_touch_handler_param = param;
- /*
- eos_evtq_set_hflags(EOS_EVT_UI | EVE_ETYPE_INTR, flags);
- eos_timer_set_hflags(EOS_TIMER_ETYPE_UI, flags);
- */
}
EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t tag_max, uint16_t *evt) {
@@ -707,17 +711,13 @@ EVETouch *eve_touch_evt(uint8_t tag0, int touch_idx, uint8_t tag_min, uint8_t ta
_tag = ret->tag_up;
if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EVE_TOUCH_ETYPE_TAG_UP;
}
- if (_evt & EVE_TOUCH_ETYPE_TRACK) {
- _tag = ret->tracker.tag;
- if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= EVE_TOUCH_ETYPE_TRACK | (_evt & (EVE_TOUCH_ETYPE_TRACK_X | EVE_TOUCH_ETYPE_TRACK_Y));
- }
- if (_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 |= EVE_TOUCH_ETYPE_TRACK_REG;
+ 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 | EVE_TOUCH_ETYPE_TRACK_DONE)) {
+ 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 | EVE_TOUCH_ETYPE_TRACK_DONE);
+ if ((_tag >= tag_min) && (_tag <= tag_max)) *evt |= _evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2);
}
return ret;
diff --git a/code/fe310/eos/eve.h b/code/fe310/eos/eve.h
index 0e6979c..8445ea1 100644
--- a/code/fe310/eos/eve.h
+++ b/code/fe310/eos/eve.h
@@ -2,24 +2,29 @@
#include "eve_def.h"
-/* events */
-#define EVE_TOUCH_ETYPE_TRACK 0x01
-#define EVE_TOUCH_ETYPE_TRACK_REG 0x02
-#define EVE_TOUCH_ETYPE_TAG 0x10
-#define EVE_TOUCH_ETYPE_TAG_UP 0x20
-#define EVE_TOUCH_ETYPE_POINT 0x40
-#define EVE_TOUCH_ETYPE_POINT_UP 0x80
-
-#define EVE_TOUCH_ETYPE_TRACK_MASK (EVE_TOUCH_ETYPE_TRACK | EVE_TOUCH_ETYPE_TRACK_REG)
-#define EVE_TOUCH_ETYPE_TAG_MASK (EVE_TOUCH_ETYPE_TAG | EVE_TOUCH_ETYPE_TAG_UP)
-#define EVE_TOUCH_ETYPE_POINT_MASK (EVE_TOUCH_ETYPE_POINT | EVE_TOUCH_ETYPE_POINT_UP)
+#define EVE_ETYPE_INTR 1
-/* extended events */
+/* 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_TRACK_DONE 0x0800
+#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_REG | 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
@@ -27,6 +32,7 @@
#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
diff --git a/code/fe310/eos/eve_text.c b/code/fe310/eos/eve_text.c
index 0f93b20..9470530 100644
--- a/code/fe310/eos/eve_text.c
+++ b/code/fe310/eos/eve_text.c
@@ -42,7 +42,7 @@ void eve_text_init(EVEText *box, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
box->dl_size += 1;
}
- eve_touch_set_opt(tag, EVE_TOUCH_ETYPE_TRACK);
+ eve_touch_set_opt(tag, EVE_TOUCH_OPT_TRACK);
eve_cmd(CMD_MEMSET, "www", mem_addr, 0x0, box->w * 2 * box->line_size);
eve_cmd_exec(1);
@@ -56,14 +56,9 @@ int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx) {
EVETouch *t = eve_touch_evt(tag0, touch_idx, box->tag, box->tag, &evt);
if (t && evt) {
- if (evt & EVE_TOUCH_ETYPE_TAG) {
- if (box->line_top < 0) {
- box->line_top = box->line0;
- box->line_top0 = box->line0;
- }
- }
- if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
- box->line_top0 = box->line_top;
+ 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);
@@ -72,6 +67,9 @@ int eve_text_touch(EVEText *box, uint8_t tag0, int touch_idx) {
box->dirty = 1;
}
}
+ if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
+ box->line_top0 = box->line_top;
+ }
return 1;
} else if (box->line_top >= 0) {
box->line_top = -1;