{"id":15634185,"url":"https://github.com/karalabe/usb","last_synced_at":"2025-05-16T09:04:29.936Z","repository":{"id":36002830,"uuid":"189414521","full_name":"karalabe/usb","owner":"karalabe","description":"Self contained USB and HID library for Go","archived":false,"fork":false,"pushed_at":"2024-01-23T14:11:43.000Z","size":1071,"stargazers_count":161,"open_issues_count":13,"forks_count":39,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-09T04:01:49.844Z","etag":null,"topics":["go","golang","hid","hidapi","libusb","usb"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karalabe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-30T12:59:51.000Z","updated_at":"2025-04-05T16:23:05.000Z","dependencies_parsed_at":"2024-06-18T12:42:09.859Z","dependency_job_id":"5ba11da8-bca2-4491-a959-29de6ff1dad2","html_url":"https://github.com/karalabe/usb","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karalabe%2Fusb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karalabe%2Fusb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karalabe%2Fusb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karalabe%2Fusb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karalabe","download_url":"https://codeload.github.com/karalabe/usb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501557,"owners_count":22081528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","hid","hidapi","libusb","usb"],"created_at":"2024-10-03T10:52:09.894Z","updated_at":"2025-05-16T09:04:27.887Z","avatar_url":"https://github.com/karalabe.png","language":"C","readme":"[![Travis][travisimg]][travisurl]\n[![AppVeyor][appveyorimg]][appveyorurl]\n[![GoDoc][docimg]][docurl]\n\n[travisimg]:   https://travis-ci.org/karalabe/usb.svg?branch=master\n[travisurl]:   https://travis-ci.org/karalabe/usb\n[appveyorimg]: https://ci.appveyor.com/api/projects/status/u96eq262bj2itprh/branch/master?svg=true\n[appveyorurl]: https://ci.appveyor.com/project/karalabe/usb\n[docimg]:      https://godoc.org/github.com/karalabe/usb?status.svg\n[docurl]:      https://godoc.org/github.com/karalabe/usb\n\n# Yet another USB library for Go\n\nThe `usb` package is a cross platform, fully self-contained library for accessing and communicating with USB devices **either via HID or low level interrupts**. The goal of the library was to create a simple way to find-, attach to- and read/write form USB devices.\n\nThere are multiple already existing USB libraries:\n\n * The original `gousb` package [created by @kylelemons](https://github.com/kylelemons/gousb) and nowadays [maintained by @google](https://github.com/google/gousb) is a CGO wrapper around `libusb`. It is the most advanced USB library for Go out there.\n   * Unfortunately, `gousb` requires the `libusb` C library to be installed both during build as well as during runtime on the host operating system. This breaks binary portability and also adds unnecessary hurdles on Windows.\n   * Furthermore, whilst HID devices are supported by `libusb`, the OS on Macos and Windows explicitly takes over these devices, so only native system calls can be used on recent versions (i.e. you **cannot** use `libusb` for HID).\n * There is a fork of `gousb` [created by @karalabe](https://github.com/karalabe/gousb) that statically linked `libusb` during build, but with the lack of HID access, that work was abandoned.\n * For HID-only devices, a previous self-contained package was created at [`github.com/karalabe/hid`](https://github.com/karalabe/hid), which worked well for hardware wallet uses cases in [`go-ethereum`](https://github.com/ethereum/go-ethereum). It's a simple package that does its thing well.\n   * Unfortunately, `hid` is not capable of talking to generic USB devices. When multiple different devices are needed, eventually some will not support the HID spec (e.g. WebUSB). Pulling in both `hid` and `gousb` will break down due to both depending internally on different versions of `libusb` on Linux.\n\nThis `usb` package is a proper integration of `hidapi` and `libusb` so that communication with HID devices is done via system calls, whereas communication with lower level USB devices is done via interrupts. All this detail is hidden away behind a tiny interface.\n\nThe package supports Linux, macOS, Windows and FreeBSD. Exclude constraints are also specified for Android and iOS to allow smoother vendoring into cross platform projects.\n\n## Cross-compiling\n\nUsing `go get`, the embedded C library is compiled into the binary format of your host OS. Cross compiling to a different platform or architecture entails disabling CGO by default in Go, causing device enumeration `hid.Enumerate()` to yield no results.\n\nTo cross compile a functional version of this library, you'll need to enable CGO during cross compilation via `CGO_ENABLED=1` and you'll need to install and set a cross compilation enabled C toolkit via `CC=your-cross-gcc`.\n\n## Acknowledgements\n\nAlthough the `usb` package is an implementation from scratch, HID support was heavily inspired by the existing [`go.hid`](https://github.com/GeertJohan/go.hid) library, which seems abandoned since 2015; is incompatible with Go 1.6+; and has various external dependencies.\n\nWide character support in the HID support is done via the [`gowchar`](https://github.com/orofarne/gowchar) library, unmaintained since 2013; non buildable with a modern Go release and failing `go vet` checks. As such, `gowchar` was also vendored in inline.\n\nError handling for the `libusb` integration originates from the [`gousb`](https://github.com/google/gousb) library.\n\n## License\n\nThis USB library is licensed under the [GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.en.html) (dictated by libusb).\n\nIf you are only interested in Human Interface devices, a less restrictive package can be found at [`github.com/karalabe/hid`](https://github.com/karalabe/hid).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaralabe%2Fusb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaralabe%2Fusb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaralabe%2Fusb/lists"}