frontend: input: pass default binds as argument
authornotaz <notasas@gmail.com>
Mon, 23 Apr 2012 22:48:17 +0000 (01:48 +0300)
committernotaz <notasas@gmail.com>
Sun, 29 Apr 2012 16:32:08 +0000 (19:32 +0300)
allows to get rid of some hacks

14 files changed:
frontend/common/in_sdl.c
frontend/common/in_sdl.h
frontend/common/input.c
frontend/common/input.h
frontend/gp2x/in_gp2x.c
frontend/gp2x/in_gp2x.h
frontend/in_tsbutton.c
frontend/linux/in_evdev.c
frontend/linux/in_evdev.h
frontend/main.c
frontend/plat_dummy.c
frontend/plat_pandora.c
frontend/plat_pollux.c
frontend/plat_sdl.c

index 27c183b..ed13610 100644 (file)
@@ -302,8 +302,8 @@ static const in_drv_t in_sdl_drv = {
        .menu_translate = in_sdl_menu_translate,
 };
 
-void in_sdl_init(void)
+void in_sdl_init(const struct in_default_bind *defbinds)
 {
-       in_register_driver(&in_sdl_drv);
+       in_register_driver(&in_sdl_drv, defbinds);
 }
 
index 9c9d406..47f7a83 100644 (file)
@@ -1 +1,3 @@
-void in_sdl_init(void);
+struct in_default_bind;
+
+void in_sdl_init(const struct in_default_bind *defbinds);
index 0b1984b..2f8a867 100644 (file)
@@ -52,15 +52,27 @@ static int menu_last_used_dev = 0;
 
 static int *in_alloc_binds(int drv_id, int key_count)
 {
+       const struct in_default_bind *defbinds;
        int *binds;
+       int i;
 
        binds = calloc(key_count * IN_BINDTYPE_COUNT * 2, sizeof(binds[0]));
        if (binds == NULL)
                return NULL;
 
-       DRV(drv_id).get_def_binds(binds + key_count * IN_BINDTYPE_COUNT);
-       memcpy(binds, binds + key_count * IN_BINDTYPE_COUNT,
-               sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT);
+       defbinds = DRV(drv_id).defbinds;
+       if (defbinds != NULL) {
+               for (i = 0; ; i++) {
+                       if (defbinds[i].bit == 0 && defbinds[i].code == 0)
+                               break;
+                       binds[IN_BIND_OFFS(defbinds[i].code, defbinds[i].btype)] =
+                               1 << defbinds[i].bit;
+               }
+
+               /* always have a copy of defbinds */
+               memcpy(binds + key_count * IN_BINDTYPE_COUNT, binds,
+                       sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT);
+       }
 
        return binds;
 }
@@ -891,7 +903,6 @@ void in_debug_dump(void)
 /* stubs for drivers that choose not to implement something */
 
 static void in_def_free(void *drv_data) {}
-static void in_def_get_def_binds(int *binds) {}
 static int  in_def_clean_binds(void *drv_data, int *b, int *db) { return 1; }
 static int  in_def_get_config(void *drv_data, int what, int *val) { return -1; }
 static int  in_def_set_config(void *drv_data, int what, int val) { return -1; }
@@ -905,7 +916,7 @@ static const char *in_def_get_key_name(int keycode) { return NULL; }
        if (d.f == NULL) d.f = in_def_##f
 
 /* to be called by drivers */
-int in_register_driver(const in_drv_t *drv)
+int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds)
 {
        int count_new = in_driver_count + 1;
        in_drv_t *new_drivers;
@@ -919,7 +930,6 @@ int in_register_driver(const in_drv_t *drv)
        memcpy(&new_drivers[in_driver_count], drv, sizeof(new_drivers[0]));
 
        CHECK_ADD_STUB(new_drivers[in_driver_count], free);
-       CHECK_ADD_STUB(new_drivers[in_driver_count], get_def_binds);
        CHECK_ADD_STUB(new_drivers[in_driver_count], clean_binds);
        CHECK_ADD_STUB(new_drivers[in_driver_count], get_config);
        CHECK_ADD_STUB(new_drivers[in_driver_count], set_config);
@@ -928,6 +938,8 @@ int in_register_driver(const in_drv_t *drv)
        CHECK_ADD_STUB(new_drivers[in_driver_count], menu_translate);
        CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_code);
        CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_name);
+       if (defbinds != NULL)
+               new_drivers[in_driver_count].defbinds = defbinds;
        in_drivers = new_drivers;
        in_driver_count = count_new;
 
index 524366f..1f90425 100644 (file)
@@ -79,7 +79,6 @@ typedef struct {
        void (*free)(void *drv_data);
        const char * const *
             (*get_key_names)(int *count);
-       void (*get_def_binds)(int *binds);
        int  (*clean_binds)(void *drv_data, int *binds, int *def_finds);
        int  (*get_config)(void *drv_data, int what, int *val);
        int  (*set_config)(void *drv_data, int what, int val);
@@ -90,6 +89,8 @@ typedef struct {
        int  (*menu_translate)(void *drv_data, int keycode);
        int  (*get_key_code)(const char *key_name);
        const char * (*get_key_name)(int keycode);
+
+       const struct in_default_bind *defbinds;
 } in_drv_t;
 
 struct in_default_bind {
@@ -99,7 +100,7 @@ struct in_default_bind {
 };
 
 /* to be called by drivers */
-int  in_register_driver(const in_drv_t *drv);
+int  in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds);
 void in_register(const char *nname, int drv_fd_hnd, void *drv_data,
                int key_count, const char * const *key_names, int combos);
 void in_combos_find(const int *binds, int last_key, int *combo_keys, int *combo_acts);
index b750e68..196f121 100644 (file)
@@ -244,18 +244,6 @@ static const struct {
 };
 #endif
 
-static void in_gp2x_get_def_binds(int *binds)
-{
-       int i;
-
-       for (i = 0; 1; i++) {
-               if (in_gp2x_defbinds[i].bit == 0 && in_gp2x_defbinds[i].code == 0)
-                       break;
-               binds[IN_BIND_OFFS(in_gp2x_defbinds[i].code, in_gp2x_defbinds[i].btype)] =
-                       1 << in_gp2x_defbinds[i].bit;
-       }
-}
-
 /* remove binds of missing keys, count remaining ones */
 static int in_gp2x_clean_binds(void *drv_data, int *binds, int *def_binds)
 {
@@ -305,20 +293,19 @@ static const in_drv_t in_gp2x_drv = {
        .probe          = in_gp2x_probe,
        .free           = in_gp2x_free,
        .get_key_names  = in_gp2x_get_key_names,
-       .get_def_binds  = in_gp2x_get_def_binds,
        .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(void)
+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;
 
-       in_register_driver(&in_gp2x_drv);
+       in_register_driver(&in_gp2x_drv, defbinds);
 }
 
index 6428a63..035cded 100644 (file)
@@ -1,8 +1,7 @@
 
-void in_gp2x_init(void);
+struct in_default_bind;
 
-/* to be set somewhere in platform code */
-extern struct in_default_bind in_gp2x_defbinds[];
+void in_gp2x_init(const struct in_default_bind *defbinds);
 
 enum  { GP2X_BTN_UP = 0,      GP2X_BTN_LEFT = 2,      GP2X_BTN_DOWN = 4,  GP2X_BTN_RIGHT = 6,
         GP2X_BTN_START = 8,   GP2X_BTN_SELECT = 9,    GP2X_BTN_L = 10,    GP2X_BTN_R = 11,
index 84d6895..80c9c58 100644 (file)
@@ -133,6 +133,6 @@ static const in_drv_t in_tsbutton_drv = {
 void in_tsbutton_init(void)
 {
        tsbutton_down_id = last_tsbutton_id = -1;
-       in_register_driver(&in_tsbutton_drv);
+       in_register_driver(&in_tsbutton_drv, NULL);
 }
 
index 23d2e2a..c615061 100644 (file)
@@ -586,18 +586,6 @@ static int in_evdev_menu_translate(void *drv_data, int keycode)
        return 0;
 }
 
-static void in_evdev_get_def_binds(int *binds)
-{
-       int i;
-
-       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;
-       }
-}
-
 /* remove binds of missing keys, count remaining ones */
 static int in_evdev_clean_binds(void *drv_data, int *binds, int *def_binds)
 {
@@ -637,7 +625,6 @@ static const in_drv_t in_evdev_drv = {
        .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,
@@ -647,8 +634,8 @@ static const in_drv_t in_evdev_drv = {
        .menu_translate = in_evdev_menu_translate,
 };
 
-void in_evdev_init(void)
+void in_evdev_init(const struct in_default_bind *defbinds)
 {
-       in_register_driver(&in_evdev_drv);
+       in_register_driver(&in_evdev_drv, defbinds);
 }
 
index 6141b2b..c5aef9b 100644 (file)
@@ -1,7 +1,5 @@
 
+struct in_default_bind;
 extern int in_evdev_allow_abs_only;
 
-void in_evdev_init(void);
-
-/* to be set somewhere in platform code */
-extern struct in_default_bind in_evdev_defbinds[];
+void in_evdev_init(const struct in_default_bind *defbinds);
index d3df714..dc5be3c 100644 (file)
@@ -364,9 +364,9 @@ int main(int argc, char *argv[])
                return 1;
 
        // frontend stuff
+       // init input but leave probing to platform code,
+       // they add input drivers and may need to modify them after probe
        in_init();
-       in_evdev_init();
-       //in_probe();
        pl_init();
        plat_init();
        menu_init(); // loads config
index 9a32549..26cd3a2 100644 (file)
@@ -5,13 +5,8 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "common/input.h"
 #include "plat.h"
 
-struct in_default_bind in_evdev_defbinds[] = {
-       { 0, 0, 0 },
-};
-
 void plat_video_menu_enter(int is_rom_loaded)
 {
 }
index 1c07924..2522b0b 100644 (file)
@@ -38,7 +38,7 @@ static const char * const pandora_gpio_keys[KEY_MAX + 1] = {
        [KEY_MENU]      = "Pandora",
 };
 
-struct in_default_bind in_evdev_defbinds[] = {
+static const struct in_default_bind in_evdev_defbinds[] = {
        { KEY_UP,       IN_BINDTYPE_PLAYER12, DKEY_UP },
        { KEY_DOWN,     IN_BINDTYPE_PLAYER12, DKEY_DOWN },
        { KEY_LEFT,     IN_BINDTYPE_PLAYER12, DKEY_LEFT },
@@ -66,6 +66,7 @@ struct in_default_bind in_evdev_defbinds[] = {
 
 int plat_pandora_init(void)
 {
+       in_evdev_init(in_evdev_defbinds);
        in_probe();
        in_set_config(in_name_to_id("evdev:gpio-keys"), IN_CFG_KEY_NAMES,
                      pandora_gpio_keys, sizeof(pandora_gpio_keys));
index 3cf3a9b..80e7a1b 100644 (file)
 #include <linux/fb.h>
 #include <sys/mman.h>
 #include <linux/soundcard.h>
+#include <linux/input.h>
 
 #include "common/input.h"
 #include "gp2x/in_gp2x.h"
+#include "linux/in_evdev.h"
 #include "common/menu.h"
 #include "warm/warm.h"
 #include "plugin_lib.h"
@@ -50,7 +52,25 @@ static int psx_offset_x, psx_offset_y, psx_src_width, psx_src_height;
 static int fb_offset_x, fb_offset_y;
 
 static void caanoo_init(void);
+static void wiz_init(void);
+
 
+static const struct in_default_bind in_evdev_defbinds[] = {
+       { KEY_UP,       IN_BINDTYPE_PLAYER12, DKEY_UP },
+       { KEY_DOWN,     IN_BINDTYPE_PLAYER12, DKEY_DOWN },
+       { KEY_LEFT,     IN_BINDTYPE_PLAYER12, DKEY_LEFT },
+       { KEY_RIGHT,    IN_BINDTYPE_PLAYER12, DKEY_RIGHT },
+       { BTN_TOP,      IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE },
+       { BTN_THUMB,    IN_BINDTYPE_PLAYER12, DKEY_CROSS },
+       { BTN_THUMB2,   IN_BINDTYPE_PLAYER12, DKEY_CIRCLE },
+       { BTN_TRIGGER,  IN_BINDTYPE_PLAYER12, DKEY_SQUARE },
+       { BTN_BASE3,    IN_BINDTYPE_PLAYER12, DKEY_START },
+       { BTN_BASE4,    IN_BINDTYPE_PLAYER12, DKEY_SELECT },
+       { BTN_TOP2,     IN_BINDTYPE_PLAYER12, DKEY_L1 },
+       { BTN_PINKIE,   IN_BINDTYPE_PLAYER12, DKEY_R1 },
+       { BTN_BASE,     IN_BINDTYPE_EMU, SACTION_ENTER_MENU },
+       { 0, 0, 0 },
+};
 
 static void *fb_flip(void)
 {
@@ -587,13 +607,14 @@ void plat_init(void)
        else {
                printf("detected Wiz\n");
                gp2x_dev_id = GP2X_DEV_WIZ;
-               in_gp2x_init();
        }
 
        in_tsbutton_init();
-       in_probe();
+       in_evdev_init(in_evdev_defbinds);
        if (gp2x_dev_id == GP2X_DEV_CAANOO)
                caanoo_init();
+       else
+               wiz_init();
 
        mixerdev = open("/dev/mixer", O_RDWR);
        if (mixerdev == -1)
@@ -632,25 +653,6 @@ void plat_finish(void)
 }
 
 /* Caanoo stuff, perhaps move later */
-#include <linux/input.h>
-
-struct in_default_bind in_evdev_defbinds[] = {
-       { KEY_UP,       IN_BINDTYPE_PLAYER12, DKEY_UP },
-       { KEY_DOWN,     IN_BINDTYPE_PLAYER12, DKEY_DOWN },
-       { KEY_LEFT,     IN_BINDTYPE_PLAYER12, DKEY_LEFT },
-       { KEY_RIGHT,    IN_BINDTYPE_PLAYER12, DKEY_RIGHT },
-       { BTN_TOP,      IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE },
-       { BTN_THUMB,    IN_BINDTYPE_PLAYER12, DKEY_CROSS },
-       { BTN_THUMB2,   IN_BINDTYPE_PLAYER12, DKEY_CIRCLE },
-       { BTN_TRIGGER,  IN_BINDTYPE_PLAYER12, DKEY_SQUARE },
-       { BTN_BASE3,    IN_BINDTYPE_PLAYER12, DKEY_START },
-       { BTN_BASE4,    IN_BINDTYPE_PLAYER12, DKEY_SELECT },
-       { BTN_TOP2,     IN_BINDTYPE_PLAYER12, DKEY_L1 },
-       { BTN_PINKIE,   IN_BINDTYPE_PLAYER12, DKEY_R1 },
-       { BTN_BASE,     IN_BINDTYPE_EMU, SACTION_ENTER_MENU },
-       { 0, 0, 0 },
-};
-
 static const char * const caanoo_keys[KEY_MAX + 1] = {
        [0 ... KEY_MAX] = NULL,
        [KEY_UP]        = "Up",
@@ -776,8 +778,15 @@ void plat_trigger_vibrate(int is_strong)
        ioctl(hapticdev, HAPTIC_PLAY_PATTERN, &haptic_seq[!!is_strong]);
 }
 
+static void caanoo_init(void)
+{
+       in_probe();
+       in_set_config(in_name_to_id("evdev:pollux-analog"), IN_CFG_KEY_NAMES,
+                     caanoo_keys, sizeof(caanoo_keys));
+}
+
 /* Wiz stuff */
-struct in_default_bind in_gp2x_defbinds[] =
+static const struct in_default_bind in_gp2x_defbinds[] =
 {
        /* MXYZ SACB RLDU */
        { GP2X_BTN_UP,          IN_BINDTYPE_PLAYER12, DKEY_UP },
@@ -824,8 +833,8 @@ void plat_step_volume(int is_up)
 // unused dummy for in_gp2x
 volatile unsigned short *gp2x_memregs;
 
-static void caanoo_init(void)
+static void wiz_init(void)
 {
-       in_set_config(in_name_to_id("evdev:pollux-analog"), IN_CFG_KEY_NAMES,
-                     caanoo_keys, sizeof(caanoo_keys));
+       in_gp2x_init(in_gp2x_defbinds);
+       in_probe();
 }
index 015450d..19d7ac0 100644 (file)
 #include "common/input.h"
 #include "common/in_sdl.h"
 #include "common/menu.h"
+#include "plugin_lib.h"
+#include "main.h"
 #include "plat.h"
 #include "revision.h"
 
-// XXX
-struct in_default_bind in_evdev_defbinds[] = {
+static const struct in_default_bind in_sdl_defbinds[] = {
+       { SDLK_UP,      IN_BINDTYPE_PLAYER12, DKEY_UP },
+       { SDLK_DOWN,    IN_BINDTYPE_PLAYER12, DKEY_DOWN },
+       { SDLK_LEFT,    IN_BINDTYPE_PLAYER12, DKEY_LEFT },
+       { SDLK_RIGHT,   IN_BINDTYPE_PLAYER12, DKEY_RIGHT },
+       { SDLK_d,       IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE },
+       { SDLK_z,       IN_BINDTYPE_PLAYER12, DKEY_CROSS },
+       { SDLK_x,       IN_BINDTYPE_PLAYER12, DKEY_CIRCLE },
+       { SDLK_s,       IN_BINDTYPE_PLAYER12, DKEY_SQUARE },
+       { SDLK_v,       IN_BINDTYPE_PLAYER12, DKEY_START },
+       { SDLK_c,       IN_BINDTYPE_PLAYER12, DKEY_SELECT },
+       { SDLK_w,       IN_BINDTYPE_PLAYER12, DKEY_L1 },
+       { SDLK_r,       IN_BINDTYPE_PLAYER12, DKEY_R1 },
+       { SDLK_e,       IN_BINDTYPE_PLAYER12, DKEY_L2 },
+       { SDLK_t,       IN_BINDTYPE_PLAYER12, DKEY_R2 },
+       { SDLK_ESCAPE,  IN_BINDTYPE_EMU, SACTION_ENTER_MENU },
        { 0, 0, 0 }
 };
 
@@ -62,7 +78,7 @@ void plat_init(void)
   }
   SDL_WM_SetCaption("PCSX-ReARMed " REV, NULL);
 
-  in_sdl_init();
+  in_sdl_init(in_sdl_defbinds);
   in_probe();
   return;