My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

UHS_usb_ch9.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* Copyright (C) 2015-2016 Andrew J. Kroll
  2. and
  3. Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  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. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Contact information
  16. -------------------
  17. Circuits At Home, LTD
  18. Web : https://www.circuitsathome.com
  19. e-mail : support@circuitsathome.com
  20. */
  21. #if !defined(_UHS_host_h_) || defined(_UHS_ch9_h_)
  22. #error "Never include UHS_usb_ch9.h directly; include UHS_Usb.h instead"
  23. #else
  24. /* USB chapter 9 structures */
  25. #define _UHS_ch9_h_
  26. /* Misc.USB constants */
  27. #define DEV_DESCR_LEN 18 //device descriptor length
  28. #define CONF_DESCR_LEN 9 //configuration descriptor length
  29. #define INTR_DESCR_LEN 9 //interface descriptor length
  30. #define EP_DESCR_LEN 7 //endpoint descriptor length
  31. /* Standard Device Requests */
  32. #define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS
  33. #define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE
  34. #define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE
  35. #define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS
  36. #define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR
  37. #define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR
  38. #define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION
  39. #define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION
  40. #define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE
  41. #define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE
  42. #define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME
  43. /* Wireless USB Device Requests */
  44. #define USB_REQ_SET_ENCRYPTION 0x0D
  45. #define USB_REQ_GET_ENCRYPTION 0x0E
  46. #define USB_REQ_RPIPE_ABORT 0x0E
  47. #define USB_REQ_SET_HANDSHAKE 0x0F
  48. #define USB_REQ_RPIPE_RESET 0x0F
  49. #define USB_REQ_GET_HANDSHAKE 0x10
  50. #define USB_REQ_SET_CONNECTION 0x11
  51. #define USB_REQ_SET_SECURITY_DATA 0x12
  52. #define USB_REQ_GET_SECURITY_DATA 0x13
  53. #define USB_REQ_SET_WUSB_DATA 0x14
  54. #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
  55. #define USB_REQ_LOOPBACK_DATA_READ 0x16
  56. #define USB_REQ_SET_INTERFACE_DS 0x17
  57. /* USB feature flags */
  58. #define USB_DEVICE_SELF_POWERED 0 /* (read only) */
  59. #define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */
  60. #define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */
  61. #define USB_DEVICE_BATTERY 2 /* (wireless) */
  62. #define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */
  63. #define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/
  64. #define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */
  65. #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */
  66. #define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */
  67. #define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt
  68. #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up
  69. #define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode
  70. /* OTG SET FEATURE Constants */
  71. #define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP
  72. #define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP
  73. #define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP
  74. /* Setup Data Constants */
  75. #define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer
  76. #define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer
  77. #define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard
  78. #define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class
  79. #define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor
  80. #define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device
  81. #define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface
  82. #define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint
  83. #define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other
  84. #define USB_SETUP_RECIPIENT_PORT 0x04 // Wireless USB 1.0
  85. #define USB_SETUP_RECIPIENT_RPIPE 0x05 // Wireless USB 1.0
  86. /* USB descriptors */
  87. #define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor.
  88. #define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor.
  89. #define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor.
  90. #define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor.
  91. #define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor.
  92. #define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier.
  93. #define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration.
  94. #define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power.
  95. #define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor.
  96. #define USB_DESCRIPTOR_DEBUG 0x0A
  97. #define USB_DESCRIPTOR_INTERFACE_ASSOCIATION 0x0B
  98. #define USB_DESCRIPTOR_SECURITY 0x0C
  99. #define USB_DESCRIPTOR_KEY 0x0D
  100. #define USB_DESCRIPTOR_ENCRYPTION_TYPE 0x0E
  101. #define USB_DESCRIPTOR_BOS 0x0F
  102. #define USB_DESCRIPTOR_DEVICE_CAPABILITY 0x10
  103. #define USB_DESCRIPTOR_WIRELESS_ENDPOINT_COMP 0x11
  104. #define USB_DESCRIPTOR_WIRE_ADAPTER 0x21
  105. #define USB_DESCRIPTOR_RPIPE 0x22
  106. #define USB_DESCRIPTOR_CS_RADIO_CONTROL 0x23
  107. #define USB_DESCRIPTOR_SS_ENDPOINT_COMP 0x30
  108. #define USB_HID_DESCRIPTOR 0x21
  109. // Conventional codes for class-specific descriptors. "Common Class" Spec (3.11)
  110. #define USB_DESCRIPTOR_CS_DEVICE 0x21
  111. #define USB_DESCRIPTOR_CS_CONFIG 0x22
  112. #define USB_DESCRIPTOR_CS_STRING 0x23
  113. #define USB_DESCRIPTOR_CS_INTERFACE 0x24
  114. #define USB_DESCRIPTOR_CS_ENDPOINT 0x25
  115. /* USB Endpoint Transfer Types */
  116. #define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint.
  117. #define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint.
  118. #define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint.
  119. #define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint.
  120. #define bmUSB_TRANSFER_TYPE 0x03 // bit mask to separate transfer type from ISO attributes
  121. #define USB_TRANSFER_DIRECTION_IN 0x80 // Indicate direction is IN
  122. /* Standard Feature Selectors for CLEAR_FEATURE Requests */
  123. #define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient
  124. #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient
  125. #define USB_FEATURE_TEST_MODE 2 // Device recipient
  126. /* descriptor data structures */
  127. /* Device descriptor structure */
  128. typedef struct {
  129. uint8_t bLength; // Length of this descriptor.
  130. uint8_t bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE).
  131. uint16_t bcdUSB; // USB Spec Release Number (BCD).
  132. uint8_t bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
  133. uint8_t bDeviceSubClass; // Subclass code (assigned by the USB-IF).
  134. uint8_t bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
  135. uint8_t bMaxPacketSize0; // Maximum packet size for endpoint 0.
  136. uint16_t idVendor; // Vendor ID (assigned by the USB-IF).
  137. uint16_t idProduct; // Product ID (assigned by the manufacturer).
  138. uint16_t bcdDevice; // Device release number (BCD).
  139. uint8_t iManufacturer; // Index of String Descriptor describing the manufacturer.
  140. uint8_t iProduct; // Index of String Descriptor describing the product.
  141. uint8_t iSerialNumber; // Index of String Descriptor with the device's serial number.
  142. uint8_t bNumConfigurations; // Number of possible configurations.
  143. } __attribute__((packed)) USB_FD_DEVICE_DESCRIPTOR;
  144. /* Configuration descriptor structure */
  145. typedef struct {
  146. uint8_t bLength; // Length of this descriptor.
  147. uint8_t bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION).
  148. uint16_t wTotalLength; // Total length of all descriptors for this configuration.
  149. uint8_t bNumInterfaces; // Number of interfaces in this configuration.
  150. uint8_t bConfigurationValue; // Value of this configuration (1 based).
  151. uint8_t iConfiguration; // Index of String Descriptor describing the configuration.
  152. uint8_t bmAttributes; // Configuration characteristics.
  153. uint8_t bMaxPower; // Maximum power consumed by this configuration.
  154. } __attribute__((packed)) USB_FD_CONFIGURATION_DESCRIPTOR;
  155. /* Interface descriptor structure */
  156. typedef struct {
  157. uint8_t bLength; // Length of this descriptor.
  158. uint8_t bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE).
  159. uint8_t bInterfaceNumber; // Number of this interface (0 based).
  160. uint8_t bAlternateSetting; // Value of this alternate interface setting.
  161. uint8_t bNumEndpoints; // Number of endpoints in this interface.
  162. uint8_t bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
  163. uint8_t bInterfaceSubClass; // Subclass code (assigned by the USB-IF).
  164. uint8_t bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
  165. uint8_t iInterface; // Index of String Descriptor describing the interface.
  166. } __attribute__((packed)) USB_FD_INTERFACE_DESCRIPTOR;
  167. /* Endpoint descriptor structure */
  168. typedef struct {
  169. uint8_t bLength; // Length of this descriptor.
  170. uint8_t bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT).
  171. uint8_t bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN).
  172. uint8_t bmAttributes; // Endpoint transfer type.
  173. uint16_t wMaxPacketSize; // Maximum packet size.
  174. uint8_t bInterval; // Polling interval in frames.
  175. } __attribute__((packed)) USB_FD_ENDPOINT_DESCRIPTOR;
  176. /* HID descriptor */
  177. /*
  178. typedef struct {
  179. uint8_t bLength;
  180. uint8_t bDescriptorType;
  181. uint16_t bcdHID; // HID class specification release
  182. uint8_t bCountryCode;
  183. uint8_t bNumDescriptors; // Number of additional class specific descriptors
  184. uint8_t bDescrType; // Type of class descriptor
  185. uint16_t wDescriptorLength; // Total size of the Report descriptor
  186. } __attribute__((packed)) USB_HID_DESCRIPTOR;
  187. */
  188. typedef struct {
  189. uint8_t bDescrType; // Type of class descriptor
  190. uint16_t wDescriptorLength; // Total size of the Report descriptor
  191. } __attribute__((packed)) HID_CLASS_DESCRIPTOR_LEN_AND_TYPE;
  192. #endif // _ch9_h_