ark::usb::UsbDevice

Defined in header “ark/usb/usb_device.hh”.


Connects to a USB device with the given configuration. The device will be open and ready for you to receive data from you must still explicitly request data on an entity identifier.

Entities can be discovered with lsusb and are device/use case specific.

Methods

  • UsbDevice(const UsbDeviceConfiguration & config)
    Constructor. Initializes the device.

  • ~UsbDevice()
    Destructor. Cleans up resources.

  • std::optional< size_t > interrupt_read(uint8_t endpoint_id, uint8_t * data, size_t maximum_size, std::optional< std::chrono::nanoseconds > timeout)
    Reads some number of bytes from the USB device (at most ‘maximum_bytes’) into the given buffer. Returns an empty optional if you timed out, or the number of bytes read on success.

    This is equivalent to an ‘interrupt transfer’.

  • std::optional< size_t > bulk_read(uint8_t endpoint_id, uint8_t * data, size_t maximum_size, std::optional< std::chrono::nanoseconds > timeout)
    Reads some number of bytes from the USB device (at most ‘maximum_bytes’) into the given buffer. Returns an empty optional if you timed out, or the number of bytes read on success.

    Note that ’endpoint_id’ needs to match USB conventions. This is equivalent to a ‘bulk transfer’.

  • std::optional< size_t > bulk_write(uint8_t endpoint_id, const uint8_t * data, size_t data_size, std::optional< std::chrono::nanoseconds > timeout)
    Writes ‘data_size’ bytes to the remote USB device at the given endpoint identifier. Note that ’endpoint_id’ needs to match USB conventions.

    Returns the number of bytes actually written (may not be the same as data_size). This is equivalent to a ‘bulk transfer’.

  • void checked_bulk_write(uint8_t endpoint_id, const uint8_t * data, size_t data_size, std::optional< std::chrono::nanoseconds > timeout)
    Writes ‘data_size’ bytes to the remote USB device at the given endpoint identifier. This is checked; if you don’t write the number of bytes you expect, this will throw.

  • std::optional< size_t > control(uint8_t request_type, uint8_t request, uint16_t value, void * data, size_t data_size, std::optional< std::chrono::nanoseconds > timeout)
    Executes a control transfer this will make a request of some type (either a read or a write) and then either fill in or transfer the data specified in the data structure. The return value (if any) is the number of bytes actually transferred.