Prusa MINI Firmware overview
usb_ch9.h
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Contact information
19  * -------------------
20  *
21  * Circuits At Home, LTD
22  * Web : http://www.circuitsathome.com
23  * e-mail : support@circuitsathome.com
24  */
25 
26 #ifndef _usb_h_
27  #error "Never include usb_ch9.h directly; include Usb.h instead"
28 #endif
29 
30 /* USB chapter 9 structures */
31 
32 /* Misc.USB constants */
33 #define DEV_DESCR_LEN 18 //device descriptor length
34 #define CONF_DESCR_LEN 9 //configuration descriptor length
35 #define INTR_DESCR_LEN 9 //interface descriptor length
36 #define EP_DESCR_LEN 7 //endpoint descriptor length
37 
38 /* Standard Device Requests */
39 
40 #define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS
41 #define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE
42 #define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE
43 #define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS
44 #define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR
45 #define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR
46 #define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION
47 #define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION
48 #define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE
49 #define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE
50 #define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME
51 
52 #define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt
53 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up
54 #define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode
55 
56 /* Setup Data Constants */
57 
58 #define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer
59 #define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer
60 #define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard
61 #define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class
62 #define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor
63 #define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device
64 #define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface
65 #define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint
66 #define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other
67 
68 /* USB descriptors */
69 
70 #define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor.
71 #define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor.
72 #define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor.
73 #define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor.
74 #define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor.
75 #define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier.
76 #define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration.
77 #define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power.
78 #define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor.
79 
80 #define HID_DESCRIPTOR_HID 0x21
81 
82 
83 /* OTG SET FEATURE Constants */
84 #define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP
85 #define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP
86 #define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP
87 
88 /* USB Endpoint Transfer Types */
89 #define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint.
90 #define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint.
91 #define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint.
92 #define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint.
93 #define bmUSB_TRANSFER_TYPE 0x03 // bit mask to separate transfer type from ISO attributes
94 
95 
96 /* Standard Feature Selectors for CLEAR_FEATURE Requests */
97 #define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient
98 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient
99 #define USB_FEATURE_TEST_MODE 2 // Device recipient
100 
101 /* descriptor data structures */
102 
103 /* Device descriptor structure */
104 typedef struct {
105  uint8_t bLength; // Length of this descriptor.
106  uint8_t bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE).
107  uint16_t bcdUSB; // USB Spec Release Number (BCD).
108  uint8_t bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
109  uint8_t bDeviceSubClass; // Subclass code (assigned by the USB-IF).
110  uint8_t bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
111  uint8_t bMaxPacketSize0; // Maximum packet size for endpoint 0.
112  uint16_t idVendor; // Vendor ID (assigned by the USB-IF).
113  uint16_t idProduct; // Product ID (assigned by the manufacturer).
114  uint16_t bcdDevice; // Device release number (BCD).
115  uint8_t iManufacturer; // Index of String Descriptor describing the manufacturer.
116  uint8_t iProduct; // Index of String Descriptor describing the product.
117  uint8_t iSerialNumber; // Index of String Descriptor with the device's serial number.
118  uint8_t bNumConfigurations; // Number of possible configurations.
119 } __attribute__((packed)) USB_DEVICE_DESCRIPTOR;
120 
121 /* Configuration descriptor structure */
122 typedef struct {
123  uint8_t bLength; // Length of this descriptor.
124  uint8_t bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION).
125  uint16_t wTotalLength; // Total length of all descriptors for this configuration.
126  uint8_t bNumInterfaces; // Number of interfaces in this configuration.
127  uint8_t bConfigurationValue; // Value of this configuration (1 based).
128  uint8_t iConfiguration; // Index of String Descriptor describing the configuration.
129  uint8_t bmAttributes; // Configuration characteristics.
130  uint8_t bMaxPower; // Maximum power consumed by this configuration.
131 } __attribute__((packed)) USB_CONFIGURATION_DESCRIPTOR;
132 
133 /* Interface descriptor structure */
134 typedef struct {
135  uint8_t bLength; // Length of this descriptor.
136  uint8_t bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE).
137  uint8_t bInterfaceNumber; // Number of this interface (0 based).
138  uint8_t bAlternateSetting; // Value of this alternate interface setting.
139  uint8_t bNumEndpoints; // Number of endpoints in this interface.
140  uint8_t bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
141  uint8_t bInterfaceSubClass; // Subclass code (assigned by the USB-IF).
142  uint8_t bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
143  uint8_t iInterface; // Index of String Descriptor describing the interface.
144 } __attribute__((packed)) USB_INTERFACE_DESCRIPTOR;
145 
146 /* Endpoint descriptor structure */
147 typedef struct {
148  uint8_t bLength; // Length of this descriptor.
149  uint8_t bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT).
150  uint8_t bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN).
151  uint8_t bmAttributes; // Endpoint transfer type.
152  uint16_t wMaxPacketSize; // Maximum packet size.
153  uint8_t bInterval; // Polling interval in frames.
154 } __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR;
155 
156 /* HID descriptor */
157 typedef struct {
158  uint8_t bLength;
159  uint8_t bDescriptorType;
160  uint16_t bcdHID; // HID class specification release
162  uint8_t bNumDescriptors; // Number of additional class specific descriptors
163  uint8_t bDescrType; // Type of class descriptor
164  uint16_t wDescriptorLength; // Total size of the Report descriptor
165 } __attribute__((packed)) USB_HID_DESCRIPTOR;
166 
167 typedef struct {
168  uint8_t bDescrType; // Type of class descriptor
169  uint16_t wDescriptorLength; // Total size of the Report descriptor
170 } __attribute__((packed)) HID_CLASS_DESCRIPTOR_LEN_AND_TYPE;
__attribute__::bDeviceSubClass
uint8_t bDeviceSubClass
Definition: usb_ch9.h:109
__attribute__::iManufacturer
uint8_t iManufacturer
Definition: usb_ch9.h:115
__attribute__::idProduct
uint16_t idProduct
Definition: usb_ch9.h:113
__attribute__::iProduct
uint8_t iProduct
Definition: usb_ch9.h:116
__attribute__::bEndpointAddress
uint8_t bEndpointAddress
Definition: usb_ch9.h:150
__attribute__
bool boolean __attribute__((deprecated))
Definition: wiring_constants.h:110
__attribute__::bNumInterfaces
uint8_t bNumInterfaces
Definition: usb_ch9.h:126
__attribute__::bNumConfigurations
uint8_t bNumConfigurations
Definition: usb_ch9.h:118
__attribute__::bcdUSB
uint16_t bcdUSB
Definition: usb_ch9.h:107
__attribute__::bcdDevice
uint16_t bcdDevice
Definition: usb_ch9.h:114
__attribute__::bInterfaceProtocol
uint8_t bInterfaceProtocol
Definition: usb_ch9.h:142
__attribute__::bInterfaceClass
uint8_t bInterfaceClass
Definition: usb_ch9.h:140
__attribute__::bDeviceProtocol
uint8_t bDeviceProtocol
Definition: usb_ch9.h:110
__attribute__::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usb_ch9.h:152
__attribute__::bInterval
uint8_t bInterval
Definition: usb_ch9.h:153
__attribute__::iConfiguration
uint8_t iConfiguration
Definition: usb_ch9.h:128
__attribute__::bNumEndpoints
uint8_t bNumEndpoints
Definition: usb_ch9.h:139
__attribute__::bLength
uint8_t bLength
Definition: usb_ch9.h:105
uint8_t
const uint8_t[]
Definition: 404_html.c:3
__attribute__::wTotalLength
uint16_t wTotalLength
Definition: usb_ch9.h:125
__attribute__::bNumDescriptors
uint8_t bNumDescriptors
Definition: usb_ch9.h:162
__attribute__::bDeviceClass
uint8_t bDeviceClass
Definition: usb_ch9.h:108
__attribute__::bInterfaceSubClass
uint8_t bInterfaceSubClass
Definition: usb_ch9.h:141
__attribute__::bcdHID
uint16_t bcdHID
Definition: usb_ch9.h:160
__attribute__::wDescriptorLength
uint16_t wDescriptorLength
Definition: usb_ch9.h:164
__attribute__::bMaxPower
uint8_t bMaxPower
Definition: usb_ch9.h:130
__attribute__::idVendor
uint16_t idVendor
Definition: usb_ch9.h:112
__attribute__::bConfigurationValue
uint8_t bConfigurationValue
Definition: usb_ch9.h:127
__attribute__::bmAttributes
uint8_t bmAttributes
Definition: usb_ch9.h:129
__attribute__::iInterface
uint8_t iInterface
Definition: usb_ch9.h:143
__attribute__::bMaxPacketSize0
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:111
__attribute__::bCountryCode
uint8_t bCountryCode
Definition: usb_ch9.h:161
__attribute__::iSerialNumber
uint8_t iSerialNumber
Definition: usb_ch9.h:117
__attribute__::bDescriptorType
uint8_t bDescriptorType
Definition: usb_ch9.h:106
__attribute__::bDescrType
uint8_t bDescrType
Definition: usb_ch9.h:163
__attribute__::bAlternateSetting
uint8_t bAlternateSetting
Definition: usb_ch9.h:138
__attribute__::bInterfaceNumber
uint8_t bInterfaceNumber
Definition: usb_ch9.h:137