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
|
|
|
|
2016-11-30 05:12:28 +01:00
|
|
|
static const hid_driver_t *generic_hid = NULL;
|
2015-04-01 20:49:26 +02:00
|
|
|
|
2015-06-03 18:22:54 +02:00
|
|
|
static bool 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)
|
2015-02-15 04:07:22 +01:00
|
|
|
return false;
|
2014-10-04 16:46:52 +02:00
|
|
|
|
2015-06-03 18:22:54 +02:00
|
|
|
(void)data;
|
|
|
|
|
2014-10-04 16:46:52 +02:00
|
|
|
return true;
|
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
|
|
|
}
|
|
|
|
|
2015-04-01 20:00:38 +02:00
|
|
|
static bool 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);
|
|
|
|
return false;
|
2013-03-03 18:50:38 -05:00
|
|
|
}
|
|
|
|
|
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 int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis)
|
2013-03-03 18:50:38 -05:00
|
|
|
{
|
2016-11-30 05:12:28 +01:00
|
|
|
if (generic_hid && generic_hid->axis)
|
|
|
|
return generic_hid->axis((void*)hid_driver_get_data(), port, joyaxis);
|
|
|
|
return 0;
|
2013-03-03 18:50:38 -05: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,
|
|
|
|
hid_joypad_get_buttons,
|
|
|
|
hid_joypad_axis,
|
|
|
|
hid_joypad_poll,
|
|
|
|
hid_joypad_rumble,
|
|
|
|
hid_joypad_name,
|
|
|
|
"hid"
|
2013-03-03 18:50:38 -05:00
|
|
|
};
|