diff options
Diffstat (limited to 'fw/fe310/eos/eve/eve_touch.c')
-rw-r--r-- | fw/fe310/eos/eve/eve_touch.c | 160 |
1 files changed, 53 insertions, 107 deletions
diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c index a729346..d4e5cea 100644 --- a/fw/fe310/eos/eve/eve_touch.c +++ b/fw/fe310/eos/eve/eve_touch.c @@ -4,10 +4,9 @@ #include "eve.h" #include "eve_touch_engine.h" -static uint8_t touch_tag0; - static EVETouch touch_obj[EVE_MAX_TOUCH]; static EVETouchTimer touch_timer; +static EVEPhyAcc touch_acc; static eve_touch_handler_t touch_handler; static void *touch_handler_param; @@ -16,7 +15,6 @@ static uint8_t touch_tag_opt[256]; void eve_touch_init(void) { int i; - touch_tag0 = 0; memset(&touch_timer, 0, sizeof(touch_timer)); for (i=0; i<EVE_MAX_TOUCH; i++) { EVETouch *touch = &touch_obj[i]; @@ -24,7 +22,7 @@ void eve_touch_init(void) { memset(&touch_obj[i], 0, sizeof(EVETouch)); touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; } - eve_vtrack_init(); + eve_phy_acc_init(&touch_acc, -EVE_TOUCH_ACC_A); } void eve_handle_touch(uint16_t intr_flags) { @@ -68,23 +66,17 @@ void eve_handle_touch(uint16_t intr_flags) { } } if (timer_evt & 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 (timer_evt & EVE_TOUCH_ETYPE_TIMER) { - _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT; - _touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT; + eve_vtrack_stop(); } if (touch_handler && _touch_evt) { - touch_handler(touch_timer.touch, _touch_evt, touch_timer.tag0, touch_handler_param); + touch_handler(touch_timer.touch, _touch_evt, touch_handler_param); } eve_timer_clear(touch); } - touch_evt |= EVE_TOUCH_ETYPE_POINT | _evt; + touch_evt = EVE_TOUCH_ETYPE_POINT0 | _evt; touch->eevt = _eevt; touch->tag0 = 0; touch->tag = 0; @@ -104,10 +96,10 @@ void eve_handle_touch(uint16_t intr_flags) { touch->vx = vx; touch->vy = vy; - touch->t = now; } touch->x = touch_x; touch->y = touch_y; + touch->t = now; timer_evt = eve_timer_get_evt(touch); check_track = touch->tracker.tag && !touch->tracker.track; @@ -120,38 +112,31 @@ void eve_handle_touch(uint16_t intr_flags) { dx = dx < 0 ? -dx : dx; dy = dy < 0 ? -dy : dy; if (check_track) { - if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) { - touch->tracker.tag = 0; - } - if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) { + if (((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) || + ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y))) { touch->tracker.tag = 0; } if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { - int track_x = 0; - - if ((dx > EVE_TOUCH_THRESHOLD_X) && (dx > EVE_TOUCH_THRESHOLD_Y) && ((touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY) == EVE_TOUCH_OPT_TRACK_XY)) { - if (dx > dy) { - track_x = 1; - } - } else if (dx > EVE_TOUCH_THRESHOLD_X) { - track_x = 1; - } - if (track_x) { - touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; - } else { - touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP; - } + int track_x, track_y; + + track_x = 0; + track_y = 0; + if ((touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X) && (dx > EVE_TOUCH_THRESHOLD_X)) track_x = 1; + if ((touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y) && (dy > EVE_TOUCH_THRESHOLD_Y)) track_y = 1; + + if (track_x) touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; + if (track_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->t = now; } } if (check_timer && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { eve_timer_set_evt(touch, timer_evt & ~(EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2)); } } - if (touch->tracker.tag && touch->tracker.track) { - if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK; + if (touch->tracker.track) { + if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY) touch_evt |= EVE_TOUCH_ETYPE_TRACK; if (touch_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) { @@ -171,19 +156,17 @@ void eve_handle_touch(uint16_t intr_flags) { if (timer_evt & EVE_TOUCH_ETYPE_LPRESS) { eve_timer_set_evt(touch, timer_evt & ~EVE_TOUCH_ETYPE_LPRESS); } - if (touch->tracker.tag && touch->tracker.track) { + if (touch->tracker.track) { int start = 0; uint8_t opt = touch_tag_opt[touch->tracker.tag]; uint8_t 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 (!eve_timer_get_evt(NULL) && track_ext) { - EVEVTrack *vtrack = eve_vtrack_get(); - - if (vtrack->start) start = vtrack->start(touch, vtrack->param); + start = eve_phy_acc_start(&touch_acc, touch->x, touch->y, touch->t, touch->vx, touch->vy); } if (start) { - eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK); + eos_vtrack_cont(&touch_acc, eve_phy_acc_tick, EVE_TOUCH_TIMEOUT_TRACK, touch); } else { touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP; } @@ -196,23 +179,22 @@ void eve_handle_touch(uint16_t intr_flags) { if (touch_tag != touch->tag) { if (touch_tag) { - if (!touch_tag0) touch_tag0 = touch_tag; if (!touch->tag0) { + touch_evt |= EVE_TOUCH_ETYPE_POINT; touch->tag0 = touch_tag; - if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) { + if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_REG)) { touch->tracker.tag = touch_tag; } if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; touch->tracker.track = 1; - touch->t = now; } if (!eve_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) { uint16_t _evt = 0; if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS; if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2; - eve_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP); + eve_timer_set(touch, _evt, EVE_TOUCH_TIMEOUT_TAP); } } } @@ -224,7 +206,7 @@ void eve_handle_touch(uint16_t intr_flags) { } if (touch_handler && touch_evt) { - touch_handler(touch, touch_evt, touch_tag0, touch_handler_param); + touch_handler(touch, touch_evt, touch_handler_param); } } } @@ -244,30 +226,19 @@ void eve_handle_time(void) { touch_evt |= EVE_TOUCH_ETYPE_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); - } + touch_evt |= EVE_TOUCH_ETYPE_TRACK; + more = eve_vtrack_tick(&touch_evt); 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 (more) { - eve_sys_timer_set(touch_timer.to); - } else { - touch_timer.evt = 0; + if (!more) { + eve_timer_reset(); } if (touch_handler && touch_evt) { - touch_handler(touch, touch_evt, touch_timer.tag0, touch_handler_param); + touch_handler(touch, touch_evt, touch_handler_param); } } } @@ -286,20 +257,17 @@ int8_t eve_touch_get_idx(EVETouch *touch) { return touch - touch_obj; } -uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_min, uint8_t tag_n) { +uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag_min, uint8_t tag_n) { int tag_max; uint8_t _tag; uint16_t _evt; if (tag_min == EVE_NOTAG) return 0; + if (evt & EVE_TOUCH_ETYPE_EXT) return 0; tag_max = tag_min + tag_n; - if ((tag0 < tag_min) || (tag0 >= tag_max)) return 0; + if ((touch->tag0 < tag_min) || (touch->tag0 >= tag_max)) return 0; - _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 = touch->tag; if ((_tag >= tag_min) && (_tag < tag_max)) _evt |= EVE_TOUCH_ETYPE_TAG; @@ -312,79 +280,57 @@ uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_ _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 = touch->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_POINT_MASK | EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2 | EVE_TOUCH_ETYPE_USR_MASK)) { + _evt |= evt & (EVE_TOUCH_ETYPE_POINT_MASK | EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP1 | EVE_TOUCH_ETYPE_TAP2 | EVE_TOUCH_ETYPE_USR_MASK); } return _evt; } -void eve_touch_set_opt(uint8_t tag, uint8_t opt) { +void eve_tag_set_opt(uint8_t tag, uint8_t opt) { + if (tag == EVE_NOTAG) return; touch_tag_opt[tag] = opt; } -uint8_t eve_touch_get_opt(uint8_t tag) { +uint8_t eve_tag_get_opt(uint8_t tag) { + if (tag == EVE_NOTAG) return 0; return touch_tag_opt[tag]; } -void eve_touch_clear_opt(void) { +void eve_tag_clear_opt(void) { memset(touch_tag_opt, 0, sizeof(touch_tag_opt)); } -void eve_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) { +void eve_timer_set(EVETouch *touch, uint16_t evt, uint32_t tick_ms) { touch_timer.touch = touch; touch_timer.evt = evt; - touch_timer.tag0 = tag0; - touch_timer.to = to; - eve_sys_timer_set(to); + eve_ostimer_set(tick_ms); } void eve_timer_clear(EVETouch *touch) { eve_timer_set_evt(touch, 0); } +void eve_timer_reset(void) { + touch_timer.touch = NULL; + touch_timer.evt = 0; +} + void eve_timer_set_evt(EVETouch *touch, uint16_t evt) { if ((touch == NULL) || (touch == touch_timer.touch)) { touch_timer.evt = evt; - } else if (touch_timer.touch == NULL) { - touch_timer.evt = evt; } if (!touch_timer.evt) { - eve_sys_timer_clear(); + eve_ostimer_clear(); touch_timer.touch = NULL; - touch_timer.tag0 = 0; - touch_timer.to = 0; } } uint16_t eve_timer_get_evt(EVETouch *touch) { - uint16_t ret = 0; + uint16_t rv = 0; if ((touch == NULL) || (touch_timer.touch == touch)) { - ret = touch_timer.evt; - } else if (touch_timer.touch == NULL) { - ret = touch_timer.evt; + rv = touch_timer.evt; } - return ret; -} - -EVETouchTimer *eve_timer_get_obj(void) { - return &touch_timer; -} - -void eve_timer_start(uint8_t tag0, uint32_t to) { - if (!touch_timer.evt) eve_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to); -} - -void eve_timer_stop(void) { - if (touch_timer.touch == NULL) eve_timer_clear(NULL); -} - -int eve_timer_running(void) { - return (touch_timer.evt == EVE_TOUCH_ETYPE_TIMER); -} - -void eve_touch_clear_tag0(void) { - touch_tag0 = 0; + return rv; } |