Added UsbInterface class to access non-HID USB interfaces
This commit is contained in:
52
src/DebugToolDrivers/USB/UsbInterface.hpp
Normal file
52
src/DebugToolDrivers/USB/UsbInterface.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <chrono>
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
namespace Usb
|
||||
{
|
||||
/**
|
||||
* The UsbInterface provides access to a particular USB interface.
|
||||
*/
|
||||
class UsbInterface
|
||||
{
|
||||
public:
|
||||
std::uint8_t interfaceNumber = 0;
|
||||
|
||||
UsbInterface(
|
||||
std::uint8_t interfaceNumber,
|
||||
::libusb_device_handle* deviceHandle
|
||||
);
|
||||
|
||||
UsbInterface(const UsbInterface& other) = delete;
|
||||
UsbInterface& operator = (const UsbInterface& other) = delete;
|
||||
|
||||
UsbInterface(UsbInterface&& other) = default;
|
||||
UsbInterface& operator = (UsbInterface&& other) = default;
|
||||
|
||||
/**
|
||||
* Attempts to claim the interface
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Releases the claimed interface
|
||||
*/
|
||||
void close();
|
||||
|
||||
std::vector<unsigned char> readBulk(
|
||||
std::uint8_t endpointAddress,
|
||||
std::optional<std::chrono::milliseconds> timeout = std::nullopt
|
||||
);
|
||||
|
||||
void writeBulk(std::uint8_t endpointAddress, std::vector<unsigned char>&& buffer);
|
||||
|
||||
private:
|
||||
::libusb_device_handle* deviceHandle;
|
||||
bool claimed = false;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user