4 #include "../common/common.h"
5 #include "../common/input.h"
8 #define IN_PREFIX "gp2x:"
9 #define IN_GP2X_NBUTTONS 32
11 extern volatile unsigned short *gp2x_memregs; /* from minimal library rlyeh */
13 enum { BTN_UP = 0, BTN_LEFT = 2, BTN_DOWN = 4, BTN_RIGHT = 6,
14 BTN_START = 8, BTN_SELECT = 9, BTN_L = 10, BTN_R = 11,
15 BTN_A = 12, BTN_B = 13, BTN_X = 14, BTN_Y = 15,
16 BTN_VOL_UP = 23, BTN_VOL_DOWN = 22, BTN_PUSH = 27 };
18 static const char * const in_gp2x_prefix = IN_PREFIX;
19 static const char * const in_gp2x_keys[IN_GP2X_NBUTTONS] = {
20 [0 ... IN_GP2X_NBUTTONS-1] = NULL,
21 [BTN_UP] = "UP", [BTN_LEFT] = "LEFT", [BTN_DOWN] = "DOWN", [BTN_RIGHT] = "RIGHT",
22 [BTN_START] = "START", [BTN_SELECT] = "SELECT", [BTN_L] = "L", [BTN_R] = "R",
23 [BTN_A] = "A", [BTN_B] = "B", [BTN_X] = "X", [BTN_Y] = "Y",
24 [BTN_VOL_DOWN]= "VOL DOWN", [BTN_VOL_UP] = "VOL UP",
29 static void in_gp2x_probe(void)
31 in_register(IN_PREFIX "GP2X pad", IN_DRVID_GP2X, -1, (void *)1);
34 static int in_gp2x_get_bind_count(void)
36 return IN_GP2X_NBUTTONS;
39 static int in_gp2x_get_gpio_bits(void)
43 value = gp2x_memregs[0x1198>>1] & 0xff; // GPIO M
44 if (value == 0xFD) value = 0xFA;
45 if (value == 0xF7) value = 0xEB;
46 if (value == 0xDF) value = 0xAF;
47 if (value == 0x7F) value = 0xBE;
48 value |= gp2x_memregs[0x1184>>1] & 0xFF00; // GPIO C
49 value |= gp2x_memregs[0x1186>>1] << 16; // GPIO D
50 value = ~value & 0x08c0ff55;
54 extern int current_keys;
59 /* returns bitfield of binds of pressed buttons */
60 int in_gp2x_update(void *drv_data, int *binds)
62 int i, value, ret = 0;
64 value = in_gp2x_get_gpio_bits();
66 for (i = 0; value; i++) {
75 int in_gp2x_update_keycode(void *data, int *is_down)
77 static int old_val = 0;
80 val = in_gp2x_get_gpio_bits();
85 /* take one bit only */
86 for (i = 0; i < sizeof(diff)*8; i++)
93 *is_down = !!(val & (1<<i));
97 static int in_gp2x_menu_translate(int keycode)
100 case BTN_UP: return PBTN_UP;
101 case BTN_LEFT: return PBTN_LEFT;
102 case BTN_DOWN: return PBTN_DOWN;
103 case BTN_RIGHT: return PBTN_RIGHT;
104 case BTN_B: return PBTN_MOK;
105 case BTN_X: return PBTN_MBACK;
106 case BTN_SELECT:return PBTN_MENU;
107 case BTN_L: return PBTN_L;
108 case BTN_R: return PBTN_R;
113 static int in_gp2x_get_key_code(const char *key_name)
117 for (i = 0; i < IN_GP2X_NBUTTONS; i++) {
118 const char *k = in_gp2x_keys[i];
119 if (k != NULL && strcasecmp(k, key_name) == 0)
126 static const char *in_gp2x_get_key_name(int keycode)
128 const char *name = NULL;
129 if (keycode >= 0 && keycode < IN_GP2X_NBUTTONS)
130 name = in_gp2x_keys[keycode];
137 static const struct {
140 } in_gp2x_def_binds[] =
147 { BTN_X, 4 }, /* B */
148 { BTN_B, 5 }, /* C */
149 { BTN_A, 6 }, /* A */
153 #define DEF_BIND_COUNT (sizeof(in_gp2x_def_binds) / sizeof(in_gp2x_def_binds[0]))
155 static void in_gp2x_get_def_binds(int *binds)
159 for (i = 0; i < DEF_BIND_COUNT; i++)
160 binds[in_gp2x_def_binds[i].code] = 1 << in_gp2x_def_binds[i].bit;
163 /* remove binds of missing keys, count remaining ones */
164 static int in_gp2x_clean_binds(void *drv_data, int *binds)
168 for (i = 0; i < IN_GP2X_NBUTTONS; i++) {
169 if (in_gp2x_keys[i] == NULL)
170 binds[i] = binds[i + IN_GP2X_NBUTTONS] = 0;
179 void in_gp2x_init(void *vdrv)
181 in_drv_t *drv = vdrv;
183 drv->prefix = in_gp2x_prefix;
184 drv->probe = in_gp2x_probe;
185 drv->get_bind_count = in_gp2x_get_bind_count;
186 drv->get_def_binds = in_gp2x_get_def_binds;
187 drv->clean_binds = in_gp2x_clean_binds;
188 drv->menu_translate = in_gp2x_menu_translate;
189 drv->get_key_code = in_gp2x_get_key_code;
190 drv->get_key_name = in_gp2x_get_key_name;
191 drv->update_keycode = in_gp2x_update_keycode;