Skip to content

Commit

Permalink
add libusb-specific hid_libusb_wrap_sys_device
Browse files Browse the repository at this point in the history
Rationale: on Android one must use UsbManager, to access any
USB device. As a result, libraries like libusb can only use file descriptors
that are provided by UsbManager.
libusb has an API to use such file descriptors: hid_libusb_wrap_sys_device.
Having hid_libusb_wrap_sys_device currently is the only way to make hidapi
work on Android without root access and without custom Android builds.

Relevant info: https://github.com/libusb/libusb/pull/830/files
  • Loading branch information
Youw committed Sep 18, 2021
1 parent 301139e commit aaf5f3d
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 197 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ jobs:
- name: Check artifacts
uses: andstor/file-existence-action@v1
with:
files: "install/shared/lib/libhidapi.dylib, install/shared/include/hidapi/hidapi.h, install/framework/lib/hidapi.framework/hidapi, install/framework/lib/hidapi.framework/Headers/hidapi.h"
files: "install/shared/lib/libhidapi.dylib, \
install/shared/include/hidapi/hidapi.h, \
install/framework/lib/hidapi.framework/hidapi, \
install/framework/lib/hidapi.framework/Headers/hidapi.h"
allow_failure: true

ubuntu-cmake:
Expand Down Expand Up @@ -76,7 +79,14 @@ jobs:
- name: Check artifacts
uses: andstor/file-existence-action@v1
with:
files: "install/shared/lib/libhidapi-libusb.so, install/shared/lib/libhidapi-hidraw.so, install/shared/include/hidapi/hidapi.h, install/static/lib/libhidapi-libusb.a, install/static/lib/libhidapi-hidraw.a, install/static/include/hidapi/hidapi.h"
files: "install/shared/lib/libhidapi-libusb.so, \
install/shared/lib/libhidapi-hidraw.so, \
install/shared/include/hidapi/hidapi.h, \
install/shared/include/hidapi/hidapi_libusb.h, \
install/static/lib/libhidapi-libusb.a, \
install/static/lib/libhidapi-hidraw.a, \
install/static/include/hidapi/hidapi.h, \
install/static/include/hidapi/hidapi_libusb.h"
allow_failure: true

windows-cmake-msvc:
Expand Down
3 changes: 2 additions & 1 deletion libusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6.3 FATAL_ERROR)
add_library(hidapi_libusb
${HIDAPI_PUBLIC_HEADERS}
hid.c
hidapi_libusb.h
)
target_link_libraries(hidapi_libusb PUBLIC hidapi_include)

Expand All @@ -23,7 +24,7 @@ set_target_properties(hidapi_libusb
OUTPUT_NAME "hidapi-libusb"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}"
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS};hidapi_libusb.h"
)

# compatibility with find_package()
Expand Down
2 changes: 1 addition & 1 deletion libusb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ libhidapi_la_LIBADD = $(LIBS_LIBUSB)
endif

hdrdir = $(includedir)/hidapi
hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h
hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h hidapi_libusb.h

EXTRA_DIST = Makefile-manual
Loading

0 comments on commit aaf5f3d

Please sign in to comment.