summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/eve_touch_engine.c
blob: 2c75ca06ad76a9bd06b0dd305b30b9737ebbc45a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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);
}