diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 54e784c61d..b68a4af620 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -160,7 +160,8 @@ "${workspaceFolder}/**" ], "defines": [ - "WIIU" + "WIIU", + "WIIU_HID" ], "windowsSdkVersion": "10.0.17763.0", "compilerPath": "/opt/devkitpro/devkitPPC/bin/powerpc-eabi-gcc", diff --git a/Makefile.common b/Makefile.common index 9f5f1f0dfd..60fd4b4e36 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1182,12 +1182,6 @@ ifeq ($(TARGET), retroarch_wiiu) INCLUDE_DIRS += -Iinput/include OBJ += input/drivers_joypad/wiiu/hidpad_driver.o OBJ += input/drivers_hid/wiiu_hid.o - OBJ += input/connect/joypad_connection.o \ - input/common/hid/hid_device_driver.o \ - input/common/hid/device_wiiu_gca.o \ - input/common/hid/device_ds3.o \ - input/common/hid/device_ds4.o \ - input/common/hid/device_null.o endif endif diff --git a/Makefile.wiiu b/Makefile.wiiu index 1d4d07450a..ac54a772ee 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -7,6 +7,7 @@ GRIFFIN_BUILD = 0 SALAMANDER_BUILD = 0 WHOLE_ARCHIVE_LINK = 0 WIIU_HID = 1 +HAVE_HID = 1 HAVE_RUNAHEAD = 1 WIIU_LOG_RPX = 0 BUILD_DIR = objs/wiiu diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 256562a988..87a8f175af 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -363,17 +363,12 @@ static void log_device(HIDDevice *device) RARCH_LOG(" max_packet_size_tx: %d\n", device->max_packet_size_tx); } + static uint8_t try_init_driver(wiiu_adapter_t *adapter) { - adapter->driver_handle = adapter->driver->init(adapter); - if (!adapter->driver_handle) - { - RARCH_ERR("[hid]: Failed to initialize driver: %s\n", - adapter->driver->name); - return ADAPTER_STATE_DONE; - } + int32_t pad = pad_connection_pad_init(HID_PAD_CONNECTION_PTR(0), &adapter->device_name[0], adapter->vendor_id, adapter->product_id, adapter, &wiiu_hid); - return ADAPTER_STATE_READY; + return (pad >= 0) ? ADAPTER_STATE_READY : ADAPTER_STATE_DONE; } static void synchronized_process_adapters(wiiu_hid_t *hid) @@ -509,9 +504,10 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) goto error; } - adapter->hid = hid; - adapter->driver = event->driver; - adapter->state = ADAPTER_STATE_NEW; + adapter->hid = hid; + adapter->vendor_id = event->vendor_id; + adapter->product_id = event->product_id; + adapter->state = ADAPTER_STATE_NEW; synchronized_add_to_adapters_list(adapter); @@ -775,8 +771,11 @@ static wiiu_adapter_t *new_adapter(wiiu_attach_event *event) adapter->handle = event->handle; adapter->interface_index = event->interface_index; + adapter->product_id = event->product_id; + adapter->vendor_id = event->vendor_id; init_cachealigned_buffer(event->max_packet_size_rx, &adapter->rx_buffer, &adapter->rx_size); init_cachealigned_buffer(event->max_packet_size_tx, &adapter->tx_buffer, &adapter->tx_size); + memcpy(adapter->device_name, event->device_name, sizeof(adapter->device_name)); adapter->connected = true; return adapter; @@ -806,20 +805,48 @@ static void delete_adapter(wiiu_adapter_t *adapter) free(adapter); } +static void get_descriptor_string_ascii(wiiu_adapter_t *adapter, uint8_t *buffer, size_t buffer_size) { + int32_t result = HIDGetDescriptor(adapter->handle, 3, 2, 0, adapter->rx_buffer, adapter->rx_size, NULL, NULL); + memset(buffer, 0, buffer_size); + uint8_t *top; + if(result > 0) { + top = buffer; + for(int i = 2; i < result; i += 2) { + top[0] = adapter->rx_buffer[i]; + top++; + } + } else { + RARCH_ERR("Failed to read descriptor string (0x%08x). Will attempt match by VID/PID\n", result); + } +} + + +static void get_device_name(HIDDevice *device, wiiu_attach_event *event) +{ + int32_t result; + uint8_t *name_buffer = alloc_zeroed(4, device->max_packet_size_rx); + uint8_t *top = &event->device_name[0]; + + if(name_buffer == NULL) { + return; + } + result = HIDGetDescriptor(device->handle, 3, 2, 0, name_buffer, device->max_packet_size_rx, NULL, NULL); + if(result > 0) { + for(int i = 2; i < result; i += 2) { + top[0] = name_buffer[i]; + top++; + } + } + free(name_buffer); +} + static wiiu_attach_event *new_attach_event(HIDDevice *device) { - hid_device_t *driver = hid_device_driver_lookup(device->vid, device->pid); - if (!driver) - { - RARCH_ERR("[hid]: Failed to locate driver for device vid=%04x pid=%04x\n", - device->vid, device->pid); - return NULL; - } wiiu_attach_event *event = alloc_zeroed(4, sizeof(wiiu_attach_event)); + if (!event) return NULL; - event->driver = driver; event->handle = device->handle; event->vendor_id = device->vid; event->product_id = device->pid; @@ -830,6 +857,7 @@ static wiiu_attach_event *new_attach_event(HIDDevice *device) && device->protocol == 2); event->max_packet_size_rx = device->max_packet_size_rx; event->max_packet_size_tx = device->max_packet_size_tx; + get_device_name(device, event); return event; } diff --git a/input/drivers_joypad/wiiu/hidpad_driver.c b/input/drivers_joypad/wiiu/hidpad_driver.c index 454b91d54a..48e9f76a8f 100644 --- a/input/drivers_joypad/wiiu/hidpad_driver.c +++ b/input/drivers_joypad/wiiu/hidpad_driver.c @@ -16,18 +16,37 @@ #include "../../include/wiiu/input.h" +static hidpad_driver_t instance; + /* TODO/FIXME - static global variables */ static bool hidpad_ready = false; +static bool init_pad_list(unsigned slots) +{ + if (slots > MAX_USERS) + return false; + + if (instance.pad_list) + return true; + + instance.pad_list = pad_connection_init(slots); + if (!instance.pad_list) + return false; + + instance.max_slot = slots; + + return true; +} + static bool init_hid_driver(void) { - return hid_init(&hid_instance, &wiiu_hid, &hidpad_driver, MAX_USERS); + return init_pad_list(MAX_USERS); } static void hidpad_poll(void) { if (hidpad_ready) - HID_POLL(); + wiiu_hid.poll(hid_driver_get_data()); } static void *hidpad_init(void *data) @@ -53,29 +72,37 @@ static void hidpad_destroy(void) { hidpad_ready = false; - hid_deinit(&hid_instance); + if(instance.pad_list) { + pad_connection_destroy(instance.pad_list); + instance.pad_list = NULL; + } + + /* Wiping instance data.. */ + memset(&instance, 0, sizeof(instance)); } static int32_t hidpad_button(unsigned port, uint16_t joykey) { if (!hidpad_query_pad(port)) return 0; - return (HID_BUTTON(port, joykey)); + + return wiiu_hid.button(hid_driver_get_data(), port, joykey); } static void hidpad_get_buttons(unsigned port, input_bits_t *state) { - if (!hidpad_query_pad(port)) - BIT256_CLEAR_ALL_PTR(state); + if (!hidpad_query_pad(port)) + BIT256_CLEAR_ALL_PTR(state); - HID_GET_BUTTONS(port, state); + wiiu_hid.get_buttons(hid_driver_get_data(), port, state); } static int16_t hidpad_axis(unsigned port, uint32_t axis) { if (!hidpad_query_pad(port)) return 0; - return HID_AXIS(port, axis); + + return wiiu_hid.axis(hid_driver_get_data(), port, axis); } static int16_t hidpad_state( @@ -116,7 +143,7 @@ static const char *hidpad_name(unsigned port) if (!hidpad_query_pad(port)) return "N/A"; - return HID_PAD_NAME(port); + return wiiu_hid.name(hid_driver_get_data(), port); } input_device_driver_t hidpad_driver = @@ -129,8 +156,8 @@ input_device_driver_t hidpad_driver = hidpad_get_buttons, hidpad_axis, hidpad_poll, - NULL, - NULL, + NULL, /* set_rumble */ + NULL, /* set_rumble_gain */ hidpad_name, "hid" }; diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index 18eb5db822..18380a7cee 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -27,8 +27,6 @@ static bool wiiu_joypad_ready = false; static void *wiiu_joypad_init(void *data) { set_connection_listener(&wiiu_pad_connection_listener); - hid_instance.pad_list = pad_connection_init(MAX_USERS); - hid_instance.max_slot = MAX_USERS; wpad_driver.init(data); kpad_driver.init(data); diff --git a/input/include/hid_driver.h b/input/include/hid_driver.h index b7c8a56fd3..127b477d94 100644 --- a/input/include/hid_driver.h +++ b/input/include/hid_driver.h @@ -54,31 +54,4 @@ 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, a) hid_instance.os_driver->axis( \ - hid_instance.os_driver_data, pad, (a)) -#define HID_PAD_NAME(pad) \ - hid_instance.os_driver->name(hid_instance.os_driver_data, pad) -#define HID_SET_PROTOCOL(pad, protocol) \ - hid_instance.os_driver->set_protocol(pad, protocol) -#define HID_SET_REPORT(pad, rpttype, rptid, data, len) \ - hid_instance.os_driver->set_report(pad, rpttype, rptid, data, len) -#define HID_SEND_CONTROL(pad, data, len) \ - hid_instance.os_driver->send_control(pad, data, len) -#define HID_POLL() hid_instance.os_driver->poll( \ - hid_instance.os_driver_data) -#define HID_MAX_SLOT() hid_instance.max_slot -#define HID_PAD_CONNECTION_PTR(slot) &(hid_instance.pad_list[(slot)]) - -struct hid_driver_instance { - hid_driver_t *os_driver; - void *os_driver_data; - input_device_driver_t *pad_driver; - joypad_connection_t *pad_list; - unsigned max_slot; -}; - #endif /* HID_DRIVER_H__ */ diff --git a/input/include/hid_types.h b/input/include/hid_types.h index 28734e9dd8..a2af1af661 100644 --- a/input/include/hid_types.h +++ b/input/include/hid_types.h @@ -19,6 +19,5 @@ #define HID_TYPES_H__ typedef struct hid_driver hid_driver_t; -typedef struct hid_driver_instance hid_driver_instance_t; #endif /* HID_TYPES_H__ */ diff --git a/input/include/wiiu/hid.h b/input/include/wiiu/hid.h index 3d2a44301e..20aafb3e10 100644 --- a/input/include/wiiu/hid.h +++ b/input/include/wiiu/hid.h @@ -55,6 +55,8 @@ struct wiiu_adapter { hid_device_t *driver; void *driver_handle; wiiu_hid_t *hid; + uint16_t vendor_id; + uint16_t product_id; uint8_t state; uint8_t *rx_buffer; int32_t rx_size; @@ -62,6 +64,7 @@ struct wiiu_adapter { int32_t tx_size; uint32_t handle; uint8_t interface_index; + uint8_t device_name[32]; bool connected; }; @@ -72,7 +75,6 @@ struct wiiu_adapter { */ struct wiiu_attach { wiiu_attach_event *next; - hid_device_t *driver; uint32_t type; uint32_t handle; uint16_t vendor_id; @@ -82,6 +84,7 @@ struct wiiu_attach { uint8_t is_mouse; uint16_t max_packet_size_rx; uint16_t max_packet_size_tx; + uint8_t device_name[32]; }; struct _wiiu_event_list { diff --git a/input/include/wiiu/input.h b/input/include/wiiu/input.h index 401dbaa426..8126c86e09 100644 --- a/input/include/wiiu/input.h +++ b/input/include/wiiu/input.h @@ -30,7 +30,6 @@ #include #include -#include "../../common/hid/hid_device_driver.h" #include "../../connect/joypad_connection.h" #include "../../../retroarch.h" #include "../../../verbosity.h" @@ -64,6 +63,14 @@ struct _wiiu_pad_functions { void (*connect)(unsigned pad, input_device_driver_t *driver); }; +struct hidpad_driver_t { + input_device_driver_t *pad_driver; + joypad_connection_t *pad_list; + unsigned max_slot; +}; + +typedef struct hidpad_driver_t hidpad_driver_t; + extern wiiu_pad_functions_t pad_functions; extern input_device_driver_t wiiu_joypad; extern input_device_driver_t wpad_driver; diff --git a/input/input_driver.c b/input/input_driver.c index c13eba5f01..9d4f84760f 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -305,6 +305,9 @@ hid_driver_t *hid_drivers[] = { #endif #ifdef HW_RVL &wiiusb_hid, +#endif +#if defined(WIIU) && defined(WIIU_HID) + &wiiu_hid, #endif &null_hid, NULL, diff --git a/input/input_driver.h b/input/input_driver.h index d372ebc22e..2dde9f6f98 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -1037,6 +1037,7 @@ extern hid_driver_t iohidmanager_hid; extern hid_driver_t btstack_hid; extern hid_driver_t libusb_hid; extern hid_driver_t wiiusb_hid; +extern hid_driver_t wiiu_hid; #endif /* HAVE_HID */ RETRO_END_DECLS