mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-20 04:17:21 +08:00
Updated hidapi to 0.14.0 release
Upstream: https://github.com/libusb/hidapi/releases/tag/hidapi-0.14.0
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
environment:
|
||||
matrix:
|
||||
- BUILD_ENV: msbuild
|
||||
arch: x64
|
||||
- BUILD_ENV: msbuild
|
||||
arch: Win32
|
||||
- BUILD_ENV: cygwin
|
||||
|
||||
for:
|
||||
-
|
||||
matrix:
|
||||
only:
|
||||
- BUILD_ENV: msbuild
|
||||
|
||||
os: Visual Studio 2015
|
||||
|
||||
build_script:
|
||||
- cmd: msbuild .\windows\hidapi.sln /p:Configuration=Release /p:Platform=%arch% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||
|
||||
-
|
||||
matrix:
|
||||
only:
|
||||
- BUILD_ENV: cygwin
|
||||
|
||||
os: Visual Studio 2022
|
||||
|
||||
install:
|
||||
- cmd: C:\cygwin64\setup-x86_64.exe --quiet-mode --no-shortcuts --upgrade-also --packages autoconf,automake
|
||||
|
||||
build_script:
|
||||
- cmd: C:\cygwin64\bin\bash -exlc "cd $APPVEYOR_BUILD_FOLDER; ./bootstrap; ./configure; make"
|
||||
@@ -0,0 +1,34 @@
|
||||
image: freebsd/latest
|
||||
packages:
|
||||
- autoconf
|
||||
- automake
|
||||
- gmake
|
||||
- libiconv
|
||||
- libtool
|
||||
- pkgconf
|
||||
- cmake
|
||||
- ninja
|
||||
sources:
|
||||
- https://github.com/libusb/hidapi
|
||||
tasks:
|
||||
- configure: |
|
||||
cd hidapi
|
||||
echo Configure Autotools build
|
||||
./bootstrap
|
||||
./configure
|
||||
echo Configure CMake build
|
||||
mkdir -p build install_cmake
|
||||
cmake -GNinja -B build -S . -DCMAKE_INSTALL_PREFIX=install_cmake
|
||||
- build-autotools: |
|
||||
cd hidapi
|
||||
make
|
||||
make DESTDIR=$PWD/root install
|
||||
make clean
|
||||
- build-cmake: |
|
||||
cd hidapi/build
|
||||
ninja
|
||||
ninja install
|
||||
ninja clean
|
||||
- build-manual: |
|
||||
cd hidapi/libusb
|
||||
gmake -f Makefile-manual
|
||||
@@ -0,0 +1,18 @@
|
||||
image: netbsd/latest
|
||||
packages:
|
||||
- cmake
|
||||
- pkgconf
|
||||
- libusb1
|
||||
- libiconv
|
||||
sources:
|
||||
- https://github.com/libusb/hidapi
|
||||
tasks:
|
||||
- configure: |
|
||||
cd hidapi
|
||||
mkdir -p build install
|
||||
cmake -B build -S . -DCMAKE_INSTALL_PREFIX=install
|
||||
- build: |
|
||||
cd hidapi/build
|
||||
make
|
||||
make install
|
||||
make clean
|
||||
@@ -0,0 +1,19 @@
|
||||
image: openbsd/latest
|
||||
packages:
|
||||
- cmake
|
||||
- pkgconf
|
||||
- libusb1--
|
||||
- libiconv
|
||||
- ninja
|
||||
sources:
|
||||
- https://github.com/libusb/hidapi
|
||||
tasks:
|
||||
- configure: |
|
||||
cd hidapi
|
||||
mkdir -p build install
|
||||
cmake -GNinja -B build -S . -DCMAKE_INSTALL_PREFIX=install
|
||||
- build: |
|
||||
cd hidapi/build
|
||||
ninja
|
||||
ninja install
|
||||
ninja clean
|
||||
@@ -0,0 +1,33 @@
|
||||
alpine_task:
|
||||
container:
|
||||
image: alpine:latest
|
||||
install_script: apk add autoconf automake g++ gcc libusb-dev libtool linux-headers eudev-dev make musl-dev
|
||||
script:
|
||||
- ./bootstrap
|
||||
- ./configure || { cat config.log; exit 1; }
|
||||
- make
|
||||
- make install
|
||||
|
||||
freebsd11_task:
|
||||
freebsd_instance:
|
||||
image: freebsd-11-2-release-amd64
|
||||
install_script:
|
||||
- pkg install -y
|
||||
autoconf automake libiconv libtool pkgconf
|
||||
script:
|
||||
- ./bootstrap
|
||||
- ./configure || { cat config.log; exit 1; }
|
||||
- make
|
||||
- make install
|
||||
|
||||
freebsd12_task:
|
||||
freebsd_instance:
|
||||
image: freebsd-12-1-release-amd64
|
||||
install_script:
|
||||
- pkg install -y
|
||||
autoconf automake libiconv libtool pkgconf
|
||||
script:
|
||||
- ./bootstrap
|
||||
- ./configure || { cat config.log; exit 1; }
|
||||
- make
|
||||
- make install
|
||||
@@ -0,0 +1,7 @@
|
||||
* text=auto
|
||||
|
||||
*.sln text eol=crlf
|
||||
*.vcproj text eol=crlf
|
||||
|
||||
bootstrap text eol=lf
|
||||
configure.ac text eol=lf
|
||||
+540
File diff suppressed because it is too large
Load Diff
+196
@@ -0,0 +1,196 @@
|
||||
name: Checks
|
||||
run-name: Code checks for '${{ github.ref_name }}'
|
||||
|
||||
# General comment:
|
||||
# Coverity doesn't support merging or including reports from multible machine/platforms (at least not officially).
|
||||
# But otherwise there is no good way to keep the issues from all platforms at Coverity Scans at once.
|
||||
# This script uses undocumented (but appears to be working) hack:
|
||||
# The build logs from one machine/platform gets moved to a next once,
|
||||
# and "fixed" so that cov-build can append logs from the next platform.
|
||||
# The "fix" is based on the fact, that Coverity perfectly allows appending logs from multiple builds
|
||||
# that are done *on the same host* machine.
|
||||
|
||||
on:
|
||||
# On-demand run
|
||||
workflow_dispatch:
|
||||
# Weekly run
|
||||
schedule:
|
||||
- cron: '30 5 * * 0'
|
||||
|
||||
jobs:
|
||||
coverity-windows:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: src
|
||||
- name: Setup MSVC
|
||||
uses: TheMrMilchmann/setup-msvc-dev@v2.0.0
|
||||
with:
|
||||
arch: x64
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake -B build -S src -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_HIDTEST=ON
|
||||
- name: Lookup Coverity Build Tool hash
|
||||
id: coverity-cache-lookup
|
||||
run: |
|
||||
$coverity_hash=Invoke-RestMethod -Uri https://scan.coverity.com/download/cxx/win64 -Method Post -Body @{token='${{ secrets.COVERITY_SCAN_TOKEN }}';project='hidapi';md5=1}
|
||||
echo "coverity_hash=$coverity_hash" >> $Env:GITHUB_OUTPUT
|
||||
- name: Get cached Coverity Build Tool
|
||||
id: cov-build-cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: cov-root
|
||||
key: cov-root-cxx-win64-${{ steps.coverity-cache-lookup.outputs.coverity_hash }}
|
||||
- name: Get and configure Coverity
|
||||
if: steps.cov-build-cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
Invoke-WebRequest -Uri https://scan.coverity.com/download/cxx/win64 -OutFile coverity.zip -Method Post -Body @{token='${{ secrets.COVERITY_SCAN_TOKEN }}';project='hidapi'}
|
||||
Remove-Item 'cov-root' -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Expand-Archive coverity.zip -DestinationPath cov-root
|
||||
|
||||
$cov_root=Get-ChildItem -Path 'cov-root'
|
||||
$Env:PATH += ";$($cov_root.FullName)\bin"
|
||||
cov-configure -msvc
|
||||
- name: Make Coverity available in PATH
|
||||
run: |
|
||||
$cov_root=Get-ChildItem -Path 'cov-root'
|
||||
echo "$($cov_root.FullName)\bin" >> $Env:GITHUB_PATH
|
||||
- name: Build with Coverity
|
||||
working-directory: build
|
||||
run: |
|
||||
cov-build --dir cov-int nmake
|
||||
Rename-Item ".\cov-int\emit\$(hostname)" hostname
|
||||
- name: Backup Coverity logs
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverity-logs-windows
|
||||
path: build/cov-int
|
||||
retention-days: 7
|
||||
|
||||
|
||||
coverity-macos:
|
||||
runs-on: macos-latest
|
||||
needs: [coverity-windows]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: src
|
||||
- name: Install dependencies
|
||||
run: brew install ninja
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake -B build -S src -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_HIDTEST=ON -DCMAKE_C_COMPILER=clang
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: coverity-logs-windows
|
||||
path: build/cov-int
|
||||
- name: Fixup cov-int
|
||||
run: |
|
||||
rm -f build/cov-int/emit/hostname/emit-db.lock build/cov-int/emit/hostname/emit-db.write-lock
|
||||
mv build/cov-int/emit/hostname build/cov-int/emit/$(hostname)
|
||||
- name: Lookup Coverity Build Tool hash
|
||||
id: coverity-cache-lookup
|
||||
shell: bash
|
||||
run: |
|
||||
hash=$(curl https://scan.coverity.com/download/cxx/Darwin --data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=hidapi&md5=1")
|
||||
echo "coverity_hash=${hash}" >> $GITHUB_OUTPUT
|
||||
- name: Get cached Coverity Build Tool
|
||||
id: cov-build-cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: cov-root
|
||||
key: cov-root-cxx-Darwin-${{ steps.coverity-cache-lookup.outputs.coverity_hash }}
|
||||
- name: Get and configure Coverity
|
||||
if: steps.cov-build-cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
curl https://scan.coverity.com/download/cxx/Darwin --output coverity.dmg --data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=hidapi"
|
||||
hdiutil attach coverity.dmg -mountroot coverity
|
||||
export COV_DIR_NAME=$(ls -1 --color=never coverity)
|
||||
rm -rf cov-root
|
||||
mkdir cov-root
|
||||
cp ./coverity/${COV_DIR_NAME}/${COV_DIR_NAME}.sh cov-root/
|
||||
cd cov-root/
|
||||
./${COV_DIR_NAME}.sh
|
||||
./bin/cov-configure --clang
|
||||
- name: Make Coverity available in PATH
|
||||
run: echo "$(pwd)/cov-root/bin" >> $GITHUB_PATH
|
||||
- name: Build with Coverity
|
||||
working-directory: build
|
||||
run: |
|
||||
cov-build --dir cov-int --append-log ninja
|
||||
mv cov-int/emit/$(hostname) cov-int/emit/hostname
|
||||
- name: Backup Coverity logs
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverity-logs-windows-macos
|
||||
path: build/cov-int
|
||||
retention-days: 7
|
||||
|
||||
|
||||
coverity-ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [coverity-macos]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: src
|
||||
- name: Install dependencies
|
||||
run: sudo apt install libudev-dev libusb-1.0-0-dev ninja-build
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake -B build -S src -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_HIDTEST=ON -DCMAKE_C_COMPILER=gcc
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: coverity-logs-windows-macos
|
||||
path: build/cov-int
|
||||
- name: Fixup cov-int
|
||||
run: |
|
||||
rm -f build/cov-int/emit/hostname/emit-db.lock build/cov-int/emit/hostname/emit-db.write-lock
|
||||
mv build/cov-int/emit/hostname build/cov-int/emit/$(hostname)
|
||||
- name: Lookup Coverity Build Tool hash
|
||||
id: coverity-cache-lookup
|
||||
shell: bash
|
||||
run: |
|
||||
hash=$(curl https://scan.coverity.com/download/cxx/linux64 --data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=hidapi&md5=1")
|
||||
echo "coverity_hash=${hash}" >> $GITHUB_OUTPUT
|
||||
- name: Get cached Coverity Build Tool
|
||||
id: cov-build-cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: cov-root
|
||||
key: cov-root-cxx-linux64-${{ steps.coverity-cache-lookup.outputs.coverity_hash }}
|
||||
- name: Get and configure Coverity
|
||||
if: steps.cov-build-cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
curl https://scan.coverity.com/download/cxx/linux64 --output coverity.tar.gz --data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=hidapi"
|
||||
rm -rf cov-root
|
||||
mkdir cov-root
|
||||
tar -xzf coverity.tar.gz --strip 1 -C cov-root
|
||||
./cov-root/bin/cov-configure --gcc
|
||||
- name: Make Coverity available in PATH
|
||||
run: echo "$(pwd)/cov-root/bin" >> $GITHUB_PATH
|
||||
- name: Build with Coverity
|
||||
working-directory: build
|
||||
run: |
|
||||
cov-build --dir cov-int --append-log ninja
|
||||
- name: Submit results to Coverity Scan
|
||||
working-directory: build
|
||||
run: |
|
||||
tar -czf cov-int.tar.gz cov-int
|
||||
curl --form token=${{ secrets.COVERITY_SCAN_TOKEN }} \
|
||||
--form email=${{ secrets.COVERITY_SCAN_EMAIL }} \
|
||||
--form file=@cov-int.tar.gz \
|
||||
--form version="$GITHUB_SHA" \
|
||||
--form description="Automatic HIDAPI build" \
|
||||
https://scan.coverity.com/builds?project=hidapi
|
||||
mv cov-int/emit/$(hostname) cov-int/emit/hostname
|
||||
- name: Backup Coverity logs
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverity-logs-windows-macos-linux
|
||||
path: build/cov-int
|
||||
retention-days: 7
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
name: Docs
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Install Doxygen static libclang deps
|
||||
run: sudo apt-get install libclang1-12 libclang-cpp12
|
||||
|
||||
- name: Install Doxygen from SF binary archives
|
||||
env:
|
||||
DOXYGEN_VERSION: '1.9.6'
|
||||
run: |
|
||||
mkdir .doxygen && cd .doxygen
|
||||
curl -L https://sourceforge.net/projects/doxygen/files/rel-$DOXYGEN_VERSION/doxygen-$DOXYGEN_VERSION.linux.bin.tar.gz > doxygen.tar.gz
|
||||
gunzip doxygen.tar.gz
|
||||
tar xf doxygen.tar
|
||||
cd doxygen-$DOXYGEN_VERSION
|
||||
sudo make install
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- run: doxygen
|
||||
working-directory: doxygen
|
||||
|
||||
- name: Save doxygen docs as artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: HIDAPI_doxygen_docs
|
||||
path: ${{ github.workspace }}/doxygen/html
|
||||
|
||||
deploy-docs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build]
|
||||
if: github.ref_type == 'branch' && github.ref_name == 'master'
|
||||
concurrency:
|
||||
group: "github-pages-deploy"
|
||||
cancel-in-progress: true
|
||||
steps:
|
||||
- name: downlod artifact
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: HIDAPI_doxygen_docs
|
||||
path: docs
|
||||
|
||||
- name: upload to github pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./docs
|
||||
force_orphan: true
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
# Autotools-added generated files
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
ar-lib
|
||||
autom4te.cache/
|
||||
config.*
|
||||
configure
|
||||
configure~
|
||||
compile
|
||||
depcomp
|
||||
install-sh
|
||||
libusb/Makefile.in
|
||||
linux/Makefile.in
|
||||
ltmain.sh
|
||||
mac/Makefile.in
|
||||
missing
|
||||
testgui/Makefile.in
|
||||
windows/Makefile.in
|
||||
|
||||
Makefile
|
||||
stamp-h1
|
||||
libtool
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# Qt Creator
|
||||
CMakeLists.txt.user
|
||||
|
||||
# doxgen output
|
||||
doxygen/html/
|
||||
@@ -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:
|
||||
https://github.com/libusb/hidapi/commits/master
|
||||
https://github.com/libusb/hidapi/graphs/contributors
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
# Building HIDAPI using Autotools (deprecated)
|
||||
|
||||
---
|
||||
**NOTE**: for all intentions and purposes the Autotools build scripts for HIDAPI are _deprecated_ and going to be obsolete in the future.
|
||||
HIDAPI Team recommends using CMake build for HIDAPI.
|
||||
If you are already using Autotools build scripts provided by HIDAPI,
|
||||
consider switching to CMake build scripts as soon as possible.
|
||||
|
||||
---
|
||||
|
||||
To be able to use Autotools to build HIDAPI, it has to be [installed](#installing-autotools)/available in the system.
|
||||
|
||||
Make sure you've checked [prerequisites](BUILD.md#prerequisites) and installed all required dependencies.
|
||||
|
||||
## Installing Autotools
|
||||
|
||||
HIDAPI uses few specific tools/packages from Autotools: `autoconf`, `automake`, `libtool`.
|
||||
|
||||
On different platforms or package managers, those could be named a bit differently or packaged together.
|
||||
You'll have to check the documentation/package list for your specific package manager.
|
||||
|
||||
### Linux
|
||||
|
||||
On Ubuntu the tools are available via APT:
|
||||
|
||||
```sh
|
||||
sudo apt install autoconf automake libtool
|
||||
```
|
||||
|
||||
### FreeBSD
|
||||
|
||||
FreeBSD Autotools can be installed as:
|
||||
|
||||
```sh
|
||||
pkg_add -r autotools
|
||||
```
|
||||
|
||||
Additionally, on FreeBSD you will need to install GNU make:
|
||||
```sh
|
||||
pkg_add -r gmake
|
||||
```
|
||||
|
||||
## Building HIDAPI with Autotools
|
||||
|
||||
A simple command list, to build HIDAPI with Autotools as a _shared library_ and install in into your system:
|
||||
|
||||
```sh
|
||||
./bootstrap # this prepares the configure script
|
||||
./configure
|
||||
make # build the library
|
||||
make install # as root, or using sudo, this will install hidapi into your system
|
||||
```
|
||||
|
||||
`./configure` can take several arguments which control the build. A few commonly used options:
|
||||
```sh
|
||||
--enable-testgui
|
||||
# Enable the build of Foxit-based Test GUI. This requires Fox toolkit to
|
||||
# be installed/available. See README.md#test-gui for remarks.
|
||||
|
||||
--prefix=/usr
|
||||
# Specify where you want the output headers and libraries to
|
||||
# be installed. The example above will put the headers in
|
||||
# /usr/include and the binaries in /usr/lib. The default is to
|
||||
# install into /usr/local which is fine on most systems.
|
||||
|
||||
--disable-shared
|
||||
# By default, both shared and static libraries are going to be built/installed.
|
||||
# This option disables shared library build, if only static library is required.
|
||||
```
|
||||
|
||||
|
||||
## Cross Compiling
|
||||
|
||||
This section talks about cross compiling HIDAPI for Linux using Autotools.
|
||||
This is useful for using HIDAPI on embedded Linux targets. These
|
||||
instructions assume the most raw kind of embedded Linux build, where all
|
||||
prerequisites will need to be built first. This process will of course vary
|
||||
based on your embedded Linux build system if you are using one, such as
|
||||
OpenEmbedded or Buildroot.
|
||||
|
||||
For the purpose of this section, it will be assumed that the following
|
||||
environment variables are exported.
|
||||
```sh
|
||||
$ export STAGING=$HOME/out
|
||||
$ export HOST=arm-linux
|
||||
```
|
||||
|
||||
`STAGING` and `HOST` can be modified to suit your setup.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Depending on what backend you want to cross-compile, you also need to prepare the dependencies:
|
||||
`libusb` for libusb HIDAPI backend, or `libudev` for hidraw HIDAPI backend.
|
||||
|
||||
An example of cross-compiling `libusb`. From `libusb` source directory, run:
|
||||
```sh
|
||||
./configure --host=$HOST --prefix=$STAGING
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
An example of cross-comping `libudev` is not covered by this section.
|
||||
Check `libudev`'s documentation for details.
|
||||
|
||||
### Building HIDAPI
|
||||
|
||||
Build HIDAPI:
|
||||
```sh
|
||||
PKG_CONFIG_DIR= \
|
||||
PKG_CONFIG_LIBDIR=$STAGING/lib/pkgconfig:$STAGING/share/pkgconfig \
|
||||
PKG_CONFIG_SYSROOT_DIR=$STAGING \
|
||||
./configure --host=$HOST --prefix=$STAGING
|
||||
# make / make install - same as for a regular build
|
||||
```
|
||||
@@ -0,0 +1,280 @@
|
||||
# Building HIDAPI using CMake
|
||||
|
||||
To build HIDAPI with CMake, it has to be [installed](#installing-cmake)/available in the system.
|
||||
|
||||
Make sure you've checked [prerequisites](BUILD.md#prerequisites) and installed all required dependencies.
|
||||
|
||||
HIDAPI CMake build system allows you to build HIDAPI in two generally different ways:
|
||||
1) As a [standalone package/library](#standalone-package-build);
|
||||
2) As [part of a larger CMake project](#hidapi-as-a-subdirectory).
|
||||
|
||||
**TL;DR**: if you're experienced developer and have been working with CMake projects or have been written some of your own -
|
||||
most of this document may not be of interest for you; just check variables names, its default values and the target names.
|
||||
|
||||
## Installing CMake
|
||||
|
||||
CMake can be installed either using your system's package manager,
|
||||
or by downloading an installer/prebuilt version from the [official website](https://cmake.org/download/).
|
||||
|
||||
On most \*nix systems, the prefered way to install CMake is via package manager,
|
||||
e.g. `sudo apt install cmake`.
|
||||
|
||||
On Windows CMake could be provided by your development environment (e.g. by Visual Studio Installer or MinGW installer),
|
||||
or you may install it system-wise using the installer from the official website.
|
||||
|
||||
On macOS CMake may be installed by Homebrew/MacPorts or using the installer from the official website.
|
||||
|
||||
## Standalone package build
|
||||
|
||||
To build HIDAPI as a standalone package, you follow [general steps](https://cmake.org/runningcmake/) of building any CMake project.
|
||||
|
||||
An example of building HIDAPI with CMake:
|
||||
```sh
|
||||
# precondition: create a <build dir> somewhere on the filesystem (preferably outside of the HIDAPI source)
|
||||
# this is the place where all intermediate/build files are going to be located
|
||||
cd <build dir>
|
||||
# configure the build
|
||||
cmake <HIDAPI source dir>
|
||||
# build it!
|
||||
cmake --build .
|
||||
# install library; by default installs into /usr/local/
|
||||
cmake --build . --target install
|
||||
# NOTE: you need to run install command as root, to be able to install into /usr/local/
|
||||
```
|
||||
Such invocation will use the default (as per CMake magic) compiler/build environment available in your system.
|
||||
|
||||
You may pass some additional CMake variables to control the build configuration as `-D<CMake Variable>=value`.
|
||||
E.g.:
|
||||
```sh
|
||||
# install command now would install things into /usr
|
||||
cmake <HIDAPI source dir> -DCMAKE_INSTALL_PREFIX=/usr
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Using a specific CMake generator</summary>
|
||||
|
||||
An example of using `Ninja` as a CMake generator:
|
||||
|
||||
```sh
|
||||
cd <build dir>
|
||||
# configure the build
|
||||
cmake -GNinja <HIDAPI source dir>
|
||||
# we know, that CMake has generated build files for Ninja,
|
||||
# so we can use `ninja` directly, instead of `cmake --build .`
|
||||
ninja
|
||||
# install library
|
||||
ninja install
|
||||
```
|
||||
|
||||
`-G` here specifies a native build system CMake would generate build files for.
|
||||
Check [CMake Documentation](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) for a list of available generators (system-specific).
|
||||
|
||||
</details><br>
|
||||
|
||||
Some of the [standard](https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html) CMake variables you may want to use to configure a build:
|
||||
|
||||
- [`CMAKE_INSTALL_PREFIX`](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) - prefix where `install` target would install the library(ies);
|
||||
- [`CMAKE_BUILD_TYPE`](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) - standard possible values: `Debug`, `Release`, `RelWithDebInfo`, `MinSizeRel`; Defaults to `Release` for HIDAPI, if not specified;
|
||||
- [`BUILD_SHARED_LIBS`](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html) - when set to TRUE, HIDAPI is built as a shared library, otherwise build statically; Defaults to `TRUE` for HIDAPI, if not specified;
|
||||
|
||||
<details>
|
||||
<summary>macOS-specific variables</summary>
|
||||
|
||||
- [`CMAKE_FRAMEWORK`](https://cmake.org/cmake/help/latest/variable/CMAKE_FRAMEWORK.html) - (since CMake 3.15) when set to TRUE, HIDAPI is built as a framework library, otherwise build as a regular static/shared library; Defaults to `FALSE` for HIDAPI, if not specified;
|
||||
- [`CMAKE_OSX_DEPLOYMENT_TARGET`](https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html) - minimum version of the target platform (e.g. macOS or iOS) on which the target binaries are to be deployed; defaults to a maximum supported target platform by currently used XCode/Toolchain;
|
||||
|
||||
</details><br>
|
||||
|
||||
HIDAPI-specific CMake variables:
|
||||
|
||||
- `HIDAPI_BUILD_HIDTEST` - when set to TRUE, build a small test application `hidtest`;
|
||||
- `HIDAPI_WITH_TESTS` - when set to TRUE, build all (unit-)tests;
|
||||
currently this option is only available on Windows, since only Windows backend has tests;
|
||||
|
||||
<details>
|
||||
<summary>Linux-specific variables</summary>
|
||||
|
||||
- `HIDAPI_WITH_HIDRAW` - when set to TRUE, build HIDRAW-based implementation of HIDAPI (`hidapi-hidraw`), otherwise don't build it; defaults to TRUE;
|
||||
- `HIDAPI_WITH_LIBUSB` - when set to TRUE, build LIBUSB-based implementation of HIDAPI (`hidapi-libusb`), otherwise don't build it; defaults to TRUE;
|
||||
|
||||
**NOTE**: at least one of `HIDAPI_WITH_HIDRAW` or `HIDAPI_WITH_LIBUSB` has to be set to TRUE.
|
||||
|
||||
</details><br>
|
||||
|
||||
To see all most-useful CMake variables available for HIDAPI, one of the most convenient ways is too use [`cmake-gui`](https://cmake.org/cmake/help/latest/manual/cmake-gui.1.html) tool ([example](https://cmake.org/runningcmake/)).
|
||||
|
||||
_NOTE_: HIDAPI packages built by CMake can be used with `pkg-config`, as if built with [Autotools](BUILD.autotools.md).
|
||||
|
||||
### MSVC and Ninja
|
||||
It is possible to build a CMake project (including HIDAPI) using MSVC compiler and Ninja (for medium and larger projects it is so much faster than msbuild).
|
||||
|
||||
For that:
|
||||
1) Open cmd.exe;
|
||||
2) Setup MSVC build environment variables, e.g.: `vcvarsall.bat x64`, where:
|
||||
- `vcvarsall.bat` is an environment setup script of your MSVC toolchain installation;<br>For MSVC 2019 Community edition it is located at: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\`;
|
||||
- `x64` -a target architecture to build;
|
||||
3) Follow general build steps, and use `Ninja` as a generator.
|
||||
|
||||
### Using HIDAPI in a CMake project
|
||||
|
||||
When HIDAPI is used as a standalone package (either installed into the system or built manually and installed elsewhere), the simplest way to use it is as showed in the example:
|
||||
|
||||
```cmake
|
||||
project(my_application)
|
||||
|
||||
add_executable(my_application main.c)
|
||||
|
||||
find_package(hidapi REQUIRED)
|
||||
target_link_libraries(my_application PRIVATE hidapi::hidapi)
|
||||
```
|
||||
|
||||
If HIDAPI isn't installed in your system, or `find_package` cannot find HIDAPI by default for any other reasons,
|
||||
the recommended way manually specify which HIDAPI package to use is via `hidapi_ROOT` CMake variable, e.g.:
|
||||
`-Dhidapi_ROOT=<path to HIDAPI installation prefix>`.
|
||||
|
||||
_NOTE_: usage of `hidapi_ROOT` is only possible (and recommended) with CMake 3.12 and higher. For older versions of CMake you'd need to specify [`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html#variable:CMAKE_PREFIX_PATH) instead.
|
||||
|
||||
Check with [`find_package`](https://cmake.org/cmake/help/latest/command/find_package.html) documentation if you need more details.
|
||||
|
||||
Available CMake targets after successful `find_package(hidapi)`:
|
||||
- `hidapi::hidapi` - indented to be used in most cases;
|
||||
- `hidapi::include` - if you need only to include `<hidapi.h>` but not link against the library;
|
||||
- `hidapi::winapi` - same as `hidapi::hidapi` on Windows; available only on Windows;
|
||||
- `hidapi::darwin` - same as `hidapi::hidapi` on macOS; available only on macOS;
|
||||
- `hidapi::libusb` - available when libusb backend is used/available;
|
||||
- `hidapi::hidraw` - available when hidraw backend is used/available on Linux;
|
||||
|
||||
**NOTE**: on Linux often both `hidapi::libusb` and `hidapi::hidraw` backends are available; in that case `hidapi::hidapi` is an alias for **`hidapi::hidraw`**. The motivation is that `hidraw` backend is a native Linux kernel implementation of HID protocol, and supports various HID devices (USB, Bluetooth, I2C, etc.). If `hidraw` backend isn't built at all (`hidapi::libusb` is the only target) - `hidapi::hidapi` is an alias for `hidapi::libusb`.
|
||||
If you're developing a cross-platform application and you are sure you need to use `libusb` backend on Linux, the simple way to achieve this is:
|
||||
```cmake
|
||||
if(TARGET hidapi::libusb)
|
||||
target_link_libraries(my_project PRIVATE hidapi::libusb)
|
||||
else()
|
||||
target_link_libraries(my_project PRIVATE hidapi::hidapi)
|
||||
endif()
|
||||
```
|
||||
|
||||
## HIDAPI as a subdirectory
|
||||
|
||||
HIDAPI can be easily used as a subdirectory of a larger CMake project:
|
||||
```cmake
|
||||
# root CMakeLists.txt
|
||||
cmake_minimum_required(VERSION 3.4.3 FATAL_ERROR)
|
||||
|
||||
add_subdirectory(hidapi)
|
||||
add_subdirectory(my_application)
|
||||
|
||||
# my_application/CMakeLists.txt
|
||||
project(my_application)
|
||||
|
||||
add_executable(my_application main.c)
|
||||
|
||||
# NOTE: no `find_package` is required, since HIDAPI targets are already a part of the project tree
|
||||
target_link_libraries(my_application PRIVATE hidapi::hidapi)
|
||||
```
|
||||
Lets call this "larger project" a "host project".
|
||||
|
||||
All of the variables described in [standalone build](#standalone-package-build) section can be used to control HIDAPI build in case of a subdirectory, e.g.:
|
||||
```cmake
|
||||
set(HIDAPI_WITH_LIBUSB FALSE) # surely will be used only on Linux
|
||||
set(BUILD_SHARED_LIBS FALSE) # HIDAPI as static library on all platforms
|
||||
add_subdirectory(hidapi)
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>NOTE</summary>
|
||||
|
||||
If you project happen to use `BUILD_SHARED_LIBS` as a `CACHE` variable globally for you project, setting it as simple variable, as showed above _will have not affect_ up until _CMake 3.13_. See [CMP0077](https://cmake.org/cmake/help/latest/policy/CMP0077.html) for details.
|
||||
</details><br>
|
||||
|
||||
There are several important differences in the behavior of HIDAPI CMake build system when CMake is built as standalone package vs subdirectory build:
|
||||
|
||||
1) In _standalone build_ a number of standard and HIDAPI-specific variables are marked as _cache variables_ or _options_.
|
||||
This is done for convenience: when you're building HIDAPI as a standalone package and using tools like `cmake-gui` - those are highlighted as variables that can be changed and has some short description/documentation. E.g.:
|
||||
<br>
|
||||
E.g.2:<br>
|
||||
<br>
|
||||
When HIDAPI is built as a _subdirectory_ - **_none of the variables are marked for cache or as options_** by HIDAPI.
|
||||
This is done to let the host project's developer decide what is important (what needs to be highlighted) and what's not.
|
||||
|
||||
2) The default behavior/default value for some of the variables is a bit different:
|
||||
- by default, none of HIDAPI targets are [installed](https://cmake.org/cmake/help/latest/command/install.html); if required, HIDAPI targets can be installed by host project _after_ including HIDAPI subdirectory (requires CMake 3.13 or later); **or**, the default installation can be enabled by setting `HIDAPI_INSTALL_TARGETS` variable _before_ including HIDAPI subdirectory.
|
||||
HIDAPI uses [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) to specify install locations. Variables like `CMAKE_INSTALL_LIBDIR` can be used to control HIDAPI's installation locations. E.g.:
|
||||
```cmake
|
||||
# enable the installation if you need it
|
||||
set(HIDAPI_INSTALL_TARGETS ON)
|
||||
# (optionally) change default installation locations if it makes sense for your target platform, etc.
|
||||
set(CMAKE_INSTALL_LIBDIR "lib64")
|
||||
add_subdirectory(hidapi)
|
||||
```
|
||||
- HIDAPI prints its version during the configuration when built as a standalone package; to enable this for subdirectory builds - set `HIDAPI_PRINT_VERSION` to TRUE before including HIDAPI;
|
||||
|
||||
3) In a subdirectory build, HIDAPI _doesn't modify or set any of the CMake variables_ that may change the build behavior.
|
||||
For instance, in a _standalone build_, if CMAKE_BUILD_TYPE or BUILD_SHARED_LIBS variables are not set, those are defaulted to "Release" and "TRUE" explicitly.
|
||||
In a _subdirectory build_, even if not set, those variables remain unchanged, so a host project's developer has a full control over the HIDAPI build configuration.
|
||||
|
||||
Available CMake targets after `add_subdirectory(hidapi)` _are the same as in case of [standalone build](#standalone-package-build)_, and a few additional ones:
|
||||
- `hidapi_include` - the interface library; `hidapi::hidapi` is an alias of it;
|
||||
- `hidapi_winapi` - library target on Windows; `hidapi::winapi` is an alias of it;
|
||||
- `hidapi_darwin` - library target on macOS; `hidapi::darwin` is an alias of it;
|
||||
- `hidapi_libusb` - library target for libusb backend; `hidapi::libusb` is an alias of it;
|
||||
- `hidapi_hidraw` - library target for hidraw backend; `hidapi::hidraw` is an alias of it;
|
||||
- `hidapi-libusb` - an alias of `hidapi_libusb` for compatibility with raw library name;
|
||||
- `hidapi-hidraw` - an alias of `hidapi_hidraw` for compatibility with raw library name;
|
||||
- `hidapi` - an alias of `hidapi_winapi` or `hidapi_darwin` on Windows or macOS respectfully.
|
||||
|
||||
Advanced:
|
||||
- Why would I need additional targets described in this section above, if I already have alias targets compatible with `find_package`?
|
||||
- an example:
|
||||
```cmake
|
||||
add_subdirectory(hidapi)
|
||||
if(TARGET hidapi_libusb)
|
||||
# see libusb/hid.c for usage of `NO_ICONV`
|
||||
target_compile_definitions(hidapi_libusb PRIVATE NO_ICONV)
|
||||
endif()
|
||||
```
|
||||
|
||||
## Both Shared and Static build
|
||||
|
||||
If you're a former (or present) user of Autotools build scripts for HIDAPI, or you're a package manager maintainer and you're often working with those - you're likely asking how to build HIDAPI with CMake and get both Shared and Static libraries (as would be done by Autotools: `./configure --enable-static --enable-shared ...`).
|
||||
|
||||
CMake doesn't have such option of-the-box and it is decided not to introduce any manual CMake-level workarounds for HIDAPI on this matter.
|
||||
|
||||
If you want to mimic the Autotools behavior, it is possible by building/installing first the static version of the library and then shared version of the library. The installation folder (`CMAKE_INSTALL_PREFIX`) should point to the same directory for both variants, that way:
|
||||
- both static and shared library binaries will be available and usable;
|
||||
- a single header file(s) for both of them;
|
||||
- Autotools/pkg-config (`.pc`) files will be generated and usable _as if_ generated by Autotools natively and build configured with both `-enable-static --enable-shared` options;
|
||||
- CMake package scripts will be generated and fully usable, but _only the last build installed_, i.e. if the last was installed Shared version of the binary - CMake targets found by `find_package(hidapi)` would point to a Shared binaries.
|
||||
|
||||
There is a historical discussion, why such solution is simplest/preferable: https://github.com/libusb/hidapi/issues/424
|
||||
|
||||
#### TL;DR/Sample
|
||||
|
||||
```sh
|
||||
# First - configure/build
|
||||
|
||||
# Static libraries
|
||||
cmake -S <HIDAPI source dir> -B "<build dir>/static" -DCMAKE_INSTALL_PREFIX=<your installation prefix> -DBUILD_SHARED_LIBS=FALSE
|
||||
cmake --build "<build dir>/static"
|
||||
# Shared libraries
|
||||
cmake -S <HIDAPI source dir> -B "<build dir>/shared" -DCMAKE_INSTALL_PREFIX=<your installation prefix> -DBUILD_SHARED_LIBS=TRUE
|
||||
cmake --build "<build dir>/shared"
|
||||
|
||||
# (Optionally) change the installation destination.
|
||||
# NOTE1: this is supported by CMake only on UNIX platforms
|
||||
# See https://cmake.org/cmake/help/latest/envvar/DESTDIR.html
|
||||
# NOTE2: this is not the same as `CMAKE_INSTALL_PREFIX` set above
|
||||
# NOTE3: this is only required if you have a staging dir other than the final runtime dir,
|
||||
# e.g. during cross-compilation
|
||||
export DESTDIR="$STAGING_DIR"
|
||||
|
||||
#
|
||||
# Install the libraries
|
||||
# NOTE: order of installation matters - install Shared variant *the last*
|
||||
|
||||
# Static libraries
|
||||
cmake --install "<build dir>/static"
|
||||
# Shared libraries
|
||||
cmake --install "<build dir>/shared"
|
||||
|
||||
```
|
||||
@@ -0,0 +1,127 @@
|
||||
# Building HIDAPI from Source
|
||||
|
||||
## Table of content
|
||||
|
||||
* [Intro](#intro)
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Linux](#linux)
|
||||
* [FreeBSD](#freebsd)
|
||||
* [Mac](#mac)
|
||||
* [Windows](#windows)
|
||||
* [Embedding HIDAPI directly into your source tree](#embedding-hidapi-directly-into-your-source-tree)
|
||||
* [Building the manual way on Unix platforms](#building-the-manual-way-on-unix-platforms)
|
||||
* [Building on Windows](#building-on-windows)
|
||||
|
||||
## Intro
|
||||
|
||||
For various reasons, you may need to build HIDAPI on your own.
|
||||
|
||||
It can be done in several different ways:
|
||||
- using [CMake](BUILD.cmake.md);
|
||||
- using [Autotools](BUILD.autotools.md) (deprecated);
|
||||
- using [manual makefiles](#building-the-manual-way-on-unix-platforms);
|
||||
- using `Meson` (requires CMake);
|
||||
|
||||
**Autotools** build system is historically the first mature build system for
|
||||
HIDAPI. The most common usage of it is in its separate README: [BUILD.autotools.md](BUILD.autotools.md).<br/>
|
||||
NOTE: for all intentions and purposes the Autotools build scripts for HIDAPI are _deprecated_ and going to be obsolete in the future.
|
||||
HIDAPI Team recommends using CMake build for HIDAPI.
|
||||
|
||||
**CMake** build system is de facto an industry standard for many open-source and proprietary projects and solutions.
|
||||
HIDAPI is one of the projects which use the power of CMake to its advantage.
|
||||
More documentation is available in its separate README: [BUILD.cmake.md](BUILD.cmake.md).
|
||||
|
||||
**Meson** build system for HIDAPI is designed as a [wrapper](https://mesonbuild.com/CMake-module.html) over CMake build script.
|
||||
It is present for the convenience of Meson users who need to use HIDAPI and need to be sure HIDAPI is built in accordance with officially supported build scripts.<br>
|
||||
In the Meson script of your project you need a `hidapi = subproject('hidapi')` subproject, and `hidapi.get_variable('hidapi_dep')` as your dependency.
|
||||
There are also backend/platform-specific dependencies available: `hidapi_winapi`, `hidapi_darwin`, `hidapi_hidraw`, `hidapi_libusb`.
|
||||
|
||||
If you don't know where to start to build HIDAPI, we recommend starting with [CMake](BUILD.cmake.md) build.
|
||||
|
||||
## Prerequisites:
|
||||
|
||||
Regardless of what build system you choose to use, there are specific dependencies for each platform/backend.
|
||||
|
||||
### Linux:
|
||||
|
||||
Depending on which backend you're going to build, you'll need to install
|
||||
additional development packages. For `linux/hidraw` backend, you need a
|
||||
development package for `libudev`. For `libusb` backend, naturally, you need
|
||||
`libusb` development package.
|
||||
|
||||
On Debian/Ubuntu systems these can be installed by running:
|
||||
```sh
|
||||
# required only by hidraw backend
|
||||
sudo apt install libudev-dev
|
||||
# required only by libusb backend
|
||||
sudo apt install libusb-1.0-0-dev
|
||||
```
|
||||
|
||||
### FreeBSD:
|
||||
|
||||
On FreeBSD, you will need to install libiconv. This is done by running
|
||||
the following:
|
||||
```sh
|
||||
pkg_add -r libiconv
|
||||
```
|
||||
|
||||
### Mac:
|
||||
|
||||
Make sure you have XCode installed and its Command Line Tools.
|
||||
|
||||
### Windows:
|
||||
|
||||
You just need a compiler. You may use Visual Studio or Cygwin/MinGW,
|
||||
depending on which environment is best for your needs.
|
||||
|
||||
## Embedding HIDAPI directly into your source tree
|
||||
|
||||
Instead of using one of the provided standalone build systems,
|
||||
you may want to integrate HIDAPI directly into your source tree.
|
||||
|
||||
---
|
||||
If your project uses CMake as a build system, it is safe to add HIDAPI as a [subdirectory](BUILD.cmake.md#hidapi-as-a-subdirectory).
|
||||
|
||||
---
|
||||
If _the only option_ that works for you is adding HIDAPI sources directly
|
||||
to your project's build system, then you need:
|
||||
- include a _single source file_ into your project's build system,
|
||||
depending on your platform and the backend you want to use:
|
||||
- [`windows\hid.c`](windows/hid.c);
|
||||
- [`linux/hid.c`](linux/hid.c);
|
||||
- [`libusb/hid.c`](libusb/hid.c);
|
||||
- [`mac/hid.c`](mac/hid.c);
|
||||
- add a [`hidapi`](hidapi) folder to the include path when building `hid.c`;
|
||||
- make the platform/backend specific [dependencies](#prerequisites) available during the compilation/linking, when building `hid.c`;
|
||||
|
||||
NOTE: the above doesn't guarantee that having a copy of `<backend>/hid.c` and `hidapi/hidapi.h` is enough to build HIDAPI.
|
||||
The only guarantee that `<backend>/hid.c` includes all necessary sources to compile it as a single file.
|
||||
|
||||
Check the manual makefiles for a simple example/reference of what are the dependencies of each specific backend.
|
||||
|
||||
## Building the manual way on Unix platforms
|
||||
|
||||
Manual Makefiles are provided mostly to give the user an idea what it takes
|
||||
to build a program which embeds HIDAPI directly inside of it. These should
|
||||
really be used as examples only. If you want to build a system-wide shared
|
||||
library, use one of the build systems mentioned above.
|
||||
|
||||
To build HIDAPI using the manual Makefiles, change the directory
|
||||
of your platform and run make. For example, on Linux run:
|
||||
```sh
|
||||
cd linux/
|
||||
make -f Makefile-manual
|
||||
```
|
||||
|
||||
## Building on Windows
|
||||
|
||||
To build the HIDAPI DLL on Windows using Visual Studio, build the `.sln` file
|
||||
in the `windows/` directory.
|
||||
|
||||
To build HIDAPI using MinGW or Cygwin using Autotools, use general Autotools
|
||||
[instruction](BUILD.autotools.md).
|
||||
|
||||
Any windows builds (MSVC or MinGW/Cygwin) are also supported by [CMake](BUILD.cmake.md).
|
||||
|
||||
If you are looking for information regarding DDK build of HIDAPI:
|
||||
- the build has been broken for a while and now the support files are obsolete.
|
||||
@@ -0,0 +1,105 @@
|
||||
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
|
||||
|
||||
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
add_subdirectory(src)
|
||||
# compatibility with find_package() vs add_subdirectory
|
||||
set(hidapi_VERSION "${hidapi_VERSION}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
# All of the below in this file is meant for a standalone build.
|
||||
# When building as a subdirectory of a larger project, most of the options may not make sense for it,
|
||||
# so it is up to developer to configure those, e.g.:
|
||||
#
|
||||
# # a subfolder of a master project, e.g.: 3rdparty/hidapi/CMakeLists.txt
|
||||
#
|
||||
# set(HIDAPI_WITH_HIDRAW OFF)
|
||||
# set(CMAKE_FRAMEWORK ON)
|
||||
# # and keep everything else to their defaults
|
||||
# add_subdirectory(hidapi)
|
||||
#
|
||||
|
||||
set(DEFAULT_CMAKE_BUILD_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
||||
if(NOT DEFINED CMAKE_BUILD_TYPE OR NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "${DEFAULT_CMAKE_BUILD_TYPES}" FORCE)
|
||||
endif()
|
||||
# This part is for convenience, when used one of the standard build types with cmake-gui
|
||||
list(FIND DEFAULT_CMAKE_BUILD_TYPES "${CMAKE_BUILD_TYPE}" _build_type_index)
|
||||
if(${_build_type_index} GREATER -1)
|
||||
# set it optionally, so a custom CMAKE_BUILD_TYPE can be used as well, if needed
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${DEFAULT_CMAKE_BUILD_TYPES})
|
||||
endif()
|
||||
unset(_build_type_index)
|
||||
#
|
||||
|
||||
project(hidapi LANGUAGES C)
|
||||
|
||||
if(APPLE)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS "3.15")
|
||||
option(CMAKE_FRAMEWORK "Build macOS/iOS Framework version of the library" OFF)
|
||||
endif()
|
||||
elseif(NOT WIN32)
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON)
|
||||
option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared version of the libraries, otherwise build statically" ON)
|
||||
|
||||
set(HIDAPI_INSTALL_TARGETS ON)
|
||||
set(HIDAPI_PRINT_VERSION ON)
|
||||
|
||||
set(IS_DEBUG_BUILD OFF)
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(IS_DEBUG_BUILD ON)
|
||||
endif()
|
||||
|
||||
option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentation" OFF)
|
||||
|
||||
if(HIDAPI_ENABLE_ASAN)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||
if(MSVC)
|
||||
# the default is to have "/INCREMENTAL" which causes a warning when "-fsanitize=address" is present
|
||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# so far only Windows has tests
|
||||
option(HIDAPI_WITH_TESTS "Build HIDAPI (unit-)tests" ${IS_DEBUG_BUILD})
|
||||
else()
|
||||
set(HIDAPI_WITH_TESTS OFF)
|
||||
endif()
|
||||
|
||||
if(HIDAPI_WITH_TESTS)
|
||||
enable_testing()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
option(HIDAPI_BUILD_PP_DATA_DUMP "Build small Windows console application pp_data_dump.exe" ${IS_DEBUG_BUILD})
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
option(HIDAPI_BUILD_HIDTEST "Build small console test application hidtest" ${IS_DEBUG_BUILD})
|
||||
if(HIDAPI_BUILD_HIDTEST)
|
||||
add_subdirectory(hidtest)
|
||||
endif()
|
||||
|
||||
if(HIDAPI_ENABLE_ASAN)
|
||||
if(NOT MSVC)
|
||||
# MSVC doesn't recognize those options, other compilers - requiring it
|
||||
foreach(HIDAPI_TARGET hidapi_winapi hidapi_darwin hidapi_hidraw hidapi_libusb hidtest_hidraw hidtest_libusb hidtest)
|
||||
if(TARGET ${HIDAPI_TARGET})
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_link_options(${HIDAPI_TARGET} PRIVATE -fsanitize=address)
|
||||
else()
|
||||
target_link_options(${HIDAPI_TARGET} PUBLIC -fsanitize=address)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
+15
-11
@@ -1,15 +1,19 @@
|
||||
This file is mostly for the maintainer.
|
||||
|
||||
1. Build hidapi.dll
|
||||
2. Build hidtest.exe in DEBUG and RELEASE
|
||||
3. Commit all
|
||||
Updating a Version:
|
||||
1. Update VERSION file.
|
||||
2. HID_API_VERSION_MAJOR/HID_API_VERSION_MINOR/HID_API_VERSION_PATCH in hidapi.h.
|
||||
|
||||
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
|
||||
Before firing a new release:
|
||||
1. Run the "Checks" Githtub Action
|
||||
2. Make sure no defects are found at: https://scan.coverity.com/projects/hidapi
|
||||
3. Fix if any
|
||||
|
||||
Firing a new release:
|
||||
1. Update the Version (if not yet updated).
|
||||
2. Prepare the Release Notes.
|
||||
3. Store the Release Notes into a file.
|
||||
4. Create locally an annotated git tag with release notes attached, e.g.: `git tag -aF ../hidapi_release_notes hidapi-<VERSION>`
|
||||
5. Push newly created tag: `git push origin hidapi-<VERSION>`
|
||||
6. Grab the hidapi-win.zip from Summary page of "GitHub Builds" Action for latest master build.
|
||||
7. Create a Github Release with hidapi-win.zip attached, for newly created tag.
|
||||
|
||||
@@ -23,10 +23,6 @@ if OS_DARWIN
|
||||
SUBDIRS += mac
|
||||
endif
|
||||
|
||||
if OS_IOS
|
||||
SUBDIRS += ios
|
||||
endif
|
||||
|
||||
if OS_FREEBSD
|
||||
SUBDIRS += libusb
|
||||
endif
|
||||
@@ -35,6 +31,10 @@ if OS_KFREEBSD
|
||||
SUBDIRS += libusb
|
||||
endif
|
||||
|
||||
if OS_HAIKU
|
||||
SUBDIRS += libusb
|
||||
endif
|
||||
|
||||
if OS_WINDOWS
|
||||
SUBDIRS += windows
|
||||
endif
|
||||
@@ -48,7 +48,7 @@ endif
|
||||
EXTRA_DIST = udev doxygen
|
||||
|
||||
dist_doc_DATA = \
|
||||
README.txt \
|
||||
README.md \
|
||||
AUTHORS.txt \
|
||||
LICENSE-bsd.txt \
|
||||
LICENSE-gpl3.txt \
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
## HIDAPI library for Windows, Linux, FreeBSD and macOS
|
||||
|
||||
| CI instance | Status |
|
||||
|----------------------|--------|
|
||||
| `Linux/macOS/Windows (master)` | [](https://github.com/libusb/hidapi/actions/workflows/builds.yml?query=branch%3Amaster) |
|
||||
| `Windows (master)` | [](https://ci.appveyor.com/project/libusb/hidapi/branch/master) |
|
||||
| `BSD, last build (branch/PR)` | [](https://builds.sr.ht/~z3ntu/hidapi) |
|
||||
| `Coverity Scan (last)` |  |
|
||||
|
||||
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
|
||||
can be embedded directly into a target application by adding a _single source_
|
||||
file (per platform) and a single header.<br>
|
||||
See [remarks](BUILD.md#embedding-hidapi-directly-into-your-source-tree) on embedding _directly_ into your build system.
|
||||
|
||||
HIDAPI library was originally developed by Alan Ott ([signal11](https://github.com/signal11)).
|
||||
|
||||
It was moved to [libusb/hidapi](https://github.com/libusb/hidapi) on June 4th, 2019, in order to merge important bugfixes and continue development of the library.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [About](#about)
|
||||
* [Test GUI](#test-gui)
|
||||
* [Console Test App](#console-test-app)
|
||||
* [What Does the API Look Like?](#what-does-the-api-look-like)
|
||||
* [License](#license)
|
||||
* [Installing HIDAPI](#installing-hidapi)
|
||||
* [Build from Source](#build-from-source)
|
||||
|
||||
|
||||
## About
|
||||
|
||||
### HIDAPI has four back-ends:
|
||||
* Windows (using `hid.dll`)
|
||||
* Linux/hidraw (using the Kernel's hidraw driver)
|
||||
* libusb (using libusb-1.0 - Linux/BSD/other UNIX-like systems)
|
||||
* macOS (using IOHidManager)
|
||||
|
||||
On Linux, either the hidraw or the libusb back-end can be used. There are
|
||||
tradeoffs, and the functionality supported is slightly different. Both are
|
||||
built by default. It is up to the application linking to hidapi to choose
|
||||
the backend at link time by linking to either `libhidapi-libusb` or
|
||||
`libhidapi-hidraw`.
|
||||
|
||||
Note that you will need to install an udev rule file with your application
|
||||
for unprivileged users to be able to access HID devices with hidapi. Refer
|
||||
to the [69-hid.rules](udev/69-hid.rules) file in the `udev` directory
|
||||
for an example.
|
||||
|
||||
#### __Linux/hidraw__ (`linux/hid.c`):
|
||||
|
||||
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`):
|
||||
|
||||
This back-end uses libusb-1.0 to communicate directly to a USB device. This
|
||||
back-end will of course not work with Bluetooth devices.
|
||||
|
||||
### Test GUI
|
||||
|
||||
HIDAPI also comes with a Test GUI. The Test GUI is cross-platform and uses
|
||||
Fox Toolkit <http://www.fox-toolkit.org>. It will build on every platform
|
||||
which HIDAPI supports. Since it relies on a 3rd party library, building it
|
||||
is optional but it is useful when debugging hardware.
|
||||
|
||||
NOTE: Test GUI based on Fox Toolkit is not actively developed nor supported
|
||||
by HIDAPI team. It is kept as a historical artifact. It may even work sometime
|
||||
or on some platforms, but it is not going to get any new features or bugfixes.
|
||||
|
||||
Instructions for installing Fox-Toolkit on each platform is not provided.
|
||||
Make sure to use Fox-Toolkit v1.6 if you choose to use it.
|
||||
|
||||
### Console Test App
|
||||
|
||||
If you want to play around with your HID device before starting
|
||||
any development with HIDAPI and using a GUI app is not an option for you, you may try [`hidapitester`](https://github.com/todbot/hidapitester).
|
||||
|
||||
This app has a console interface for most of the features supported
|
||||
by HIDAPI library.
|
||||
|
||||
## What Does the API Look Like?
|
||||
|
||||
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 (`hid_write`) at random to your HID devices can break them.**
|
||||
|
||||
```c
|
||||
#include <stdio.h> // printf
|
||||
#include <wchar.h> // wchar_t
|
||||
|
||||
#include <hidapi.h>
|
||||
|
||||
#define MAX_STR 255
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int res;
|
||||
unsigned char buf[65];
|
||||
wchar_t wstr[MAX_STR];
|
||||
hid_device *handle;
|
||||
int i;
|
||||
|
||||
// Initialize the hidapi library
|
||||
res = hid_init();
|
||||
|
||||
// Open the device using the VID, PID,
|
||||
// and optionally the Serial number.
|
||||
handle = hid_open(0x4d8, 0x3f, NULL);
|
||||
if (!handle) {
|
||||
printf("Unable to open device\n");
|
||||
hid_exit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read the Manufacturer String
|
||||
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
|
||||
printf("Manufacturer String: %ls\n", wstr);
|
||||
|
||||
// Read the Product String
|
||||
res = hid_get_product_string(handle, wstr, MAX_STR);
|
||||
printf("Product String: %ls\n", wstr);
|
||||
|
||||
// Read the Serial Number String
|
||||
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
|
||||
printf("Serial Number String: (%d) %ls\n", wstr[0], wstr);
|
||||
|
||||
// Read Indexed String 1
|
||||
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
|
||||
printf("Indexed String 1: %ls\n", wstr);
|
||||
|
||||
// Toggle LED (cmd 0x80). The first byte is the report number (0x0).
|
||||
buf[0] = 0x0;
|
||||
buf[1] = 0x80;
|
||||
res = hid_write(handle, buf, 65);
|
||||
|
||||
// Request state (cmd 0x81). The first byte is the report number (0x0).
|
||||
buf[0] = 0x0;
|
||||
buf[1] = 0x81;
|
||||
res = hid_write(handle, buf, 65);
|
||||
|
||||
// Read requested state
|
||||
res = hid_read(handle, buf, 65);
|
||||
|
||||
// Print out the returned buffer.
|
||||
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();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
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).
|
||||
|
||||
## Installing HIDAPI
|
||||
|
||||
If you want to build your own application that uses HID devices with HIDAPI,
|
||||
you need to get HIDAPI development package.
|
||||
|
||||
Depending on what your development environment is, HIDAPI likely to be provided
|
||||
by your package manager.
|
||||
|
||||
For instance on Ubuntu, HIDAPI is available via APT:
|
||||
```sh
|
||||
sudo apt install libhidapi-dev
|
||||
```
|
||||
|
||||
HIDAPI package name for other systems/package managers may differ.
|
||||
Check the documentation/package list of your package manager.
|
||||
|
||||
## Build from Source
|
||||
|
||||
Check [BUILD.md](BUILD.md) for details.
|
||||
@@ -1,339 +0,0 @@
|
||||
HIDAPI library for Windows, Linux, FreeBSD and Mac OS X
|
||||
=========================================================
|
||||
|
||||
About
|
||||
======
|
||||
|
||||
HIDAPI is a multi-platform library which allows an application to interface
|
||||
with USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and Mac
|
||||
OS X. HIDAPI can be either built as a shared library (.so or .dll) or
|
||||
can be embedded directly into a target application by adding a single source
|
||||
file (per platform) and a single header.
|
||||
|
||||
HIDAPI has four back-ends:
|
||||
* Windows (using hid.dll)
|
||||
* Linux/hidraw (using the Kernel's hidraw driver)
|
||||
* Linux/libusb (using libusb-1.0)
|
||||
* FreeBSD (using libusb-1.0)
|
||||
* Mac (using IOHidManager)
|
||||
|
||||
On Linux, either the hidraw or the libusb back-end can be used. There are
|
||||
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.
|
||||
|
||||
Linux/FreeBSD/libusb (libusb/hid.c):
|
||||
This back-end uses libusb-1.0 to communicate directly to a USB device. This
|
||||
back-end will of course not work with Bluetooth devices.
|
||||
|
||||
HIDAPI also comes with a Test GUI. The Test GUI is cross-platform and uses
|
||||
Fox Toolkit (http://www.fox-toolkit.org). It will build on every platform
|
||||
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,
|
||||
which communicates with a heavily hacked up version of the Microchip USB
|
||||
Generic HID sample looks like this (with error checking removed for
|
||||
simplicity):
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "hidapi.h"
|
||||
|
||||
#define MAX_STR 255
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int res;
|
||||
unsigned char buf[65];
|
||||
wchar_t wstr[MAX_STR];
|
||||
hid_device *handle;
|
||||
int i;
|
||||
|
||||
// Initialize the hidapi library
|
||||
res = hid_init();
|
||||
|
||||
// Open the device using the VID, PID,
|
||||
// and optionally the Serial number.
|
||||
handle = hid_open(0x4d8, 0x3f, NULL);
|
||||
|
||||
// Read the Manufacturer String
|
||||
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
|
||||
wprintf(L"Manufacturer String: %s\n", wstr);
|
||||
|
||||
// Read the Product String
|
||||
res = hid_get_product_string(handle, wstr, MAX_STR);
|
||||
wprintf(L"Product String: %s\n", wstr);
|
||||
|
||||
// Read the Serial Number String
|
||||
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
|
||||
wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr);
|
||||
|
||||
// Read Indexed String 1
|
||||
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
|
||||
wprintf(L"Indexed String 1: %s\n", wstr);
|
||||
|
||||
// Toggle LED (cmd 0x80). The first byte is the report number (0x0).
|
||||
buf[0] = 0x0;
|
||||
buf[1] = 0x80;
|
||||
res = hid_write(handle, buf, 65);
|
||||
|
||||
// Request state (cmd 0x81). The first byte is the report number (0x0).
|
||||
buf[0] = 0x0;
|
||||
buf[1] = 0x81;
|
||||
res = hid_write(handle, buf, 65);
|
||||
|
||||
// Read requested state
|
||||
res = hid_read(handle, buf, 65);
|
||||
|
||||
// Print out the returned buffer.
|
||||
for (i = 0; i < 4; i++)
|
||||
printf("buf[%d]: %d\n", i, buf[i]);
|
||||
|
||||
// Finalize the hidapi library
|
||||
res = hid_exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
If you have your own simple test programs which communicate with standard
|
||||
hardware development boards (such as those from Microchip, TI, Atmel,
|
||||
FreeScale and others), please consider sending me something like the above
|
||||
for inclusion into the HIDAPI source. This will help others who have the
|
||||
same hardware as you do.
|
||||
|
||||
License
|
||||
========
|
||||
HIDAPI may be used by one of three licenses as outlined in LICENSE.txt.
|
||||
|
||||
Download
|
||||
=========
|
||||
HIDAPI can be downloaded from github
|
||||
git clone git://github.com/libusb/hidapi.git
|
||||
|
||||
Build Instructions
|
||||
===================
|
||||
|
||||
This section is long. Don't be put off by this. It's not long because it's
|
||||
complicated to build HIDAPI; it's quite the opposite. This section is long
|
||||
because of the flexibility of HIDAPI and the large number of ways in which
|
||||
it can be built and used. You will likely pick a single build method.
|
||||
|
||||
HIDAPI can be built in several different ways. If you elect to build a
|
||||
shared library, you will need to build it from the HIDAPI source
|
||||
distribution. If you choose instead to embed HIDAPI directly into your
|
||||
application, you can skip the building and look at the provided platform
|
||||
Makefiles for guidance. These platform Makefiles are located in linux/
|
||||
libusb/ mac/ and windows/ and are called Makefile-manual. In addition,
|
||||
Visual Studio projects are provided. Even if you're going to embed HIDAPI
|
||||
into your project, it is still beneficial to build the example programs.
|
||||
|
||||
|
||||
Prerequisites:
|
||||
---------------
|
||||
|
||||
Linux:
|
||||
-------
|
||||
On Linux, you will need to install development packages for libudev,
|
||||
libusb and optionally Fox-toolkit (for the test GUI). On
|
||||
Debian/Ubuntu systems these can be installed by running:
|
||||
sudo apt-get install libudev-dev libusb-1.0-0-dev libfox-1.6-dev
|
||||
|
||||
If you downloaded the source directly from the git repository (using
|
||||
git clone), you'll need Autotools:
|
||||
sudo apt-get install autotools-dev autoconf automake libtool
|
||||
|
||||
FreeBSD:
|
||||
---------
|
||||
On FreeBSD you will need to install GNU make, libiconv, and
|
||||
optionally Fox-Toolkit (for the test GUI). This is done by running
|
||||
the following:
|
||||
pkg_add -r gmake libiconv fox16
|
||||
|
||||
If you downloaded the source directly from the git repository (using
|
||||
git clone), you'll need Autotools:
|
||||
pkg_add -r autotools
|
||||
|
||||
Mac:
|
||||
-----
|
||||
On Mac, you will need to install Fox-Toolkit if you wish to build
|
||||
the Test GUI. There are two ways to do this, and each has a slight
|
||||
complication. Which method you use depends on your use case.
|
||||
|
||||
If you wish to build the Test GUI just for your own testing on your
|
||||
own computer, then the easiest method is to install Fox-Toolkit
|
||||
using ports:
|
||||
sudo port install fox
|
||||
|
||||
If you wish to build the TestGUI app bundle to redistribute to
|
||||
others, you will need to install Fox-toolkit from source. This is
|
||||
because the version of fox that gets installed using ports uses the
|
||||
ports X11 libraries which are not compatible with the Apple X11
|
||||
libraries. If you install Fox with ports and then try to distribute
|
||||
your built app bundle, it will simply fail to run on other systems.
|
||||
To install Fox-Toolkit manually, download the source package from
|
||||
http://www.fox-toolkit.org, extract it, and run the following from
|
||||
within the extracted source:
|
||||
./configure && make && make install
|
||||
|
||||
Windows:
|
||||
---------
|
||||
On Windows, if you want to build the test GUI, you will need to get
|
||||
the hidapi-externals.zip package from the download site. This
|
||||
contains pre-built binaries for Fox-toolkit. Extract
|
||||
hidapi-externals.zip just outside of hidapi, so that
|
||||
hidapi-externals and hidapi are on the same level, as shown:
|
||||
|
||||
Parent_Folder
|
||||
|
|
||||
+hidapi
|
||||
+hidapi-externals
|
||||
|
||||
Again, this step is not required if you do not wish to build the
|
||||
test GUI.
|
||||
|
||||
|
||||
Building HIDAPI into a shared library on Unix Platforms:
|
||||
---------------------------------------------------------
|
||||
|
||||
On Unix-like systems such as Linux, FreeBSD, Mac, and even Windows, using
|
||||
Mingw or Cygwin, the easiest way to build a standard system-installed shared
|
||||
library is to use the GNU Autotools build system. If you checked out the
|
||||
source from the git repository, run the following:
|
||||
|
||||
./bootstrap
|
||||
./configure
|
||||
make
|
||||
make install <----- as root, or using sudo
|
||||
|
||||
If you downloaded a source package (ie: if you did not run git clone), you
|
||||
can skip the ./bootstrap step.
|
||||
|
||||
./configure can take several arguments which control the build. The two most
|
||||
likely to be used are:
|
||||
--enable-testgui
|
||||
Enable build of the Test GUI. This requires Fox toolkit to
|
||||
be installed. Instructions for installing Fox-Toolkit on
|
||||
each platform are in the Prerequisites section above.
|
||||
|
||||
--prefix=/usr
|
||||
Specify where you want the output headers and libraries to
|
||||
be installed. The example above will put the headers in
|
||||
/usr/include and the binaries in /usr/lib. The default is to
|
||||
install into /usr/local which is fine on most systems.
|
||||
|
||||
Building the manual way on Unix platforms:
|
||||
-------------------------------------------
|
||||
|
||||
Manual Makefiles are provided mostly to give the user and idea what it takes
|
||||
to build a program which embeds HIDAPI directly inside of it. These should
|
||||
really be used as examples only. If you want to build a system-wide shared
|
||||
library, use the Autotools method described above.
|
||||
|
||||
To build HIDAPI using the manual makefiles, change to the directory
|
||||
of your platform and run make. For example, on Linux run:
|
||||
cd linux/
|
||||
make -f Makefile-manual
|
||||
|
||||
To build the Test GUI using the manual makefiles:
|
||||
cd testgui/
|
||||
make -f Makefile-manual
|
||||
|
||||
Building on Windows:
|
||||
---------------------
|
||||
|
||||
To build the HIDAPI DLL on Windows using Visual Studio, build the .sln file
|
||||
in the windows/ directory.
|
||||
|
||||
To build the Test GUI on windows using Visual Studio, build the .sln file in
|
||||
the testgui/ directory.
|
||||
|
||||
To build HIDAPI using MinGW or Cygwin using Autotools, use the instructions
|
||||
in the section titled "Building HIDAPI into a shared library on Unix
|
||||
Platforms" above. Note that building the Test GUI with MinGW or Cygwin will
|
||||
require the Windows procedure in the Prerequisites section above (ie:
|
||||
hidapi-externals.zip).
|
||||
|
||||
To build HIDAPI using MinGW using the Manual Makefiles, see the section
|
||||
"Building the manual way on Unix platforms" above.
|
||||
|
||||
HIDAPI can also be built using the Windows DDK (now also called the Windows
|
||||
Driver Kit or WDK). This method was originally required for the HIDAPI build
|
||||
but not anymore. However, some users still prefer this method. It is not as
|
||||
well supported anymore but should still work. Patches are welcome if it does
|
||||
not. To build using the DDK:
|
||||
|
||||
1. Install the Windows Driver Kit (WDK) from Microsoft.
|
||||
2. From the Start menu, in the Windows Driver Kits folder, select Build
|
||||
Environments, then your operating system, then the x86 Free Build
|
||||
Environment (or one that is appropriate for your system).
|
||||
3. From the console, change directory to the windows/ddk_build/ directory,
|
||||
which is part of the HIDAPI distribution.
|
||||
4. Type build.
|
||||
5. You can find the output files (DLL and LIB) in a subdirectory created
|
||||
by the build system which is appropriate for your environment. On
|
||||
Windows XP, this directory is objfre_wxp_x86/i386.
|
||||
|
||||
Cross Compiling
|
||||
================
|
||||
|
||||
This section talks about cross compiling HIDAPI for Linux using autotools.
|
||||
This is useful for using HIDAPI on embedded Linux targets. These
|
||||
instructions assume the most raw kind of embedded Linux build, where all
|
||||
prerequisites will need to be built first. This process will of course vary
|
||||
based on your embedded Linux build system if you are using one, such as
|
||||
OpenEmbedded or Buildroot.
|
||||
|
||||
For the purpose of this section, it will be assumed that the following
|
||||
environment variables are exported.
|
||||
|
||||
$ export STAGING=$HOME/out
|
||||
$ export HOST=arm-linux
|
||||
|
||||
STAGING and HOST can be modified to suit your setup.
|
||||
|
||||
Prerequisites
|
||||
--------------
|
||||
|
||||
Note that the build of libudev is the very basic configuration.
|
||||
|
||||
Build Libusb. From the libusb source directory, run:
|
||||
./configure --host=$HOST --prefix=$STAGING
|
||||
make
|
||||
make install
|
||||
|
||||
Build libudev. From the libudev source directory, run:
|
||||
./configure --disable-gudev --disable-introspection --disable-hwdb \
|
||||
--host=$HOST --prefix=$STAGING
|
||||
make
|
||||
make install
|
||||
|
||||
Building HIDAPI
|
||||
----------------
|
||||
|
||||
Build HIDAPI:
|
||||
|
||||
PKG_CONFIG_DIR= \
|
||||
PKG_CONFIG_LIBDIR=$STAGING/lib/pkgconfig:$STAGING/share/pkgconfig \
|
||||
PKG_CONFIG_SYSROOT_DIR=$STAGING \
|
||||
./configure --host=$HOST --prefix=$STAGING
|
||||
|
||||
|
||||
Signal 11 Software - 2010-04-11
|
||||
2010-07-28
|
||||
2011-09-10
|
||||
2012-05-01
|
||||
2012-07-03
|
||||
@@ -0,0 +1 @@
|
||||
0.14.0
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 2022 Valve Corporation
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
// Purpose: Exporting table containing HIDDeviceManager native methods
|
||||
|
||||
#ifndef SDL_android_hid_h_
|
||||
#define SDL_android_hid_h_
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern JNINativeMethod HIDDeviceManager_tab[8];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
HIDAPI_ROOT_REL:= ../..
|
||||
HIDAPI_ROOT_ABS:= $(LOCAL_PATH)/../..
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_CPPFLAGS += -std=c++11
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
$(HIDAPI_ROOT_REL)/android/hid.cpp
|
||||
|
||||
LOCAL_MODULE := libhidapi
|
||||
LOCAL_LDLIBS := -llog
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
@@ -1,2 +0,0 @@
|
||||
APP_STL := gnustl_static
|
||||
APP_ABI := armeabi-v7a
|
||||
@@ -1,14 +0,0 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-21
|
||||
+44
-24
@@ -1,13 +1,9 @@
|
||||
AC_PREREQ(2.63)
|
||||
|
||||
# Version number. This is currently the only place.
|
||||
m4_define([HIDAPI_MAJOR], 0)
|
||||
m4_define([HIDAPI_MINOR], 8)
|
||||
m4_define([HIDAPI_RELEASE], 0)
|
||||
m4_define([HIDAPI_RC], -rc1)
|
||||
m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC)
|
||||
AC_INIT([hidapi],[m4_normalize(m4_builtin([include], VERSION))],[https://github.com/libusb/hidapi/issues])
|
||||
|
||||
AC_INIT([hidapi],[VERSION_STRING],[alan@signal11.us])
|
||||
echo "This build script for HIDAPI is deprecated."
|
||||
echo "Consider using CMake instead."
|
||||
|
||||
# Library soname version
|
||||
# Follow the following rules (particularly the ones in the second link):
|
||||
@@ -20,7 +16,6 @@ LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
|
||||
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
||||
LT_INIT
|
||||
@@ -63,14 +58,14 @@ case $host in
|
||||
|
||||
# HIDAPI/hidraw libs
|
||||
PKG_CHECK_MODULES([libudev], [libudev], true, [hidapi_lib_error libudev])
|
||||
LIBS_HIDRAW_PR+=" $libudev_LIBS"
|
||||
CFLAGS_HIDRAW+=" $libudev_CFLAGS"
|
||||
LIBS_HIDRAW_PR="${LIBS_HIDRAW_PR} $libudev_LIBS"
|
||||
CFLAGS_HIDRAW="${CFLAGS_HIDRAW} $libudev_CFLAGS"
|
||||
|
||||
# HIDAPI/libusb libs
|
||||
AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE+=" -lrt"], [hidapi_lib_error librt])
|
||||
AC_CHECK_LIB([rt], [clock_gettime], [LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} -lrt"], [hidapi_lib_error librt])
|
||||
PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9], true, [hidapi_lib_error libusb-1.0])
|
||||
LIBS_LIBUSB_PRIVATE+=" $libusb_LIBS"
|
||||
CFLAGS_LIBUSB+=" $libusb_CFLAGS"
|
||||
LIBS_LIBUSB_PRIVATE="${LIBS_LIBUSB_PRIVATE} $libusb_LIBS"
|
||||
CFLAGS_LIBUSB="${CFLAGS_LIBUSB} $libusb_CFLAGS"
|
||||
;;
|
||||
*-darwin*)
|
||||
AC_MSG_RESULT([ (Mac OS X back-end)])
|
||||
@@ -79,7 +74,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 +87,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 +100,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)])
|
||||
@@ -113,6 +123,15 @@ case $host in
|
||||
os="windows"
|
||||
threads="windows"
|
||||
win_implementation="mingw"
|
||||
LDFLAGS="${LDFLAGS} -static-libgcc"
|
||||
;;
|
||||
*-msys*)
|
||||
AC_MSG_RESULT([ (Windows back-end, using MSYS2)])
|
||||
backend="windows"
|
||||
os="windows"
|
||||
threads="windows"
|
||||
win_implementation="mingw"
|
||||
LDFLAGS="${LDFLAGS} -static-libgcc"
|
||||
;;
|
||||
*-cygwin*)
|
||||
AC_MSG_RESULT([ (Windows back-end, using Cygwin)])
|
||||
@@ -136,7 +155,7 @@ if test "x$os" = xwindows; then
|
||||
AC_DEFINE(OS_WINDOWS, 1, [Windows implementations])
|
||||
AC_SUBST(OS_WINDOWS)
|
||||
LDFLAGS="${LDFLAGS} -no-undefined"
|
||||
LIBS="${LIBS} -lsetupapi"
|
||||
LIBS="${LIBS}"
|
||||
fi
|
||||
|
||||
if test "x$threads" = xpthreads; then
|
||||
@@ -175,15 +194,15 @@ mkdir testgui/TestGUI.app/Contents/MacOS/
|
||||
|
||||
if test "x$testgui_enabled" != "xno"; then
|
||||
if test "x$os" = xdarwin; then
|
||||
# On Mac OS, don't use pkg-config.
|
||||
# On Mac OS, do not use pkg-config.
|
||||
AC_CHECK_PROG([foxconfig], [fox-config], [fox-config], false)
|
||||
if test "x$foxconfig" = "xfalse"; then
|
||||
hidapi_prog_error fox-config "FOX Toolkit"
|
||||
fi
|
||||
LIBS_TESTGUI+=`$foxconfig --libs`
|
||||
LIBS_TESTGUI+=" -framework Cocoa -L/usr/X11R6/lib"
|
||||
CFLAGS_TESTGUI+=`$foxconfig --cflags`
|
||||
OBJCFLAGS+=" -x objective-c++"
|
||||
LIBS_TESTGUI="${LIBS_TESTGUI} `$foxconfig --libs`"
|
||||
LIBS_TESTGUI="${LIBS_TESTGUI} -framework Cocoa -L/usr/X11R6/lib"
|
||||
CFLAGS_TESTGUI="${CFLAGS_TESTGUI} `$foxconfig --cflags`"
|
||||
OBJCFLAGS="${OBJCFLAGS} -x objective-c++"
|
||||
elif test "x$os" = xwindows; then
|
||||
# On Windows, just set the paths for Fox toolkit
|
||||
if test "x$win_implementation" = xmingw; then
|
||||
@@ -213,6 +232,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])
|
||||
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
Pod::Spec.new do |spec|
|
||||
|
||||
spec.name = "hidapi"
|
||||
spec.version = File.read('../VERSION')
|
||||
spec.summary = "A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac and Windows."
|
||||
|
||||
spec.description = <<-DESC
|
||||
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 can be embedded directly into a target application by adding a single source file (per platform) and a single header.
|
||||
DESC
|
||||
|
||||
spec.homepage = "https://github.com/libusb/hidapi"
|
||||
|
||||
spec.license = { :type=> "GNU GPLv3 or BSD or HIDAPI original", :file => "LICENSE.txt" }
|
||||
|
||||
spec.authors = { "Alan Ott" => "alan@signal11.us",
|
||||
"Ludovic Rousseau" => "rousseau@debian.org",
|
||||
"libusb/hidapi Team" => "https://github.com/libusb/hidapi/blob/master/AUTHORS.txt",
|
||||
}
|
||||
|
||||
spec.platform = :osx
|
||||
spec.osx.deployment_target = "10.7"
|
||||
|
||||
spec.source = { :git => "https://github.com/libusb/hidapi.git", :tag => "hidapi-#{spec.version}" }
|
||||
|
||||
spec.source_files = "mac/hid.c", "hidapi/hidapi.h", "mac/hidapi_darwin.h"
|
||||
|
||||
spec.public_header_files = "hidapi/hidapi.h", "mac/hidapi_darwin.h"
|
||||
|
||||
spec.frameworks = "IOKit", "CoreFoundation", "AppKit"
|
||||
|
||||
end
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
+1963
-869
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
# HIDAPI Doxygen output
|
||||
|
||||
This site is dedicated to hosting an [API reference for the HIDAPI library](#API).
|
||||
|
||||
For general information, see the [source repository](https://github.com/libusb/hidapi#readme).
|
||||
|
||||
There are also build instructions hosted on github:
|
||||
|
||||
- [Building from source](https://github.com/libusb/hidapi/blob/master/BUILD.md)
|
||||
- [Using CMake](https://github.com/libusb/hidapi/blob/master/BUILD.cmake.md)
|
||||
- [Using Autotools (deprecated)](https://github.com/libusb/hidapi/blob/master/BUILD.autotools.md)
|
||||
|
||||
\example test.c contains a basic example usage of the HIDAPI library.
|
||||
+261
-58
@@ -5,9 +5,9 @@
|
||||
Alan Ott
|
||||
Signal 11 Software
|
||||
|
||||
8/22/2009
|
||||
libusb/hidapi Team
|
||||
|
||||
Copyright 2009, All Rights Reserved.
|
||||
Copyright 2023, All Rights Reserved.
|
||||
|
||||
At the discretion of the user of this library,
|
||||
this software may be licensed under the terms of the
|
||||
@@ -29,36 +29,123 @@
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#ifdef SDL_hidapi_h_
|
||||
#define SDL_HIDAPI_IMPLEMENTATION
|
||||
#define hid_device_info SDL_hid_device_info
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(NAMESPACE) && !defined(SDL_HIDAPI_IMPLEMENTATION) /* SDL: don't export hidapi syms */
|
||||
/* #480: this is to be refactored properly for v1.0 */
|
||||
#ifdef _WIN32
|
||||
#ifndef HID_API_NO_EXPORT_DEFINE
|
||||
#define HID_API_EXPORT __declspec(dllexport)
|
||||
#define HID_API_CALL
|
||||
#else
|
||||
#endif
|
||||
#endif
|
||||
#ifndef HID_API_EXPORT
|
||||
#define HID_API_EXPORT /**< API export macro */
|
||||
#endif
|
||||
#ifndef HID_API_CALL
|
||||
#define HID_API_CALL /**< API call macro */
|
||||
#endif
|
||||
#define HID_API_EXPORT /**< API export macro */
|
||||
#endif
|
||||
/* To be removed in v1.0 */
|
||||
#define HID_API_CALL /**< API call macro */
|
||||
|
||||
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
|
||||
|
||||
#if defined(__cplusplus) && !defined(NAMESPACE)
|
||||
/** @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 14
|
||||
/** @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 Coverts a version as Major/Minor/Patch into a number:
|
||||
<8 bit major><16 bit minor><8 bit patch>.
|
||||
|
||||
This macro was added in version 0.12.0.
|
||||
|
||||
Convenient function to be used for compile-time checks, like:
|
||||
@code{.c}
|
||||
#if HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
|
||||
@endcode
|
||||
|
||||
@ingroup API
|
||||
*/
|
||||
#define HID_API_MAKE_VERSION(mj, mn, p) (((mj) << 24) | ((mn) << 8) | (p))
|
||||
|
||||
/** @brief Static/compile-time version of the library.
|
||||
|
||||
This macro was added in version 0.12.0.
|
||||
|
||||
@see @ref HID_API_MAKE_VERSION.
|
||||
|
||||
@ingroup API
|
||||
*/
|
||||
#define HID_API_VERSION HID_API_MAKE_VERSION(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH)
|
||||
|
||||
/** @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)
|
||||
|
||||
/** @brief Maximum expected HID Report descriptor size in bytes.
|
||||
|
||||
Since version 0.13.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 13, 0)
|
||||
|
||||
@ingroup API
|
||||
*/
|
||||
#define HID_API_MAX_REPORT_DESCRIPTOR_SIZE 4096
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef NAMESPACE
|
||||
namespace NAMESPACE {
|
||||
#endif
|
||||
/** A structure to hold the version numbers. */
|
||||
struct hid_api_version {
|
||||
int major; /**< major version number */
|
||||
int minor; /**< minor version number */
|
||||
int patch; /**< patch version number */
|
||||
};
|
||||
|
||||
struct hid_device_;
|
||||
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
|
||||
|
||||
#ifndef SDL_HIDAPI_IMPLEMENTATION
|
||||
/** @brief HID underlying bus types.
|
||||
|
||||
@ingroup API
|
||||
*/
|
||||
typedef enum {
|
||||
/** Unknown bus type */
|
||||
HID_API_BUS_UNKNOWN = 0x00,
|
||||
|
||||
/** USB bus
|
||||
Specifications:
|
||||
https://usb.org/hid */
|
||||
HID_API_BUS_USB = 0x01,
|
||||
|
||||
/** Bluetooth or Bluetooth LE bus
|
||||
Specifications:
|
||||
https://www.bluetooth.com/specifications/specs/human-interface-device-profile-1-1-1/
|
||||
https://www.bluetooth.com/specifications/specs/hid-service-1-0/
|
||||
https://www.bluetooth.com/specifications/specs/hid-over-gatt-profile-1-0/ */
|
||||
HID_API_BUS_BLUETOOTH = 0x02,
|
||||
|
||||
/** I2C bus
|
||||
Specifications:
|
||||
https://docs.microsoft.com/previous-versions/windows/hardware/design/dn642101(v=vs.85) */
|
||||
HID_API_BUS_I2C = 0x03,
|
||||
|
||||
/** SPI bus
|
||||
Specifications:
|
||||
https://www.microsoft.com/download/details.aspx?id=103325 */
|
||||
HID_API_BUS_SPI = 0x04,
|
||||
} hid_bus_type;
|
||||
|
||||
/** hidapi info structure */
|
||||
struct hid_device_info {
|
||||
/** Platform-specific device path */
|
||||
@@ -77,29 +164,27 @@ namespace NAMESPACE {
|
||||
/** Product string */
|
||||
wchar_t *product_string;
|
||||
/** Usage Page for this Device/Interface
|
||||
(Windows/Mac only). */
|
||||
(Windows/Mac/hidraw only) */
|
||||
unsigned short usage_page;
|
||||
/** Usage for this Device/Interface
|
||||
(Windows/Mac only).*/
|
||||
(Windows/Mac/hidraw only) */
|
||||
unsigned short usage;
|
||||
/** The USB interface which this logical device
|
||||
represents.
|
||||
|
||||
* Valid on both Linux implementations in all cases.
|
||||
* Valid on the Windows implementation only if the device
|
||||
contains more than one interface. */
|
||||
Valid only if the device is a USB HID device.
|
||||
Set to -1 in all other cases.
|
||||
*/
|
||||
int interface_number;
|
||||
|
||||
/** Additional information about the USB interface.
|
||||
Valid on libusb and Android implementations. */
|
||||
int interface_class;
|
||||
int interface_subclass;
|
||||
int interface_protocol;
|
||||
|
||||
/** Pointer to the next device */
|
||||
struct hid_device_info *next;
|
||||
|
||||
/** Underlying bus type
|
||||
Since version 0.13.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 13, 0)
|
||||
*/
|
||||
hid_bus_type bus_type;
|
||||
};
|
||||
#endif /* !SDL_HIDAPI_IMPLEMENTATION */
|
||||
|
||||
|
||||
/** @brief Initialize the HIDAPI library.
|
||||
@@ -115,6 +200,7 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns 0 on success and -1 on error.
|
||||
Call hid_error(NULL) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT HID_API_CALL hid_init(void);
|
||||
|
||||
@@ -126,7 +212,7 @@ namespace NAMESPACE {
|
||||
|
||||
@ingroup API
|
||||
|
||||
@returns
|
||||
@returns
|
||||
This function returns 0 on success and -1 on error.
|
||||
*/
|
||||
int HID_API_EXPORT HID_API_CALL hid_exit(void);
|
||||
@@ -146,21 +232,25 @@ namespace NAMESPACE {
|
||||
@param product_id The Product ID (PID) of the types of
|
||||
device to open.
|
||||
|
||||
@returns
|
||||
This function returns a pointer to a linked list of type
|
||||
struct #hid_device_info, containing information about the HID devices
|
||||
attached to the system, or NULL in the case of failure. Free
|
||||
this linked list by calling hid_free_enumeration().
|
||||
@returns
|
||||
This function returns a pointer to a linked list of type
|
||||
struct #hid_device_info, containing information about the HID devices
|
||||
attached to the system,
|
||||
or NULL in the case of failure or if no HID devices present in the system.
|
||||
Call hid_error(NULL) to get the failure reason.
|
||||
|
||||
@note The returned value by this function must to be freed by calling hid_free_enumeration(),
|
||||
when not needed anymore.
|
||||
*/
|
||||
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
|
||||
|
||||
/** @brief Free an enumeration Linked List
|
||||
|
||||
This function frees a linked list created by hid_enumerate().
|
||||
This function frees a linked list created by hid_enumerate().
|
||||
|
||||
@ingroup API
|
||||
@param devs Pointer to a list of struct_device returned from
|
||||
hid_enumerate().
|
||||
@param devs Pointer to a list of struct_device returned from
|
||||
hid_enumerate().
|
||||
*/
|
||||
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
|
||||
|
||||
@@ -174,11 +264,15 @@ namespace NAMESPACE {
|
||||
@param vendor_id The Vendor ID (VID) of the device to open.
|
||||
@param product_id The Product ID (PID) of the device to open.
|
||||
@param serial_number The Serial Number of the device to open
|
||||
(Optionally NULL).
|
||||
(Optionally NULL).
|
||||
|
||||
@returns
|
||||
This function returns a pointer to a #hid_device object on
|
||||
success or NULL on failure.
|
||||
Call hid_error(NULL) to get the failure reason.
|
||||
|
||||
@note The returned object must be freed by calling hid_close(),
|
||||
when not needed anymore.
|
||||
*/
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
|
||||
|
||||
@@ -189,13 +283,17 @@ namespace NAMESPACE {
|
||||
Linux).
|
||||
|
||||
@ingroup API
|
||||
@param path The path name of the device to open
|
||||
@param path The path name of the device to open
|
||||
|
||||
@returns
|
||||
This function returns a pointer to a #hid_device object on
|
||||
success or NULL on failure.
|
||||
Call hid_error(NULL) to get the failure reason.
|
||||
|
||||
@note The returned object must be freed by calling hid_close(),
|
||||
when not needed anymore.
|
||||
*/
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bExclusive /* = false */);
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
|
||||
|
||||
/** @brief Write an Output report to a HID device.
|
||||
|
||||
@@ -222,6 +320,7 @@ namespace NAMESPACE {
|
||||
@returns
|
||||
This function returns the actual number of bytes written and
|
||||
-1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length);
|
||||
|
||||
@@ -241,7 +340,9 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns the actual number of bytes read and
|
||||
-1 on error. If no packet was available to be read within
|
||||
-1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
If no packet was available to be read within
|
||||
the timeout period, this function returns 0.
|
||||
*/
|
||||
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
|
||||
@@ -249,7 +350,7 @@ namespace NAMESPACE {
|
||||
/** @brief Read an Input report from a HID device.
|
||||
|
||||
Input reports are returned
|
||||
to the host through the INTERRUPT IN endpoint. The first byte will
|
||||
to the host through the INTERRUPT IN endpoint. The first byte will
|
||||
contain the Report number if the device uses numbered reports.
|
||||
|
||||
@ingroup API
|
||||
@@ -261,7 +362,9 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns the actual number of bytes read and
|
||||
-1 on error. If no packet was available to be read and
|
||||
-1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
If no packet was available to be read and
|
||||
the handle is in non-blocking mode, this function returns 0.
|
||||
*/
|
||||
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length);
|
||||
@@ -283,6 +386,7 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns 0 on success and -1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock);
|
||||
|
||||
@@ -311,6 +415,7 @@ namespace NAMESPACE {
|
||||
@returns
|
||||
This function returns the actual number of bytes written and
|
||||
-1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length);
|
||||
|
||||
@@ -336,9 +441,38 @@ namespace NAMESPACE {
|
||||
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.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
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.
|
||||
|
||||
Since version 0.10.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 10, 0)
|
||||
|
||||
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 dev 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.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
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.
|
||||
|
||||
@ingroup API
|
||||
@@ -355,6 +489,7 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns 0 on success and -1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen);
|
||||
|
||||
@@ -367,6 +502,7 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns 0 on success and -1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen);
|
||||
|
||||
@@ -379,9 +515,27 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns 0 on success and -1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen);
|
||||
|
||||
/** @brief Get The struct #hid_device_info from a HID device.
|
||||
|
||||
Since version 0.13.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 13, 0)
|
||||
|
||||
@ingroup API
|
||||
@param dev A device handle returned from hid_open().
|
||||
|
||||
@returns
|
||||
This function returns a pointer to the struct #hid_device_info
|
||||
for this hid_device, or NULL in the case of failure.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
This struct is valid until the device is closed with hid_close().
|
||||
|
||||
@note The returned object is owned by the @p dev, and SHOULD NOT be freed by the user.
|
||||
*/
|
||||
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_get_device_info(hid_device *dev);
|
||||
|
||||
/** @brief Get a string from a HID device, based on its string index.
|
||||
|
||||
@ingroup API
|
||||
@@ -392,30 +546,79 @@ namespace NAMESPACE {
|
||||
|
||||
@returns
|
||||
This function returns 0 on success and -1 on error.
|
||||
Call hid_error(dev) to get the failure reason.
|
||||
*/
|
||||
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
|
||||
|
||||
/** @brief Get a string describing the last error which occurred.
|
||||
/** @brief Get a report descriptor from a HID device.
|
||||
|
||||
Since version 0.14.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 14, 0)
|
||||
|
||||
User has to provide a preallocated buffer where descriptor will be copied to.
|
||||
The recommended size for preallocated buffer is @ref HID_API_MAX_REPORT_DESCRIPTOR_SIZE bytes.
|
||||
|
||||
@ingroup API
|
||||
@param dev A device handle returned from hid_open().
|
||||
@param buf The buffer to copy descriptor into.
|
||||
@param buf_size The size of the buffer in bytes.
|
||||
|
||||
@returns
|
||||
This function returns a string containing the last error
|
||||
which occurred or NULL if none has occurred.
|
||||
This function returns non-negative number of bytes actually copied, or -1 on error.
|
||||
*/
|
||||
int HID_API_EXPORT_CALL hid_get_report_descriptor(hid_device *dev, unsigned char *buf, size_t buf_size);
|
||||
|
||||
/** @brief Get a string describing the last error which occurred.
|
||||
|
||||
This function is intended for logging/debugging purposes.
|
||||
|
||||
This function guarantees to never return NULL.
|
||||
If there was no error in the last function call -
|
||||
the returned string clearly indicates that.
|
||||
|
||||
Any HIDAPI function that can explicitly indicate an execution failure
|
||||
(e.g. by an error code, or by returning NULL) - may set the error string,
|
||||
to be returned by this function.
|
||||
|
||||
Strings returned from hid_error() must not be freed by the user,
|
||||
i.e. owned by HIDAPI library.
|
||||
Device-specific error string may remain allocated at most until hid_close() is called.
|
||||
Global error string may remain allocated at most until hid_exit() is called.
|
||||
|
||||
@ingroup API
|
||||
@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() or hid_enumerate()).
|
||||
|
||||
@returns
|
||||
A string describing the last error (if any).
|
||||
*/
|
||||
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
|
||||
|
||||
#if defined(__IOS__) || defined(__TVOS__)
|
||||
HID_API_EXPORT void HID_API_CALL hid_ble_scan(int active);
|
||||
#endif
|
||||
/** @brief Get a runtime version of the library.
|
||||
|
||||
#if defined(__cplusplus) && !defined(NAMESPACE)
|
||||
}
|
||||
#endif
|
||||
#ifdef NAMESPACE
|
||||
This function is thread-safe.
|
||||
|
||||
@ingroup API
|
||||
|
||||
@returns
|
||||
Pointer to statically allocated struct, that contains version.
|
||||
*/
|
||||
HID_API_EXPORT const struct hid_api_version* HID_API_CALL hid_version(void);
|
||||
|
||||
|
||||
/** @brief Get a runtime version string of the library.
|
||||
|
||||
This function is thread-safe.
|
||||
|
||||
@ingroup API
|
||||
|
||||
@returns
|
||||
Pointer to statically allocated string, that contains version string.
|
||||
*/
|
||||
HID_API_EXPORT const char* HID_API_CALL hid_version_str(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
Debug
|
||||
Release
|
||||
*.exp
|
||||
*.ilk
|
||||
*.lib
|
||||
*.suo
|
||||
*.vcproj.*
|
||||
*.ncb
|
||||
*.suo
|
||||
*.dll
|
||||
*.pdb
|
||||
*.o
|
||||
.deps/
|
||||
.libs/
|
||||
hidtest-hidraw
|
||||
hidtest-libusb
|
||||
hidtest
|
||||
@@ -0,0 +1,40 @@
|
||||
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
|
||||
project(hidtest C)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
# hidtest is build as a standalone project
|
||||
|
||||
if(POLICY CMP0074)
|
||||
# allow using hidapi_ROOT if CMake supports it
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
endif()
|
||||
|
||||
find_package(hidapi 0.12 REQUIRED)
|
||||
message(STATUS "Using HIDAPI: ${hidapi_VERSION}")
|
||||
else()
|
||||
# hidtest is built as part of the main HIDAPI build
|
||||
message(STATUS "Building hidtest")
|
||||
endif()
|
||||
|
||||
set(HIDAPI_HIDTEST_TARGETS)
|
||||
if(NOT WIN32 AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
if(TARGET hidapi::hidraw)
|
||||
add_executable(hidtest_hidraw test.c)
|
||||
target_link_libraries(hidtest_hidraw hidapi::hidraw)
|
||||
list(APPEND HIDAPI_HIDTEST_TARGETS hidtest_hidraw)
|
||||
endif()
|
||||
if(TARGET hidapi::libusb)
|
||||
add_executable(hidtest_libusb test.c)
|
||||
target_compile_definitions(hidtest_libusb PRIVATE USING_HIDAPI_LIBUSB)
|
||||
target_link_libraries(hidtest_libusb hidapi::libusb)
|
||||
list(APPEND HIDAPI_HIDTEST_TARGETS hidtest_libusb)
|
||||
endif()
|
||||
else()
|
||||
add_executable(hidtest test.c)
|
||||
target_link_libraries(hidtest hidapi::hidapi)
|
||||
list(APPEND HIDAPI_HIDTEST_TARGETS hidtest)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${HIDAPI_HIDTEST_TARGETS}
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
)
|
||||
@@ -4,17 +4,25 @@ AM_CPPFLAGS = -I$(top_srcdir)/hidapi/
|
||||
if OS_LINUX
|
||||
noinst_PROGRAMS = hidtest-libusb hidtest-hidraw
|
||||
|
||||
hidtest_hidraw_SOURCES = hidtest.cpp
|
||||
hidtest_hidraw_SOURCES = test.c
|
||||
hidtest_hidraw_LDADD = $(top_builddir)/linux/libhidapi-hidraw.la
|
||||
|
||||
hidtest_libusb_SOURCES = hidtest.cpp
|
||||
hidtest_libusb_SOURCES = test.c
|
||||
hidtest_libusb_LDADD = $(top_builddir)/libusb/libhidapi-libusb.la
|
||||
else
|
||||
|
||||
# Other OS's
|
||||
noinst_PROGRAMS = hidtest
|
||||
|
||||
hidtest_SOURCES = hidtest.cpp
|
||||
hidtest_SOURCES = test.c
|
||||
hidtest_LDADD = $(top_builddir)/$(backend)/libhidapi.la
|
||||
|
||||
endif
|
||||
|
||||
if OS_DARWIN
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/mac/
|
||||
endif
|
||||
|
||||
if OS_WINDOWS
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/windows/
|
||||
endif
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
/*******************************************************
|
||||
Windows HID simplification
|
||||
|
||||
Alan Ott
|
||||
Signal 11 Software
|
||||
|
||||
8/22/2009
|
||||
|
||||
Copyright 2009
|
||||
|
||||
This contents of this file may be used by anyone
|
||||
for any reason without any conditions and may be
|
||||
used as a starting point for your own applications
|
||||
which use HIDAPI.
|
||||
********************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "hidapi.h"
|
||||
|
||||
// Headers needed for sleeping.
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int res;
|
||||
unsigned char buf[256];
|
||||
#define MAX_STR 255
|
||||
wchar_t wstr[MAX_STR];
|
||||
hid_device *handle;
|
||||
int i;
|
||||
|
||||
#ifdef WIN32
|
||||
UNREFERENCED_PARAMETER(argc);
|
||||
UNREFERENCED_PARAMETER(argv);
|
||||
#endif
|
||||
|
||||
struct hid_device_info *devs, *cur_dev;
|
||||
|
||||
if (hid_init())
|
||||
return -1;
|
||||
|
||||
devs = hid_enumerate(0x0, 0x0);
|
||||
cur_dev = devs;
|
||||
while (cur_dev) {
|
||||
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
|
||||
printf("\n");
|
||||
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
|
||||
printf(" Product: %ls\n", cur_dev->product_string);
|
||||
printf(" Release: %hx\n", cur_dev->release_number);
|
||||
printf(" Interface: %d\n", cur_dev->interface_number);
|
||||
printf("\n");
|
||||
cur_dev = cur_dev->next;
|
||||
}
|
||||
hid_free_enumeration(devs);
|
||||
|
||||
// Set up the command buffer.
|
||||
memset(buf,0x00,sizeof(buf));
|
||||
buf[0] = 0x01;
|
||||
buf[1] = 0x81;
|
||||
|
||||
|
||||
// Open the device using the VID, PID,
|
||||
// and optionally the Serial number.
|
||||
////handle = hid_open(0x4d8, 0x3f, L"12345");
|
||||
handle = hid_open(0x4d8, 0x3f, NULL);
|
||||
if (!handle) {
|
||||
printf("unable to open device\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read the Manufacturer String
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read manufacturer string\n");
|
||||
printf("Manufacturer String: %ls\n", wstr);
|
||||
|
||||
// Read the Product String
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_product_string(handle, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read product string\n");
|
||||
printf("Product String: %ls\n", wstr);
|
||||
|
||||
// Read the Serial Number String
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read serial number string\n");
|
||||
printf("Serial Number String: (%d) %ls", wstr[0], wstr);
|
||||
printf("\n");
|
||||
|
||||
// Read Indexed String 1
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read indexed string 1\n");
|
||||
printf("Indexed String 1: %ls\n", wstr);
|
||||
|
||||
// Set the hid_read() function to be non-blocking.
|
||||
hid_set_nonblocking(handle, 1);
|
||||
|
||||
// Try to read from the device. There shoud be no
|
||||
// data here, but execution should not block.
|
||||
res = hid_read(handle, buf, 17);
|
||||
|
||||
// Send a Feature Report to the device
|
||||
buf[0] = 0x2;
|
||||
buf[1] = 0xa0;
|
||||
buf[2] = 0x0a;
|
||||
buf[3] = 0x00;
|
||||
buf[4] = 0x00;
|
||||
res = hid_send_feature_report(handle, buf, 17);
|
||||
if (res < 0) {
|
||||
printf("Unable to send a feature report.\n");
|
||||
}
|
||||
|
||||
memset(buf,0,sizeof(buf));
|
||||
|
||||
// Read a Feature Report from the device
|
||||
buf[0] = 0x2;
|
||||
res = hid_get_feature_report(handle, buf, sizeof(buf));
|
||||
if (res < 0) {
|
||||
printf("Unable to get a feature report.\n");
|
||||
printf("%ls", hid_error(handle));
|
||||
}
|
||||
else {
|
||||
// Print out the returned buffer.
|
||||
printf("Feature Report\n ");
|
||||
for (i = 0; i < res; i++)
|
||||
printf("%02hhx ", buf[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
memset(buf,0,sizeof(buf));
|
||||
|
||||
// Toggle LED (cmd 0x80). The first byte is the report number (0x1).
|
||||
buf[0] = 0x1;
|
||||
buf[1] = 0x80;
|
||||
res = hid_write(handle, buf, 17);
|
||||
if (res < 0) {
|
||||
printf("Unable to write()\n");
|
||||
printf("Error: %ls\n", hid_error(handle));
|
||||
}
|
||||
|
||||
|
||||
// Request state (cmd 0x81). The first byte is the report number (0x1).
|
||||
buf[0] = 0x1;
|
||||
buf[1] = 0x81;
|
||||
hid_write(handle, buf, 17);
|
||||
if (res < 0)
|
||||
printf("Unable to write() (2)\n");
|
||||
|
||||
// Read requested state. hid_read() has been set to be
|
||||
// non-blocking by the call to hid_set_nonblocking() above.
|
||||
// This loop demonstrates the non-blocking nature of hid_read().
|
||||
res = 0;
|
||||
while (res == 0) {
|
||||
res = hid_read(handle, buf, sizeof(buf));
|
||||
if (res == 0)
|
||||
printf("waiting...\n");
|
||||
if (res < 0)
|
||||
printf("Unable to read()\n");
|
||||
#ifdef WIN32
|
||||
Sleep(500);
|
||||
#else
|
||||
usleep(500*1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("Data read:\n ");
|
||||
// Print out the returned buffer.
|
||||
for (i = 0; i < res; i++)
|
||||
printf("%02hhx ", buf[i]);
|
||||
printf("\n");
|
||||
|
||||
hid_close(handle);
|
||||
|
||||
/* Free static HIDAPI objects. */
|
||||
hid_exit();
|
||||
|
||||
#ifdef WIN32
|
||||
system("pause");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/*******************************************************
|
||||
HIDAPI - Multi-Platform library for
|
||||
communication with HID devices.
|
||||
|
||||
Alan Ott
|
||||
Signal 11 Software
|
||||
|
||||
libusb/hidapi Team
|
||||
|
||||
Copyright 2022.
|
||||
|
||||
This contents of this file may be used by anyone
|
||||
for any reason without any conditions and may be
|
||||
used as a starting point for your own applications
|
||||
which use HIDAPI.
|
||||
********************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <hidapi.h>
|
||||
|
||||
// Headers needed for sleeping.
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
// Fallback/example
|
||||
#ifndef HID_API_MAKE_VERSION
|
||||
#define HID_API_MAKE_VERSION(mj, mn, p) (((mj) << 24) | ((mn) << 8) | (p))
|
||||
#endif
|
||||
#ifndef HID_API_VERSION
|
||||
#define HID_API_VERSION HID_API_MAKE_VERSION(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH)
|
||||
#endif
|
||||
|
||||
//
|
||||
// Sample using platform-specific headers
|
||||
#if defined(__APPLE__) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
|
||||
#include <hidapi_darwin.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
|
||||
#include <hidapi_winapi.h>
|
||||
#endif
|
||||
|
||||
#if defined(USING_HIDAPI_LIBUSB) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
|
||||
#include <hidapi_libusb.h>
|
||||
#endif
|
||||
//
|
||||
|
||||
const char *hid_bus_name(hid_bus_type bus_type) {
|
||||
static const char *const HidBusTypeName[] = {
|
||||
"Unknown",
|
||||
"USB",
|
||||
"Bluetooth",
|
||||
"I2C",
|
||||
"SPI",
|
||||
};
|
||||
|
||||
if ((int)bus_type < 0)
|
||||
bus_type = HID_API_BUS_UNKNOWN;
|
||||
if ((int)bus_type >= (int)(sizeof(HidBusTypeName) / sizeof(HidBusTypeName[0])))
|
||||
bus_type = HID_API_BUS_UNKNOWN;
|
||||
|
||||
return HidBusTypeName[bus_type];
|
||||
}
|
||||
|
||||
void print_device(struct hid_device_info *cur_dev) {
|
||||
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
|
||||
printf("\n");
|
||||
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
|
||||
printf(" Product: %ls\n", cur_dev->product_string);
|
||||
printf(" Release: %hx\n", cur_dev->release_number);
|
||||
printf(" Interface: %d\n", cur_dev->interface_number);
|
||||
printf(" Usage (page): 0x%hx (0x%hx)\n", cur_dev->usage, cur_dev->usage_page);
|
||||
printf(" Bus type: %d (%s)\n", cur_dev->bus_type, hid_bus_name(cur_dev->bus_type));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_hid_report_descriptor_from_device(hid_device *device) {
|
||||
unsigned char descriptor[HID_API_MAX_REPORT_DESCRIPTOR_SIZE];
|
||||
int res = 0;
|
||||
|
||||
printf(" Report Descriptor: ");
|
||||
res = hid_get_report_descriptor(device, descriptor, sizeof(descriptor));
|
||||
if (res < 0) {
|
||||
printf("error getting: %ls", hid_error(device));
|
||||
}
|
||||
else {
|
||||
printf("(%d bytes)", res);
|
||||
}
|
||||
for (int i = 0; i < res; i++) {
|
||||
if (i % 10 == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
printf("0x%02x, ", descriptor[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_hid_report_descriptor_from_path(const char *path) {
|
||||
hid_device *device = hid_open_path(path);
|
||||
if (device) {
|
||||
print_hid_report_descriptor_from_device(device);
|
||||
hid_close(device);
|
||||
}
|
||||
else {
|
||||
printf(" Report Descriptor: Unable to open device by path\n");
|
||||
}
|
||||
}
|
||||
|
||||
void print_devices(struct hid_device_info *cur_dev) {
|
||||
for (; cur_dev; cur_dev = cur_dev->next) {
|
||||
print_device(cur_dev);
|
||||
}
|
||||
}
|
||||
|
||||
void print_devices_with_descriptor(struct hid_device_info *cur_dev) {
|
||||
for (; cur_dev; cur_dev = cur_dev->next) {
|
||||
print_device(cur_dev);
|
||||
print_hid_report_descriptor_from_path(cur_dev->path);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
int res;
|
||||
unsigned char buf[256];
|
||||
#define MAX_STR 255
|
||||
wchar_t wstr[MAX_STR];
|
||||
hid_device *handle;
|
||||
int i;
|
||||
|
||||
struct hid_device_info *devs;
|
||||
|
||||
printf("hidapi test/example tool. Compiled with hidapi version %s, runtime version %s.\n", HID_API_VERSION_STR, hid_version_str());
|
||||
if (HID_API_VERSION == HID_API_MAKE_VERSION(hid_version()->major, hid_version()->minor, hid_version()->patch)) {
|
||||
printf("Compile-time version matches runtime version of hidapi.\n\n");
|
||||
}
|
||||
else {
|
||||
printf("Compile-time version is different than runtime version of hidapi.\n]n");
|
||||
}
|
||||
|
||||
if (hid_init())
|
||||
return -1;
|
||||
|
||||
#if defined(__APPLE__) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
|
||||
// To work properly needs to be called before hid_open/hid_open_path after hid_init.
|
||||
// Best/recommended option - call it right after hid_init.
|
||||
hid_darwin_set_open_exclusive(0);
|
||||
#endif
|
||||
|
||||
devs = hid_enumerate(0x0, 0x0);
|
||||
print_devices_with_descriptor(devs);
|
||||
hid_free_enumeration(devs);
|
||||
|
||||
// Set up the command buffer.
|
||||
memset(buf,0x00,sizeof(buf));
|
||||
buf[0] = 0x01;
|
||||
buf[1] = 0x81;
|
||||
|
||||
|
||||
// Open the device using the VID, PID,
|
||||
// and optionally the Serial number.
|
||||
////handle = hid_open(0x4d8, 0x3f, L"12345");
|
||||
handle = hid_open(0x4d8, 0x3f, NULL);
|
||||
if (!handle) {
|
||||
printf("unable to open device\n");
|
||||
hid_exit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read the Manufacturer String
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read manufacturer string\n");
|
||||
printf("Manufacturer String: %ls\n", wstr);
|
||||
|
||||
// Read the Product String
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_product_string(handle, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read product string\n");
|
||||
printf("Product String: %ls\n", wstr);
|
||||
|
||||
// Read the Serial Number String
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read serial number string\n");
|
||||
printf("Serial Number String: (%d) %ls\n", wstr[0], wstr);
|
||||
|
||||
print_hid_report_descriptor_from_device(handle);
|
||||
|
||||
struct hid_device_info* info = hid_get_device_info(handle);
|
||||
if (info == NULL) {
|
||||
printf("Unable to get device info\n");
|
||||
} else {
|
||||
print_devices(info);
|
||||
}
|
||||
|
||||
// Read Indexed String 1
|
||||
wstr[0] = 0x0000;
|
||||
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
|
||||
if (res < 0)
|
||||
printf("Unable to read indexed string 1\n");
|
||||
printf("Indexed String 1: %ls\n", wstr);
|
||||
|
||||
// Set the hid_read() function to be non-blocking.
|
||||
hid_set_nonblocking(handle, 1);
|
||||
|
||||
// Try to read from the device. There should be no
|
||||
// data here, but execution should not block.
|
||||
res = hid_read(handle, buf, 17);
|
||||
|
||||
// Send a Feature Report to the device
|
||||
buf[0] = 0x2;
|
||||
buf[1] = 0xa0;
|
||||
buf[2] = 0x0a;
|
||||
buf[3] = 0x00;
|
||||
buf[4] = 0x00;
|
||||
res = hid_send_feature_report(handle, buf, 17);
|
||||
if (res < 0) {
|
||||
printf("Unable to send a feature report.\n");
|
||||
}
|
||||
|
||||
memset(buf,0,sizeof(buf));
|
||||
|
||||
// Read a Feature Report from the device
|
||||
buf[0] = 0x2;
|
||||
res = hid_get_feature_report(handle, buf, sizeof(buf));
|
||||
if (res < 0) {
|
||||
printf("Unable to get a feature report: %ls\n", hid_error(handle));
|
||||
}
|
||||
else {
|
||||
// Print out the returned buffer.
|
||||
printf("Feature Report\n ");
|
||||
for (i = 0; i < res; i++)
|
||||
printf("%02x ", (unsigned int) buf[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
memset(buf,0,sizeof(buf));
|
||||
|
||||
// Toggle LED (cmd 0x80). The first byte is the report number (0x1).
|
||||
buf[0] = 0x1;
|
||||
buf[1] = 0x80;
|
||||
res = hid_write(handle, buf, 17);
|
||||
if (res < 0) {
|
||||
printf("Unable to write(): %ls\n", hid_error(handle));
|
||||
}
|
||||
|
||||
|
||||
// Request state (cmd 0x81). The first byte is the report number (0x1).
|
||||
buf[0] = 0x1;
|
||||
buf[1] = 0x81;
|
||||
hid_write(handle, buf, 17);
|
||||
if (res < 0) {
|
||||
printf("Unable to write()/2: %ls\n", hid_error(handle));
|
||||
}
|
||||
|
||||
// Read requested state. hid_read() has been set to be
|
||||
// non-blocking by the call to hid_set_nonblocking() above.
|
||||
// This loop demonstrates the non-blocking nature of hid_read().
|
||||
res = 0;
|
||||
i = 0;
|
||||
while (res == 0) {
|
||||
res = hid_read(handle, buf, sizeof(buf));
|
||||
if (res == 0) {
|
||||
printf("waiting...\n");
|
||||
}
|
||||
if (res < 0) {
|
||||
printf("Unable to read(): %ls\n", hid_error(handle));
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
if (i >= 10) { /* 10 tries by 500 ms - 5 seconds of waiting*/
|
||||
printf("read() timeout\n");
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
Sleep(500);
|
||||
#else
|
||||
usleep(500*1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (res > 0) {
|
||||
printf("Data read:\n ");
|
||||
// Print out the returned buffer.
|
||||
for (i = 0; i < res; i++)
|
||||
printf("%02x ", (unsigned int) buf[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
hid_close(handle);
|
||||
|
||||
/* Free static HIDAPI objects. */
|
||||
hid_exit();
|
||||
|
||||
#ifdef _WIN32
|
||||
system("pause");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
###########################################
|
||||
# Simple Makefile for HIDAPI test program
|
||||
#
|
||||
# Alan Ott
|
||||
# Signal 11 Software
|
||||
# 2010-07-03
|
||||
###########################################
|
||||
|
||||
all: hidtest
|
||||
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
COBJS=hid.o
|
||||
CPPOBJS=../hidtest/hidtest.o
|
||||
OBJS=$(COBJS) $(CPPOBJS)
|
||||
CFLAGS+=-I../hidapi -Wall -g -c
|
||||
LIBS=-framework CoreBluetooth -framework CoreFoundation
|
||||
|
||||
|
||||
hidtest: $(OBJS)
|
||||
g++ -Wall -g $^ $(LIBS) -o hidtest
|
||||
|
||||
$(COBJS): %.o: %.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
$(CPPOBJS): %.o: %.cpp
|
||||
$(CXX) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o hidtest $(CPPOBJS)
|
||||
|
||||
.PHONY: clean
|
||||
@@ -1,9 +0,0 @@
|
||||
lib_LTLIBRARIES = libhidapi.la
|
||||
libhidapi_la_SOURCES = hid.m
|
||||
libhidapi_la_LDFLAGS = $(LTLDFLAGS)
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/hidapi/
|
||||
|
||||
hdrdir = $(includedir)/hidapi
|
||||
hdr_HEADERS = $(top_srcdir)/hidapi/hidapi.h
|
||||
|
||||
EXTRA_DIST = Makefile-manual
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
*.o
|
||||
*.so
|
||||
*.la
|
||||
*.lo
|
||||
*.a
|
||||
.libs
|
||||
.deps
|
||||
hidtest-libusb
|
||||
@@ -0,0 +1,107 @@
|
||||
cmake_minimum_required(VERSION 3.6.3 FATAL_ERROR)
|
||||
|
||||
list(APPEND HIDAPI_PUBLIC_HEADERS "hidapi_libusb.h")
|
||||
|
||||
add_library(hidapi_libusb
|
||||
${HIDAPI_PUBLIC_HEADERS}
|
||||
hid.c
|
||||
)
|
||||
target_link_libraries(hidapi_libusb PUBLIC hidapi_include)
|
||||
|
||||
if(TARGET usb-1.0)
|
||||
target_link_libraries(hidapi_libusb PRIVATE usb-1.0)
|
||||
else()
|
||||
include(FindPkgConfig)
|
||||
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.9)
|
||||
target_link_libraries(hidapi_libusb PRIVATE PkgConfig::libusb)
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(hidapi_libusb PRIVATE Threads::Threads)
|
||||
|
||||
if(HIDAPI_NO_ICONV)
|
||||
target_compile_definitions(hidapi_libusb PRIVATE NO_ICONV)
|
||||
else()
|
||||
if(NOT ANDROID)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.11)
|
||||
message(STATUS "Check for Iconv")
|
||||
find_package(Iconv)
|
||||
if(Iconv_FOUND)
|
||||
if(NOT Iconv_IS_BUILT_IN)
|
||||
target_link_libraries(hidapi_libusb PRIVATE Iconv::Iconv)
|
||||
set(CMAKE_REQUIRED_LIBRARIES "Iconv::Iconv")
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
set(HIDAPI_NEED_EXPORT_ICONV TRUE PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Iconv Explicitly check '-liconv'")
|
||||
# Sometime the build environment is not setup
|
||||
# in a way CMake can find Iconv on its own by default.
|
||||
# But if we simply link against iconv (-liconv), the build may succeed
|
||||
# due to other compiler/link flags.
|
||||
set(CMAKE_REQUIRED_LIBRARIES "iconv")
|
||||
check_c_source_compiles("
|
||||
#include <stddef.h>
|
||||
#include <iconv.h>
|
||||
int main() {
|
||||
char *a, *b;
|
||||
size_t i, j;
|
||||
iconv_t ic;
|
||||
ic = iconv_open(\"to\", \"from\");
|
||||
iconv(ic, &a, &i, &b, &j);
|
||||
iconv_close(ic);
|
||||
}
|
||||
"
|
||||
Iconv_EXPLICITLY_AT_ENV)
|
||||
if(Iconv_EXPLICITLY_AT_ENV)
|
||||
message(STATUS "Iconv Explicitly check '-liconv' - Available")
|
||||
target_link_libraries(hidapi_libusb PRIVATE iconv)
|
||||
else()
|
||||
message(FATAL_ERROR "Iconv is not found, make sure to provide it in the build environment")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
# otherwise there is 2 options:
|
||||
# 1) iconv is provided by Standard C library and the build will be just fine
|
||||
# 2) The _user_ has to provide additiona compilation options for this project/target
|
||||
endif()
|
||||
|
||||
# check for error: "conflicting types for 'iconv'"
|
||||
check_c_source_compiles("#include<iconv.h>
|
||||
extern size_t iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
|
||||
int main() {}"
|
||||
HIDAPI_ICONV_CONST)
|
||||
if(HIDAPI_ICONV_CONST)
|
||||
target_compile_definitions(hidapi_libusb PRIVATE "ICONV_CONST=const")
|
||||
endif()
|
||||
else()
|
||||
# On Android Iconv is disabled on the code level anyway, so no issue;
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set_target_properties(hidapi_libusb
|
||||
PROPERTIES
|
||||
EXPORT_NAME "libusb"
|
||||
OUTPUT_NAME "hidapi-libusb"
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}"
|
||||
)
|
||||
|
||||
# compatibility with find_package()
|
||||
add_library(hidapi::libusb ALIAS hidapi_libusb)
|
||||
# compatibility with raw library link
|
||||
add_library(hidapi-libusb ALIAS hidapi_libusb)
|
||||
|
||||
if(HIDAPI_INSTALL_TARGETS)
|
||||
install(TARGETS hidapi_libusb EXPORT hidapi
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/hidapi"
|
||||
)
|
||||
endif()
|
||||
|
||||
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-libusb.pc.in")
|
||||
@@ -10,6 +10,10 @@ ifeq ($(OS), FreeBSD)
|
||||
FILE=Makefile.freebsd
|
||||
endif
|
||||
|
||||
ifeq ($(OS), Haiku)
|
||||
FILE=Makefile.haiku
|
||||
endif
|
||||
|
||||
ifeq ($(FILE), )
|
||||
all:
|
||||
$(error Your platform ${OS} is not supported by hidapi/libusb at this time.)
|
||||
|
||||
@@ -21,7 +21,14 @@ libhidapi_la_LDFLAGS = $(LTLDFLAGS)
|
||||
libhidapi_la_LIBADD = $(LIBS_LIBUSB)
|
||||
endif
|
||||
|
||||
if OS_HAIKU
|
||||
lib_LTLIBRARIES = libhidapi.la
|
||||
libhidapi_la_SOURCES = hid.c
|
||||
libhidapi_la_LDFLAGS = $(LTLDFLAGS)
|
||||
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
|
||||
|
||||
@@ -13,20 +13,16 @@ libs: libhidapi.so
|
||||
CC ?= cc
|
||||
CFLAGS ?= -Wall -g -fPIC
|
||||
|
||||
CXX ?= c++
|
||||
CXXFLAGS ?= -Wall -g
|
||||
|
||||
COBJS = hid.o
|
||||
CPPOBJS = ../hidtest/hidtest.o
|
||||
OBJS = $(COBJS) $(CPPOBJS)
|
||||
INCLUDES = -I../hidapi -I/usr/local/include
|
||||
COBJS = hid.o ../hidtest/test.o
|
||||
OBJS = $(COBJS)
|
||||
INCLUDES = -I../hidapi -I. -I/usr/local/include
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
LIBS = -lusb -liconv -pthread
|
||||
|
||||
|
||||
# Console Test Program
|
||||
hidtest: $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
|
||||
|
||||
# Shared Libs
|
||||
libhidapi.so: $(COBJS)
|
||||
@@ -36,9 +32,6 @@ libhidapi.so: $(COBJS)
|
||||
$(COBJS): %.o: %.c
|
||||
$(CC) $(CFLAGS) -c $(INCLUDES) $< -o $@
|
||||
|
||||
$(CPPOBJS): %.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $(INCLUDES) $< -o $@
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) hidtest libhidapi.so ../hidtest/hidtest.o
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
###########################################
|
||||
# Simple Makefile for HIDAPI test program
|
||||
#
|
||||
# Alan Ott
|
||||
# Signal 11 Software
|
||||
# 2010-06-01
|
||||
###########################################
|
||||
|
||||
all: hidtest libs
|
||||
|
||||
libs: libhidapi.so
|
||||
|
||||
CC ?= cc
|
||||
CFLAGS ?= -Wall -g -fPIC
|
||||
|
||||
COBJS = hid.o ../hidtest/test.o
|
||||
OBJS = $(COBJS)
|
||||
INCLUDES = -I../hidapi -I. -I/usr/local/include
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
LIBS = -lusb -liconv -pthread
|
||||
|
||||
|
||||
# Console Test Program
|
||||
hidtest: $(OBJS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
|
||||
|
||||
# Shared Libs
|
||||
libhidapi.so: $(COBJS)
|
||||
$(CC) $(LDFLAGS) -shared -Wl,-soname,$@.0 $^ -o $@ $(LIBS)
|
||||
|
||||
# Objects
|
||||
$(COBJS): %.o: %.c
|
||||
$(CC) $(CFLAGS) -c $(INCLUDES) $< -o $@
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) hidtest libhidapi.so ../hidtest/hidtest.o
|
||||
|
||||
.PHONY: clean libs
|
||||
@@ -13,23 +13,19 @@ libs: libhidapi-libusb.so
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -g -fpic
|
||||
|
||||
CXX ?= g++
|
||||
CXXFLAGS ?= -Wall -g -fpic
|
||||
|
||||
LDFLAGS ?= -Wall -g
|
||||
|
||||
COBJS_LIBUSB = hid.o
|
||||
COBJS = $(COBJS_LIBUSB)
|
||||
CPPOBJS = ../hidtest/hidtest.o
|
||||
OBJS = $(COBJS) $(CPPOBJS)
|
||||
COBJS = $(COBJS_LIBUSB) ../hidtest/test.o
|
||||
OBJS = $(COBJS)
|
||||
LIBS_USB = `pkg-config libusb-1.0 --libs` -lrt -lpthread
|
||||
LIBS = $(LIBS_USB)
|
||||
INCLUDES ?= -I../hidapi `pkg-config libusb-1.0 --cflags`
|
||||
INCLUDES ?= -I../hidapi -I. `pkg-config libusb-1.0 --cflags`
|
||||
|
||||
|
||||
# Console Test Program
|
||||
hidtest-libusb: $(COBJS_LIBUSB) $(CPPOBJS)
|
||||
$(CXX) $(LDFLAGS) $^ $(LIBS_USB) -o $@
|
||||
hidtest-libusb: $(COBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(LIBS_USB) -o $@
|
||||
|
||||
# Shared Libs
|
||||
libhidapi-libusb.so: $(COBJS_LIBUSB)
|
||||
@@ -39,9 +35,6 @@ libhidapi-libusb.so: $(COBJS_LIBUSB)
|
||||
$(COBJS): %.o: %.c
|
||||
$(CC) $(CFLAGS) -c $(INCLUDES) $< -o $@
|
||||
|
||||
$(CPPOBJS): %.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $(INCLUDES) $< -o $@
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) hidtest-libusb libhidapi-libusb.so ../hidtest/hidtest.o
|
||||
|
||||
+648
-677
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
||||
/*******************************************************
|
||||
HIDAPI - Multi-Platform library for
|
||||
communication with HID devices.
|
||||
|
||||
libusb/hidapi Team
|
||||
|
||||
Copyright 2021, All Rights Reserved.
|
||||
|
||||
At the discretion of the user of this library,
|
||||
this software may be licensed under the terms of the
|
||||
GNU General Public License v3, a BSD-Style license, or the
|
||||
original HIDAPI license as outlined in the LICENSE.txt,
|
||||
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
|
||||
files located at the root of the source distribution.
|
||||
These files may also be found in the public source
|
||||
code repository located at:
|
||||
https://github.com/libusb/hidapi .
|
||||
********************************************************/
|
||||
|
||||
/** @file
|
||||
* @defgroup API hidapi API
|
||||
|
||||
* Since version 0.11.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 11, 0).
|
||||
*/
|
||||
|
||||
#ifndef HIDAPI_LIBUSB_H__
|
||||
#define HIDAPI_LIBUSB_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hidapi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Open a HID device using libusb_wrap_sys_device.
|
||||
See https://libusb.sourceforge.io/api-1.0/group__libusb__dev.html#ga98f783e115ceff4eaf88a60e6439563c,
|
||||
for details on libusb_wrap_sys_device.
|
||||
|
||||
@ingroup API
|
||||
@param sys_dev Platform-specific file descriptor that can be recognised by libusb.
|
||||
@param interface_num USB interface number of the device to be used as HID interface.
|
||||
Pass -1 to select first HID interface of the device.
|
||||
|
||||
@returns
|
||||
This function returns a pointer to a #hid_device object on
|
||||
success or NULL on failure.
|
||||
*/
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_libusb_wrap_sys_device(intptr_t sys_dev, int interface_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,3 +0,0 @@
|
||||
|
||||
#define NAMESPACE HIDUSB
|
||||
#include "hid.c"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user