(HID) Start refactoring the Apple HID joypad driver to be a more

general-purpose HID joypad driver
This commit is contained in:
twinaphex 2015-04-01 20:00:38 +02:00
parent 687d11318f
commit f1533f8ebf
7 changed files with 53 additions and 36 deletions

View File

@ -100,7 +100,7 @@ enum
JOYPAD_LINUXRAW,
JOYPAD_ANDROID,
JOYPAD_SDL,
JOYPAD_APPLE_HID,
JOYPAD_HID,
JOYPAD_APPLE_IOS,
JOYPAD_QNX,
JOYPAD_NULL,
@ -262,8 +262,8 @@ enum
#define JOYPAD_DEFAULT_DRIVER JOYPAD_SDL
#elif defined(__MACH__) && defined(IOS)
#define JOYPAD_DEFAULT_DRIVER JOYPAD_APPLE_IOS
#elif defined(__MACH__) && defined(HAVE_HID)
#define JOYPAD_DEFAULT_DRIVER JOYPAD_APPLE_HID
#elif defined(HAVE_HID)
#define JOYPAD_DEFAULT_DRIVER JOYPAD_HID
#elif defined(__QNX__)
#define JOYPAD_DEFAULT_DRIVER JOYPAD_QNX
#else

View File

@ -280,8 +280,8 @@ const char *config_get_default_joypad(void)
#else
return "sdl";
#endif
case JOYPAD_APPLE_HID:
return "apple_hid";
case JOYPAD_HID:
return "hid";
case JOYPAD_APPLE_IOS:
return "apple_ios";
case JOYPAD_QNX:

View File

@ -343,7 +343,10 @@ INPUT
#ifdef HAVE_HID
#include "../input/drivers_hid/apple_hid.c"
#include "../input/drivers_joypad/apple_joypad_hid.c"
#endif
#ifdef HAVE_HID
#include "../input/drivers_joypad/hid_joypad.c"
#endif
#ifdef IOS

View File

@ -35,6 +35,20 @@ struct pad_connection
uint8_t data[2048];
};
static bool apple_hid_joypad_query_pad(unsigned pad)
{
return pad < MAX_USERS;
}
static const char *apple_hid_joypad_name(unsigned pad)
{
/* TODO/FIXME - implement properly */
if (pad >= MAX_USERS)
return NULL;
return NULL;
}
static bool apple_hid_joypad_button(unsigned port, uint16_t joykey)
{
driver_t *driver = driver_get_ptr();
@ -432,3 +446,7 @@ static void apple_hid_free(void)
free(hid_apple);
hid_apple = NULL;
}
static void apple_hid_poll(void)
{
}

View File

@ -14,11 +14,10 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../input_autodetect.h"
#include "../input_common.h"
static bool apple_joypad_init(void)
static bool hid_joypad_init(void)
{
if (!apple_hid_init())
return false;
@ -26,59 +25,56 @@ static bool apple_joypad_init(void)
return true;
}
static bool apple_joypad_query_pad(unsigned pad)
static bool hid_joypad_query_pad(unsigned pad)
{
return pad < MAX_USERS;
return apple_hid_joypad_query_pad(pad);
}
static void apple_joypad_destroy(void)
static void hid_joypad_destroy(void)
{
apple_hid_free();
}
static bool apple_joypad_button(unsigned port, uint16_t joykey)
static bool hid_joypad_button(unsigned port, uint16_t joykey)
{
return apple_hid_joypad_button(port, joykey);
}
static uint64_t apple_joypad_get_buttons(unsigned port)
static uint64_t hid_joypad_get_buttons(unsigned port)
{
return apple_hid_joypad_get_buttons(port);
}
static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis)
static int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis)
{
return apple_hid_joypad_axis(port, joyaxis);
}
static void apple_joypad_poll(void)
static void hid_joypad_poll(void)
{
apple_hid_poll();
}
static bool apple_joypad_rumble(unsigned pad,
static bool hid_joypad_rumble(unsigned pad,
enum retro_rumble_effect effect, uint16_t strength)
{
return apple_hid_joypad_rumble(pad, effect, strength);
}
static const char *apple_joypad_name(unsigned pad)
static const char *hid_joypad_name(unsigned pad)
{
/* TODO/FIXME - implement properly */
if (pad >= MAX_USERS)
return NULL;
return NULL;
return apple_hid_joypad_name(pad);
}
rarch_joypad_driver_t apple_hid_joypad = {
apple_joypad_init,
apple_joypad_query_pad,
apple_joypad_destroy,
apple_joypad_button,
apple_joypad_get_buttons,
apple_joypad_axis,
apple_joypad_poll,
apple_joypad_rumble,
apple_joypad_name,
"apple_hid"
rarch_joypad_driver_t hid_joypad = {
hid_joypad_init,
hid_joypad_query_pad,
hid_joypad_destroy,
hid_joypad_button,
hid_joypad_get_buttons,
hid_joypad_axis,
hid_joypad_poll,
hid_joypad_rumble,
hid_joypad_name,
"hid"
};

View File

@ -56,10 +56,10 @@ static rarch_joypad_driver_t *joypad_drivers[] = {
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
&sdl_joypad,
#endif
#ifdef __MACH__
#ifdef HAVE_HID
&apple_hid_joypad,
&hid_joypad,
#endif
#ifdef __MACH__
#ifdef IOS
&apple_ios_joypad,
#endif

View File

@ -54,7 +54,7 @@ extern rarch_joypad_driver_t ps3_joypad;
extern rarch_joypad_driver_t psp_joypad;
extern rarch_joypad_driver_t xdk_joypad;
extern rarch_joypad_driver_t gx_joypad;
extern rarch_joypad_driver_t apple_hid_joypad;
extern rarch_joypad_driver_t hid_joypad;
extern rarch_joypad_driver_t apple_ios_joypad;
extern rarch_joypad_driver_t android_joypad;
extern rarch_joypad_driver_t qnx_joypad;