From ae19eed00f0aaff0bea6af7ed9d4c6fe1f50cf67 Mon Sep 17 00:00:00 2001 From: gblues Date: Mon, 5 Feb 2018 23:21:00 -0800 Subject: [PATCH] implement hid device search --- Makefile.wiiu | 8 +++++-- input/common/hid/device_ds3.c | 26 ++++++++++++++++++++ input/common/hid/device_ds4.c | 26 ++++++++++++++++++++ input/common/hid/device_wiiu_gca.c | 25 +++++++++++++++++++ input/common/hid/hid_device_driver.c | 36 ++++++++++++++++++++++++++++ input/common/hid/hid_device_driver.h | 32 +++++++++++++++++++++++++ wiiu/include/wiiu/pad_driver.h | 2 ++ wiiu/input/wiiu_hid.c | 8 +++++++ 8 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 input/common/hid/device_ds3.c create mode 100644 input/common/hid/device_ds4.c create mode 100644 input/common/hid/device_wiiu_gca.c create mode 100644 input/common/hid/hid_device_driver.c create mode 100644 input/common/hid/hid_device_driver.h diff --git a/Makefile.wiiu b/Makefile.wiiu index 4b5eeafc02..798028e5de 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -6,7 +6,7 @@ DEBUG = 0 GRIFFIN_BUILD = 0 SALAMANDER_BUILD = 0 WHOLE_ARCHIVE_LINK = 0 -WIIU_HID = 0 +WIIU_HID = 1 WIIU_LOG_RPX = 0 BUILD_DIR = objs/wiiu PC_DEVELOPMENT_IP_ADDRESS ?= @@ -56,7 +56,11 @@ ifeq ($(WIIU_HID),1) input/connect/connect_nesusb.o \ input/connect/connect_snesusb.o \ input/connect/connect_wiiupro.o \ - input/connect/connect_wiiugca.o + input/connect/connect_wiiugca.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 endif ifeq ($(SALAMANDER_BUILD),1) diff --git a/input/common/hid/device_ds3.c b/input/common/hid/device_ds3.c new file mode 100644 index 0000000000..04325ace7b --- /dev/null +++ b/input/common/hid/device_ds3.c @@ -0,0 +1,26 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "hid_device_driver.h" + +static bool ds3_detect(uint16_t vendor_id, uint16_t product_id) +{ + return false; +} + +hid_device_t ds3_hid_device = { + ds3_detect +}; diff --git a/input/common/hid/device_ds4.c b/input/common/hid/device_ds4.c new file mode 100644 index 0000000000..0f049e5cbc --- /dev/null +++ b/input/common/hid/device_ds4.c @@ -0,0 +1,26 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "hid_device_driver.h" + +static bool ds4_detect(uint16_t vendor_id, uint16_t product_id) +{ + return false; +} + +hid_device_t ds4_hid_device = { + ds4_detect +}; diff --git a/input/common/hid/device_wiiu_gca.c b/input/common/hid/device_wiiu_gca.c new file mode 100644 index 0000000000..0829a22ac1 --- /dev/null +++ b/input/common/hid/device_wiiu_gca.c @@ -0,0 +1,25 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "hid_device_driver.h" + +static bool wiiu_gca_detect(uint16_t vendor_id, uint16_t product_id) { + return false; +} + +hid_device_t wiiu_gca_hid_device = { + wiiu_gca_detect +}; diff --git a/input/common/hid/hid_device_driver.c b/input/common/hid/hid_device_driver.c new file mode 100644 index 0000000000..0f049ca728 --- /dev/null +++ b/input/common/hid/hid_device_driver.c @@ -0,0 +1,36 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "hid_device_driver.h" + +hid_device_t *hid_device_list[] = { + &wiiu_gca_hid_device, + &ds3_hid_device, + &ds4_hid_device, + NULL /* must be last entry in list */ +}; + +hid_device_t *hid_device_driver_lookup(uint16_t vendor_id, uint16_t product_id) { + int i = 0; + + for(i = 0; hid_device_list[i] != NULL; i++) { + if(hid_device_list[i]->detect(vendor_id, product_id)) + return hid_device_list[i]; + } + + return NULL; +} + diff --git a/input/common/hid/hid_device_driver.h b/input/common/hid/hid_device_driver.h new file mode 100644 index 0000000000..90e0659026 --- /dev/null +++ b/input/common/hid/hid_device_driver.h @@ -0,0 +1,32 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef HID_DEVICE_DRIVER__H +#define HID_DEVICE_DRIVER__H + +#include "../../input_driver.h" + +typedef struct hid_device { + bool (*detect)(uint16_t vid, uint16_t pid); +} hid_device_t; + +extern hid_device_t wiiu_gca_hid_device; +extern hid_device_t ds3_hid_device; +extern hid_device_t ds4_hid_device; + +hid_device_t *hid_device_driver_lookup(uint16_t vendor_id, uint16_t product_id); + +#endif /* HID_DEVICE_DRIVER__H */ diff --git a/wiiu/include/wiiu/pad_driver.h b/wiiu/include/wiiu/pad_driver.h index 376b899f43..8a93798de7 100644 --- a/wiiu/include/wiiu/pad_driver.h +++ b/wiiu/include/wiiu/pad_driver.h @@ -31,6 +31,7 @@ #include #include "../../input/input_driver.h" +#include "../../input/common/hid/hid_device_driver.h" #include "../../input/connect/joypad_connection.h" #include "../../tasks/tasks_internal.h" #include "../../retroarch.h" @@ -149,6 +150,7 @@ typedef struct wiiu_attach wiiu_attach_event; struct wiiu_attach { wiiu_attach_event *next; + hid_device_t *driver; uint32_t type; uint32_t handle; uint16_t vendor_id; diff --git a/wiiu/input/wiiu_hid.c b/wiiu/input/wiiu_hid.c index db0fcd074b..43eb372752 100644 --- a/wiiu/input/wiiu_hid.c +++ b/wiiu/input/wiiu_hid.c @@ -649,10 +649,18 @@ static void delete_adapter(wiiu_adapter_t *adapter) 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;