blob: f87f235ec14dadcadf60174fb41fe5ea67f89b98 [file] [log] [blame]
Austin Schuh9b360e92013-03-27 04:47:04 +00001#ifndef LIBUSB_H_
2#define LIBUSB_H_
3
4#include <libusb.h>
5
6class LibUSBDeviceHandle;
7
8class LibUSB {
9 public:
10 explicit LibUSB();
11 virtual ~LibUSB();
12 // Return a device handle or NULL with the correct VID and PID.
13 LibUSBDeviceHandle *FindDeviceWithVIDPID(
14 int vid, int pid);
15
16 private:
17 libusb_context *ctx_;
18};
19
20class LibUSBDeviceHandle {
21 public:
22 virtual ~LibUSBDeviceHandle();
23 // Transfers data using an interrupt transfer.
24 int interrupt_transfer(unsigned char endpoint, unsigned char *data,
25 int length, int *transferred, unsigned int timeout);
26
27 // Transfers data using a bulk transfer.
28 int bulk_transfer(unsigned char endpoint, unsigned char *data,
29 int length, int *transferred, unsigned int timeout);
30
31 private:
32 friend class LibUSB; // For constructor
33 // Takes ownership of the device handle and frees it when destructed.
34 explicit LibUSBDeviceHandle(libusb_device_handle *dev_handle);
35 libusb_device_handle *dev_handle_;
36};
37
38#endif // LIBUSB_H_