2013-03-03 18:50:38 -05:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2017-11-28 10:04:34 +00:00
|
|
|
*
|
2013-03-03 18:50:38 -05:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-01 20:38:20 +01:00
|
|
|
#include "../../tasks/tasks_internal.h"
|
2015-12-05 13:22:50 +01:00
|
|
|
#include "../input_driver.h"
|
2014-10-04 16:46:52 +02:00
|
|
|
|
2020-08-03 17:31:22 +02:00
|
|
|
/* TODO/FIXME - static global */
|
2016-11-30 05:12:28 +01:00
|
|
|
static const hid_driver_t *generic_hid = NULL;
|
2015-04-01 20:49:26 +02:00
|
|
|
|
2020-09-22 02:30:47 +02:00
|
|
|
static void *hid_joypad_init(void *data)
|
2015-02-15 04:07:22 +01:00
|
|
|
{
|
2015-04-01 23:33:00 +02:00
|
|
|
generic_hid = input_hid_init_first();
|
2015-04-01 20:49:26 +02:00
|
|
|
if (!generic_hid)
|
2020-09-22 02:30:47 +02:00
|
|
|
return NULL;
|
|
|
|
return (void*)-1;
|
2013-03-03 18:50:38 -05:00
|
|
|
}
|
|
|
|
|
2015-04-01 20:00:38 +02:00
|
|
|
static bool hid_joypad_query_pad(unsigned pad)
|
2013-03-03 18:50:38 -05:00
|
|
|
{
|
2016-11-30 05:12:28 +01:00
|
|
|
if (generic_hid && generic_hid->query_pad)
|
|
|
|
return generic_hid->query_pad((void*)hid_driver_get_data(), pad);
|
|
|
|
return false;
|
2013-03-03 18:50:38 -05:00
|
|
|
}
|
|
|
|
|
2015-04-01 22:31:43 +02:00
|
|
|
static void hid_joypad_free(void)
|
2013-03-03 18:50:38 -05:00
|
|
|
{
|
2016-11-30 05:06:50 +01:00
|
|
|
if (!generic_hid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (generic_hid->free)
|
|
|
|
generic_hid->free((void*)hid_driver_get_data());
|
2017-11-28 10:04:34 +00:00
|
|
|
|
2015-04-01 20:49:26 +02:00
|
|
|
generic_hid = NULL;
|
2013-03-03 18:50:38 -05:00
|
|
|
}
|
|
|
|
|
2021-08-08 21:48:19 +02:00
|
|
|
static int32_t hid_joypad_button(unsigned port, uint16_t joykey)
|
2013-03-03 18:50:38 -05:00
|
|
|
{
|
2016-11-30 05:12:28 +01:00
|
|
|
if (generic_hid && generic_hid->button)
|
|
|
|
return generic_hid->button((void*)hid_driver_get_data(), port, joykey);
|
2020-07-18 18:07:57 +02:00
|
|
|
return 0;
|
2013-03-03 18:50:38 -05:00
|
|
|
}
|
|
|
|
|
2020-07-19 03:18:12 +02:00
|
|
|
static int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis)
|
|
|
|
{
|
|
|
|
if (generic_hid && generic_hid->axis)
|
|
|
|
return generic_hid->axis((void*)hid_driver_get_data(), port, joyaxis);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int16_t hid_joypad_state(
|
|
|
|
rarch_joypad_info_t *joypad_info,
|
|
|
|
const struct retro_keybind *binds,
|
|
|
|
unsigned port)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
int16_t ret = 0;
|
2020-07-29 05:31:23 +02:00
|
|
|
uint16_t port_idx = joypad_info->joy_idx;
|
|
|
|
|
|
|
|
if (port_idx >= DEFAULT_MAX_PADS)
|
|
|
|
return 0;
|
2020-07-19 03:18:12 +02:00
|
|
|
|
|
|
|
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
|
|
|
{
|
|
|
|
/* Auto-binds are per joypad, not per user. */
|
|
|
|
const uint64_t joykey = (binds[i].joykey != NO_BTN)
|
|
|
|
? binds[i].joykey : joypad_info->auto_binds[i].joykey;
|
|
|
|
const uint32_t joyaxis = (binds[i].joyaxis != AXIS_NONE)
|
|
|
|
? binds[i].joyaxis : joypad_info->auto_binds[i].joyaxis;
|
|
|
|
if ((uint16_t)joykey != NO_BTN && hid_joypad_button(
|
2020-07-29 05:31:23 +02:00
|
|
|
port_idx, (uint16_t)joykey))
|
2020-07-19 03:18:12 +02:00
|
|
|
ret |= ( 1 << i);
|
|
|
|
else if (joyaxis != AXIS_NONE &&
|
2020-07-29 05:31:23 +02:00
|
|
|
((float)abs(hid_joypad_axis(port_idx, joyaxis))
|
2020-07-19 03:18:12 +02:00
|
|
|
/ 0x8000) > joypad_info->axis_threshold)
|
|
|
|
ret |= (1 << i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-08 20:21:12 +02:00
|
|
|
static void hid_joypad_get_buttons(unsigned port, input_bits_t *state)
|
2015-02-15 01:57:29 +01:00
|
|
|
{
|
2017-12-05 09:22:33 +01:00
|
|
|
if (generic_hid && generic_hid->get_buttons)
|
2017-11-28 10:04:34 +00:00
|
|
|
generic_hid->get_buttons((void*)hid_driver_get_data(), port, state);
|
2017-12-05 09:22:33 +01:00
|
|
|
else
|
2017-12-05 12:07:35 +01:00
|
|
|
BIT256_CLEAR_ALL_PTR(state);
|
2015-02-15 01:57:29 +01:00
|
|
|
}
|
|
|
|
|
2015-04-01 20:00:38 +02:00
|
|
|
static void hid_joypad_poll(void)
|
2013-03-03 18:50:38 -05:00
|
|
|
{
|
2016-11-30 05:12:28 +01:00
|
|
|
if (generic_hid && generic_hid->poll)
|
|
|
|
generic_hid->poll((void*)hid_driver_get_data());
|
2013-03-03 18:50:38 -05:00
|
|
|
}
|
|
|
|
|
2015-04-01 20:00:38 +02:00
|
|
|
static bool hid_joypad_rumble(unsigned pad,
|
2014-09-09 18:15:17 +02:00
|
|
|
enum retro_rumble_effect effect, uint16_t strength)
|
2013-10-03 18:04:28 -04:00
|
|
|
{
|
2016-11-30 05:12:28 +01:00
|
|
|
if (generic_hid && generic_hid->set_rumble)
|
|
|
|
return generic_hid->set_rumble((void*)hid_driver_get_data(), pad, effect, strength);
|
|
|
|
return false;
|
2013-10-03 18:04:28 -04:00
|
|
|
}
|
|
|
|
|
2015-04-01 20:00:38 +02:00
|
|
|
static const char *hid_joypad_name(unsigned pad)
|
2013-04-27 00:08:52 +02:00
|
|
|
{
|
2016-12-01 17:37:27 +01:00
|
|
|
if (generic_hid && generic_hid->name)
|
|
|
|
return generic_hid->name((void*)hid_driver_get_data(), pad);
|
|
|
|
return NULL;
|
2013-04-27 00:08:52 +02:00
|
|
|
}
|
|
|
|
|
2015-04-14 16:37:59 +02:00
|
|
|
input_device_driver_t hid_joypad = {
|
2015-04-01 20:00:38 +02:00
|
|
|
hid_joypad_init,
|
|
|
|
hid_joypad_query_pad,
|
2015-04-01 22:31:43 +02:00
|
|
|
hid_joypad_free,
|
2015-04-01 20:00:38 +02:00
|
|
|
hid_joypad_button,
|
2020-07-19 03:18:12 +02:00
|
|
|
hid_joypad_state,
|
2015-04-01 20:00:38 +02:00
|
|
|
hid_joypad_get_buttons,
|
|
|
|
hid_joypad_axis,
|
|
|
|
hid_joypad_poll,
|
|
|
|
hid_joypad_rumble,
|
2024-07-25 00:13:16 +02:00
|
|
|
NULL, /* set_rumble_gain */
|
|
|
|
NULL, /* set_sensor_state */
|
|
|
|
NULL, /* get_sensor_input */
|
2015-04-01 20:00:38 +02:00
|
|
|
hid_joypad_name,
|
|
|
|
"hid"
|
2013-03-03 18:50:38 -05:00
|
|
|
};
|