My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usb_ch9.h 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #ifndef _usb_h_
  26. #error "Never include usb_ch9.h directly; include Usb.h instead"
  27. #endif
  28. /* USB chapter 9 structures */
  29. /* Misc.USB constants */
  30. #define DEV_DESCR_LEN 18 //device descriptor length
  31. #define CONF_DESCR_LEN 9 //configuration descriptor length
  32. #define INTR_DESCR_LEN 9 //interface descriptor length
  33. #define EP_DESCR_LEN 7 //endpoint descriptor length
  34. /* Standard Device Requests */
  35. #define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS
  36. #define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE
  37. #define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE
  38. #define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS
  39. #define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR
  40. #define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR
  41. #define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION
  42. #define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION
  43. #define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE
  44. #define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE
  45. #define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME
  46. #define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt
  47. #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up
  48. #define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode
  49. /* Setup Data Constants */
  50. #define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer
  51. #define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer
  52. #define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard
  53. #define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class
  54. #define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor
  55. #define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device
  56. #define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface
  57. #define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint
  58. #define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other
  59. /* USB descriptors */
  60. #define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor.
  61. #define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor.
  62. #define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor.
  63. #define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor.
  64. #define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor.
  65. #define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier.
  66. #define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration.
  67. #define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power.
  68. #define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor.
  69. #define HID_DESCRIPTOR_HID 0x21
  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. /* USB Endpoint Transfer Types */
  75. #define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint.
  76. #define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint.
  77. #define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint.
  78. #define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint.
  79. #define bmUSB_TRANSFER_TYPE 0x03 // bit mask to separate transfer type from ISO attributes
  80. /* Standard Feature Selectors for CLEAR_FEATURE Requests */
  81. #define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient
  82. #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient
  83. #define USB_FEATURE_TEST_MODE 2 // Device recipient
  84. /* descriptor data structures */
  85. /* Device descriptor structure */
  86. typedef struct {
  87. uint8_t bLength; // Length of this descriptor.
  88. uint8_t bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE).
  89. uint16_t bcdUSB; // USB Spec Release Number (BCD).
  90. uint8_t bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
  91. uint8_t bDeviceSubClass; // Subclass code (assigned by the USB-IF).
  92. uint8_t bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
  93. uint8_t bMaxPacketSize0; // Maximum packet size for endpoint 0.
  94. uint16_t idVendor; // Vendor ID (assigned by the USB-IF).
  95. uint16_t idProduct; // Product ID (assigned by the manufacturer).
  96. uint16_t bcdDevice; // Device release number (BCD).
  97. uint8_t iManufacturer; // Index of String Descriptor describing the manufacturer.
  98. uint8_t iProduct; // Index of String Descriptor describing the product.
  99. uint8_t iSerialNumber; // Index of String Descriptor with the device's serial number.
  100. uint8_t bNumConfigurations; // Number of possible configurations.
  101. } __attribute__((packed)) USB_DEVICE_DESCRIPTOR;
  102. /* Configuration descriptor structure */
  103. typedef struct {
  104. uint8_t bLength; // Length of this descriptor.
  105. uint8_t bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION).
  106. uint16_t wTotalLength; // Total length of all descriptors for this configuration.
  107. uint8_t bNumInterfaces; // Number of interfaces in this configuration.
  108. uint8_t bConfigurationValue; // Value of this configuration (1 based).
  109. uint8_t iConfiguration; // Index of String Descriptor describing the configuration.
  110. uint8_t bmAttributes; // Configuration characteristics.
  111. uint8_t bMaxPower; // Maximum power consumed by this configuration.
  112. } __attribute__((packed)) USB_CONFIGURATION_DESCRIPTOR;
  113. /* Interface descriptor structure */
  114. typedef struct {
  115. uint8_t bLength; // Length of this descriptor.
  116. uint8_t bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE).
  117. uint8_t bInterfaceNumber; // Number of this interface (0 based).
  118. uint8_t bAlternateSetting; // Value of this alternate interface setting.
  119. uint8_t bNumEndpoints; // Number of endpoints in this interface.
  120. uint8_t bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
  121. uint8_t bInterfaceSubClass; // Subclass code (assigned by the USB-IF).
  122. uint8_t bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
  123. uint8_t iInterface; // Index of String Descriptor describing the interface.
  124. } __attribute__((packed)) USB_INTERFACE_DESCRIPTOR;
  125. /* Endpoint descriptor structure */
  126. typedef struct {
  127. uint8_t bLength; // Length of this descriptor.
  128. uint8_t bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT).
  129. uint8_t bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN).
  130. uint8_t bmAttributes; // Endpoint transfer type.
  131. uint16_t wMaxPacketSize; // Maximum packet size.
  132. uint8_t bInterval; // Polling interval in frames.
  133. } __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR;
  134. /* HID descriptor */
  135. typedef struct {
  136. uint8_t bLength;
  137. uint8_t bDescriptorType;
  138. uint16_t bcdHID; // HID class specification release
  139. uint8_t bCountryCode;
  140. uint8_t bNumDescriptors; // Number of additional class specific descriptors
  141. uint8_t bDescrType; // Type of class descriptor
  142. uint16_t wDescriptorLength; // Total size of the Report descriptor
  143. } __attribute__((packed)) USB_HID_DESCRIPTOR;
  144. typedef struct {
  145. uint8_t bDescrType; // Type of class descriptor
  146. uint16_t wDescriptorLength; // Total size of the Report descriptor
  147. } __attribute__((packed)) HID_CLASS_DESCRIPTOR_LEN_AND_TYPE;