forked from charlieh0tel/google-libusb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglibusb_internal.cc
49 lines (41 loc) · 1.37 KB
/
glibusb_internal.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2012 Google Inc. All Rights Reserved.
#include "glibusb_internal.h"
#include <libusb.h>
#include "glog/logging.h"
#include "glibusb_endpoint.h"
namespace glibusb {
// Converts libusb endpoint address to integer
int DescriptorToAddress(const struct libusb_endpoint_descriptor *descriptor) {
return descriptor->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK;
}
// Converts libusb direction to UsbEndpoint direction.
UsbEndpoint::DirectionType DescriptorToDirection(
const struct libusb_endpoint_descriptor *descriptor) {
if ((descriptor->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) ==
LIBUSB_ENDPOINT_IN) {
return UsbEndpoint::kIn;
} else {
return UsbEndpoint::kOut;
}
}
// Converts libusb transfer type to UsbEndpoint transfer type.
UsbEndpoint::TransferType DescriptorToTransfer(
const struct libusb_endpoint_descriptor *descriptor) {
switch (descriptor->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
return UsbEndpoint::kControl;
break;
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
return UsbEndpoint::kIsochronous;
break;
case LIBUSB_TRANSFER_TYPE_BULK:
return UsbEndpoint::kBulk;
break;
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
return UsbEndpoint::kInterrupt;
break;
default:
LOG(FATAL) << "bogus transfer type";
}
}
} // namespace glibusb