mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-20 18:00:57 +00:00
139 lines
3.2 KiB
C
139 lines
3.2 KiB
C
/* 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "input_hid_driver.h"
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <string/string_list.h>
|
|
#include "../driver.h"
|
|
#include "../general.h"
|
|
|
|
static hid_driver_t *hid_drivers[] = {
|
|
#if defined(__APPLE__) && defined(IOS)
|
|
&btstack_hid,
|
|
#endif
|
|
#if defined(__APPLE__) && defined(HAVE_IOHIDMANAGER)
|
|
&iohidmanager_hid,
|
|
#endif
|
|
#ifdef HAVE_LIBUSB
|
|
&libusb_hid,
|
|
#endif
|
|
&null_hid,
|
|
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_first:
|
|
*
|
|
* Finds first suitable HID driver and initializes.
|
|
*
|
|
* Returns: HID driver if found, otherwise NULL.
|
|
**/
|
|
const hid_driver_t *input_hid_init_first(void)
|
|
{
|
|
unsigned i;
|
|
|
|
for (i = 0; hid_drivers[i]; i++)
|
|
{
|
|
driver_t *driver = driver_get_ptr();
|
|
driver->hid_data = hid_drivers[i]->init();
|
|
|
|
if (driver->hid_data)
|
|
{
|
|
RARCH_LOG("Found HID driver: \"%s\".\n",
|
|
hid_drivers[i]->ident);
|
|
return hid_drivers[i];
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|