initial import of hidapi netbsd uhid native backend from mainstream

c19ae126d8
https://github.com/libusb/hidapi/pull/612
main
Ozkan Sezer 2023-11-26 08:55:02 +03:00 committed by Ozkan Sezer
parent 1b284cd415
commit 2f806c89b5
8 changed files with 1290 additions and 0 deletions

View File

@ -42,6 +42,9 @@ elseif(NOT WIN32)
option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON)
option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
option(HIDAPI_WITH_NETBSD "Build NetBSD/UHID implementation of HIDAPI" ON)
endif()
endif()
option(BUILD_SHARED_LIBS "Build shared version of the libraries, otherwise build statically" ON)

View File

@ -573,6 +573,8 @@ typedef struct PLATFORM_hid_device_ PLATFORM_hid_device;
#ifdef __LINUX__
#include "SDL_hidapi_linux.h"
#elif defined(__NETBSD__)
#include "SDL_hidapi_netbsd.h"
#elif defined(__MACOS__)
#include "SDL_hidapi_mac.h"
#elif defined(__WINDOWS__) || defined(__WINGDK__)

View File

@ -0,0 +1,25 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
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.
*/
#undef HIDAPI_H__
#include "netbsd/hid.c"
#define HAVE_PLATFORM_BACKEND 1
#define udev_ctx 1

View File

@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.6.3 FATAL_ERROR)
add_library(hidapi_netbsd
${HIDAPI_PUBLIC_HEADERS}
hid.c
)
target_link_libraries(hidapi_netbsd PUBLIC hidapi_include)
find_package(Threads REQUIRED)
target_link_libraries(hidapi_netbsd PRIVATE Threads::Threads)
set_target_properties(hidapi_netbsd
PROPERTIES
EXPORT_NAME "netbsd"
OUTPUT_NAME "hidapi-netbsd"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}"
)
# compatibility with find_package()
add_library(hidapi::netbsd ALIAS hidapi_netbsd)
# compatibility with raw library link
add_library(hidapi-netbsd ALIAS hidapi_netbsd)
if(HIDAPI_INSTALL_TARGETS)
install(TARGETS hidapi_netbsd 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-netbsd.pc.in")

View File

@ -0,0 +1,29 @@
Implementation Notes
--------------------
NetBSD maps every `uhidev` device to one or more `uhid`
devices. Each `uhid` device only supports one report ID.
The parent device `uhidev` creates one `uhid` device per
report ID found in the hardware's report descriptor.
In the event there are no report ID(s) found within the
report descriptor, only one `uhid` device with a report ID
of `0` is created.
In order to remain compatible with existing `hidapi` APIs,
all the `uhid` devices created by the parent `uhidev` device
must be opened under the same `hid_device` instance to ensure
that we can route reports to their appropriate `uhid` device.
Internally the `uhid` driver will insert the report ID as
needed so we must also omit the report ID in any situation
where the `hidapi` API expects it to be included in the
report data stream.
Given the design of `uhid`, it must be augmented with extra
platform specific APIs to ensure that the exact relationship
between `uhidev` devices and `uhid` devices can be determined.
The NetBSD implementation does this via the `drvctl` kernel
driver. At present there is no known way to do this on OpenBSD
for a `uhid` implementation to be at the same level as the
NetBSD one.

1173
src/hidapi/netbsd/hid.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: hidapi-netbsd
Description: C Library for USB/Bluetooth HID device access from Linux, Mac OS X, FreeBSD, and Windows. This is the netbsd implementation.
URL: https://github.com/libusb/hidapi
Version: @VERSION@
Libs: -L${libdir} -lhidapi-netbsd
Cflags: -I${includedir}/hidapi

View File

@ -141,6 +141,18 @@ else()
set(HIDAPI_NEED_EXPORT_LIBUDEV TRUE)
endif()
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
if(NOT DEFINED HIDAPI_WITH_NETBSD)
set(HIDAPI_WITH_NETBSD ON)
endif()
if(HIDAPI_WITH_NETBSD)
add_subdirectory("${PROJECT_ROOT}/netbsd" netbsd)
list(APPEND EXPORT_COMPONENTS netbsd)
set(EXPORT_ALIAS netbsd)
if(NOT BUILD_SHARED_LIBS)
set(HIDAPI_NEED_EXPORT_THREADS TRUE)
endif()
endif()
else()
set(HIDAPI_WITH_LIBUSB ON)
endif()