libusb specific implementation details

This document details implementation details specific to libusb, used on all platforms with USB interactions.

libusb context management

All system resources with libusb are represented using a libusb_context instance, opened using libusb_init. Cahute stores this as a context pointer; see Context pointers for more information.

Note

libusb can provide logs through a callback, using libusb_set_log_cb. However, instead of taking a cookie, this callback takes the libusb context, so matching it to a Cahute context would require a global mapping.

See #80 for more information.

USB device detection using libusb

Cahute can use libusb to detect USB devices, using cahute_libusb_detect_usb().

This function gets the device list using libusb_get_device_list, then browses it. If an entry matches one of the entries in USB detection for CASIO calculators, then it is yielded.

Note

libusb requires opening the device with libusb_open in order to get a string descriptor using control flows. Thus, we cannot use iManufacturer to distinguish between models.