X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fin_gp2x.c;h=bfa2df156516edb3e0c6e73d178bd1197ba59ba9;hb=HEAD;hp=f0da43608a6665a6967b980e43845e041a9f2660;hpb=0114ccc43b628801282c5a076e0f3a9f368ea329;p=libpicofe.git diff --git a/gp2x/in_gp2x.c b/gp2x/in_gp2x.c index f0da436..bfa2df1 100644 --- a/gp2x/in_gp2x.c +++ b/gp2x/in_gp2x.c @@ -1,3 +1,14 @@ +/* + * (C) Gražvydas "notaz" Ignotas, 2006-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 #include #include @@ -6,14 +17,15 @@ #include #include -#include "../common/input.h" -#include "in_gp2x.h" +#include "../input.h" #include "soc.h" +#include "plat_gp2x.h" +#include "in_gp2x.h" -#define IN_PREFIX "gp2x:" +#define IN_GP2X_PREFIX "gp2x:" #define IN_GP2X_NBUTTONS 32 -/* note: in_gp2x hadles combos (if 2 btns have the same bind, +/* note: in_gp2x handles combos (if 2 btns have the same bind, * both must be pressed for action to happen) */ static int in_gp2x_combo_keys = 0; static int in_gp2x_combo_acts = 0; @@ -21,33 +33,30 @@ static int gpiodev = -1; /* Wiz only */ static int (*in_gp2x_get_bits)(void); -enum { BTN_UP = 0, BTN_LEFT = 2, BTN_DOWN = 4, BTN_RIGHT = 6, - BTN_START = 8, BTN_SELECT = 9, BTN_L = 10, BTN_R = 11, - BTN_A = 12, BTN_B = 13, BTN_X = 14, BTN_Y = 15, - BTN_VOL_UP = 23, BTN_VOL_DOWN = 22, BTN_PUSH = 27 }; - -static const char * const in_gp2x_prefix = IN_PREFIX; -static const char * const in_gp2x_keys[IN_GP2X_NBUTTONS] = { +static const char *in_gp2x_keys[IN_GP2X_NBUTTONS] = { [0 ... IN_GP2X_NBUTTONS-1] = NULL, - [BTN_UP] = "UP", [BTN_LEFT] = "LEFT", [BTN_DOWN] = "DOWN", [BTN_RIGHT] = "RIGHT", - [BTN_START] = "START", [BTN_SELECT] = "SELECT", [BTN_L] = "L", [BTN_R] = "R", - [BTN_A] = "A", [BTN_B] = "B", [BTN_X] = "X", [BTN_Y] = "Y", - [BTN_VOL_DOWN]= "VOL DOWN", [BTN_VOL_UP] = "VOL UP", - [BTN_PUSH] = "PUSH" + [GP2X_BTN_UP] = "Up", [GP2X_BTN_LEFT] = "Left", + [GP2X_BTN_DOWN] = "Down", [GP2X_BTN_RIGHT] = "Right", + [GP2X_BTN_START] = "Start", [GP2X_BTN_SELECT] = "Select", + [GP2X_BTN_L] = "L", [GP2X_BTN_R] = "R", + [GP2X_BTN_A] = "A", [GP2X_BTN_B] = "B", + [GP2X_BTN_X] = "X", [GP2X_BTN_Y] = "Y", + [GP2X_BTN_VOL_DOWN] = "VOL DOWN", + [GP2X_BTN_VOL_UP] = "VOL UP", + [GP2X_BTN_PUSH] = "PUSH" }; static int in_gp2x_get_mmsp2_bits(void) { - extern volatile unsigned short *gp2x_memregs; int value; - value = gp2x_memregs[0x1198>>1] & 0xff; // GPIO M + value = memregs[0x1198>>1] & 0xff; // GPIO M if (value == 0xFD) value = 0xFA; if (value == 0xF7) value = 0xEB; if (value == 0xDF) value = 0xAF; if (value == 0x7F) value = 0xBE; - value |= gp2x_memregs[0x1184>>1] & 0xFF00; // GPIO C - value |= gp2x_memregs[0x1186>>1] << 16; // GPIO D + value |= memregs[0x1184>>1] & 0xFF00; // GPIO C + value |= memregs[0x1186>>1] << 16; // GPIO D value = ~value & 0x08c0ff55; return value; @@ -55,8 +64,8 @@ static int in_gp2x_get_mmsp2_bits(void) static int in_gp2x_get_wiz_bits(void) { - int value = 0; - read(gpiodev, &value, 4); + int r, value = 0; + r = read(gpiodev, &value, 4); if (value & 0x02) value |= 0x05; if (value & 0x08) @@ -69,35 +78,24 @@ static int in_gp2x_get_wiz_bits(void) /* convert to GP2X style */ value &= 0x7ff55; if (value & (1 << 16)) - value |= 1 << BTN_VOL_UP; + value |= 1 << GP2X_BTN_VOL_UP; if (value & (1 << 17)) - value |= 1 << BTN_VOL_DOWN; + value |= 1 << GP2X_BTN_VOL_DOWN; if (value & (1 << 18)) - value |= 1 << BTN_PUSH; + value |= 1 << GP2X_BTN_PUSH; value &= ~0x70000; return value; } -#ifdef FAKE_IN_GP2X -static int in_gp2x_get_fake_bits(void) +static void in_gp2x_probe(const in_drv_t *drv) { - extern int current_keys; - return current_keys; -} -#endif - -static void in_gp2x_probe(void) -{ - gp2x_soc_t soc; - - soc = soc_detect(); - switch (soc) + switch (gp2x_dev_id) { - case SOCID_MMSP2: + case GP2X_DEV_GP2X: in_gp2x_get_bits = in_gp2x_get_mmsp2_bits; break; - case SOCID_POLLUX: + case GP2X_DEV_WIZ: gpiodev = open("/dev/GPIO", O_RDONLY); if (gpiodev < 0) { perror("in_gp2x: couldn't open /dev/GPIO"); @@ -105,15 +103,13 @@ static void in_gp2x_probe(void) } in_gp2x_get_bits = in_gp2x_get_wiz_bits; break; + // we'll use evdev for Caanoo default: -#ifdef FAKE_IN_GP2X - in_gp2x_get_bits = in_gp2x_get_fake_bits; - break; -#endif return; } - in_register(IN_PREFIX "GP2X pad", IN_DRVID_GP2X, -1, (void *)1, 1); + in_register(IN_GP2X_PREFIX "GP2X pad", -1, NULL, + IN_GP2X_NBUTTONS, in_gp2x_keys, 1); } static void in_gp2x_free(void *drv_data) @@ -124,28 +120,36 @@ static void in_gp2x_free(void *drv_data) } } -static int in_gp2x_get_bind_count(void) +static const char * const * +in_gp2x_get_key_names(const in_drv_t *drv, int *count) { - return IN_GP2X_NBUTTONS; + *count = IN_GP2X_NBUTTONS; + return in_gp2x_keys; } -/* returns bitfield of binds of pressed buttons */ -int in_gp2x_update(void *drv_data, int *binds) +/* ORs result with pressed buttons */ +static int in_gp2x_update(void *drv_data, const int *binds, int *result) { - int i, keys, ret = 0; + int type_start = 0; + int i, t, keys; keys = in_gp2x_get_bits(); - if (keys & in_gp2x_combo_keys) - return in_combos_do(keys, binds, BTN_PUSH, in_gp2x_combo_keys, in_gp2x_combo_acts); + if (keys & in_gp2x_combo_keys) { + result[IN_BINDTYPE_EMU] = in_combos_do(keys, binds, GP2X_BTN_PUSH, + in_gp2x_combo_keys, in_gp2x_combo_acts); + type_start = IN_BINDTYPE_PLAYER12; + } + + for (i = 0; keys; i++, keys >>= 1) { + if (!(keys & 1)) + continue; - for (i = 0; keys; i++) { - if (keys & 1) - ret |= binds[i]; - keys >>= 1; + for (t = type_start; t < IN_BINDTYPE_COUNT; t++) + result[t] |= binds[IN_BIND_OFFS(i, t)]; } - return ret; + return 0; } int in_gp2x_update_keycode(void *data, int *is_down) @@ -175,22 +179,22 @@ static const struct { short pbtn; } key_pbtn_map[] = { - { BTN_UP, PBTN_UP }, - { BTN_DOWN, PBTN_DOWN }, - { BTN_LEFT, PBTN_LEFT }, - { BTN_RIGHT, PBTN_RIGHT }, - { BTN_B, PBTN_MOK }, - { BTN_X, PBTN_MBACK }, - { BTN_A, PBTN_MA2 }, - { BTN_Y, PBTN_MA3 }, - { BTN_L, PBTN_L }, - { BTN_R, PBTN_R }, - { BTN_SELECT, PBTN_MENU }, + { GP2X_BTN_UP, PBTN_UP }, + { GP2X_BTN_DOWN, PBTN_DOWN }, + { GP2X_BTN_LEFT, PBTN_LEFT }, + { GP2X_BTN_RIGHT, PBTN_RIGHT }, + { GP2X_BTN_B, PBTN_MOK }, + { GP2X_BTN_X, PBTN_MBACK }, + { GP2X_BTN_A, PBTN_MA2 }, + { GP2X_BTN_Y, PBTN_MA3 }, + { GP2X_BTN_L, PBTN_L }, + { GP2X_BTN_R, PBTN_R }, + { GP2X_BTN_SELECT, PBTN_MENU }, }; #define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0])) -static int in_gp2x_menu_translate(int keycode) +static int in_gp2x_menu_translate(void *drv_data, int keycode, char *charcode) { int i; if (keycode < 0) @@ -211,109 +215,94 @@ static int in_gp2x_menu_translate(int keycode) return 0; } -static int in_gp2x_get_key_code(const char *key_name) -{ - int i; - - for (i = 0; i < IN_GP2X_NBUTTONS; i++) { - const char *k = in_gp2x_keys[i]; - if (k != NULL && strcasecmp(k, key_name) == 0) - return i; - } - - return -1; -} - -static const char *in_gp2x_get_key_name(int keycode) -{ - const char *name = NULL; - if (keycode >= 0 && keycode < IN_GP2X_NBUTTONS) - name = in_gp2x_keys[keycode]; - if (name == NULL) - name = "Unkn"; - - return name; -} - +#if 0 // TODO: move to pico static const struct { short code; - short bit; -} in_gp2x_def_binds[] = + char btype; + char bit; +} in_gp2x_defbinds[] = { /* MXYZ SACB RLDU */ - { BTN_UP, 0 }, - { BTN_DOWN, 1 }, - { BTN_LEFT, 2 }, - { BTN_RIGHT, 3 }, - { BTN_X, 4 }, /* B */ - { BTN_B, 5 }, /* C */ - { BTN_A, 6 }, /* A */ - { BTN_START, 7 }, - { BTN_SELECT, 23 }, /* menu */ - { BTN_Y, 26 }, /* switch rend */ - { BTN_L, 27 }, /* save state */ - { BTN_R, 28 }, /* load state */ - { BTN_VOL_UP, 29 }, /* vol up */ - { BTN_VOL_DOWN, 30 }, /* vol down */ + { BTN_UP, IN_BINDTYPE_PLAYER12, 0 }, + { BTN_DOWN, IN_BINDTYPE_PLAYER12, 1 }, + { BTN_LEFT, IN_BINDTYPE_PLAYER12, 2 }, + { BTN_RIGHT, IN_BINDTYPE_PLAYER12, 3 }, + { BTN_X, IN_BINDTYPE_PLAYER12, 4 }, /* B */ + { BTN_B, IN_BINDTYPE_PLAYER12, 5 }, /* C */ + { BTN_A, IN_BINDTYPE_PLAYER12, 6 }, /* A */ + { BTN_START, IN_BINDTYPE_PLAYER12, 7 }, + { BTN_SELECT, IN_BINDTYPE_EMU, PEVB_MENU }, +// { BTN_Y, IN_BINDTYPE_EMU, PEVB_SWITCH_RND }, + { BTN_L, IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, + { BTN_R, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, + { BTN_VOL_UP, IN_BINDTYPE_EMU, PEVB_VOL_UP }, + { BTN_VOL_DOWN, IN_BINDTYPE_EMU, PEVB_VOL_DOWN }, + { 0, 0, 0 }, }; - -#define DEF_BIND_COUNT (sizeof(in_gp2x_def_binds) / sizeof(in_gp2x_def_binds[0])) - -static void in_gp2x_get_def_binds(int *binds) -{ - int i; - - for (i = 0; i < DEF_BIND_COUNT; i++) - binds[in_gp2x_def_binds[i].code] = 1 << in_gp2x_def_binds[i].bit; -} +#endif /* remove binds of missing keys, count remaining ones */ -static int in_gp2x_clean_binds(void *drv_data, int *binds) +static int in_gp2x_clean_binds(void *drv_data, int *binds, int *def_binds) { - int i, count = 0, have_vol = 0, have_menu = 0; + int i, count = 0; +// int eb, have_vol = 0, have_menu = 0; for (i = 0; i < IN_GP2X_NBUTTONS; i++) { - if (in_gp2x_keys[i] == NULL) - binds[i] = binds[i + IN_GP2X_NBUTTONS] = 0; - if (binds[i]) { - count++; - if (binds[i] & ((1 << 29)|(1 << 30))) - have_vol = 1; - if (binds[i] & (1 << 23)) - have_menu = 1; + int t, offs; + for (t = 0; t < IN_BINDTYPE_COUNT; t++) { + offs = IN_BIND_OFFS(i, t); + if (in_gp2x_keys[i] == NULL) + binds[offs] = def_binds[offs] = 0; + if (binds[offs]) + count++; } +#if 0 + eb = binds[IN_BIND_OFFS(i, IN_BINDTYPE_EMU)]; + if (eb & (PEV_VOL_DOWN|PEV_VOL_UP)) + have_vol = 1; + if (eb & PEV_MENU) + have_menu = 1; +#endif } + // TODO: move to pico +#if 0 /* autobind some important keys, if they are unbound */ - if (!have_vol && binds[BTN_VOL_UP] == 0 && binds[BTN_VOL_DOWN] == 0) { - binds[BTN_VOL_UP] = 1 << 29; - binds[BTN_VOL_DOWN] = 1 << 30; + if (!have_vol && binds[GP2X_BTN_VOL_UP] == 0 && binds[GP2X_BTN_VOL_DOWN] == 0) { + binds[IN_BIND_OFFS(GP2X_BTN_VOL_UP, IN_BINDTYPE_EMU)] = PEV_VOL_UP; + binds[IN_BIND_OFFS(GP2X_BTN_VOL_DOWN, IN_BINDTYPE_EMU)] = PEV_VOL_DOWN; + count += 2; } - if (!have_menu && binds[BTN_SELECT] == 0) - binds[BTN_SELECT] = 1 << 23; + if (!have_menu) { + binds[IN_BIND_OFFS(GP2X_BTN_SELECT, IN_BINDTYPE_EMU)] = PEV_MENU; + count++; + } +#endif - in_combos_find(binds, BTN_PUSH, &in_gp2x_combo_keys, &in_gp2x_combo_acts); + in_combos_find(binds, GP2X_BTN_PUSH, &in_gp2x_combo_keys, &in_gp2x_combo_acts); return count; - } -void in_gp2x_init(void *vdrv) -{ - in_drv_t *drv = vdrv; +static const in_drv_t in_gp2x_drv = { + .prefix = IN_GP2X_PREFIX, + .probe = in_gp2x_probe, + .free = in_gp2x_free, + .get_key_names = in_gp2x_get_key_names, + .clean_binds = in_gp2x_clean_binds, + .update = in_gp2x_update, + .update_keycode = in_gp2x_update_keycode, + .menu_translate = in_gp2x_menu_translate, +}; +void in_gp2x_init(const struct in_default_bind *defbinds) +{ + if (gp2x_dev_id == GP2X_DEV_WIZ) + in_gp2x_keys[GP2X_BTN_START] = "MENU"; + in_gp2x_combo_keys = in_gp2x_combo_acts = 0; - drv->prefix = in_gp2x_prefix; - drv->probe = in_gp2x_probe; - drv->free = in_gp2x_free; - drv->get_bind_count = in_gp2x_get_bind_count; - drv->get_def_binds = in_gp2x_get_def_binds; - drv->clean_binds = in_gp2x_clean_binds; - drv->menu_translate = in_gp2x_menu_translate; - drv->get_key_code = in_gp2x_get_key_code; - drv->get_key_name = in_gp2x_get_key_name; - drv->update_keycode = in_gp2x_update_keycode; + in_register_driver(&in_gp2x_drv, defbinds, NULL); }