Add termux-usb library #204
Open
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
It contains the following functions:
These functions are replacements for the corresponding libusb_* functions, kind of. The termux variants uses structs like struct termux_usb_device and struct termux_usb_config_descriptor that are similar, but not identical, to libusb_device and
libusb_config_descriptor. They work by calling termux-api and get back information about devices and configs as a protobuf stream.
The free functions also frees all array elements, whereas the libusb variants only frees elements that have a reference count of 1 or less. For the termux variants where do not keep track of the reference count, so information that should be kept around should be memcpy'ed or similar before termux_usb_free_* is called.
termux_usb_open requires user interaction. It calls termux-api which opens the device through the android API, which shows a prompt to the user to accept or deny opening the device.
See the accompanying termux-api PR for the other side of the coin: termux/termux-api#759
I also have two test programs that I will incorperate in a testsuite later: https://github.com/Grimler91/termux-api-package/tree/usb-protobuf-with-test-programs