Skip to content

Commit

Permalink
add HID over GATT protocol on Zephyr implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
benedekkupper committed Dec 31, 2023
1 parent 1e6bb65 commit 67fc673
Show file tree
Hide file tree
Showing 8 changed files with 1,197 additions and 10 deletions.
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,44 @@ C libraries of similar functionality.

### Device classes

* Human Interface Device Class (HID) specification version 1.11 (HID over I2C transport also supported)
#### HID - Human Interface Device Class

HID specification version 1.11 is fully supported, with extensive report descriptor tooling
via [hid-rp][hid-rp] library.
HID has outgrown itself from a pure USB class to a transport-independent protocol,
and so this library also provides alternative transports for HID applications,
which interact with the same high-level application API.
The additional transport layers supported are:
* BLE (HID over GATT Protocol)
* I2C

### Platforms

* NXP MCUs supported via `kusb_mac` (see [c2usb/port/nxp](c2usb/port/nxp))
* Zephyr RTOS supported via `udc_mac` (see [c2usb/port/zephyr](c2usb/port/zephyr))
* support the project to see more!

### Vendor extensions

* Microsoft OS descriptors version 2.0
* Microsoft XBOX-360 controller interface
#### Microsoft OS descriptors

### Platforms
Microsoft OS descriptors version 2.0 is supported.
The main motivation to support this functionality is because
MS likes to make everybody else's life difficult.
In the case of USB, this means that in many cases the USB standardized device classes
don't get the correct OS driver assigned (even if it's available on the system, such as CDC-NCM on Windows 10),
or get a downgraded driver instead (such as HID gamepads getting DirectInput driver, except if manufactured by MS, see xinputhid.inf),
or no driver at all.
The only possible solution to deal with these is using [Windows Compatible IDs][WCID].
This is stored in the USB device's descriptors, and tells Windows which driver to load for the given USB function.

* NXP MCUs supported via `kusb_mac`
* Zephyr OS supported via `udc_mac`
* support the project to see more!
#### Microsoft XBOX-360 controller interface

Microsoft XBOX-360 gamepad controller interface is implemented to leverage XInput driver on Windows
for gamepad applications without any user step. Combining this with Microsoft OS descriptors
makes it possible to have a USB device that either presents an HID or an XInput gamepad interface
towards the host computer, depending on its OS.

[project-structure]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1204r0.html
[hid-rp]: https://github.com/IntergatedCircuits/hid-rp
[WCID]: https://github.com/pbatard/libwdi/wiki/WCID-Devices
4 changes: 4 additions & 0 deletions c2usb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ set(C2USB_NXP_PORT_SOURCES

set(C2USB_ZEPHYR_PORT_PUBLIC_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/port/zephyr/udc_mac.hpp
${CMAKE_CURRENT_SOURCE_DIR}/port/zephyr/bluetooth/gatt.hpp
${CMAKE_CURRENT_SOURCE_DIR}/port/zephyr/bluetooth/hid.hpp
)

set(C2USB_ZEPHYR_PORT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/port/zephyr/udc_mac.cpp
${CMAKE_CURRENT_SOURCE_DIR}/port/zephyr/bluetooth/hid.cpp
)

set(C2USB_PUBLIC_HEADERS
Expand Down Expand Up @@ -50,6 +53,7 @@ set(C2USB_PUBLIC_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/c2usb.hpp
${CMAKE_CURRENT_SOURCE_DIR}/reference_array_view.hpp
${CMAKE_CURRENT_SOURCE_DIR}/single_elem_queue.hpp
${CMAKE_CURRENT_SOURCE_DIR}/uninit_store.hpp
${C2USB_NXP_PORT_PUBLIC_HEADERS}
${C2USB_ZEPHYR_PORT_PUBLIC_HEADERS}
PARENT_SCOPE
Expand Down
4 changes: 2 additions & 2 deletions c2usb/port/zephyr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(C2USB_PATH "c2usb")
add_subdirectory(${C2USB_PATH})
# link c2usb to the abstract Zephyr interface to inherit the build flags
target_link_libraries(c2usb zephyr_interface)
target_link_libraries(c2usb PUBLIC zephyr_interface)
# link the application to c2usb
target_link_libraries(app PRIVATE
Expand All @@ -39,7 +39,7 @@ CONFIG_UDC_DRIVER=y
# RAM optimization:
# the buffer pool size can be cut down, as it's only used for control transfers
# CONFIG_UDC_BUF_POOL_SIZE=256
# CONFIG_UDC_BUF_POOL_SIZE=optimize based on your application (and check asserts)
# CONFIG_UDC_BUF_COUNT=3 + maximal used endpoint count in a configuration
```

Expand Down
Loading

0 comments on commit 67fc673

Please sign in to comment.