Version v2.0.0
co_usb is an asynchronous USB library using C++20 coroutines and Capy to
create a high-level interface for libusb. It provides lightweight and feature-rich
adaptors around libusb API to enable easy integration into the coroutine ecosystem.
libusb asynchronous code is very efficient, but because it is a C library it is lacking in ergonomics when
put into modern C++20 project, especially one utilizing coroutines. This library serves as a bridge between
Capy based coroutine ecosystem and libusb asynchronous code.
- Asynchronous transfer submission for partial and complete I/O in a form of light adaptor types
- Hotplug API for dynamically connecting devices with an Asio style acceptor loop
- Wrappers around core
libusbentities such as devices for smooth initialization of the library - Event handler system for easy extension and safe shutdown
- Querying information for devices and endpoint
- Iteration over device list
- Generally, everything that does not relate to asynchronous operations
Not all USB code needs a whole networking library. Using Capy allows the user to choose not to use networking code and just keep the coroutines.
If you need to use networking I advise use co_usb with Corosio,
since both operate on shared Capy concepts the code is easily made interoperable.
To use it in your vcpkg-based projects, do the following:
- Add portfile and vcpkg.json to your
portsdirectory - Copy Capy port to your
portsdirectory and provide it as an overlay - Add
co_usbas a dependency to yourvcpkg.jsonascousb
The library will be available in CMake as the following:
find_package(co_usb CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE co_usb::co_usb)For non-vcpkg projects, you will have to use CMake's FetchContent module and provide
Capy and libusb on your own. This is method of consuming co_usb is not endorsed and may not work.
include(FetchContent)
FetchContent_Declare(co_usb
GIT_REPOSITORY https://github.com/gubnik/co_usb.git
GIT_TAG master
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(co_usb)
target_link_libraries(my_app co_usb::co_usb)To build from source:
cmake --preset="$PRESET"
cmake --build "build/$PRESET" --config "$BUILD_TYPE"
Available presets are:
x64-linuxx64-linux-static(udevis disabled in port for static builds)no-vcpkg(used by docs CI)
Native Windows builds are coming soon.
Available build types are: Release, Debug
See docs for generated docs
For unit tests, see ./tests. For QEMU device code, see ./qemu.
I will gladly accept contributions to the testing suite.
Source code of the library is distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at https://www.boost.org/LICENSE_1_0.txt)
QEMU devices code at qemu/ is distributed under GNU General Public License v3.
(See accompanying file qemu/LICENSE.md or copy at
https://www.gnu.org/licenses/gpl-3.0.md)