/*
- * (C) Gražvydas "notaz" Ignotas, 2008-2010
+ * (C) Gražvydas "notaz" Ignotas, 2008-2012
*
* This work is licensed under the terms of any of these licenses
* (at your option):
* - GNU GPL, version 2 or later.
* - GNU LGPL, version 2.1 or later.
+ * - MAME license.
* See the COPYING file in the top-level directory.
*/
#include <linux/input.h>
#include <errno.h>
-#include "../common/input.h"
+#include "../input.h"
#include "in_evdev.h"
#define MAX_ABS_DEVS 8
int abs_mult[MAX_ABS_DEVS]; /* 16.16 multiplier to IN_ABS_RANGE */
int abs_adj[MAX_ABS_DEVS]; /* adjust for centering */
unsigned int abs_to_digital:1;
+
+ const in_drv_t *drv;
} in_evdev_t;
#ifndef KEY_CNT
#define IN_EVDEV_PREFIX "evdev:"
static const char * const in_evdev_keys[KEY_CNT] = {
- [0 ... KEY_MAX] = NULL,
+ // [0 ... KEY_MAX] = NULL, // not necessary
[KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc",
[KEY_1] = "1", [KEY_2] = "2",
[KEY_3] = "3", [KEY_4] = "4",
};
-static void in_evdev_probe(void)
+static void in_evdev_probe(const in_drv_t *drv)
{
long keybits[KEY_CNT / sizeof(long) / 8];
long absbits[(ABS_MAX+1) / sizeof(long) / 8];
if (dev == NULL)
goto skip;
+ dev->drv = drv;
+
ret = ioctl(fd, EVIOCGKEY(sizeof(keybits)), keybits);
if (ret == -1) {
printf("Warning: EVIOCGKEY not supported, will have to track state\n");
}
static const char * const *
-in_evdev_get_key_names(int *count)
+in_evdev_get_key_names(const in_drv_t *drv, int *count)
{
+ const struct in_pdata *pdata = drv->pdata;
*count = KEY_CNT;
+
+ if (pdata->key_names)
+ return pdata->key_names;
return in_evdev_keys;
}
return ret_kc;
}
-static const struct {
- short key;
- short pbtn;
-} key_pbtn_map[] =
-{
- { KEY_UP, PBTN_UP },
- { KEY_DOWN, PBTN_DOWN },
- { KEY_LEFT, PBTN_LEFT },
- { KEY_RIGHT, PBTN_RIGHT },
- /* XXX: maybe better set this from it's plat code somehow */
- /* Pandora */
- { KEY_END, PBTN_MOK },
- { KEY_PAGEDOWN, PBTN_MBACK },
- { KEY_HOME, PBTN_MA2 },
- { KEY_PAGEUP, PBTN_MA3 },
- { KEY_LEFTCTRL, PBTN_MENU },
- { KEY_RIGHTSHIFT, PBTN_L },
- { KEY_RIGHTCTRL, PBTN_R },
- /* Caanoo */
- { BTN_THUMB2, PBTN_MOK },
- { BTN_THUMB, PBTN_MBACK },
- { BTN_TRIGGER, PBTN_MA2 },
- { BTN_TOP, PBTN_MA3 },
- { BTN_BASE, PBTN_MENU },
- { BTN_TOP2, PBTN_L },
- { BTN_PINKIE, PBTN_R },
- /* "normal" keyboards */
- { KEY_ENTER, PBTN_MOK },
- { KEY_ESC, PBTN_MBACK },
- { KEY_A, PBTN_MA2 },
- { KEY_S, PBTN_MA3 },
- { KEY_BACKSLASH, PBTN_MENU },
- { KEY_LEFTBRACE, PBTN_L },
- { KEY_RIGHTBRACE, PBTN_R },
-};
-
-#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-
-static int in_evdev_menu_translate(void *drv_data, int keycode)
+static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
{
in_evdev_t *dev = drv_data;
+ const struct in_pdata *pdata = dev->drv->pdata;
+ int ret = 0;
int i;
if (keycode < 0)
{
/* menu -> kc */
keycode = -keycode;
- for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
- if (key_pbtn_map[i].pbtn == keycode) {
- int k = key_pbtn_map[i].key;
+ for (i = 0; i < pdata->kmap_size; i++)
+ if (pdata->key_map[i].pbtn == keycode) {
+ int k = pdata->key_map[i].key;
/* should really check EVIOCGBIT, but this is enough for now */
if (dev->kc_first <= k && k <= dev->kc_last)
return k;
}
else
{
- for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
- if (key_pbtn_map[i].key == keycode)
- return key_pbtn_map[i].pbtn;
- }
-
- return 0;
-}
-
-static void in_evdev_get_def_binds(int *binds)
-{
- int i;
+ for (i = 0; i < pdata->kmap_size; i++) {
+ if (pdata->key_map[i].key == keycode) {
+ ret = pdata->key_map[i].pbtn;
+ break;
+ }
+ }
- for (i = 0; ; i++) {
- if (in_evdev_defbinds[i].bit == 0 && in_evdev_defbinds[i].code == 0)
- break;
- binds[IN_BIND_OFFS(in_evdev_defbinds[i].code, in_evdev_defbinds[i].btype)] =
- 1 << in_evdev_defbinds[i].bit;
+ if (charcode != NULL && (unsigned int)keycode < KEY_CNT &&
+ in_evdev_keys[keycode] != NULL && in_evdev_keys[keycode][1] == 0)
+ {
+ char c = in_evdev_keys[keycode][0];
+ if ('A' <= c && c <= 'Z')
+ c = 'a' + c - 'A';
+ ret |= PBTN_CHAR;
+ *charcode = c;
+ }
}
+
+ return ret;
}
/* remove binds of missing keys, count remaining ones */
.probe = in_evdev_probe,
.free = in_evdev_free,
.get_key_names = in_evdev_get_key_names,
- .get_def_binds = in_evdev_get_def_binds,
.clean_binds = in_evdev_clean_binds,
.get_config = in_evdev_get_config,
.set_config = in_evdev_set_config,
.menu_translate = in_evdev_menu_translate,
};
-void in_evdev_init(void)
+int in_evdev_init(const struct in_pdata *pdata)
{
- in_register_driver(&in_evdev_drv);
+ if (!pdata) {
+ fprintf(stderr, "in_sdl: Missing input platform data\n");
+ return -1;
+ }
+
+ in_register_driver(&in_evdev_drv, pdata->defbinds, pdata);
+ return 0;
}