Skip to content

Commit c19ae12

Browse files
author
braewoods
authored
NetBSD: Initial UHID native backend implementation (#612)
1 parent 4009466 commit c19ae12

File tree

6 files changed

+1263
-0
lines changed

6 files changed

+1263
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ elseif(NOT WIN32)
4242
option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON)
4343
option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON)
4444
endif()
45+
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
46+
option(HIDAPI_WITH_NETBSD "Build NetBSD/UHID implementation of HIDAPI" ON)
47+
endif()
4548
endif()
4649

4750
option(BUILD_SHARED_LIBS "Build shared version of the libraries, otherwise build statically" ON)

netbsd/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.6.3 FATAL_ERROR)
2+
3+
add_library(hidapi_netbsd
4+
${HIDAPI_PUBLIC_HEADERS}
5+
hid.c
6+
)
7+
target_link_libraries(hidapi_netbsd PUBLIC hidapi_include)
8+
9+
find_package(Threads REQUIRED)
10+
11+
target_link_libraries(hidapi_netbsd PRIVATE Threads::Threads)
12+
13+
set_target_properties(hidapi_netbsd
14+
PROPERTIES
15+
EXPORT_NAME "netbsd"
16+
OUTPUT_NAME "hidapi-netbsd"
17+
VERSION ${PROJECT_VERSION}
18+
SOVERSION ${PROJECT_VERSION_MAJOR}
19+
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}"
20+
)
21+
22+
# compatibility with find_package()
23+
add_library(hidapi::netbsd ALIAS hidapi_netbsd)
24+
# compatibility with raw library link
25+
add_library(hidapi-netbsd ALIAS hidapi_netbsd)
26+
27+
if(HIDAPI_INSTALL_TARGETS)
28+
install(TARGETS hidapi_netbsd EXPORT hidapi
29+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
30+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
31+
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/hidapi"
32+
)
33+
endif()
34+
35+
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-netbsd.pc.in")

netbsd/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Implementation Notes
2+
--------------------
3+
NetBSD maps every `uhidev` device to one or more `uhid`
4+
devices. Each `uhid` device only supports one report ID.
5+
The parent device `uhidev` creates one `uhid` device per
6+
report ID found in the hardware's report descriptor.
7+
8+
In the event there are no report ID(s) found within the
9+
report descriptor, only one `uhid` device with a report ID
10+
of `0` is created.
11+
12+
In order to remain compatible with existing `hidapi` APIs,
13+
all the `uhid` devices created by the parent `uhidev` device
14+
must be opened under the same `hid_device` instance to ensure
15+
that we can route reports to their appropriate `uhid` device.
16+
17+
Internally the `uhid` driver will insert the report ID as
18+
needed so we must also omit the report ID in any situation
19+
where the `hidapi` API expects it to be included in the
20+
report data stream.
21+
22+
Given the design of `uhid`, it must be augmented with extra
23+
platform specific APIs to ensure that the exact relationship
24+
between `uhidev` devices and `uhid` devices can be determined.
25+
26+
The NetBSD implementation does this via the `drvctl` kernel
27+
driver. At present there is no known way to do this on OpenBSD
28+
for a `uhid` implementation to be at the same level as the
29+
NetBSD one.

0 commit comments

Comments
 (0)