blob: 3990e6a6585e02e90268d41d69ffc42f9ea77f05 [file] [log] [blame]
Brian Silverman395d6252013-09-13 20:58:14 -07001// Copyright 2012 Google Inc. All Rights Reserved.
Brian Silverman7037e872013-09-14 15:35:45 -07002//
3// Modified by FRC Team 971.
Brian Silverman395d6252013-09-13 20:58:14 -07004
5#include "glibusb_internal.h"
6
Brian Silverman7037e872013-09-14 15:35:45 -07007#include <libusb-1.0/libusb.h>
Brian Silverman395d6252013-09-13 20:58:14 -07008
Brian Silverman7037e872013-09-14 15:35:45 -07009#include "aos/common/logging/logging.h"
Brian Silverman395d6252013-09-13 20:58:14 -070010#include "glibusb_endpoint.h"
11
12namespace glibusb {
13
14// Converts libusb endpoint address to integer
15int DescriptorToAddress(const struct libusb_endpoint_descriptor *descriptor) {
16 return descriptor->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK;
17}
18
19// Converts libusb direction to UsbEndpoint direction.
20UsbEndpoint::DirectionType DescriptorToDirection(
21 const struct libusb_endpoint_descriptor *descriptor) {
22 if ((descriptor->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) ==
23 LIBUSB_ENDPOINT_IN) {
24 return UsbEndpoint::kIn;
25 } else {
26 return UsbEndpoint::kOut;
27 }
28}
29
30// Converts libusb transfer type to UsbEndpoint transfer type.
31UsbEndpoint::TransferType DescriptorToTransfer(
32 const struct libusb_endpoint_descriptor *descriptor) {
33 switch (descriptor->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) {
34 case LIBUSB_TRANSFER_TYPE_CONTROL:
35 return UsbEndpoint::kControl;
36 break;
37 case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
38 return UsbEndpoint::kIsochronous;
39 break;
40 case LIBUSB_TRANSFER_TYPE_BULK:
41 return UsbEndpoint::kBulk;
42 break;
43 case LIBUSB_TRANSFER_TYPE_INTERRUPT:
44 return UsbEndpoint::kInterrupt;
45 break;
46 default:
Brian Silverman7037e872013-09-14 15:35:45 -070047 LOG(FATAL, "bogus transfer type\n");
Brian Silverman395d6252013-09-13 20:58:14 -070048 }
49}
50
51} // namespace glibusb