diff options
Diffstat (limited to 'fw/fe310/eos/eve/eve_touch_engine.c')
-rw-r--r-- | fw/fe310/eos/eve/eve_touch_engine.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/fw/fe310/eos/eve/eve_touch_engine.c b/fw/fe310/eos/eve/eve_touch_engine.c new file mode 100644 index 0000000..2c75ca0 --- /dev/null +++ b/fw/fe310/eos/eve/eve_touch_engine.c @@ -0,0 +1,119 @@ +#include <stdlib.h> + +#include "eve.h" +#include "eve_touch_engine.h" + +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_touch_init_engine(void) { + /* configure touch */ + eve_write8(REG_CPURESET, 2); /* touch engine reset */ + eve_write16(REG_TOUCH_CONFIG, 0x4000); /* host mode multi touch */ + eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */ + eve_write8(REG_CPURESET, 0); /* clear reset */ + + eve_touch_ehost_enter(0, 0x8000, 0x8000); + eve_touch_ehost_end(); +} + +void eve_touch_start(void) { + uint16_t intr_mask; + + intr_mask = eve_read16(REG_INT_MASK); + eve_write16(REG_INT_MASK, intr_mask | (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)); + + eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); +} + +void eve_touch_stop(void) { + uint16_t intr_mask; + + intr_mask = eve_read16(REG_INT_MASK); + eve_write16(REG_INT_MASK, intr_mask & ~(EVE_INT_CONVCOMPLETE | EVE_INT_TAG)); + eve_timer_clear(NULL); + + eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF); +} + +void eve_touch_set_extended(int extended) { + eve_write8(REG_CPURESET, 2); /* touch engine reset */ + eve_write8(REG_CTOUCH_EXTENDED, !extended); /* set / clear extended mode */ + eve_write8(REG_CPURESET, 0); /* clear reset */ +} + +void eve_touch_get_matrix(uint32_t *touch_matrix) { + touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A); + touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B); + touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C); + touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D); + touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E); + touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F); +} + +void eve_touch_set_matrix(const uint32_t *touch_matrix) { + eve_write32(REG_TOUCH_TRANSFORM_A, touch_matrix[0]); + eve_write32(REG_TOUCH_TRANSFORM_B, touch_matrix[1]); + eve_write32(REG_TOUCH_TRANSFORM_C, touch_matrix[2]); + eve_write32(REG_TOUCH_TRANSFORM_D, touch_matrix[3]); + eve_write32(REG_TOUCH_TRANSFORM_E, touch_matrix[4]); + eve_write32(REG_TOUCH_TRANSFORM_F, touch_matrix[5]); +} + +uint32_t eve_touch_reg_xy(int i) { + uint32_t touch_xy; + + touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y)); + return touch_xy; +} + +uint8_t eve_touch_reg_tag(int i) { + uint8_t touch_tag; + + touch_tag = eve_read8(_reg_tag[i]); + return touch_tag; +} + +uint32_t eve_touch_reg_track(int i) { + uint32_t touch_track; + + touch_track = eve_read32(_reg_track[i]); + return touch_track; +} + +int eve_touch_ehost_ready(void) { + uint8_t ack; + + ack = eve_read8(REG_EHOST_TOUCH_ACK); + return (ack == 1); +} + +void eve_touch_ehost_enter(uint8_t id, uint16_t x, uint16_t y) { + eve_write16(REG_EHOST_TOUCH_X, x); + eve_write16(REG_EHOST_TOUCH_Y, y); + eve_write8(REG_EHOST_TOUCH_ID, id); +} + +void eve_touch_ehost_end(void) { + eve_write8(REG_EHOST_TOUCH_ID, 0xf); +} |