/* 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 . */ #include "../../include/wiiu/input.h" /* TODO/FIXME - static global variables */ static bool hidpad_ready = false; static bool init_hid_driver(void) { return hid_init(&hid_instance, &wiiu_hid, &hidpad_driver, MAX_USERS); } static void hidpad_poll(void) { if (hidpad_ready) HID_POLL(); } static bool hidpad_init(void *data) { (void)data; if(!init_hid_driver()) { RARCH_ERR("Failed to initialize HID driver.\n"); return false; } hidpad_poll(); hidpad_ready = true; return true; } static bool hidpad_query_pad(unsigned pad) { return hidpad_ready && pad < MAX_USERS; } static void hidpad_destroy(void) { hidpad_ready = false; hid_deinit(&hid_instance); } static int16_t hidpad_button(unsigned pad, uint16_t joykey) { int16_t ret = 0; uint16_t i = joykey; uint16_t end = joykey + 1; if (!hidpad_query_pad(pad)) return 0; for (; i < end; i++) { if (HID_BUTTON(pad, i)) ret |= (1 << i); } return ret; } static void hidpad_get_buttons(unsigned pad, input_bits_t *state) { if (!hidpad_query_pad(pad)) BIT256_CLEAR_ALL_PTR(state); HID_GET_BUTTONS(pad, state); } static int16_t hidpad_axis(unsigned pad, uint32_t axis) { if (!hidpad_query_pad(pad)) return 0; return HID_AXIS(pad, axis); } static const char *hidpad_name(unsigned pad) { if (!hidpad_query_pad(pad)) return "N/A"; return HID_PAD_NAME(pad); } 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" };