-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusb_constants.cc
109 lines (96 loc) · 2.8 KB
/
usb_constants.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mist/usb_constants.h"
#include <base/logging.h>
namespace mist {
UsbDirection GetUsbDirectionOfEndpointAddress(uint8_t endpoint_address) {
// The MSB of an endpoint address indicates the direction, and kUsbDirectionIn
// is effectively a mask to extract the MSB.
return (endpoint_address & kUsbDirectionIn) == kUsbDirectionIn
? kUsbDirectionIn
: kUsbDirectionOut;
}
const char* UsbDirectionToString(UsbDirection direction) {
switch (direction) {
case kUsbDirectionIn:
return "In";
case kUsbDirectionOut:
return "Out";
}
NOTREACHED();
return nullptr;
}
const char* UsbSpeedToString(UsbSpeed speed) {
switch (speed) {
case kUsbSpeedUnknown:
return "Unknown";
case kUsbSpeedLow:
return "Low";
case kUsbSpeedFull:
return "Full";
case kUsbSpeedHigh:
return "High";
case kUsbSpeedSuper:
return "Super";
}
NOTREACHED();
return nullptr;
}
const char* UsbTransferTypeToString(UsbTransferType transfer_type) {
switch (transfer_type) {
case kUsbTransferTypeControl:
return "Control";
case kUsbTransferTypeIsochronous:
return "Isochronous";
case kUsbTransferTypeBulk:
return "Bulk";
case kUsbTransferTypeInterrupt:
return "Interrupt";
case kUsbTransferTypeUnknown:
return "Unknown";
}
NOTREACHED();
return nullptr;
}
const char* UsbTransferStatusToString(UsbTransferStatus transfer_status) {
switch (transfer_status) {
case kUsbTransferStatusCompleted:
return "Completed";
case kUsbTransferStatusError:
return "Error";
case kUsbTransferStatusTimedOut:
return "TimedOut";
case kUsbTransferStatusCancelled:
return "Cancelled";
case kUsbTransferStatusStall:
return "Stall";
case kUsbTransferStatusNoDevice:
return "NoDevice";
case kUsbTransferStatusOverflow:
return "Overflow";
case kUsbTransferStatusUnknown:
return "Unknown";
}
NOTREACHED();
return nullptr;
}
} // namespace mist
std::ostream& operator<<(std::ostream& stream, mist::UsbDirection direction) {
stream << UsbDirectionToString(direction);
return stream;
}
std::ostream& operator<<(std::ostream& stream, mist::UsbSpeed speed) {
stream << UsbSpeedToString(speed);
return stream;
}
std::ostream& operator<<(std::ostream& stream,
mist::UsbTransferType transfer_type) {
stream << UsbTransferTypeToString(transfer_type);
return stream;
}
std::ostream& operator<<(std::ostream& stream,
mist::UsbTransferStatus transfer_status) {
stream << UsbTransferStatusToString(transfer_status);
return stream;
}