2017-12-27 23:15:01 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2014-2017 - Ali Bouhlel
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wiiu/pad_driver.h>
|
|
|
|
|
|
|
|
static bool hidpad_init(void *data);
|
|
|
|
static bool hidpad_query_pad(unsigned pad);
|
|
|
|
static void hidpad_destroy(void);
|
|
|
|
static bool hidpad_button(unsigned pad, uint16_t button);
|
2018-04-08 18:21:12 +00:00
|
|
|
static void hidpad_get_buttons(unsigned pad, input_bits_t *state);
|
2017-12-27 23:15:01 +00:00
|
|
|
static int16_t hidpad_axis(unsigned pad, uint32_t axis);
|
|
|
|
static void hidpad_poll(void);
|
|
|
|
static const char *hidpad_name(unsigned pad);
|
|
|
|
|
|
|
|
static bool ready = false;
|
|
|
|
|
2017-12-29 06:30:46 +00:00
|
|
|
static wiiu_hid_t *hid_data;
|
|
|
|
static hid_driver_t *hid_driver;
|
|
|
|
|
2018-01-05 12:09:05 +00:00
|
|
|
static unsigned to_slot(unsigned pad)
|
|
|
|
{
|
|
|
|
return pad - (WIIU_WIIMOTE_CHANNELS+1);
|
2017-12-29 06:30:46 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 12:09:05 +00:00
|
|
|
const void *get_hid_data(void)
|
|
|
|
{
|
|
|
|
return hid_data;
|
2017-12-29 06:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static hid_driver_t *init_hid_driver(void)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
joypad_connection_t *connections = NULL;
|
|
|
|
unsigned connections_size = MAX_USERS - (WIIU_WIIMOTE_CHANNELS+1);
|
|
|
|
|
|
|
|
hid_data = (wiiu_hid_t *)wiiu_hid.init();
|
|
|
|
connections = pad_connection_init(connections_size);
|
2017-12-29 06:30:46 +00:00
|
|
|
|
2018-01-05 12:09:05 +00:00
|
|
|
if (!hid_data || !connections)
|
|
|
|
goto error;
|
2017-12-29 06:30:46 +00:00
|
|
|
|
2018-01-05 12:09:05 +00:00
|
|
|
hid_data->connections = connections;
|
|
|
|
hid_data->connections_size = connections_size;
|
|
|
|
return &wiiu_hid;
|
2017-12-29 06:30:46 +00:00
|
|
|
|
2018-01-05 12:09:05 +00:00
|
|
|
error:
|
|
|
|
if (connections)
|
2017-12-29 06:30:46 +00:00
|
|
|
free(connections);
|
2018-01-05 12:09:05 +00:00
|
|
|
if (hid_data)
|
|
|
|
{
|
2017-12-29 06:30:46 +00:00
|
|
|
wiiu_hid.free(hid_data);
|
|
|
|
hid_data = NULL;
|
2018-01-05 12:09:05 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
2017-12-29 06:30:46 +00:00
|
|
|
}
|
2017-12-27 23:15:01 +00:00
|
|
|
|
|
|
|
static bool hidpad_init(void *data)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
(void *)data;
|
|
|
|
|
|
|
|
hid_driver = init_hid_driver();
|
|
|
|
if (!hid_driver)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to initialize HID driver.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hidpad_poll();
|
|
|
|
ready = true;
|
|
|
|
|
|
|
|
return true;
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool hidpad_query_pad(unsigned pad)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
return ready && (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS);
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hidpad_destroy(void)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
ready = false;
|
|
|
|
|
2018-01-28 06:54:59 +00:00
|
|
|
if(hid_driver) {
|
|
|
|
hid_driver->free(hid_data);
|
|
|
|
hid_data = NULL;
|
|
|
|
hid_driver = NULL;
|
|
|
|
}
|
2018-01-05 12:09:05 +00:00
|
|
|
|
2018-01-28 06:54:59 +00:00
|
|
|
if(hid_data) {
|
|
|
|
free(hid_data);
|
|
|
|
hid_data = NULL;
|
|
|
|
}
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool hidpad_button(unsigned pad, uint16_t button)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
if (!hidpad_query_pad(pad))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
return hid_driver->button(hid_data, to_slot(pad), button);
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-08 18:21:12 +00:00
|
|
|
static void hidpad_get_buttons(unsigned pad, input_bits_t *state)
|
2017-12-27 23:15:01 +00:00
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
if (!hidpad_query_pad(pad))
|
2017-12-29 06:30:46 +00:00
|
|
|
BIT256_CLEAR_ALL_PTR(state);
|
|
|
|
|
2018-01-05 12:09:05 +00:00
|
|
|
#if 0
|
|
|
|
hid_driver->get_buttons(hid_data, to_slot(pad), state);
|
|
|
|
#endif
|
2017-12-29 07:08:08 +00:00
|
|
|
BIT256_CLEAR_ALL_PTR(state);
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int16_t hidpad_axis(unsigned pad, uint32_t axis)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
if (!hidpad_query_pad(pad));
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
return hid_driver->axis(hid_data, to_slot(pad), axis);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hidpad_poll(void)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
#if 0
|
|
|
|
if (ready)
|
|
|
|
hid_driver->poll(hid_data);
|
|
|
|
#endif
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *hidpad_name(unsigned pad)
|
|
|
|
{
|
2018-01-05 12:09:05 +00:00
|
|
|
if (!hidpad_query_pad(pad))
|
|
|
|
return "N/A";
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
return PAD_NAME_HID;
|
|
|
|
#else
|
|
|
|
return hid_driver->name(hid_data, to_slot(pad));
|
|
|
|
#endif
|
2017-12-27 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input_device_driver_t hidpad_driver =
|
|
|
|
{
|
|
|
|
hidpad_init,
|
|
|
|
hidpad_query_pad,
|
|
|
|
hidpad_destroy,
|
|
|
|
hidpad_button,
|
|
|
|
hidpad_get_buttons,
|
|
|
|
hidpad_axis,
|
|
|
|
hidpad_poll,
|
|
|
|
NULL,
|
|
|
|
hidpad_name,
|
|
|
|
"hid"
|
|
|
|
};
|