gp2x->common menu migration finished, gp2x now only uses input fwk
[picodrive.git] / platform / common / input.c
CommitLineData
e1f99f2b 1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "input.h"
0403eead 6#include "plat.h"
3b13ec65 7#include "../linux/in_evdev.h"
217d08bc 8#include "../gp2x/in_gp2x.h"
e1f99f2b 9
10typedef struct
11{
12 int drv_id;
7201dc73 13 int drv_fd_hnd;
e1f99f2b 14 void *drv_data;
e1f99f2b 15 char *name;
f484a9fe 16 int *binds;
e1f99f2b 17 int probed:1;
9025b931 18 int does_combos:1;
e1f99f2b 19} in_dev_t;
20
819ef025 21static in_drv_t in_drivers[IN_DRVID_COUNT];
e1f99f2b 22static in_dev_t in_devices[IN_MAX_DEVS];
23static int in_dev_count = 0;
217d08bc 24static int in_have_async_devs = 0;
991473ad 25static int menu_key_state = 0;
26static int menu_last_used_dev = 0;
e1f99f2b 27
819ef025 28#define DRV(id) in_drivers[(unsigned)(id) < IN_DRVID_COUNT ? (id) : 0]
29
217d08bc 30
e1f99f2b 31static int in_bind_count(int drv_id)
32{
819ef025 33 int count = DRV(drv_id).get_bind_count();
e1f99f2b 34 if (count <= 0)
35 printf("input: failed to get bind count for drv %d\n", drv_id);
36
37 return count;
38}
39
40static int *in_alloc_binds(int drv_id)
41{
819ef025 42 int count, *binds;
e1f99f2b 43
44 count = in_bind_count(drv_id);
819ef025 45 if (count <= 0)
e1f99f2b 46 return NULL;
e1f99f2b 47
819ef025 48 binds = calloc(count * 2, sizeof(binds[0]));
49 if (binds == NULL)
50 return NULL;
51
52 DRV(drv_id).get_def_binds(binds + count);
53 memcpy(binds, binds + count, count * sizeof(binds[0]));
54
55 return binds;
e1f99f2b 56}
57
58static void in_free(in_dev_t *dev)
59{
819ef025 60 if (dev->probed)
61 DRV(dev->drv_id).free(dev->drv_data);
e1f99f2b 62 dev->probed = 0;
63 dev->drv_data = NULL;
64 free(dev->name);
65 dev->name = NULL;
66 free(dev->binds);
67 dev->binds = NULL;
68}
69
217d08bc 70/* to be called by drivers
71 * async devices must set drv_fd_hnd to -1 */
9025b931 72void in_register(const char *nname, int drv_id, int drv_fd_hnd, void *drv_data, int combos)
e1f99f2b 73{
819ef025 74 int i, ret, dupe_count = 0, *binds;
e1f99f2b 75 char name[256], *name_end, *tmp;
76
77 strncpy(name, nname, sizeof(name));
78 name[sizeof(name)-12] = 0;
79 name_end = name + strlen(name);
80
81 for (i = 0; i < in_dev_count; i++)
82 {
83 if (in_devices[i].name == NULL)
84 continue;
85 if (strcmp(in_devices[i].name, name) == 0)
86 {
87 if (in_devices[i].probed) {
88 dupe_count++;
89 sprintf(name_end, " [%d]", dupe_count);
90 continue;
91 }
92 goto update;
93 }
94 }
95
96 if (i >= IN_MAX_DEVS)
97 {
98 /* try to find unused device */
99 for (i = 0; i < IN_MAX_DEVS; i++)
100 if (!in_devices[i].probed) break;
101 if (i >= IN_MAX_DEVS) {
102 printf("input: too many devices, can't add %s\n", name);
103 return;
104 }
105 in_free(&in_devices[i]);
106 }
107
108 tmp = strdup(name);
109 if (tmp == NULL)
110 return;
111
112 binds = in_alloc_binds(drv_id);
113 if (binds == NULL) {
114 free(tmp);
115 return;
116 }
117
118 in_devices[i].name = tmp;
119 in_devices[i].binds = binds;
120 if (i + 1 > in_dev_count)
121 in_dev_count = i + 1;
122
123 printf("input: new device #%d \"%s\"\n", i, name);
124update:
125 in_devices[i].probed = 1;
9025b931 126 in_devices[i].does_combos = combos;
e1f99f2b 127 in_devices[i].drv_id = drv_id;
7201dc73 128 in_devices[i].drv_fd_hnd = drv_fd_hnd;
e1f99f2b 129 in_devices[i].drv_data = drv_data;
819ef025 130
131 if (in_devices[i].binds != NULL) {
132 ret = DRV(drv_id).clean_binds(drv_data, in_devices[i].binds);
133 if (ret == 0) {
134 /* no useable binds */
135 free(in_devices[i].binds);
136 in_devices[i].binds = NULL;
137 }
138 }
e1f99f2b 139}
140
9025b931 141/* key combo handling, to be called by drivers that support it */
142void in_combos_find(int *binds, int last_key, int *combo_keys, int *combo_acts)
143{
144 int act, u;
145
146 *combo_keys = *combo_acts = 0;
147 for (act = 0; act < sizeof(binds[0]) * 8; act++)
148 {
149 int keyc = 0;
150 for (u = 0; u <= last_key; u++)
151 if (binds[u] & (1 << act))
152 keyc++;
153
154 if (keyc > 1)
155 {
156 // loop again and mark those keys and actions as combo
157 for (u = 0; u <= last_key; u++)
158 {
159 if (binds[u] & (1 << act)) {
160 *combo_keys |= 1 << u;
161 *combo_acts |= 1 << act;
162 }
163 }
164 }
165 }
166}
167
168int in_combos_do(int keys, int *binds, int last_key, int combo_keys, int combo_acts)
169{
170 int i, ret = 0;
171
172 for (i = 0; i <= last_key; i++)
173 {
174 int acts;
175 if (!(keys & (1 << i)))
176 continue;
177
178 acts = binds[i];
179 if (!acts)
180 continue;
181
182 if (combo_keys & (1 << i))
183 {
184 int acts_c = acts & combo_acts;
185 int u = last_key;
186 if (acts_c) {
187 // let's try to find the other one
188 for (u = i + 1; u <= last_key; u++)
189 if ( (keys & (1 << u)) && (binds[u] & acts_c) ) {
190 ret |= acts_c & binds[u];
191 keys &= ~((1 << i) | (1 << u));
192 break;
193 }
194 }
195 // add non-combo actions if combo ones were not found
196 if (u >= last_key)
197 ret |= acts & ~combo_acts;
198 } else
199 ret |= acts;
200 }
201
202 return ret;
203}
204
e1f99f2b 205void in_probe(void)
206{
207 int i;
217d08bc 208
209 in_have_async_devs = 0;
e1f99f2b 210 for (i = 0; i < in_dev_count; i++)
211 in_devices[i].probed = 0;
212
819ef025 213 for (i = 1; i < IN_DRVID_COUNT; i++)
214 in_drivers[i].probe();
e1f99f2b 215
216 /* get rid of devs without binds and probes */
217 for (i = 0; i < in_dev_count; i++) {
218 if (!in_devices[i].probed && in_devices[i].binds == NULL) {
219 in_dev_count--;
220 if (i < in_dev_count) {
221 free(in_devices[i].name);
222 memmove(&in_devices[i], &in_devices[i+1],
223 (in_dev_count - i) * sizeof(in_devices[0]));
224 }
217d08bc 225
226 continue;
e1f99f2b 227 }
217d08bc 228
229 if (in_devices[i].probed && in_devices[i].drv_fd_hnd == -1)
230 in_have_async_devs = 1;
e1f99f2b 231 }
217d08bc 232
233 if (in_have_async_devs)
234 printf("input: async-only devices detected..\n");
e1f99f2b 235}
236
7201dc73 237/* async update */
e1f99f2b 238int in_update(void)
239{
240 int i, result = 0;
241
242 for (i = 0; i < in_dev_count; i++) {
f484a9fe 243 in_dev_t *dev = &in_devices[i];
f484a9fe 244 if (dev->probed && dev->binds != NULL) {
245 switch (dev->drv_id) {
819ef025 246#ifdef IN_EVDEV
3427e573 247 case IN_DRVID_EVDEV:
483230c7 248 result |= in_evdev_update(dev->drv_data, dev->binds);
3427e573 249 break;
217d08bc 250#endif
251#ifdef IN_GP2X
252 case IN_DRVID_GP2X:
253 result |= in_gp2x_update(dev->drv_data, dev->binds);
254 break;
819ef025 255#endif
3427e573 256 }
e1f99f2b 257 }
258 }
259
260 return result;
261}
262
3427e573 263void in_set_blocking(int is_blocking)
264{
217d08bc 265 int i, ret;
3427e573 266
217d08bc 267 /* have_async_devs means we will have to do all reads async anyway.. */
268 if (!in_have_async_devs) {
269 for (i = 0; i < in_dev_count; i++) {
270 if (in_devices[i].probed)
271 DRV(in_devices[i].drv_id).set_blocking(in_devices[i].drv_data, is_blocking);
272 }
3427e573 273 }
f484a9fe 274
275 menu_key_state = 0;
217d08bc 276
f484a9fe 277 /* flush events */
217d08bc 278 do {
279 ret = in_update_keycode(NULL, NULL, 0);
280 } while (ret >= 0);
3427e573 281}
282
217d08bc 283static int in_update_kc_async(int *dev_id_out, int *is_down_out, int timeout_ms)
284{
217d08bc 285 int i, is_down, result;
0403eead 286 unsigned int ticks;
217d08bc 287
0403eead 288 ticks = plat_get_ticks_ms();
217d08bc 289
290 while (1)
291 {
292 for (i = 0; i < in_dev_count; i++) {
293 in_dev_t *d = &in_devices[i];
294 if (!d->probed)
295 continue;
296
297 result = DRV(d->drv_id).update_keycode(d->drv_data, &is_down);
298 if (result == -1)
299 continue;
300
301 if (dev_id_out)
302 *dev_id_out = i;
303 if (is_down_out)
304 *is_down_out = is_down;
305 return result;
306 }
307
0403eead 308 if (timeout_ms >= 0 && (int)(plat_get_ticks_ms() - ticks) > timeout_ms)
309 break;
217d08bc 310
0403eead 311 plat_sleep_ms(10);
217d08bc 312 }
313
314 return -1;
315}
7201dc73 316
3b13ec65 317/*
217d08bc 318 * wait for a press, always return some keycode or -1 on timeout or error
3b13ec65 319 */
f484a9fe 320int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
3b13ec65 321{
0403eead 322 int result = -1, dev_id = 0, is_down, result_menu;
7201dc73 323 int fds_hnds[IN_MAX_DEVS];
324 int i, ret, count = 0;
74f5e726 325 in_drv_t *drv = NULL;
0403eead 326 unsigned int ticks;
7201dc73 327
217d08bc 328 if (in_have_async_devs) {
329 result = in_update_kc_async(&dev_id, &is_down, timeout_ms);
330 if (result == -1)
331 return -1;
332 drv = &DRV(in_devices[dev_id].drv_id);
333 goto finish;
334 }
335
0403eead 336 ticks = plat_get_ticks_ms();
337
7201dc73 338 for (i = 0; i < in_dev_count; i++) {
339 if (in_devices[i].probed)
340 fds_hnds[count++] = in_devices[i].drv_fd_hnd;
341 }
3b13ec65 342
343 if (count == 0) {
344 /* don't deadlock, fail */
345 printf("input: failed to find devices to read\n");
346 exit(1);
347 }
348
0403eead 349 while (1)
7201dc73 350 {
0403eead 351 ret = plat_wait_event(fds_hnds, count, timeout_ms);
352 if (ret < 0)
353 break;
7201dc73 354
0403eead 355 for (i = 0; i < in_dev_count; i++) {
356 if (in_devices[i].drv_fd_hnd == ret) {
357 dev_id = i;
358 break;
359 }
7201dc73 360 }
361
0403eead 362 drv = &DRV(in_devices[dev_id].drv_id);
363 result = drv->update_keycode(in_devices[dev_id].drv_data, &is_down);
7201dc73 364
0403eead 365 /* update_keycode() might return -1 when some not interesting
366 * event happened, like sync event for evdev. */
367 if (result >= 0)
f484a9fe 368 break;
0403eead 369
370 if (timeout_ms >= 0) {
371 unsigned int ticks2 = plat_get_ticks_ms();
372 timeout_ms -= ticks2 - ticks;
373 ticks = ticks2;
374 if (timeout_ms <= 0)
375 break;
3427e573 376 }
377 }
7201dc73 378
217d08bc 379 if (result == -1)
0403eead 380 return -1;
217d08bc 381finish:
f484a9fe 382 /* keep track of menu key state, to allow mixing
b6820926 383 * in_update_keycode() and in_menu_wait_any() calls */
7201dc73 384 result_menu = drv->menu_translate(result);
f484a9fe 385 if (result_menu != 0) {
386 if (is_down)
387 menu_key_state |= result_menu;
388 else
389 menu_key_state &= ~result_menu;
390 }
391
392 if (dev_id_out != NULL)
393 *dev_id_out = dev_id;
394 if (is_down_out != NULL)
395 *is_down_out = is_down;
3b13ec65 396 return result;
397}
398
b6820926 399/* same as above, only return bitfield of PBTN_* */
400int in_menu_wait_any(int timeout_ms)
3427e573 401{
f484a9fe 402 int keys_old = menu_key_state;
3427e573 403
404 while (1)
405 {
819ef025 406 int code, is_down = 0, dev_id = 0;
3427e573 407
f484a9fe 408 code = in_update_keycode(&dev_id, &is_down, timeout_ms);
217d08bc 409 if (code >= 0)
410 code = DRV(in_devices[dev_id].drv_id).menu_translate(code);
3427e573 411
b6820926 412 if (timeout_ms >= 0)
f484a9fe 413 break;
217d08bc 414 if (code < 0)
f484a9fe 415 continue;
991473ad 416 menu_last_used_dev = dev_id;
f484a9fe 417 if (keys_old != menu_key_state)
3427e573 418 break;
419 }
420
f484a9fe 421 return menu_key_state;
3427e573 422}
423
b6820926 424/* wait for menu input, do autorepeat */
713c9224 425int in_menu_wait(int interesting, int autorep_delay_ms)
b6820926 426{
427 static int inp_prev = 0;
299acadc 428 static int repeats = 0;
9025b931 429 int ret, release = 0, wait = 450;
b6820926 430
299acadc 431 if (repeats)
713c9224 432 wait = autorep_delay_ms;
b6820926 433
299acadc 434 ret = in_menu_wait_any(wait);
435 if (ret == inp_prev)
436 repeats++;
b6820926 437
438 while (!(ret & interesting)) {
439 ret = in_menu_wait_any(-1);
440 release = 1;
441 }
442
299acadc 443 if (release || ret != inp_prev)
b6820926 444 repeats = 0;
299acadc 445
b6820926 446 inp_prev = ret;
447
299acadc 448 /* we don't need diagonals in menus */
b6820926 449 if ((ret & PBTN_UP) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
450 if ((ret & PBTN_UP) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
451 if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
452 if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
453
454 return ret;
455}
456
819ef025 457const int *in_get_dev_binds(int dev_id)
458{
459 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
460 return NULL;
461
462 return in_devices[dev_id].binds;
463}
464
465const int *in_get_dev_def_binds(int dev_id)
466{
467 int count;
468
469 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
470 return NULL;
471
472 count = in_bind_count(in_devices[dev_id].drv_id);
473 return in_devices[dev_id].binds + count;
474}
475
9025b931 476int in_get_dev_info(int dev_id, int what)
819ef025 477{
478 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
479 return 0;
480
9025b931 481 switch (what) {
482 case IN_INFO_BIND_COUNT:
483 return in_bind_count(in_devices[dev_id].drv_id);
484 case IN_INFO_DOES_COMBOS:
485 return in_devices[dev_id].does_combos;
486 }
487
488 return 0;
819ef025 489}
490
713c9224 491const char *in_get_dev_name(int dev_id, int must_be_active, int skip_pfix)
819ef025 492{
713c9224 493 const char *name, *tmp;
494
819ef025 495 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
496 return NULL;
497
b6820926 498 if (must_be_active && !in_devices[dev_id].probed)
499 return NULL;
713c9224 500
501 name = in_devices[dev_id].name;
8c2a3661 502 if (name == NULL || !skip_pfix)
503 return name;
027c898c 504
8c2a3661 505 /* skip prefix */
713c9224 506 tmp = strchr(name, ':');
507 if (tmp != NULL)
508 name = tmp + 1;
509
510 return name;
819ef025 511}
512
f484a9fe 513/* never returns NULL */
3427e573 514const char *in_get_key_name(int dev_id, int keycode)
515{
f484a9fe 516 static char xname[16];
517 const char *name;
518
991473ad 519 if (dev_id < 0) /* want last used dev? */
520 dev_id = menu_last_used_dev;
521
3427e573 522 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
523 return "Unkn0";
819ef025 524
991473ad 525 if (keycode < 0) /* want name for menu key? */
526 keycode = DRV(in_devices[dev_id].drv_id).menu_translate(keycode);
527
f484a9fe 528 name = DRV(in_devices[dev_id].drv_id).get_key_name(keycode);
529 if (name != NULL)
530 return name;
531
532 /* assume scancode */
533 if ((keycode >= '0' && keycode <= '9') || (keycode >= 'a' && keycode <= 'z')
534 || (keycode >= 'A' && keycode <= 'Z'))
535 sprintf(xname, "%c", keycode);
536 else
537 sprintf(xname, "\\x%02X", keycode);
538 return xname;
539}
540
541int in_bind_key(int dev_id, int keycode, int mask, int force_unbind)
542{
543 int ret, count;
544 in_dev_t *dev;
545
546 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
547 return -1;
548 dev = &in_devices[dev_id];
549
550 if (dev->binds == NULL) {
551 if (force_unbind)
552 return 0;
553 dev->binds = in_alloc_binds(dev->drv_id);
554 if (dev->binds == NULL)
555 return -1;
556 }
557
558 count = in_bind_count(dev->drv_id);
559 if (keycode < 0 || keycode >= count)
560 return -1;
561
562 if (force_unbind)
563 dev->binds[keycode] &= ~mask;
564 else
565 dev->binds[keycode] ^= mask;
566
567 ret = DRV(dev->drv_id).clean_binds(dev->drv_data, dev->binds);
568 if (ret == 0) {
569 free(dev->binds);
570 dev->binds = NULL;
571 }
572
573 return 0;
819ef025 574}
575
576/* returns device id, or -1 on error */
577int in_config_parse_dev(const char *name)
578{
579 int drv_id = -1, i;
580
581 for (i = 0; i < IN_DRVID_COUNT; i++) {
582 int len = strlen(in_drivers[i].prefix);
583 if (strncmp(name, in_drivers[i].prefix, len) == 0) {
584 drv_id = i;
585 break;
586 }
587 }
588
589 if (drv_id < 0) {
590 printf("input: missing driver for %s\n", name);
591 return -1;
592 }
593
594 for (i = 0; i < in_dev_count; i++)
595 {
596 if (in_devices[i].name == NULL)
597 continue;
598 if (strcmp(in_devices[i].name, name) == 0)
599 return i;
600 }
601
602 if (i >= IN_MAX_DEVS)
603 {
604 /* try to find unused device */
605 for (i = 0; i < IN_MAX_DEVS; i++)
606 if (in_devices[i].name == NULL) break;
607 if (i >= IN_MAX_DEVS) {
608 printf("input: too many devices, can't add %s\n", name);
609 return -1;
610 }
611 }
612
613 memset(&in_devices[i], 0, sizeof(in_devices[i]));
614
615 in_devices[i].name = strdup(name);
616 if (in_devices[i].name == NULL)
617 return -1;
618
619 if (i + 1 > in_dev_count)
620 in_dev_count = i + 1;
621 in_devices[i].drv_id = drv_id;
622
623 return i;
624}
625
299acadc 626/*
627 * To reduce size of game specific configs, default binds are not saved.
628 * So we mark default binds in in_config_start(), override them in in_config_bind_key(),
629 * and restore whatever default binds are left in in_config_end().
630 */
819ef025 631void in_config_start(void)
632{
633 int i;
634
635 /* mark all default binds, so they get overwritten by func below */
636 for (i = 0; i < IN_MAX_DEVS; i++) {
637 int n, count, *binds, *def_binds;
638
f484a9fe 639 binds = in_devices[i].binds;
640 if (binds == NULL)
819ef025 641 continue;
642
643 count = in_bind_count(in_devices[i].drv_id);
819ef025 644 def_binds = binds + count;
645
646 for (n = 0; n < count; n++)
647 if (binds[n] == def_binds[n])
648 binds[n] = -1;
649 }
650}
651
652int in_config_bind_key(int dev_id, const char *key, int binds)
653{
f484a9fe 654 int count, kc;
655 in_dev_t *dev;
819ef025 656
657 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
658 return -1;
f484a9fe 659 dev = &in_devices[dev_id];
819ef025 660
f484a9fe 661 count = in_bind_count(dev->drv_id);
662
663 /* maybe a raw code? */
664 if (key[0] == '\\' && key[1] == 'x') {
665 char *p = NULL;
666 kc = (int)strtoul(key + 2, &p, 16);
667 if (p == NULL || *p != 0)
668 kc = -1;
669 }
670 else {
671 /* device specific key name */
672 if (dev->binds == NULL) {
673 dev->binds = in_alloc_binds(dev->drv_id);
674 if (dev->binds == NULL)
675 return -1;
676 in_config_start();
677 }
678
679 kc = DRV(dev->drv_id).get_key_code(key);
680 if (kc < 0 && strlen(key) == 1) {
681 /* assume scancode */
682 kc = key[0];
683 }
819ef025 684 }
685
f484a9fe 686 if (kc < 0 || kc >= count) {
819ef025 687 printf("input: bad key: %s\n", key);
688 return -1;
3427e573 689 }
690
f484a9fe 691 if (dev->binds[kc] == -1)
692 dev->binds[kc] = 0;
693 dev->binds[kc] |= binds;
819ef025 694
695 return 0;
696}
697
698void in_config_end(void)
699{
700 int i;
701
702 for (i = 0; i < IN_MAX_DEVS; i++) {
703 int n, ret, count, *binds, *def_binds;
f484a9fe 704 in_dev_t *dev = &in_devices[i];
819ef025 705
f484a9fe 706 if (dev->binds == NULL)
819ef025 707 continue;
708
f484a9fe 709 count = in_bind_count(dev->drv_id);
710 binds = dev->binds;
819ef025 711 def_binds = binds + count;
712
713 for (n = 0; n < count; n++)
714 if (binds[n] == -1)
715 binds[n] = def_binds[n];
716
f484a9fe 717 if (dev->drv_data == NULL)
819ef025 718 continue;
719
f484a9fe 720 ret = DRV(dev->drv_id).clean_binds(dev->drv_data, binds);
819ef025 721 if (ret == 0) {
722 /* no useable binds */
f484a9fe 723 free(dev->binds);
724 dev->binds = NULL;
819ef025 725 }
726 }
3427e573 727}
728
819ef025 729void in_debug_dump(void)
730{
731 int i;
732
733 printf("# drv probed binds name\n");
734 for (i = 0; i < IN_MAX_DEVS; i++) {
735 in_dev_t *d = &in_devices[i];
736 if (!d->probed && d->name == NULL && d->binds == NULL)
737 continue;
738 printf("%d %3d %6c %5c %s\n", i, d->drv_id, d->probed ? 'y' : 'n',
739 d->binds ? 'y' : 'n', d->name);
740 }
741}
742
743/* handlers for unknown/not_preset drivers */
744
745static void in_def_probe(void) {}
746static void in_def_free(void *drv_data) {}
747static int in_def_get_bind_count(void) { return 0; }
748static void in_def_get_def_binds(int *binds) {}
749static int in_def_clean_binds(void *drv_data, int *binds) { return 0; }
750static void in_def_set_blocking(void *data, int y) {}
7201dc73 751static int in_def_update_keycode(void *drv_data, int *is_down) { return 0; }
819ef025 752static int in_def_menu_translate(int keycode) { return keycode; }
753static int in_def_get_key_code(const char *key_name) { return 0; }
754static const char *in_def_get_key_name(int keycode) { return NULL; }
755
e1f99f2b 756void in_init(void)
757{
819ef025 758 int i;
759
760 memset(in_drivers, 0, sizeof(in_drivers));
e1f99f2b 761 memset(in_devices, 0, sizeof(in_devices));
762 in_dev_count = 0;
819ef025 763
764 for (i = 0; i < IN_DRVID_COUNT; i++) {
765 in_drivers[i].prefix = "none:";
766 in_drivers[i].probe = in_def_probe;
767 in_drivers[i].free = in_def_free;
768 in_drivers[i].get_bind_count = in_def_get_bind_count;
769 in_drivers[i].get_def_binds = in_def_get_def_binds;
770 in_drivers[i].clean_binds = in_def_clean_binds;
771 in_drivers[i].set_blocking = in_def_set_blocking;
7201dc73 772 in_drivers[i].update_keycode = in_def_update_keycode;
819ef025 773 in_drivers[i].menu_translate = in_def_menu_translate;
774 in_drivers[i].get_key_code = in_def_get_key_code;
775 in_drivers[i].get_key_name = in_def_get_key_name;
776 }
777
217d08bc 778#ifdef IN_GP2X
779 in_gp2x_init(&in_drivers[IN_DRVID_GP2X]);
780#endif
819ef025 781#ifdef IN_EVDEV
782 in_evdev_init(&in_drivers[IN_DRVID_EVDEV]);
783#endif
e1f99f2b 784}
785
819ef025 786#if 0
e1f99f2b 787int main(void)
788{
3b13ec65 789 int ret;
790
e1f99f2b 791 in_init();
792 in_probe();
793
3427e573 794 in_set_blocking(1);
795
796#if 1
797 while (1) {
798 int dev = 0, down;
799 ret = in_update_keycode(&dev, &down);
800 printf("#%i: %i %i (%s)\n", dev, down, ret, in_get_key_name(dev, ret));
801 }
802#else
e1f99f2b 803 while (1) {
b6820926 804 ret = in_menu_wait_any();
3b13ec65 805 printf("%08x\n", ret);
e1f99f2b 806 }
3427e573 807#endif
e1f99f2b 808
809 return 0;
810}
819ef025 811#endif