diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c')
-rw-r--r-- | firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c index ea97f6d0db..f31c6ecb9f 100644 --- a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c +++ b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c | |||
@@ -38,7 +38,7 @@ | |||
38 | #define BUTTON_START_BYTE2 0xF4 /* not sure why, but sometimes you get F0 or F4, */ | 38 | #define BUTTON_START_BYTE2 0xF4 /* not sure why, but sometimes you get F0 or F4, */ |
39 | /* but always the same one for the session? */ | 39 | /* but always the same one for the session? */ |
40 | static short last_x, last_y, last_z1, last_z2; /* for the touch screen */ | 40 | static short last_x, last_y, last_z1, last_z2; /* for the touch screen */ |
41 | static int last_touch; | 41 | static bool touch_available = false; |
42 | 42 | ||
43 | static struct touch_calibration_point topleft, bottomright; | 43 | static struct touch_calibration_point topleft, bottomright; |
44 | static bool using_calibration = false; | 44 | static bool using_calibration = false; |
@@ -76,7 +76,7 @@ static int touch_to_pixels(short val_x, short val_y) | |||
76 | 76 | ||
77 | void button_init_device(void) | 77 | void button_init_device(void) |
78 | { | 78 | { |
79 | last_touch = 0; | 79 | touch_available = false; |
80 | /* GIO is the power button, set as input */ | 80 | /* GIO is the power button, set as input */ |
81 | IO_GIO_DIR0 |= 0x01; | 81 | IO_GIO_DIR0 |= 0x01; |
82 | topleft.px_x = 0; topleft.px_y = 0; | 82 | topleft.px_x = 0; topleft.px_y = 0; |
@@ -104,28 +104,50 @@ inline bool button_hold(void) | |||
104 | return false; | 104 | return false; |
105 | } | 105 | } |
106 | 106 | ||
107 | int button_get_last_touch(void) | ||
108 | { | ||
109 | int ret_val = last_touch; | ||
110 | last_touch = 0; | ||
111 | return ret_val; | ||
112 | } | ||
113 | |||
114 | static void remote_heartbeat(void) | 107 | static void remote_heartbeat(void) |
115 | { | 108 | { |
116 | char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; | 109 | char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; |
117 | uart1_puts(data); | 110 | uart1_puts(data); |
118 | } | 111 | } |
119 | 112 | ||
120 | int button_read_device(void) | 113 | #define TOUCH_MARGIN 8 |
114 | int button_read_device(int *data) | ||
121 | { | 115 | { |
122 | char c; | 116 | char c; |
123 | int i = 0; | 117 | int i = 0; |
124 | int btn = BUTTON_NONE; | 118 | int btn = BUTTON_NONE; |
125 | 119 | *data = 0; | |
120 | |||
126 | if ((IO_GIO_BITSET0&0x01) == 0) | 121 | if ((IO_GIO_BITSET0&0x01) == 0) |
127 | btn |= BUTTON_POWER; | 122 | btn |= BUTTON_POWER; |
128 | 123 | if (touch_available) | |
124 | { | ||
125 | short x,y; | ||
126 | static long last_touch = 0; | ||
127 | bool send_touch = false; | ||
128 | tsc2100_read_values(&x, &y, &last_z1, &last_z2); | ||
129 | if (TIME_BEFORE(last_touch + HZ/5, current_tick)) | ||
130 | { | ||
131 | if ((x > last_x + TOUCH_MARGIN) || | ||
132 | (x < last_x - TOUCH_MARGIN) || | ||
133 | (y > last_y + TOUCH_MARGIN) || | ||
134 | (y < last_y - TOUCH_MARGIN)) | ||
135 | { | ||
136 | send_touch = true; | ||
137 | } | ||
138 | } | ||
139 | else | ||
140 | send_touch = true; | ||
141 | if (send_touch) | ||
142 | { | ||
143 | last_x = x; | ||
144 | last_y = y; | ||
145 | *data = touch_to_pixels(x, y); | ||
146 | btn |= BUTTON_TOUCHPAD; | ||
147 | } | ||
148 | last_touch = current_tick; | ||
149 | touch_available = false; | ||
150 | } | ||
129 | remote_heartbeat(); | 151 | remote_heartbeat(); |
130 | while (uart1_getch(&c)) | 152 | while (uart1_getch(&c)) |
131 | { | 153 | { |
@@ -163,27 +185,10 @@ int button_read_device(void) | |||
163 | } | 185 | } |
164 | return btn; | 186 | return btn; |
165 | } | 187 | } |
166 | #define TOUCH_MARGIN 8 | 188 | |
189 | /* Touchpad data available interupt */ | ||
167 | void GIO14(void) | 190 | void GIO14(void) |
168 | { | 191 | { |
169 | short x,y; | 192 | touch_available = true; |
170 | static int last_tick = 0; | 193 | IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */ |
171 | tsc2100_read_values(&x, &y, | ||
172 | &last_z1, &last_z2); | ||
173 | if (TIME_BEFORE(last_tick+HZ/5, current_tick)) | ||
174 | { | ||
175 | if ((x > last_x + TOUCH_MARGIN) || | ||
176 | (x < last_x - TOUCH_MARGIN) || | ||
177 | (y > last_y + TOUCH_MARGIN) || | ||
178 | (y < last_y - TOUCH_MARGIN)) | ||
179 | { | ||
180 | last_x = x; | ||
181 | last_y = y; | ||
182 | queue_clear(&button_queue); | ||
183 | queue_post(&button_queue, BUTTON_TOUCHPAD, | ||
184 | touch_to_pixels(x, y)); | ||
185 | } | ||
186 | last_tick = current_tick; | ||
187 | } | ||
188 | IO_INTC_IRQ2 = (1<<3); | ||
189 | } | 194 | } |