diff options
67 files changed, 1766 insertions, 935 deletions
diff --git a/.github/workflows/clazy.yml b/.github/workflows/clazy.yml index 700db4173f..c4aae2f6f7 100644 --- a/.github/workflows/clazy.yml +++ b/.github/workflows/clazy.yml @@ -22,4 +22,4 @@ jobs: LD: clang++ CC: clang CXX: clazy - CLAZY_CHECKS: range-loop,unused-non-trivial-variable + CLAZY_CHECKS: range-loop,qstring-arg,unused-non-trivial-variable diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c7aa95671..012a68937a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2327,6 +2327,10 @@ if(HID) target_sources(mixxx-hidapi PRIVATE lib/hidapi/windows/hid.c) elseif(APPLE) target_sources(mixxx-hidapi PRIVATE lib/hidapi/mac/hid.c) + find_library(APPKIT_LIBRARY AppKit REQUIRED) + target_link_libraries(mixxx-lib PUBLIC + ${APPKIT_LIBRARY} + ) elseif(UNIX) if(NOT LibUSB_FOUND) message(FATAL_ERROR "USB HID controller support on Unix with statically linked libhidapi-libusb requires libusb 1.0 and its development headers.") diff --git a/build/features.py b/build/features.py index 31d38dd187..2dea3ff003 100644 --- a/build/features.py +++ b/build/features.py @@ -91,7 +91,7 @@ class HID(Feature): if build.platform_is_windows and not conf.CheckLib(['setupapi', 'libsetupapi']): raise Exception('Did not find the setupapi library, exiting.') elif build.platform_is_osx: - build.env.AppendUnique(FRAMEWORKS=['IOKit', 'CoreFoundation']) + build.env.AppendUnique(FRAMEWORKS=['IOKit', 'CoreFoundation', 'AppKit']) build.env.Append(CPPDEFINES='__HID__') if self.INTERNAL_LINK: diff --git a/lib/hidapi/.gitignore b/lib/hidapi/.gitignore index b43ca58c25..9963751f30 100644 --- a/lib/hidapi/.gitignore +++ b/lib/hidapi/.gitignore @@ -2,9 +2,11 @@ # Autotools-added generated files Makefile.in aclocal.m4 +ar-lib autom4te.cache/ config.* configure +compile depcomp install-sh libusb/Makefile.in @@ -18,3 +20,5 @@ windows/Makefile.in Makefile stamp-h1 libtool + +.DS_Store diff --git a/lib/hidapi/AUTHORS.txt b/lib/hidapi/AUTHORS.txt index 7acafd78c3..e08cb16196 100644 --- a/lib/hidapi/AUTHORS.txt +++ b/lib/hidapi/AUTHORS.txt @@ -10,7 +10,9 @@ Ludovic Rousseau <rousseau@debian.org>: Bug fixes Correctness fixes +libusb/hidapi Team: + Development/maintainance since June 4th 2019 For a comprehensive list of contributions, see the commit list at github: - http://github.com/signal11/hidapi/commits/master + https://github.com/libusb/hidapi/commits/master diff --git a/lib/hidapi/HACKING.txt b/lib/hidapi/HACKING.txt index 761d4b6550..be8c0d7612 100644 --- a/lib/hidapi/HACKING.txt +++ b/lib/hidapi/HACKING.txt @@ -1,15 +1,10 @@ This file is mostly for the maintainer. -1. Build hidapi.dll -2. Build hidtest.exe in DEBUG and RELEASE -3. Commit all - -4. Run the Following - export VERSION=0.1.0 - export TAG_NAME=hidapi-$VERSION - git tag $TAG_NAME - git archive --format zip --prefix $TAG_NAME/ $TAG_NAME >../$TAG_NAME.zip -5. Test the zip file. -6. Run the following: - git push origin $TAG_NAME +Updating a Version: +1. Update VERSION file. +2. HID_API_VERSION_MAJOR/HID_API_VERSION_MINOR/HID_API_VERSION_PATCH in hidapi.h. +Firing a new release: +1. Update the Version (if not yet updated). +2. Build hidapi.dll/.lib for x86/x64. +3. Upload Windows binaries to Github release page. diff --git a/lib/hidapi/Makefile.am b/lib/hidapi/Makefile.am index a6e47e8ab3..00bcb73cf4 100644 --- a/lib/hidapi/Makefile.am +++ b/lib/hidapi/Makefile.am @@ -31,6 +31,10 @@ if OS_KFREEBSD SUBDIRS += libusb endif +if OS_HAIKU +SUBDIRS += libusb +endif + if OS_WINDOWS SUBDIRS += windows endif diff --git a/lib/hidapi/README.md b/lib/hidapi/README.md index 5243a0ba59..f5582d7a9a 100644 --- a/lib/hidapi/README.md +++ b/lib/hidapi/README.md @@ -1,5 +1,11 @@ ## HIDAPI library for Windows, Linux, FreeBSD and macOS +| CI instance | Status | +|----------------------|--------| +| `macOS master` | [![Build Status](https://travis-ci.org/libusb/hidapi.svg?branch=master)](https://travis-ci.org/libusb/hidapi) | +| `Windows master` | [![Build status](https://ci.appveyor.com/api/projects/status/r482aevuigmi86rk/branch/master?svg=true)](https://ci.appveyor.com/project/Youw/hidapi/branch/master) | +| `Linux/BSD, last build (branch/PR)` | [![builds.sr.ht status](https://builds.sr.ht/~qbicz/hidapi.svg)](https://builds.sr.ht/~qbicz/hidapi?) | + HIDAPI is a multi-platform library which allows an application to interface with USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and macOS. HIDAPI can be either built as a shared library (`.so`, `.dll` or `.dylib`) or @@ -43,13 +49,13 @@ tradeoffs, and the functionality supported is slightly different. __Linux/hidraw__ (`linux/hid.c`): -This back-end uses the hidraw interface in the Linux kernel. While this -back-end will support both USB and Bluetooth, it has some limitations on -kernels prior to 2.6.39, including the inability to send or receive feature -reports. In addition, it will only communicate with devices which have -hidraw nodes associated with them. Keyboards, mice, and some other devices -which are blacklisted from having hidraw nodes will not work. Fortunately, -for nearly all the uses of hidraw, this is not a problem. +This back-end uses the hidraw interface in the Linux kernel, and supports +both USB and Bluetooth HID devices. It requires kernel version at least 2.6.39 +to build. In addition, it will only communicate with devices which have hidraw +nodes associated with them. +Keyboards, mice, and some other devices which are blacklisted from having +hidraw nodes will not work. Fortunately, for nearly all the uses of hidraw, +this is not a problem. __Linux/FreeBSD/libusb__ (`libusb/hid.c`): @@ -62,12 +68,15 @@ which HIDAPI supports. Since it relies on a 3rd party library, building it is optional but recommended because it is so useful when debugging hardware. ## What Does the API Look Like? -The API provides the the most commonly used HID functions including sending -and receiving of input, output, and feature reports. The sample program, +The API provides the most commonly used HID functions including sending +and receiving of input, output, and feature reports. The sample program, which communicates with a heavily hacked up version of the Microchip USB Generic HID sample looks like this (with error checking removed for simplicity): +**Warning: Only run the code you understand, and only when it conforms to the +device spec. Writing data at random to your HID devices can break them.** + ```c #ifdef WIN32 #include <windows.h> @@ -126,6 +135,9 @@ int main(int argc, char* argv[]) for (i = 0; i < 4; i++) printf("buf[%d]: %d\n", i, buf[i]); + // Close the device + hid_close(handle); + // Finalize the hidapi library res = hid_exit(); @@ -133,6 +145,10 @@ int main(int argc, char* argv[]) } ``` +You can also use [hidtest/test.c](hidtest/test.c) +as a starting point for your applications. + + ## License HIDAPI may be used by one of three licenses as outlined in [LICENSE.txt](LICENSE.txt). diff --git a/lib/hidapi/VERSION b/lib/hidapi/VERSION new file mode 100644 index 0000000000..2774f8587f --- /dev/null +++ b/lib/hidapi/VERSION @@ -0,0 +1 @@ +0.10.0
\ No newline at end of file diff --git a/lib/hidapi/configure.ac b/lib/hidapi/configure.ac index b9f670eb88..220909a052 100644 --- a/lib/hidapi/configure.ac +++ b/lib/hidapi/configure.ac @@ -1,13 +1,6 @@ AC_PREREQ(2.63) -# Version number. This is currently the only place. -m4_define([HIDAPI_MAJOR], 0) -m4_define([HIDAPI_MINOR], 9) -m4_define([HIDAPI_RELEASE], 0) -m4_define([HIDAPI_RC], ) -m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC) - -AC_INIT([hidapi],[VERSION_STRING],[alan@signal11.us]) +AC_INIT([hidapi],[m4_normalize(m4_builtin([include], VERSION))],[https://github.com/libusb/hidapi/issues]) # Library soname version # Follow the following rules (particularly the ones in the second link): @@ -79,7 +72,7 @@ case $host in backend="mac" os="darwin" threads="pthreads" - LIBS="${LIBS} -framework IOKit -framework CoreFoundation" + LIBS="${LIBS} -framework IOKit -framework CoreFoundation -framework AppKit" ;; *-freebsd*) AC_MSG_RESULT([ (FreeBSD back-end)]) @@ -92,9 +85,10 @@ case $host in CFLAGS="$CFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" LIBS="${LIBS}" - AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb]) + PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0]) + LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS" + CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS" AC_CHECK_LIB([iconv], [iconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv]) - echo libs_priv: $LIBS_LIBUSB_PRIVATE ;; *-kfreebsd*) AC_MSG_RESULT([ (kFreeBSD back-end)]) @@ -104,8 +98,22 @@ case $host in os="kfreebsd" threads="pthreads" - AC_CHECK_LIB([usb], [libusb_init], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lusb"], [hidapi_lib_error libusb]) - echo libs_priv: $LIBS_LIBUSB_PRIVATE + PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0]) + LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS" + CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS" + ;; +*-*-haiku) + AC_MSG_RESULT([ (Haiku back-end)]) + AC_DEFINE(OS_HAIKU, 1, [Haiku implementation]) + AC_SUBST(OS_HAIKU) + backend="libusb" + os="haiku" + threads="pthreads" + + PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0]) + LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS" + CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS" + AC_CHECK_LIB([iconv], [libiconv_open], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -liconv"], [hidapi_lib_error libiconv]) ;; *-mingw*) AC_MSG_RESULT([ (Windows back-end, using MinGW)]) @@ -213,6 +221,7 @@ AM_CONDITIONAL(OS_LINUX, test "x$os" = xlinux) AM_CONDITIONAL(OS_DARWIN, test "x$os" = xdarwin) AM_CONDITIONAL(OS_FREEBSD, test "x$os" = xfreebsd) AM_CONDITIONAL(OS_KFREEBSD, test "x$os" = xkfreebsd) +AM_CONDITIONAL(OS_HAIKU, test "x$os" = xhaiku) AM_CONDITIONAL(OS_WINDOWS, test "x$os" = xwindows) AC_CONFIG_HEADERS([config.h]) diff --git a/lib/hidapi/hidapi/hidapi.h b/lib/hidapi/hidapi/hidapi.h index 1819f8de09..c8f7bc50af 100644 --- a/lib/hidapi/hidapi/hidapi.h +++ b/lib/hidapi/hidapi/hidapi.h @@ -17,7 +17,7 @@ files located at the root of the source distribution. These files may also be found in the public source code repository located at: - http://github.com/signal11/hidapi . + https://github.com/libusb/hidapi . ********************************************************/ /** @file @@ -39,9 +39,42 @@ #define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/ +/** @brief Static/compile-time major version of the library. + + @ingroup API +*/ +#define HID_API_VERSION_MAJOR 0 +/** @brief Static/compile-time minor version of the library. + + @ingroup API +*/ +#define HID_API_VERSION_MINOR 10 +/** @brief Static/compile-time patch version of the library. + + @ingroup API +*/ +#define HID_API_VERSION_PATCH 0 + +/* Helper macros */ +#define HID_API_AS_STR_IMPL(x) #x +#define HID_API_AS_STR(x) HID_API_AS_STR_IMPL(x) +#define HID_API_TO_VERSION_STR(v1, v2, v3) HID_API_AS_STR(v1.v2.v3) + +/** @brief Static/compile-time string version of the library. + + @ingroup API +*/ +#define HID_API_VERSION_STR HID_API_TO_VERSION_STR(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH) + #ifdef __cplusplus extern "C" { #endif + struct hid_api_version { + int major; + int minor; + int patch; + }; + struct hid_device_; typedef struct hid_device_ hid_device; /**< opaque hidapi structure */ @@ -151,6 +184,8 @@ extern "C" { If @p serial_number is NULL, the first device with the specified VID and PID is opened. + This function sets the return value of hid_error(). + @ingroup API @param vendor_id The Vendor ID (VID) of the device to open. @param product_id The Product ID (PID) of the device to open. @@ -169,6 +204,8 @@ extern "C" { platform-specific path name can be used (eg: /dev/hidraw0 on Linux). + This function sets the return value of hid_error(). + @ingroup API @param path The path name of the device to open @@ -194,6 +231,8 @@ extern "C" { one exists. If it does not, it will send the data through the Control Endpoint (Endpoint 0). + This function sets the return value of hid_error(). + @ingroup API @param dev A device handle returned from hid_open(). @param data The data to send, including the report number as @@ -212,6 +251,8 @@ extern "C" { to the host through the INTERRUPT IN endpoint. The first byte will contain the Report number if the device uses numbered reports. + This function sets the return value of hid_error(). + @ingroup API @param dev A device handle returned from hid_open(). @param data A buffer to put the read data into. @@ -233,6 +274,8 @@ extern "C" { to the host through the INTERRUPT IN endpoint. The first byte will contain the Report number if the device uses numbered reports. + This function sets the return value of hid_error(). + @ingroup API @param dev A device handle returned from hid_open(). @param data A buffer to put the read data into. @@ -282,6 +325,8 @@ extern "C" { report data (16 bytes). In this example, the length passed in would be 17. + This function sets the return value of hid_error(). + @ingroup API @param dev A device handle returned from hid_open(). @param data The data to send, including the report number as @@ -303,6 +348,8 @@ extern "C" { still contain the Report ID, and the report data will start in data[1]. + This function sets the return value of hid_error(). + @ingroup API @param dev A device handle returned from hid_open(). @param data A buffer to put the read data into, including @@ -320,8 +367,35 @@ extern "C" { */ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length); + /** @brief Get a input report from a HID device. + + Set the first byte of @p data[] to the Report ID of the + report to be read. Make sure to allow space for this + extra byte in @p data[]. Upon return, the first byte will + still contain the Report ID, and the report data will + start in data[1]. + + @ingroup API + @param device A device handle returned from hid_open(). + @param data A buffer to put the read data into, including + the Report ID. Set the first byte of @p data[] to the + Report ID of the report to be read, or set it to zero + if your device does not use numbered reports. + @param length The number of bytes to read, including an + extra byte for the report ID. The buffer can be longer + than the actual report. + + @returns + This function returns the number of bytes read plus + one for the report ID (which is still in the first + byte), or -1 on error. + */ + int HID_API_EXPORT HID_API_CALL hid_get_input_report(hid_device *dev, unsigned char *data, size_t length); + /** @brief Close a HID device. + This function sets the return value of hid_error(). + @ingroup API @param dev A device handle returned from hid_open(). */ @@ -378,8 +452,18 @@ extern "C" { /** @brief Get a string describing the last error which occurred. + Whether a function sets the last error is noted in its + documentation. These functions will reset the last error + to NULL before their execution. + + Strings returned from hid_error() must not be freed by the user! + + This function is thread-safe, and error messages are thread-local. + @ingroup API - @param dev A device handle returned from hid_open(). + @param dev A device handle returned from hid_open(), + or NULL to get the last non-device-specific error + (e.g. for errors in hid_open() itself). @returns This function returns a string containing the last error @@ -387,6 +471,25 @@ extern "C" { */ HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev); + /** @brief Get a runtime version of the library. + + @ingroup API + + @returns + Pointer to statically allocated struct, that contains version. + */ + HID_API_EXPORT const struct hid_api_version* HID_API_CALL hid_version(); + + + /** @brief Get a runtime version string of the library. + + @ingroup API + + @returns + Pointer to statically allocated string, that contains version string. + */ + HID_API_EXPORT const char* HID_API_CALL hid_version_str(); + #ifdef __cplusplus } #endif diff --git a/lib/hidapi/hidtest/Makefile.am b/lib/hidapi/hidtest/Makefile.am index d2786445a3..4fb01e1215 100644 --- a/lib/hidapi/hidtest/Makefile.am +++ b/lib/hidapi/hidtest/Makefile.am @@ -4,17 +4,17 @@ AM_CPPFLAGS = -I$(top_srcdir)/hidapi/ if OS_LINUX noinst_PROGRAMS = hidtest-libusb hidtest-hidr |