The Pedigree Project  0.1
Usb.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef USB_H
21 #define USB_H
22 
23 #include "pedigree/kernel/processor/types.h"
24 
25 // PID types, ordered as they appear in the EHCI spec
26 enum UsbPid
27 {
28  // Token PID Types
29  UsbPidOut = 0xe1,
30  UsbPidIn = 0x69,
31  UsbPidSOF = 0xa5,
32  UsbPidSetup = 0x2d,
33 
34  // Data PID Types
35  UsbPidData0 = 0xc3,
36  UsbPidData1 = 0x4b,
37  UsbPidData2 = 0x87,
38  UsbPidMdata = 0x0f,
39 
40  // Handshake PID Types
41  UsbPidAck = 0xd2,
42  UsbPidNak = 0x5a,
43  UsbPidStall = 0x1e,
44  UsbPidNyet = 0x96,
45 
46  // Special PID Types
47  UsbPidPre = 0x3c, // Token
48  UsbPidErr = 0x3c, // Handshake
49  UsbPidSplit = 0x78,
50  UsbPidPing = 0xb4,
51  UsbPidRsvd = 0xf0
52 };
53 
54 enum UsbSpeed
55 {
56  LowSpeed = 0,
57  FullSpeed,
58  HighSpeed,
59  SuperSpeed
60 };
61 
62 enum UsbError
63 {
64  Stall = 1,
65  NakNyet,
66  Timeout,
67  Babble,
68  CrcError,
69  TransactionError
70 };
71 
73 {
74  inline UsbEndpoint()
75  : nAddress(0), nEndpoint(0), speed(LowSpeed), nMaxPacketSize(8),
76  nHubAddress(0), nHubPort(0)
77  {
78  }
79  inline UsbEndpoint(
80  uint8_t address, uint8_t hubPort, uint8_t endpoint, UsbSpeed _speed,
81  size_t maxPacketSize)
82  : nAddress(address), nEndpoint(endpoint), speed(_speed),
83  nMaxPacketSize(maxPacketSize), nHubAddress(0), nHubPort(hubPort)
84  {
85  }
86 
87  uint8_t nAddress;
88  uint8_t nEndpoint;
89  UsbSpeed speed;
90  size_t nMaxPacketSize;
91  uint8_t nHubAddress;
92  uint8_t nHubPort;
93 };
94 
95 #endif