libnx v4.12.0
Loading...
Searching...
No Matches
usb.h
Go to the documentation of this file.
1/**
2 * @file usb.h
3 * @brief Common USB (usb:*) service IPC header.
4 * @author SciresM, yellows8
5 * @copyright libnx Authors
6 */
7#pragma once
8#include "../types.h"
9
10/// Names starting with "libusb" were changed to "usb" to avoid collision with actual libusb if it's ever used.
11
12/// Imported from libusb with changed names.
13/* Descriptor sizes per descriptor type */
14#define USB_DT_INTERFACE_SIZE 0x09
15#define USB_DT_ENDPOINT_SIZE 0x07
16#define USB_DT_INTERFACE_ASSOCIATION_SIZE 0x08
17#define USB_DT_DEVICE_SIZE 0x12
18#define USB_DT_HID_SIZE 0x09
19#define USB_DT_SS_ENDPOINT_COMPANION_SIZE 0x06
20
21#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
22#define USB_ENDPOINT_DIR_MASK 0x80
23
24#define USB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
25
26/// Imported from libusb, with some adjustments.
28 uint8_t bmRequestType;
29 uint8_t bRequest;
30 uint16_t wValue;
31 uint16_t wIndex;
32 uint16_t wLength;
33};
34
35/// Imported from libusb, with some adjustments.
37 uint8_t bLength;
38 uint8_t bDescriptorType; ///< Must match USB_DT_ENDPOINT.
39 uint8_t bEndpointAddress; ///< Should be one of the usb_endpoint_direction values, the endpoint-number is automatically allocated.
40 uint8_t bmAttributes;
41 uint16_t wMaxPacketSize;
42 uint8_t bInterval;
43} NX_PACKED;
44
45/// Imported from libusb, with some adjustments.
47 uint8_t bLength;
48 uint8_t bDescriptorType; ///< Must match USB_DT_INTERFACE.
49 uint8_t bInterfaceNumber; ///< See also USBDS_DEFAULT_InterfaceNumber.
50 uint8_t bAlternateSetting; ///< Must match 0.
51 uint8_t bNumEndpoints;
52 uint8_t bInterfaceClass;
53 uint8_t bInterfaceSubClass;
54 uint8_t bInterfaceProtocol;
55 uint8_t iInterface; ///< Ignored.
56};
57
58/// Imported from libusb, with some adjustments.
60 uint8_t bLength;
61 uint8_t bDescriptorType; ///< Must match USB_DT_Device.
62 uint16_t bcdUSB;
63 uint8_t bDeviceClass;
64 uint8_t bDeviceSubClass;
65 uint8_t bDeviceProtocol;
66 uint8_t bMaxPacketSize0;
67 uint16_t idVendor;
68 uint16_t idProduct;
69 uint16_t bcdDevice;
70 uint8_t iManufacturer;
71 uint8_t iProduct;
72 uint8_t iSerialNumber;
73 uint8_t bNumConfigurations;
74};
75
76/// Imported from libusb, with some adjustments.
78 uint8_t bLength;
79 uint8_t bDescriptorType;
80 uint16_t wTotalLength;
81 uint8_t bNumInterfaces;
82 uint8_t bConfigurationValue;
83 uint8_t iConfiguration;
84 uint8_t bmAttributes;
85 uint8_t MaxPower;
86} NX_PACKED;
87
88/// Imported from libusb, with some adjustments.
90 uint8_t bLength;
91 uint8_t bDescriptorType; ///< Must match USB_DT_SS_ENDPOINT_COMPANION.
92 uint8_t bMaxBurst;
93 uint8_t bmAttributes;
94 uint16_t wBytesPerInterval;
95};
96
97/// Imported from libusb, with some adjustments.
99 uint8_t bLength;
100 uint8_t bDescriptorType; ///< Must match USB_DT_STRING.
101 uint16_t wData[0x40];
102};
103
104/// Imported from libusb, with some adjustments.
106 uint8_t bLength;
107 uint8_t bDescriptorType; ///< Must match USB_DT_INTERFACE_ASSOCIATION.
108 uint8_t bFirstInterface;
109 uint8_t bInterfaceCount;
110 uint8_t bFunctionClass;
111 uint8_t bFunctionSubClass;
112 uint8_t bFunctionProtocol;
113 uint8_t iFunction;
114};
115
116/// Imported from libusb, with some adjustments.
118 uint8_t bLength;
119 uint8_t bDescriptorType; ///< Must match USB_DT_HID.
120 uint16_t bcdHID;
121 uint8_t bCountryCode;
122 uint8_t bNumDescriptors;
123 uint8_t bClassDescriptorType;
124 uint16_t wClassDescriptorLength;
125} NX_PACKED;
126
127/// Imported from libusb, with changed names.
129 USB_CLASS_PER_INTERFACE = 0,
130 USB_CLASS_AUDIO = 1,
131 USB_CLASS_COMM = 2,
132 USB_CLASS_HID = 3,
133 USB_CLASS_PHYSICAL = 5,
134 USB_CLASS_PRINTER = 7,
135 USB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
136 USB_CLASS_IMAGE = 6,
137 USB_CLASS_MASS_STORAGE = 8,
138 USB_CLASS_HUB = 9,
139 USB_CLASS_DATA = 10,
140 USB_CLASS_SMART_CARD = 0x0b,
141 USB_CLASS_CONTENT_SECURITY = 0x0d,
142 USB_CLASS_VIDEO = 0x0e,
143 USB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
144 USB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
145 USB_CLASS_WIRELESS = 0xe0,
146 USB_CLASS_APPLICATION = 0xfe,
147 USB_CLASS_VENDOR_SPEC = 0xff
148};
149
150/// Imported from libusb, with changed names.
152 USB_DT_DEVICE = 0x01,
153 USB_DT_CONFIG = 0x02,
154 USB_DT_STRING = 0x03,
155 USB_DT_INTERFACE = 0x04,
156 USB_DT_ENDPOINT = 0x05,
157 USB_DT_INTERFACE_ASSOCIATION = 0x0b,
158 USB_DT_BOS = 0x0f,
159 USB_DT_DEVICE_CAPABILITY = 0x10,
160 USB_DT_HID = 0x21,
161 USB_DT_REPORT = 0x22,
162 USB_DT_PHYSICAL = 0x23,
163 USB_DT_HUB = 0x29,
164 USB_DT_SUPERSPEED_HUB = 0x2a,
165 USB_DT_SS_ENDPOINT_COMPANION = 0x30
166};
167
168/// Imported from libusb, with changed names.
170 USB_ENDPOINT_IN = 0x80,
171 USB_ENDPOINT_OUT = 0x00
172};
173
174/// Imported from libusb, with changed names.
176 USB_TRANSFER_TYPE_CONTROL = 0,
177 USB_TRANSFER_TYPE_ISOCHRONOUS = 1,
178 USB_TRANSFER_TYPE_BULK = 2,
179 USB_TRANSFER_TYPE_INTERRUPT = 3,
180 USB_TRANSFER_TYPE_BULK_STREAM = 4,
181};
182
183/// Imported from libusb, with changed names.
185 /** Request status of the specific recipient */
187
188 /** Clear or disable a specific feature */
190
191 /* 0x02 is reserved */
192
193 /** Set or enable a specific feature */
195
196 /* 0x04 is reserved */
197
198 /** Set device address for all future accesses */
200
201 /** Get the specified descriptor */
203
204 /** Used to update existing descriptors or add new descriptors */
206
207 /** Get the current device configuration value */
209
210 /** Set device configuration */
212
213 /** Return the selected alternate setting for the specified interface */
215
216 /** Select an alternate interface for the specified interface */
218
219 /** Set then report an endpoint's synchronization frame */
221
222 /** Sets both the U1 and U2 Exit Latency */
224
225 /** Delay from the time a host transmits a packet to the time it is
226 * received by the device. */
228};
229
230/// Imported from libusb, with changed names.
232 USB_REQUEST_TYPE_STANDARD = (0x00 << 5),
233 USB_REQUEST_TYPE_CLASS = (0x01 << 5),
234 USB_REQUEST_TYPE_VENDOR = (0x02 << 5),
235 USB_REQUEST_TYPE_RESERVED = (0x03 << 5)
236};
237
238/// Imported from libusb, with changed names.
240 USB_RECIPIENT_DEVICE = 0x00,
241 USB_RECIPIENT_INTERFACE = 0x01,
242 USB_RECIPIENT_ENDPOINT = 0x02,
243 USB_RECIPIENT_OTHER = 0x03
244};
245
246/// Imported from libusb, with changed names.
248 USB_ISO_SYNC_TYPE_NONE = 0,
249 USB_ISO_SYNC_TYPE_ASYNC = 1,
250 USB_ISO_SYNC_TYPE_ADAPTIVE = 2,
251 USB_ISO_SYNC_TYPE_SYNC = 3
252};
253
254/// Imported from libusb, with changed names.
256 USB_ISO_USAGE_TYPE_DATA = 0,
257 USB_ISO_USAGE_TYPE_FEEDBACK = 1,
258 USB_ISO_USAGE_TYPE_IMPLICIT = 2,
259};
260
261/// USB Device States, per USB 2.0 spec
262typedef enum {
263 UsbState_Detached = 0, ///< Device is not attached to USB.
264 UsbState_Attached = 1, ///< Device is attached, but is not powered.
265 UsbState_Powered = 2, ///< Device is attached and powered, but has not been reset.
266 UsbState_Default = 3, ///< Device is attached, powered, and has been reset, but does not have an address.
267 UsbState_Address = 4, ///< Device is attached, powered, has been reset, has an address, but is not configured.
268 UsbState_Configured = 5, ///< Device is attached, powered, has been reset, has an address, configured, and may be used.
269 UsbState_Suspended = 6, ///< Device is attached and powered, but has not seen bus activity for 3ms. Device is suspended and cannot be used.
270} UsbState;
271
Imported from libusb, with some adjustments.
Definition usb.h:77
Imported from libusb, with some adjustments.
Definition usb.h:27
Imported from libusb, with some adjustments.
Definition usb.h:59
uint8_t bDescriptorType
Must match USB_DT_Device.
Definition usb.h:61
Imported from libusb, with some adjustments.
Definition usb.h:36
uint8_t bEndpointAddress
Should be one of the usb_endpoint_direction values, the endpoint-number is automatically allocated.
Definition usb.h:39
uint8_t bDescriptorType
Must match USB_DT_ENDPOINT.
Definition usb.h:38
Imported from libusb, with some adjustments.
Definition usb.h:117
uint8_t bDescriptorType
Must match USB_DT_HID.
Definition usb.h:119
Imported from libusb, with some adjustments.
Definition usb.h:105
uint8_t bDescriptorType
Must match USB_DT_INTERFACE_ASSOCIATION.
Definition usb.h:107
Imported from libusb, with some adjustments.
Definition usb.h:46
uint8_t iInterface
Ignored.
Definition usb.h:55
uint8_t bDescriptorType
Must match USB_DT_INTERFACE.
Definition usb.h:48
uint8_t bAlternateSetting
Must match 0.
Definition usb.h:50
uint8_t bInterfaceNumber
See also USBDS_DEFAULT_InterfaceNumber.
Definition usb.h:49
Imported from libusb, with some adjustments.
Definition usb.h:89
uint8_t bDescriptorType
Must match USB_DT_SS_ENDPOINT_COMPANION.
Definition usb.h:91
Imported from libusb, with some adjustments.
Definition usb.h:98
uint8_t bDescriptorType
Must match USB_DT_STRING.
Definition usb.h:100
#define NX_PACKED
Packs a struct so that it won't include padding bytes.
Definition types.h:63
usb_request_type
Imported from libusb, with changed names.
Definition usb.h:231
usb_class_code
Imported from libusb, with changed names.
Definition usb.h:128
usb_standard_request
Imported from libusb, with changed names.
Definition usb.h:184
@ USB_REQUEST_SET_CONFIGURATION
Set device configuration.
Definition usb.h:211
@ USB_REQUEST_SET_ADDRESS
Set device address for all future accesses.
Definition usb.h:199
@ USB_REQUEST_SYNCH_FRAME
Set then report an endpoint's synchronization frame.
Definition usb.h:220
@ USB_REQUEST_CLEAR_FEATURE
Clear or disable a specific feature.
Definition usb.h:189
@ USB_SET_ISOCH_DELAY
Delay from the time a host transmits a packet to the time it is received by the device.
Definition usb.h:227
@ USB_REQUEST_GET_INTERFACE
Return the selected alternate setting for the specified interface.
Definition usb.h:214
@ USB_REQUEST_SET_DESCRIPTOR
Used to update existing descriptors or add new descriptors.
Definition usb.h:205
@ USB_REQUEST_SET_SEL
Sets both the U1 and U2 Exit Latency.
Definition usb.h:223
@ USB_REQUEST_GET_STATUS
Request status of the specific recipient.
Definition usb.h:186
@ USB_REQUEST_SET_FEATURE
Set or enable a specific feature.
Definition usb.h:194
@ USB_REQUEST_SET_INTERFACE
Select an alternate interface for the specified interface.
Definition usb.h:217
@ USB_REQUEST_GET_DESCRIPTOR
Get the specified descriptor.
Definition usb.h:202
@ USB_REQUEST_GET_CONFIGURATION
Get the current device configuration value.
Definition usb.h:208
UsbState
USB Device States, per USB 2.0 spec.
Definition usb.h:262
@ UsbState_Default
Device is attached, powered, and has been reset, but does not have an address.
Definition usb.h:266
@ UsbState_Detached
Device is not attached to USB.
Definition usb.h:263
@ UsbState_Address
Device is attached, powered, has been reset, has an address, but is not configured.
Definition usb.h:267
@ UsbState_Powered
Device is attached and powered, but has not been reset.
Definition usb.h:265
@ UsbState_Suspended
Device is attached and powered, but has not seen bus activity for 3ms. Device is suspended and cannot...
Definition usb.h:269
@ UsbState_Configured
Device is attached, powered, has been reset, has an address, configured, and may be used.
Definition usb.h:268
@ UsbState_Attached
Device is attached, but is not powered.
Definition usb.h:264
usb_descriptor_type
Imported from libusb, with changed names.
Definition usb.h:151
usb_request_recipient
Imported from libusb, with changed names.
Definition usb.h:239
usb_endpoint_direction
Imported from libusb, with changed names.
Definition usb.h:169
usb_iso_usage_type
Imported from libusb, with changed names.
Definition usb.h:255
usb_iso_sync_type
Imported from libusb, with changed names.
Definition usb.h:247
usb_transfer_type
Imported from libusb, with changed names.
Definition usb.h:175