Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 2 | // |
| 3 | // Modified by FRC Team 971. |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 4 | |
| 5 | #include "glibusb_internal.h" |
| 6 | |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 7 | #include <libusb-1.0/libusb.h> |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 8 | |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 9 | #include "aos/common/logging/logging.h" |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 10 | #include "glibusb_endpoint.h" |
| 11 | |
| 12 | namespace glibusb { |
| 13 | |
| 14 | // Converts libusb endpoint address to integer |
| 15 | int DescriptorToAddress(const struct libusb_endpoint_descriptor *descriptor) { |
| 16 | return descriptor->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; |
| 17 | } |
| 18 | |
| 19 | // Converts libusb direction to UsbEndpoint direction. |
| 20 | UsbEndpoint::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. |
| 31 | UsbEndpoint::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 Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 47 | LOG(FATAL, "bogus transfer type\n"); |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | } // namespace glibusb |