diff --git a/Makefile.common b/Makefile.common index b7834bf9c1..4bb6f2bc12 100644 --- a/Makefile.common +++ b/Makefile.common @@ -109,6 +109,7 @@ OBJ += frontend/frontend.o \ audio/audio_driver.o \ audio/audio_monitor.o \ input/input_driver.o \ + input/input_hid_driver.o \ gfx/video_driver.o \ gfx/video_monitor.o \ gfx/video_pixel_converter.o \ @@ -164,6 +165,7 @@ OBJ += frontend/frontend.o \ audio/drivers/nullaudio.o \ input/drivers/nullinput.o \ input/drivers_joypad/nullinput_joypad.o \ + input/drivers_joypad/hid_joypad.o \ playlist.o \ movie.o \ record/record_driver.o \ diff --git a/driver.h b/driver.h index f1b4c4bd0b..90e3d0146b 100644 --- a/driver.h +++ b/driver.h @@ -204,6 +204,7 @@ typedef struct driver void *video_context_data; void *video_shader_data; void *input_data; + void *hid_data; void *camera_data; void *location_data; void *resampler_data; diff --git a/griffin/griffin.c b/griffin/griffin.c index 251607f1ac..ff953ad5e3 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -290,6 +290,7 @@ INPUT #include "../input/input_autodetect.c" #include "../input/input_joypad_driver.c" #include "../input/input_joypad.c" +#include "../input/input_hid_driver.c" #include "../input/input_common.c" #include "../input/input_keymaps.c" #include "../input/input_remapping.c" @@ -345,9 +346,7 @@ INPUT #include "../input/drivers_hid/apple_hid.c" #endif -#ifdef HAVE_HID #include "../input/drivers_joypad/hid_joypad.c" -#endif #ifdef IOS #include "../apple/iOS/bluetooth/btdynamic.c" diff --git a/input/drivers_hid/apple_hid.c b/input/drivers_hid/apple_hid.c index 4e6dd34054..5f9fc6f9f2 100644 --- a/input/drivers_hid/apple_hid.c +++ b/input/drivers_hid/apple_hid.c @@ -18,6 +18,7 @@ #include #include "../connect/joypad_connection.h" #include "../drivers/apple_input.h" +#include "../input_hid_driver.h" typedef struct apple_hid { @@ -458,3 +459,16 @@ static void apple_hid_poll(void *data) { (void)data; } + +hid_driver_t apple_hid = { + apple_hid_init, + apple_hid_query_pad, + apple_hid_joypad_destroy, + apple_hid_joypad_button, + apple_hid_joypad_get_buttons, + apple_hid_joypad_axis, + apple_hid_joypad_poll, + apple_hid_joypad_rumble, + apple_hid_joypad_name, + "apple", +}; diff --git a/input/drivers_joypad/hid_joypad.c b/input/drivers_joypad/hid_joypad.c index c4db218fb1..ffa3249741 100644 --- a/input/drivers_joypad/hid_joypad.c +++ b/input/drivers_joypad/hid_joypad.c @@ -16,12 +16,15 @@ #include "../input_autodetect.h" #include "../input_common.h" +#include "../input_hid_driver.h" +#include "../../driver.h" -static void *generic_hid; +static hid_driver_t *generic_hid; static bool hid_joypad_init(void) { - generic_hid = apple_hid_init(); + driver_t *driver = driver_get_ptr(); + generic_hid = (hid_driver_t*)input_hid_init_first(driver->hid_data); if (!generic_hid) return false; @@ -30,50 +33,58 @@ static bool hid_joypad_init(void) static bool hid_joypad_query_pad(unsigned pad) { - return apple_hid_joypad_query_pad(generic_hid, pad); + driver_t *driver = driver_get_ptr(); + return generic_hid->query_pad(driver->hid_data, pad); } -static void hid_joypad_destroy(void) +static void hid_joypad_free(void) { - apple_hid_free(generic_hid); + driver_t *driver = driver_get_ptr(); + generic_hid->free(driver->hid_data); generic_hid = NULL; } static bool hid_joypad_button(unsigned port, uint16_t joykey) { - return apple_hid_joypad_button(generic_hid, port, joykey); + driver_t *driver = driver_get_ptr(); + return generic_hid->button(driver->hid_data, port, joykey); } static uint64_t hid_joypad_get_buttons(unsigned port) { - return apple_hid_joypad_get_buttons(generic_hid, port); + driver_t *driver = driver_get_ptr(); + return generic_hid->get_buttons(driver->hid_data, port); } static int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis) { - return apple_hid_joypad_axis(generic_hid, port, joyaxis); + driver_t *driver = driver_get_ptr(); + return generic_hid->axis(driver->hid_data, port, joyaxis); } static void hid_joypad_poll(void) { - apple_hid_poll(generic_hid); + driver_t *driver = driver_get_ptr(); + generic_hid->poll(driver->hid_data); } static bool hid_joypad_rumble(unsigned pad, enum retro_rumble_effect effect, uint16_t strength) { - return apple_hid_joypad_rumble(generic_hid, pad, effect, strength); + driver_t *driver = driver_get_ptr(); + return generic_hid->set_rumble(driver->hid_data, pad, effect, strength); } static const char *hid_joypad_name(unsigned pad) { - return apple_hid_joypad_name(generic_hid, pad); + driver_t *driver = driver_get_ptr(); + return generic_hid->name(driver->hid_data, pad); } rarch_joypad_driver_t hid_joypad = { hid_joypad_init, hid_joypad_query_pad, - hid_joypad_destroy, + hid_joypad_free, hid_joypad_button, hid_joypad_get_buttons, hid_joypad_axis, diff --git a/input/input_hid_driver.c b/input/input_hid_driver.c new file mode 100644 index 0000000000..2d4d4dfd6d --- /dev/null +++ b/input/input_hid_driver.c @@ -0,0 +1,163 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2015 - 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 "input_hid_driver.h" +#include +#include +#include +#include +#include "../driver.h" +#include "../general.h" + +static hid_driver_t *hid_drivers[] = { +#ifdef __APPLE__ + &apple_hid, +#endif + NULL, +}; + +/** + * hid_driver_find_handle: + * @idx : index of driver to get handle to. + * + * Returns: handle to HID driver at index. Can be NULL + * if nothing found. + **/ +const void *hid_driver_find_handle(int idx) +{ + const void *drv = hid_drivers[idx]; + if (!drv) + return NULL; + return drv; +} + +/** + * hid_driver_find_ident: + * @idx : index of driver to get handle to. + * + * Returns: Human-readable identifier of HID driver at index. Can be NULL + * if nothing found. + **/ +const char *hid_driver_find_ident(int idx) +{ + const hid_driver_t *drv = hid_drivers[idx]; + if (!drv) + return NULL; + return drv->ident; +} + +/** + * config_get_hid_driver_options: + * + * Get an enumerated list of all HID driver names, separated by '|'. + * + * Returns: string listing of all HID driver names, separated by '|'. + **/ +const char* config_get_hid_driver_options(void) +{ + union string_list_elem_attr attr; + unsigned i; + char *options = NULL; + int options_len = 0; + struct string_list *options_l = string_list_new(); + + attr.i = 0; + + if (!options_l) + return NULL; + + for (i = 0; hid_drivers[i]; i++) + { + const char *opt = hid_drivers[i]->ident; + options_len += strlen(opt) + 1; + string_list_append(options_l, opt, attr); + } + + options = (char*)calloc(options_len, sizeof(char)); + + if (!options) + { + string_list_free(options_l); + options_l = NULL; + return NULL; + } + + string_list_join_concat(options, options_len, options_l, "|"); + + string_list_free(options_l); + options_l = NULL; + + return options; +} + +/** + * input_hid_init_driver: + * @ident : identifier of driver to initialize. + * + * Initialize a HID driver of name @ident. + * + * If ident points to NULL or a zero-length string, + * equivalent to calling input_hid_init_first(). + * + * Returns: HID driver if found, otherwise NULL. + **/ +const hid_driver_t *input_hid_init_driver(const char *ident) +{ + unsigned i; + driver_t *driver = driver_get_ptr(); + + if (!ident || !*ident) + return input_hid_init_first(driver->hid_data); + + for (i = 0; hid_drivers[i]; i++) + { + if (strcmp(ident, hid_drivers[i]->ident) == 0 + && hid_drivers[i]->init()) + { + RARCH_LOG("Found HID driver: \"%s\".\n", + hid_drivers[i]->ident); + return hid_drivers[i]; + } + } + + return input_hid_init_first(driver->hid_data); +} + +/** + * input_hid_init_first: + * + * Finds first suitable HID driver and initializes. + * + * Returns: HID driver if found, otherwise NULL. + **/ +const hid_driver_t *input_hid_init_first(void *data) +{ + unsigned i; + + for (i = 0; hid_drivers[i]; i++) + { + data = hid_drivers[i]->init(); + + if (data) + { + RARCH_LOG("Found HID driver: \"%s\".\n", + hid_drivers[i]->ident); + return hid_drivers[i]; + } + } + + return NULL; +} diff --git a/input/input_hid_driver.h b/input/input_hid_driver.h new file mode 100644 index 0000000000..59bcb90efa --- /dev/null +++ b/input/input_hid_driver.h @@ -0,0 +1,101 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2015 - 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 INPUT_HID_DRIVER_H__ +#define INPUT_HID_DRIVER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include "../libretro.h" + +typedef struct hid_driver hid_driver_t; + +struct hid_driver +{ + void *(*init)(void); + bool (*query_pad)(void *, unsigned); + void (*free)(void *); + bool (*button)(void *, unsigned, uint16_t); + uint64_t (*get_buttons)(void *, unsigned); + int16_t (*axis)(void *, unsigned, uint32_t); + void (*poll)(void *); + bool (*set_rumble)(void *, unsigned, enum retro_rumble_effect, uint16_t); + const char *(*name)(void *, unsigned); + + const char *ident; +}; + +extern hid_driver_t apple_hid; + +/** + * hid_driver_find_handle: + * @index : index of driver to get handle to. + * + * Returns: handle to HID driver at index. Can be NULL + * if nothing found. + **/ +const void *hid_driver_find_handle(int index); + +/** + * hid_driver_find_ident: + * @index : index of driver to get handle to. + * + * Returns: Human-readable identifier of HID driver at index. Can be NULL + * if nothing found. + **/ +const char *hid_driver_find_ident(int index); + +/** + * config_get_hid_driver_options: + * + * Get an enumerated list of all HID driver names, separated by '|'. + * + * Returns: string listing of all HID driver names, separated by '|'. + **/ +const char* config_get_hid_driver_options(void); + +/** + * input_hid_init_driver: + * @ident : identifier of driver to initialize. + * + * Initialize a HID driver of name @ident. + * + * If ident points to NULL or a zero-length string, + * equivalent to calling input_hid_init_first(). + * + * Returns: HID driver if found, otherwise NULL. + **/ +const hid_driver_t *input_hid_init_driver(const char *ident); + +/** + * input_hid_init_first: + * + * Finds first suitable HID driver and initializes. + * + * Returns: HID driver if found, otherwise NULL. + **/ +const hid_driver_t *input_hid_init_first(void *data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/input/input_joypad_driver.c b/input/input_joypad_driver.c index fe061ce33a..051cbb5db2 100644 --- a/input/input_joypad_driver.c +++ b/input/input_joypad_driver.c @@ -56,9 +56,6 @@ static rarch_joypad_driver_t *joypad_drivers[] = { #if defined(HAVE_SDL) || defined(HAVE_SDL2) &sdl_joypad, #endif -#ifdef HAVE_HID - &hid_joypad, -#endif #ifdef __MACH__ #ifdef IOS &apple_ios_joypad, @@ -67,6 +64,7 @@ static rarch_joypad_driver_t *joypad_drivers[] = { #ifdef __QNX__ &qnx_joypad, #endif + &hid_joypad, &null_joypad, NULL, }; diff --git a/menu/menu_entries_cbs.c b/menu/menu_entries_cbs.c index 7e8ad5f27d..475076db49 100644 --- a/menu/menu_entries_cbs.c +++ b/menu/menu_entries_cbs.c @@ -25,6 +25,7 @@ #include "../config.def.h" #include "../retroarch.h" #include "../runloop.h" +#include "../file_ops.h" void menu_entries_common_load_content(bool persist) { diff --git a/tools/retroarch-joyconfig-griffin.c b/tools/retroarch-joyconfig-griffin.c index 916e6925ff..3d8dea90c0 100644 --- a/tools/retroarch-joyconfig-griffin.c +++ b/tools/retroarch-joyconfig-griffin.c @@ -48,8 +48,10 @@ #include "../libretro-common/compat/compat.c" #include "../input/drivers/nullinput.c" +#include "../input/drivers_joypad/hid_joypad.c" #include "../input/drivers_joypad/nullinput_joypad.c" +#include "../input/input_hid_driver.c" #include "../input/input_joypad_driver.c" #include "../input/input_joypad.c" #include "../input/input_common.c"