Skip to content

Add termux-usb library #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Grimler91
Copy link
Member

@Grimler91 Grimler91 commented Apr 3, 2025

It contains the following functions:

  • termux_usb_get_device_list
  • termux_usb_free_device_list
  • termux_usb_open
  • termux_usb_get_config_descriptor
  • termux_usb_free_config_descriptor

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

It contains the following functions:

* termux_usb_get_device_list
* termux_usb_free_device_list
* termux_usb_open
* termux_usb_get_config_descriptor
* termux_usb_free_config_descriptor

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant