diff --git a/input/common/hid/device_wiiu_gca.c b/input/common/hid/device_wiiu_gca.c index 6cda78cad2..7556305f6d 100644 --- a/input/common/hid/device_wiiu_gca.c +++ b/input/common/hid/device_wiiu_gca.c @@ -101,6 +101,8 @@ static void wiiu_gca_handle_packet(void *data, uint8_t *buffer, size_t size) return; } + //RARCH_LOG_BUFFER(buffer, size); + memcpy(instance->device_state, buffer, size); update_pad_state(instance); } @@ -239,6 +241,29 @@ static void wiiu_gca_get_buttons(void *data, retro_bits_t *state) } } +static void log_bitmask(uint32_t bits) +{ + char buf[33]; + int i; + + for(i = 0; i < 32; i++) + { + buf[i] = (bits & (1 << i)) ? '1' : '0'; + } + buf[32] = '\0'; + + RARCH_LOG("pressed_keys: %s\n", buf); +} + +/** + * The USB packet provides a 9-byte data packet for each pad. + * + * byte 0: connection status (0x14 = connected, 0x04 = disconnected) + * bytes 1-2: digital buttons + * bytes 3-4: left analog stick x/y + * bytes 5-6: right analog stick x/y + * bytes 7-8: L/R analog state (note that these have digital buttons too) + */ static void wiiu_gca_packet_handler(void *data, uint8_t *packet, uint16_t size) { gca_pad_t *pad = (gca_pad_t *)data; @@ -263,9 +288,13 @@ static void wiiu_gca_packet_handler(void *data, uint8_t *packet, uint16_t size) if(!pad || !packet || size > sizeof(pad->data)) return; +/* RARCH_LOG_BUFFER(packet, size); */ + memcpy(pad->data, packet, size); pad->buttons = 0; - pressed_keys = pad->data[3] | (pad->data[4] << 8); + pressed_keys = pad->data[1] | (pad->data[2] << 8); + + log_bitmask(pressed_keys); for(i = 0; i < 12; i++) { @@ -289,7 +318,7 @@ static int16_t wiiu_gca_get_axis(void *data, unsigned axis) if(!pad || axis >= 4) return 0; - val = pad->data[5+axis]; + val = pad->data[3+axis]; switch(axis) { @@ -309,13 +338,23 @@ static int16_t wiiu_gca_get_axis(void *data, unsigned axis) return val; } -const char *wiiu_gca_get_name(void *data) +static const char *wiiu_gca_get_name(void *data) { gca_pad_t *pad = (gca_pad_t *)data; return "GameCube Controller"; } +static bool wiiu_gca_button(void *data, uint16_t joykey) +{ + gca_pad_t *pad = (gca_pad_t *)data; + + if(!pad) + return false; + + return (pad->buttons & joykey); +} + pad_connection_interface_t wiiu_gca_pad_connection = { wiiu_gca_pad_init, wiiu_gca_pad_deinit, @@ -323,5 +362,6 @@ pad_connection_interface_t wiiu_gca_pad_connection = { wiiu_gca_set_rumble, wiiu_gca_get_buttons, wiiu_gca_get_axis, - wiiu_gca_get_name + wiiu_gca_get_name, + wiiu_gca_button }; diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index ec78b3c4df..e2f421dd45 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -61,6 +61,7 @@ typedef struct pad_connection_interface void (*get_buttons)(void *data, retro_bits_t *state); int16_t (*get_axis)(void *data, unsigned axis); const char* (*get_name)(void *data); + bool (*button)(void *data, uint16_t joykey); } pad_connection_interface_t; typedef struct joypad_connection joypad_connection_t; diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index 4ae4a4863a..aa9c3ab277 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -40,9 +40,10 @@ static input_device_driver_t *get_driver_for_pad(unsigned pad) { if(wpad_driver.query_pad(pad)) return &wpad_driver; +/* if(kpad_driver.query_pad(pad)) return &kpad_driver; - +*/ #ifdef WIIU_HID return &hidpad_driver; #else @@ -84,11 +85,7 @@ static bool wiiu_joypad_init(void* data) static bool wiiu_joypad_query_pad(unsigned pad) { -#ifdef WIIU_HID return ready && pad < MAX_USERS; -#else - return ready && pad < 5; -#endif } static void wiiu_joypad_destroy(void) @@ -138,7 +135,7 @@ static void wiiu_joypad_poll(void) static const char* wiiu_joypad_name(unsigned pad) { if(!wiiu_joypad_query_pad(pad)) - return "N/A"; + return "Snuffleupagus"; return pad_drivers[pad]->name(pad); } diff --git a/input/include/hid_driver.h b/input/include/hid_driver.h index 59b5a62d28..1eee8a3f85 100644 --- a/input/include/hid_driver.h +++ b/input/include/hid_driver.h @@ -52,6 +52,19 @@ struct hid_driver int32_t (*read)(void *handle, void *buf, size_t size); }; +#define HID_GET_BUTTONS(pad, state) hid_instance.os_driver->get_buttons( \ + hid_instance.os_driver_data, pad, state) +#define HID_BUTTON(pad, key) hid_instance.os_driver->button( \ + hid_instance.os_driver_data, pad, key) +#define HID_AXIS(pad, axis) hid_instance.os_driver->axis( \ + hid_instance.os_driver_data, pad, axis) +#define HID_PAD_NAME(pad) hid_instance.os_driver->name( \ + hid_instance.os_driver_data, pad) +#define HID_POLL() hid_instance.os_driver->poll( \ + hid_instance.os_driver_data) + + + struct hid_driver_instance { hid_driver_t *os_driver; void *os_driver_data; diff --git a/input/input_autodetect_builtin.c b/input/input_autodetect_builtin.c index a6096f2d87..45bbed0775 100644 --- a/input/input_autodetect_builtin.c +++ b/input/input_autodetect_builtin.c @@ -228,6 +228,20 @@ DECL_AXIS(r_y_minus, +3) #ifdef WIIU +#define WIIUINPUT_GAMECUBE_DEFAULT_BINDS \ +DECL_BTN_EX(b, 0, "B") \ +DECL_BTN_EX(y, 1, "Y") \ +DECL_BTN_EX(select, 2, "Z") \ +DECL_BTN_EX(start, 3, "Start/Pause") \ +DECL_BTN_EX(up, 4, "D-Pad Up") \ +DECL_BTN_EX(down, 5, "D-Pad Down") \ +DECL_BTN_EX(left, 6, "D-Pad Left") \ +DECL_BTN_EX(right, 7, "D-Pad Right") \ +DECL_BTN_EX(a, 8, "A") \ +DECL_BTN_EX(x, 9, "X") \ +DECL_BTN_EX(l, 10, "L") \ +DECL_BTN_EX(r, 11, "R") + #define WIIUINPUT_GAMEPAD_DEFAULT_BINDS \ DECL_BTN_EX(menu_toggle, 1, "Home") \ DECL_BTN_EX(select, 2, "-") \ diff --git a/verbosity.c b/verbosity.c index ddb46512a9..ee6837132c 100644 --- a/verbosity.c +++ b/verbosity.c @@ -193,6 +193,37 @@ void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) #endif } +void RARCH_LOG_BUFFER(uint8_t *data, size_t size) +{ + int i, offset; + int padding = size % 16; + uint8_t buf[16]; + + RARCH_LOG("== %d-byte buffer ==================\n", size); + for(i = 0, offset = 0; i < size; i++) + { + buf[offset] = data[i]; + offset++; + + if(offset == 16) + { + offset = 0; + RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n", + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], + buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); + } + } + if(padding) + { + for(i = padding; i < 16; i++) + buf[i] = 0xff; + RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n", + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], + buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); + } + RARCH_LOG("==================================\n"); +} + void RARCH_LOG(const char *fmt, ...) { va_list ap; diff --git a/verbosity.h b/verbosity.h index 5f5cdcf30a..42ae964f58 100644 --- a/verbosity.h +++ b/verbosity.h @@ -86,7 +86,7 @@ void logger_send_v(const char *__format, va_list args); logger_send_v(fmt, vp); \ } while (0) -#else +#else /* IS_SALAMANDER */ #define RARCH_LOG(...) do { \ logger_send("" __VA_ARGS__); \ @@ -123,11 +123,14 @@ void logger_send_v(const char *__format, va_list args); logger_send("[OUTPUT] " tag); \ logger_send_v(fmt, vp); \ } while (0) - #endif -#else + +#define RARCH_LOG_BUFFER(...) do { } while(0) + +#else /* HAVE_LOGGER */ void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap); void RARCH_LOG(const char *fmt, ...); +void RARCH_LOG_BUFFER(uint8_t *buffer, size_t size); void RARCH_LOG_OUTPUT(const char *msg, ...); void RARCH_WARN(const char *fmt, ...); void RARCH_ERR(const char *fmt, ...); @@ -135,7 +138,7 @@ void RARCH_ERR(const char *fmt, ...); #define RARCH_LOG_OUTPUT_V RARCH_LOG_V #define RARCH_WARN_V RARCH_LOG_V #define RARCH_ERR_V RARCH_LOG_V -#endif +#endif /* HAVE_LOGGER */ RETRO_END_DECLS diff --git a/wiiu/input/hidpad_driver.c b/wiiu/input/hidpad_driver.c index 8db27a66dc..97f05e9d06 100644 --- a/wiiu/input/hidpad_driver.c +++ b/wiiu/input/hidpad_driver.c @@ -47,13 +47,13 @@ static bool hidpad_init(void *data) return false; } -/* hid_instance.pad_list[0].connected = true; */ - + hid_instance.pad_list[0].connected = true; +/* for(i = 0; i < (WIIU_WIIMOTE_CHANNELS+1); i++) { hid_instance.pad_list[i].connected = true; } - +*/ hidpad_poll(); ready = true; @@ -63,7 +63,7 @@ static bool hidpad_init(void *data) static bool hidpad_query_pad(unsigned pad) { - return ready && (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS); + return ready && pad < MAX_USERS; } static void hidpad_destroy(void) @@ -78,11 +78,7 @@ static bool hidpad_button(unsigned pad, uint16_t button) if (!hidpad_query_pad(pad)) return false; -#if 0 - return hid_driver->button(hid_data, pad, button); -#else - return false; -#endif + return HID_BUTTON(pad, button); } static void hidpad_get_buttons(unsigned pad, retro_bits_t *state) @@ -90,10 +86,7 @@ static void hidpad_get_buttons(unsigned pad, retro_bits_t *state) if (!hidpad_query_pad(pad)) BIT256_CLEAR_ALL_PTR(state); -#if 0 - hid_driver->get_buttons(hid_data, pad, state); -#endif - BIT256_CLEAR_ALL_PTR(state); + HID_GET_BUTTONS(pad, state); } static int16_t hidpad_axis(unsigned pad, uint32_t axis) @@ -101,17 +94,13 @@ static int16_t hidpad_axis(unsigned pad, uint32_t axis) if (!hidpad_query_pad(pad)); return 0; -#if 0 - return hid_driver->axis(hid_data, pad, axis); -#else - return 0; -#endif + return HID_AXIS(pad, axis); } static void hidpad_poll(void) { if (ready) - hid_instance.os_driver->poll(hid_instance.os_driver_data); + HID_POLL(); } static const char *hidpad_name(unsigned pad) @@ -119,11 +108,7 @@ static const char *hidpad_name(unsigned pad) if (!hidpad_query_pad(pad)) return "N/A"; -#if 1 - return PAD_NAME_HID; -#else - return hid_driver->name(hid_data, pad); -#endif + return HID_PAD_NAME(pad); } input_device_driver_t hidpad_driver = diff --git a/wiiu/input/wiiu_hid.c b/wiiu/input/wiiu_hid.c index d6a1a6c707..44c2822305 100644 --- a/wiiu/input/wiiu_hid.c +++ b/wiiu/input/wiiu_hid.c @@ -19,8 +19,6 @@ static wiiu_event_list events; static wiiu_adapter_list adapters; -static void log_buffer(uint8_t *data, uint32_t len); - static bool wiiu_hid_joypad_query(void *data, unsigned slot) { wiiu_hid_t *hid = (wiiu_hid_t *)data; @@ -30,51 +28,66 @@ static bool wiiu_hid_joypad_query(void *data, unsigned slot) return slot < hid->driver->max_slot; } -static const char *wiiu_hid_joypad_name(void *data, unsigned slot) +static joypad_connection_t *get_pad(wiiu_hid_t *hid, unsigned slot) { - if (!wiiu_hid_joypad_query(data, slot)) + if(!wiiu_hid_joypad_query(hid, slot)) return NULL; - wiiu_hid_t *hid = (wiiu_hid_t *)data; + joypad_connection_t *result = &(hid->driver->pad_list[slot]); + if(!result || !result->connected || !result->iface || !result->data) + return NULL; - return hid->driver->pad_list[slot].iface->get_name(data); + return result; } -static void wiiu_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state) +static const char *wiiu_hid_joypad_name(void *data, unsigned slot) { - (void)data; - (void)port; + joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); - BIT256_CLEAR_ALL_PTR(state); + if(!pad) + return NULL; + + return pad->iface->get_name(pad->data); } -static bool wiiu_hid_joypad_button(void *data, unsigned port, uint16_t joykey) +static void wiiu_hid_joypad_get_buttons(void *data, unsigned slot, retro_bits_t *state) { - (void)data; - (void)port; - (void)joykey; + joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); - return false; + if(pad) + pad->iface->get_buttons(pad->data, state); } -static bool wiiu_hid_joypad_rumble(void *data, unsigned pad, +static bool wiiu_hid_joypad_button(void *data, unsigned slot, uint16_t joykey) +{ + joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); + + if(!pad) + return false; + + return pad->iface->button(pad->data, joykey); +} + +static bool wiiu_hid_joypad_rumble(void *data, unsigned slot, enum retro_rumble_effect effect, uint16_t strength) { - (void)data; - (void)pad; - (void)effect; - (void)strength; + joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); + if(!pad) + return false; + + pad->iface->set_rumble(pad->data, effect, strength); return false; } -static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) +static int16_t wiiu_hid_joypad_axis(void *data, unsigned slot, uint32_t joyaxis) { - (void)data; - (void)port; - (void)joyaxis; + joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); - return 0; + if(!pad) + return 0; + + return pad->iface->get_axis(pad->data, joyaxis); } static void *wiiu_hid_init(hid_driver_instance_t *driver) @@ -464,53 +477,6 @@ void wiiu_start_read_loop(wiiu_adapter_t *adapter) adapter); } -/** - * Takes a buffer and formats it for the log file, 16 bytes per line. - * - * When the end of the buffer is reached, it is padded out with 0xff. So e.g. - * a 5-byte buffer might look like: - * - * 5 bytes read fro HIDRead: - * 0102030405ffffff ffffffffffffffff - * ================================== - */ -static void log_buffer(uint8_t *data, uint32_t len) -{ - int i, o; - int padding = len % 16; - uint8_t buf[16]; - - (uint8_t *)data; - (uint32_t)len; - - RARCH_LOG("%d bytes read from HIDRead:\n", len); - - for(i = 0, o = 0; i < len; i++) - { - buf[o] = data[i]; - o++; - if(o == 16) - { - o = 0; - RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n", - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], - buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); - } - } - - if(padding) - { - for(i = padding; i < 16; i++) - buf[i] = 0xff; - - RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x\n", - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], - buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); - } - RARCH_LOG("==================================\n"); - -} - static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error, uint8_t *buffer, uint32_t buffer_size, void *userdata) {