XenevaOS
Loading...
Searching...
No Matches
usb.h
Go to the documentation of this file.
1//
2// usb.h
3//
4// USPi - An USB driver for Raspberry Pi written in C
5// Copyright (C) 2014 R. Stange <rsta2@o2online.de>
6//
7// This program is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19//
20#ifndef _uspi_usb_h
21#define _uspi_usb_h
22
23#include "uspi/macros.h"
24
25// PID
26typedef enum
27{
31 //USBPIDData2,
32 //USBPIDMData
33}
35
36// Device Addresses
37#define USB_DEFAULT_ADDRESS 0
38#define USB_FIRST_DEDICATED_ADDRESS 1
39#define USB_MAX_ADDRESS 127
40
41// Speed
50
51#pragma pack(push,1)
52// Setup Data
53typedef struct
54{
55 unsigned char bmRequestType;
56 unsigned char bRequest;
57 unsigned short wValue;
58 unsigned short wIndex;
59 unsigned short wLength;
60 // Data follows
62#pragma pack(pop)
63//PACKED TSetupData;
64
65// Request Types
66#define REQUEST_OUT 0
67#define REQUEST_IN 0x80
68
69#define REQUEST_CLASS 0x20
70#define REQUEST_VENDOR 0x40
71
72#define REQUEST_TO_INTERFACE 1
73#define REQUEST_TO_OTHER 3
74
75// Standard Request Codes
76#define GET_STATUS 0
77#define CLEAR_FEATURE 1
78#define SET_FEATURE 3
79#define SET_ADDRESS 5
80#define GET_DESCRIPTOR 6
81#define SET_CONFIGURATION 9
82#define SET_INTERFACE 11
83
84// Descriptor Types
85#define DESCRIPTOR_DEVICE 1
86#define DESCRIPTOR_CONFIGURATION 2
87#define DESCRIPTOR_STRING 3
88#define DESCRIPTOR_INTERFACE 4
89#define DESCRIPTOR_ENDPOINT 5
90#define DESCRIPTOR_CS_INTERFACE 36
91#define DESCRIPTOR_CS_ENDPOINT 37
92
93#define DESCRIPTOR_INDEX_DEFAULT 0
94
95#pragma pack(push,1)
96// Device Descriptor
97typedef struct
98{
99 unsigned char bLength;
100 unsigned char bDescriptorType;
101 unsigned short bcdUSB;
102 unsigned char bDeviceClass;
103 unsigned char bDeviceSubClass;
104 unsigned char bDeviceProtocol;
105 unsigned char bMaxPacketSize0;
106 #define USB_DEFAULT_MAX_PACKET_SIZE 8
107 unsigned short idVendor;
108 unsigned short idProduct;
109 unsigned short bcdDevice;
110 unsigned char iManufacturer;
111 unsigned char iProduct;
112 unsigned char iSerialNumber;
113 unsigned char bNumConfigurations;
115#pragma pack(pop)
116//PACKED TUSBDeviceDescriptor;
117
118#pragma pack(push,1)
119// Configuration Descriptor
120typedef struct
121{
122 unsigned char bLength;
123 unsigned char bDescriptorType;
124 unsigned short wTotalLength;
125 unsigned char bNumInterfaces;
126 unsigned char bConfigurationValue;
127 unsigned char iConfiguration;
128 unsigned char bmAttributes;
129 unsigned char bMaxPower;
131#pragma pack(pop)
132
133//PACKED TUSBConfigurationDescriptor;
134
135#pragma pack(push,1)
136// Interface Descriptor
137typedef struct
138{
139 unsigned char bLength;
140 unsigned char bDescriptorType;
141 unsigned char bInterfaceNumber;
142 unsigned char bAlternateSetting;
143 unsigned char bNumEndpoints;
144 unsigned char bInterfaceClass;
145 unsigned char bInterfaceSubClass;
146 unsigned char bInterfaceProtocol;
147 unsigned char iInterface;
149#pragma pack(pop)
150//PACKED TUSBInterfaceDescriptor;
151
152#pragma pack(push,1)
153// Endpoint Descriptor
154typedef struct
155{
156 unsigned char bLength;
157 unsigned char bDescriptorType;
158 unsigned char bEndpointAddress;
159 unsigned char bmAttributes;
160 unsigned short wMaxPacketSize;
161 unsigned char bInterval;
163#pragma pack(pop)
164//PACKED TUSBEndpointDescriptor;
165
166#pragma pack(push,1)
167// Audio class Endpoint Descriptor
168typedef struct
169{
170 unsigned char bLength;
171 unsigned char bDescriptorType;
172 unsigned char bEndpointAddress;
173 unsigned char bmAttributes;
174 unsigned short wMaxPacketSize;
175 unsigned char bInterval;
176 unsigned char bRefresh;
177 unsigned char bSynchAddress;
179#pragma pack(pop)
180//PACKED TUSBAudioEndpointDescriptor;
181
182#pragma pack(push,1)
183// MIDI-streaming class-specific Endpoint Descriptor
184typedef struct
185{
186 unsigned char bLength;
187 unsigned char bDescriptorType;
188 unsigned char bDescriptorSubType;
189 unsigned char bNumEmbMIDIJack;
190 unsigned char bAssocJackIDs[];
192#pragma pack(pop)
193//PACKED TUSBMIDIStreamingEndpointDescriptor;
194
195#pragma pack(push,1)
196// Descriptor union
212#pragma pack(pop)
213//PACKED TUSBDescriptor;
214
215#pragma pack(push,1)
217{
218 unsigned char bLength;
219 unsigned char bDescriptorType;
220 unsigned short bString[0];
222#pragma pack(pop)
223//PACKED TUSBStringDescriptor;
224
225#endif
TUSBPID
Definition usb.h:27
@ USBPIDSetup
Definition usb.h:28
@ USBPIDData1
Definition usb.h:30
@ USBPIDData0
Definition usb.h:29
TUSBSpeed
Definition usb.h:43
@ USBSpeedLow
Definition usb.h:44
@ USBSpeedFull
Definition usb.h:45
@ USBSpeedHigh
Definition usb.h:46
@ USBSpeedUnknown
Definition usb.h:47
Definition usb.h:54
unsigned char bmRequestType
Definition usb.h:55
unsigned char bRequest
Definition usb.h:56
unsigned short wValue
Definition usb.h:57
unsigned short wIndex
Definition usb.h:58
unsigned short wLength
Definition usb.h:59
Definition usb.h:169
unsigned char bDescriptorType
Definition usb.h:171
unsigned char bLength
Definition usb.h:170
unsigned char bEndpointAddress
Definition usb.h:172
unsigned char bSynchAddress
Definition usb.h:177
unsigned char bRefresh
Definition usb.h:176
unsigned char bInterval
Definition usb.h:175
unsigned short wMaxPacketSize
Definition usb.h:174
unsigned char bmAttributes
Definition usb.h:173
Definition usb.h:121
unsigned short wTotalLength
Definition usb.h:124
unsigned char bConfigurationValue
Definition usb.h:126
unsigned char bmAttributes
Definition usb.h:128
unsigned char bMaxPower
Definition usb.h:129
unsigned char iConfiguration
Definition usb.h:127
unsigned char bDescriptorType
Definition usb.h:123
unsigned char bNumInterfaces
Definition usb.h:125
unsigned char bLength
Definition usb.h:122
Definition usb.h:98
unsigned char bDeviceProtocol
Definition usb.h:104
unsigned char iProduct
Definition usb.h:111
unsigned char bDescriptorType
Definition usb.h:100
unsigned char bDeviceClass
Definition usb.h:102
unsigned short idProduct
Definition usb.h:108
unsigned short bcdDevice
Definition usb.h:109
unsigned short bcdUSB
Definition usb.h:101
unsigned char iManufacturer
Definition usb.h:110
unsigned short idVendor
Definition usb.h:107
unsigned char iSerialNumber
Definition usb.h:112
unsigned char bNumConfigurations
Definition usb.h:113
unsigned char bLength
Definition usb.h:99
unsigned char bMaxPacketSize0
Definition usb.h:105
unsigned char bDeviceSubClass
Definition usb.h:103
Definition usb.h:155
unsigned char bDescriptorType
Definition usb.h:157
unsigned char bmAttributes
Definition usb.h:159
unsigned char bLength
Definition usb.h:156
unsigned char bEndpointAddress
Definition usb.h:158
unsigned char bInterval
Definition usb.h:161
unsigned short wMaxPacketSize
Definition usb.h:160
Definition usb.h:138
unsigned char bNumEndpoints
Definition usb.h:143
unsigned char bInterfaceSubClass
Definition usb.h:145
unsigned char bInterfaceProtocol
Definition usb.h:146
unsigned char bInterfaceClass
Definition usb.h:144
unsigned char bDescriptorType
Definition usb.h:140
unsigned char bInterfaceNumber
Definition usb.h:141
unsigned char iInterface
Definition usb.h:147
unsigned char bLength
Definition usb.h:139
unsigned char bAlternateSetting
Definition usb.h:142
unsigned char bLength
Definition usb.h:186
unsigned char bNumEmbMIDIJack
Definition usb.h:189
unsigned char bDescriptorType
Definition usb.h:187
unsigned char bDescriptorSubType
Definition usb.h:188
Definition usb.h:217
unsigned char bLength
Definition usb.h:218
unsigned short bString[0]
Definition usb.h:220
unsigned char bDescriptorType
Definition usb.h:219
Definition usb.h:198
TUSBInterfaceDescriptor Interface
Definition usb.h:207
struct TUSBDescriptor::@474 Header
unsigned char bLength
Definition usb.h:201
TUSBEndpointDescriptor Endpoint
Definition usb.h:208
TUSBConfigurationDescriptor Configuration
Definition usb.h:206
TUSBMIDIStreamingEndpointDescriptor MIDIStreamingEndpoint
Definition usb.h:210
unsigned char bDescriptorType
Definition usb.h:202
TUSBAudioEndpointDescriptor AudioEndpoint
Definition usb.h:209