Commit 922e3fe2 authored by Sam Lantinga's avatar Sam Lantinga

Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40382
parent 26d1c3e5
...@@ -1445,6 +1445,86 @@ CheckDLOPEN() ...@@ -1445,6 +1445,86 @@ CheckDLOPEN()
fi fi
} }
dnl Check for the usbhid(3) library on *BSD
CheckUSBHID()
{
if test x$enable_joystick = xyes; then
have_libusbhid=no
have_libusb=no
AC_CHECK_LIB(usbhid, hid_init, have_libusbhid=yes)
AC_CHECK_LIB(usb, hid_init, have_libusb=yes)
if test x$have_libusbhid = xyes; then
SYSTEM_LIBS="$SYSTEM_LIBS -lusbhid"
fi
if test x$have_libusb = xyes; then
SYSTEM_LIBS="$SYSTEM_LIBS -lusb"
fi
AC_CHECK_HEADER(usbhid.h, have_usbhid_h=yes)
AC_CHECK_HEADER(libusb.h, have_libusb_h=yes)
AC_CHECK_HEADER(libusbhid.h, have_libusbhid_h=yes)
if test x$have_usbhid_h = xyes; then
CFLAGS="$CFLAGS -DHAVE_USBHID_H"
fi
if test x$have_libusb_h = xyes; then
CFLAGS="$CFLAGS -DHAVE_LIBUSB_H"
fi
if test x$have_libusbhid_h = xyes; then
CFLAGS="$CFLAGS -DHAVE_LIBUSBHID_H"
fi
AC_MSG_CHECKING(for usbhid)
have_usbhid=no
AC_TRY_COMPILE([
#include <dev/usb/usb.h>
#include <dev/usb/usbhid.h>
#if defined(HAVE_USBHID_H)
#include <usbhid.h>
#elif defined(HAVE_LIBUSB_H)
#include <libusb.h>
#elif defined(HAVE_LIBUSBHID_H)
#include <libusbhid.h>
#endif
],[
struct report_desc *repdesc;
struct usb_ctl_report *repbuf;
enum hid_kind hidkind;
],[
have_usbhid=yes
])
AC_MSG_RESULT($have_usbhid)
if test x$have_usbhid = xyes; then
AC_MSG_CHECKING(for ucr_data member of usb_ctl_report)
have_usbhid_ucr_data=no
AC_TRY_COMPILE([
#include <dev/usb/usb.h>
#include <dev/usb/usbhid.h>
#include <stdio.h>
#if defined(HAVE_USBHID_H)
#include <usbhid.h>
#elif defined(HAVE_LIBUSB_H)
#include <libusb.h>
#elif defined(HAVE_LIBUSBHID_H)
#include <libusbhid.h>
#endif
],[
struct usb_ctl_report buf;
if (buf.ucr_data) { }
],[
have_usbhid_ucr_data=yes
])
if test x$have_usbhid_ucr_data = xyes; then
CFLAGS="$CFLAGS -DUSBHID_UCR_DATA"
fi
AC_MSG_RESULT($have_usbhid_ucr_data)
JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS bsd"
JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS bsd/libjoystick_bsd.la"
fi
fi
}
case "$target" in case "$target" in
*-*-linux*) *-*-linux*)
ARCH=linux ARCH=linux
...@@ -1598,6 +1678,7 @@ case "$target" in ...@@ -1598,6 +1678,7 @@ case "$target" in
CheckAAlib CheckAAlib
CheckOpenGL CheckOpenGL
CheckPTHREAD CheckPTHREAD
CheckUSBHID
# Set up files for the main() stub # Set up files for the main() stub
COPY_ARCH_SRC(src/main, linux, SDL_main.c) COPY_ARCH_SRC(src/main, linux, SDL_main.c)
# Set up files for the audio library # Set up files for the audio library
...@@ -1607,12 +1688,6 @@ case "$target" in ...@@ -1607,12 +1688,6 @@ case "$target" in
# AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun" # AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun"
# AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la" # AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la"
#fi #fi
# Set up files for the joystick library
if test x$enable_joystick = xyes; then
JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS bsd"
JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS bsd/libjoystick_bsd.la"
SYSTEM_LIBS="$SYSTEM_LIBS -lusb"
fi
# Set up files for the cdrom library # Set up files for the cdrom library
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
CDROM_SUBDIRS="$CDROM_SUBDIRS freebsd" CDROM_SUBDIRS="$CDROM_SUBDIRS freebsd"
...@@ -1652,6 +1727,7 @@ case "$target" in ...@@ -1652,6 +1727,7 @@ case "$target" in
CheckAAlib CheckAAlib
CheckOpenGL CheckOpenGL
CheckPTHREAD CheckPTHREAD
CheckUSBHID
# Set up files for the main() stub # Set up files for the main() stub
COPY_ARCH_SRC(src/main, linux, SDL_main.c) COPY_ARCH_SRC(src/main, linux, SDL_main.c)
# Set up files for the audio library # Set up files for the audio library
...@@ -1660,12 +1736,6 @@ case "$target" in ...@@ -1660,12 +1736,6 @@ case "$target" in
AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun" AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun"
AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la" AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la"
fi fi
# Set up files for the joystick library
if test x$enable_joystick = xyes; then
JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS bsd"
JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS bsd/libjoystick_bsd.la"
SYSTEM_LIBS="$SYSTEM_LIBS -lusb"
fi
# Set up files for the cdrom library # Set up files for the cdrom library
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
CDROM_SUBDIRS="$CDROM_SUBDIRS openbsd" CDROM_SUBDIRS="$CDROM_SUBDIRS openbsd"
...@@ -1707,6 +1777,7 @@ case "$target" in ...@@ -1707,6 +1777,7 @@ case "$target" in
CheckAAlib CheckAAlib
CheckOpenGL CheckOpenGL
CheckPTHREAD CheckPTHREAD
CheckUSBHID
# Set up files for the main() stub # Set up files for the main() stub
COPY_ARCH_SRC(src/main, linux, SDL_main.c) COPY_ARCH_SRC(src/main, linux, SDL_main.c)
# Set up files for the audio library # Set up files for the audio library
...@@ -1719,12 +1790,6 @@ case "$target" in ...@@ -1719,12 +1790,6 @@ case "$target" in
if test x$have_oss = xyes; then if test x$have_oss = xyes; then
SYSTEM_LIBS="$SYSTEM_LIBS -lossaudio" SYSTEM_LIBS="$SYSTEM_LIBS -lossaudio"
fi fi
# Set up files for the joystick library
if test x$enable_joystick = xyes; then
JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS bsd"
JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS bsd/libjoystick_bsd.la"
SYSTEM_LIBS="$SYSTEM_LIBS -lusbhid"
fi
# Set up files for the cdrom library # Set up files for the cdrom library
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
CDROM_SUBDIRS="$CDROM_SUBDIRS openbsd" CDROM_SUBDIRS="$CDROM_SUBDIRS openbsd"
......
...@@ -42,10 +42,12 @@ static char rcsid = ...@@ -42,10 +42,12 @@ static char rcsid =
#include <dev/usb/usb.h> #include <dev/usb/usb.h>
#include <dev/usb/usbhid.h> #include <dev/usb/usbhid.h>
#if defined(__FreeBSD__) #if defined(HAVE_USBHID_H)
# include <libusb.h> #include <usbhid.h>
#else #elif defined(HAVE_LIBUSB_H)
# include <usbhid.h> #include <libusb.h>
#elif defined(HAVE_LIBUSBHID_H)
#include <libusbhid.h>
#endif #endif
#include "SDL_error.h" #include "SDL_error.h"
...@@ -113,6 +115,12 @@ static char *joydevnames[MAX_JOYS]; ...@@ -113,6 +115,12 @@ static char *joydevnames[MAX_JOYS];
static int report_alloc(struct report *, struct report_desc *, int); static int report_alloc(struct report *, struct report_desc *, int);
static void report_free(struct report *); static void report_free(struct report *);
#ifdef USBHID_UCR_DATA
#define REP_BUF_DATA(rep) ((rep)->buf->ucr_data)
#else
#define REP_BUF_DATA(rep) ((rep)->buf->data)
#endif
int int
SDL_SYS_JoystickInit(void) SDL_SYS_JoystickInit(void)
{ {
...@@ -274,14 +282,15 @@ usberr: ...@@ -274,14 +282,15 @@ usberr:
void void
SDL_SYS_JoystickUpdate(SDL_Joystick *joy) SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
{ {
static struct hid_item hitem; struct hid_item hitem;
static struct hid_data *hdata; struct hid_data *hdata;
static struct report *rep; struct report *rep;
int nbutton, naxe = -1; int nbutton, naxe = -1;
Sint32 v; Sint32 v;
rep = &joy->hwdata->inreport; rep = &joy->hwdata->inreport;
if (read(joy->hwdata->fd, rep->buf->data, rep->size) != rep->size) {
if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) {
return; return;
} }
hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input); hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
...@@ -316,7 +325,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joy) ...@@ -316,7 +325,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
goto scaleaxe; goto scaleaxe;
} }
scaleaxe: scaleaxe:
v = (Sint32)hid_get_data(rep->buf->data, &hitem); v = (Sint32)hid_get_data(REP_BUF_DATA(rep),
&hitem);
if (v != 127) { if (v != 127) {
if (v < 127) { if (v < 127) {
v = -(256 - v); v = -(256 - v);
...@@ -335,7 +345,7 @@ scaleaxe: ...@@ -335,7 +345,7 @@ scaleaxe:
} }
break; break;
case HUP_BUTTON: case HUP_BUTTON:
v = (Sint32)hid_get_data(rep->buf->data, v = (Sint32)hid_get_data(REP_BUF_DATA(rep),
&hitem); &hitem);
if (joy->buttons[nbutton] != v) { if (joy->buttons[nbutton] != v) {
SDL_PrivateJoystickButton(joy, SDL_PrivateJoystickButton(joy,
...@@ -395,7 +405,7 @@ report_alloc(struct report *r, struct report_desc *rd, int repind) ...@@ -395,7 +405,7 @@ report_alloc(struct report *r, struct report_desc *rd, int repind)
r->size = len; r->size = len;
if (r->size > 0) { if (r->size > 0) {
r->buf = malloc(sizeof(*r->buf) - sizeof(r->buf->data) + r->buf = malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
r->size); r->size);
if (r->buf == NULL) { if (r->buf == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment