Skip to content

Commit 3270daf

Browse files
committed
hosted: Have common /dev/input code handle touchscreens.
With this we should be able to consolidate some of the hosted variations. Change-Id: Ie03631b4e700e3a0adcdc1b8476237384f0ace1a
1 parent f38109f commit 3270daf

File tree

2 files changed

+137
-32
lines changed

2 files changed

+137
-32
lines changed

firmware/target/hosted/button-devinput.c

Lines changed: 127 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,79 @@ static int button_delay_release = 0;
9292
static int delay_tick = 0;
9393
#endif
9494

95-
int button_read_device(void)
95+
#ifdef HAVE_TOUCHSCREEN
96+
/* Last known touchscreen coordinates. */
97+
static int _last_x = 0;
98+
static int _last_y = 0;
99+
100+
/* Last known touchscreen state. */
101+
static enum
102+
{
103+
TOUCHSCREEN_STATE_UNKNOWN = 0,
104+
TOUCHSCREEN_STATE_UP,
105+
TOUCHSCREEN_STATE_DOWN
106+
} _last_touch_state = TOUCHSCREEN_STATE_UNKNOWN;
107+
108+
// XXX ... figure out what is standard.
109+
#define EVENT_VALUE_TOUCHSCREEN_PRESS 1
110+
#define EVENT_VALUE_TOUCHSCREEN_RELEASE -1
111+
112+
static int ts_enabled = 0;
113+
114+
void touchscreen_enable_device(bool en)
115+
{
116+
ts_enabled = en;
117+
}
118+
119+
static bool handle_touchscreen_event(__u16 code, __s32 value)
120+
{
121+
bool read_more = false;
122+
123+
switch(code)
124+
{
125+
case ABS_MT_POSITION_X:
126+
{
127+
_last_x = value;
128+
129+
/* x -> next will be y. */
130+
read_more = true;
131+
132+
break;
133+
}
134+
135+
case ABS_MT_POSITION_Y:
136+
{
137+
_last_y = value;
138+
break;
139+
}
140+
141+
case ABS_MT_TRACKING_ID:
142+
{
143+
if(value == EVENT_VALUE_TOUCHSCREEN_PRESS)
144+
{
145+
_last_touch_state = TOUCHSCREEN_STATE_DOWN;
146+
147+
/* Press -> next will be x. */
148+
read_more = true;
149+
}
150+
else
151+
{
152+
_last_touch_state = TOUCHSCREEN_STATE_UP;
153+
}
154+
break;
155+
}
156+
}
157+
158+
return read_more;
159+
}
160+
#endif
161+
162+
#ifdef HAVE_TOUCHSCREEN
163+
#define BDATA int *data
164+
#else
165+
#define BDATA void
166+
#endif
167+
int button_read_device(BDATA)
96168
{
97169
static int button_bitmap = 0;
98170
struct input_event event;
@@ -121,44 +193,62 @@ int button_read_device(void)
121193
int size = read(poll_fds[i].fd, &event, sizeof(event));
122194
if(size == (int)sizeof(event))
123195
{
124-
/* map linux event code to rockbox button bitmap */
125-
int bmap = button_map(event.code);
126-
127-
/* event.value == 0x10000 means press
128-
* event.value == 0 means release
129-
*/
130-
if(event.value)
131-
{
196+
switch(event.type) {
197+
case EV_KEY: {
198+
/* map linux event code to rockbox button bitmap */
199+
int bmap = button_map(event.code);
200+
201+
/* event.value == 0x10000 means press
202+
* event.value == 0 means release
203+
*/
204+
if(event.value)
205+
{
132206
#ifdef HAVE_SCROLLWHEEL
133-
/* Filter out wheel ticks */
134-
if (bmap & BUTTON_SCROLL_BACK)
135-
wheel_ticks--;
136-
else if (bmap & BUTTON_SCROLL_FWD)
137-
wheel_ticks++;
138-
bmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
207+
/* Filter out wheel ticks */
208+
if (bmap & BUTTON_SCROLL_BACK)
209+
wheel_ticks--;
210+
else if (bmap & BUTTON_SCROLL_FWD)
211+
wheel_ticks++;
212+
bmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
139213
#endif
140214
#ifdef BUTTON_DELAY_RELEASE
141-
bmap &= ~BUTTON_DELAY_RELEASE;
215+
bmap &= ~BUTTON_DELAY_RELEASE;
142216
#endif
143-
button_bitmap |= bmap;
144-
}
145-
else
146-
{
147-
#ifdef BUTTON_DELAY_RELEASE
148-
/* Delay the release of any requested buttons */
149-
if (bmap & BUTTON_DELAY_RELEASE)
150-
{
151-
button_delay_release |= bmap & ~BUTTON_DELAY_RELEASE;
152-
delay_tick = current_tick + HZ/20;
153-
bmap = 0;
217+
button_bitmap |= bmap;
154218
}
219+
else
220+
{
221+
#ifdef BUTTON_DELAY_RELEASE
222+
/* Delay the release of any requested buttons */
223+
if (bmap & BUTTON_DELAY_RELEASE)
224+
{
225+
button_delay_release |= bmap & ~BUTTON_DELAY_RELEASE;
226+
delay_tick = current_tick + HZ/20;
227+
bmap = 0;
228+
}
155229
#endif
156-
230+
}
157231
#ifdef HAVE_SCROLLWHEEL
158232
/* Wheel gives us press+release back to back; ignore the release */
159233
bmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
160234
#endif
161235
button_bitmap &= ~bmap;
236+
break;
237+
}
238+
#ifdef HAVE_TOUCHSCREEN
239+
case EV_ABS: {
240+
if (ts_enabled) {
241+
handle_touchscreen_event(event.code, event.value);
242+
} else {
243+
/* If disabled... ignore */
244+
_last_touch_state = TOUCHSCREEN_STATE_UNKNOWN;
245+
}
246+
break;
247+
}
248+
#endif
249+
default:
250+
/* Ignore other event types */
251+
break;
162252
}
163253
}
164254
}
@@ -193,5 +283,14 @@ int button_read_device(void)
193283
}
194284
#endif /* HAVE_SCROLLWHEEL */
195285

286+
#ifdef HAVE_TOUCHSCREEN
287+
int touch = touchscreen_to_pixels(_last_x, _last_y, data);
288+
289+
if(_last_touch_state == TOUCHSCREEN_STATE_DOWN)
290+
{
291+
return button_bitmap | touch;
292+
}
293+
#endif
294+
196295
return button_bitmap;
197296
}

firmware/target/hosted/system-hosted.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,16 @@ void system_exception_wait(void)
125125
backlight_hw_on();
126126
backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING);
127127
/* wait until button press and release */
128-
while(button_read_device() != 0) {}
129-
while(button_read_device() == 0) {}
130-
while(button_read_device() != 0) {}
131-
while(button_read_device() == 0) {}
128+
#ifdef HAVE_BUTTON_DATA
129+
int bdata;
130+
#define BDATA &bdata
131+
#else
132+
#define BDATA
133+
#endif
134+
while(button_read_device(BDATA) != 0) {}
135+
while(button_read_device(BDATA) == 0) {}
136+
while(button_read_device(BDATA) != 0) {}
137+
while(button_read_device(BDATA) == 0) {}
132138
}
133139

134140
bool hostfs_removable(IF_MD_NONVOID(int drive))

0 commit comments

Comments
 (0)