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.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*----------------------------------------------------------------------------
  2. * U S B - K e r n e l
  3. *----------------------------------------------------------------------------
  4. * Name: usb.h
  5. * Purpose: USB Definitions
  6. * Version: V1.20
  7. *----------------------------------------------------------------------------
  8. * This software is supplied "AS IS" without any warranties, express,
  9. * implied or statutory, including but not limited to the implied
  10. * warranties of fitness for purpose, satisfactory quality and
  11. * noninfringement. Keil extends you a royalty-free right to reproduce
  12. * and distribute executable files created using this software for use
  13. * on NXP Semiconductors LPC family microcontroller devices only. Nothing
  14. * else gives you the right to use this software.
  15. *
  16. * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
  17. *---------------------------------------------------------------------------*/
  18. #ifndef __USB_H__
  19. #define __USB_H__
  20. extern "C" {
  21. #include "lpc_types.h"
  22. }
  23. #if defined ( __GNUC__ )
  24. #define __packed __attribute__((__packed__))
  25. #endif
  26. #if defined ( __CC_ARM )
  27. typedef __packed union {
  28. #elif defined ( __GNUC__ )
  29. typedef union __packed {
  30. #elif defined ( __IAR_SYSTEMS_ICC__ )
  31. #pragma pack(1)
  32. typedef union {
  33. #endif
  34. uint16_t W;
  35. #if defined ( __CC_ARM )
  36. __packed struct {
  37. #elif defined ( __GNUC__ )
  38. struct __packed {
  39. #elif defined ( __IAR_SYSTEMS_ICC__ )
  40. #pragma pack(1)
  41. struct {
  42. #endif
  43. uint8_t L;
  44. uint8_t H;
  45. } WB;
  46. #ifdef __IAR_SYSTEMS_ICC__
  47. #pragma pack()
  48. #endif
  49. } WORD_BYTE;
  50. #ifdef __IAR_SYSTEMS_ICC__
  51. #pragma pack()
  52. #endif
  53. /* bmRequestType.Dir */
  54. #define REQUEST_HOST_TO_DEVICE 0
  55. #define REQUEST_DEVICE_TO_HOST 1
  56. /* bmRequestType.Type */
  57. #define REQUEST_STANDARD 0
  58. #define REQUEST_CLASS 1
  59. #define REQUEST_VENDOR 2
  60. #define REQUEST_RESERVED 3
  61. /* bmRequestType.Recipient */
  62. #define REQUEST_TO_DEVICE 0
  63. #define REQUEST_TO_INTERFACE 1
  64. #define REQUEST_TO_ENDPOINT 2
  65. #define REQUEST_TO_OTHER 3
  66. /* bmRequestType Definition */
  67. #if defined ( __CC_ARM )
  68. typedef __packed union _REQUEST_TYPE {
  69. #elif defined ( __GNUC__ )
  70. typedef union __packed _REQUEST_TYPE {
  71. #elif defined ( __IAR_SYSTEMS_ICC__ )
  72. #pragma pack(1)
  73. typedef union _REQUEST_TYPE {
  74. #endif
  75. #if defined ( __CC_ARM )
  76. __packed struct _BM {
  77. #elif defined ( __GNUC__ )
  78. struct __packed _BM {
  79. #elif defined ( __IAR_SYSTEMS_ICC__ )
  80. #pragma pack(1)
  81. struct _BM {
  82. #endif
  83. uint8_t Recipient : 5;
  84. uint8_t Type : 2;
  85. uint8_t Dir : 1;
  86. } BM;
  87. #ifdef __IAR_SYSTEMS_ICC__
  88. #pragma pack()
  89. #endif
  90. uint8_t B;
  91. } REQUEST_TYPE;
  92. #ifdef __IAR_SYSTEMS_ICC__
  93. #pragma pack()
  94. #endif
  95. /* USB Standard Request Codes */
  96. #define USB_REQUEST_GET_STATUS 0
  97. #define USB_REQUEST_CLEAR_FEATURE 1
  98. #define USB_REQUEST_SET_FEATURE 3
  99. #define USB_REQUEST_SET_ADDRESS 5
  100. #define USB_REQUEST_GET_DESCRIPTOR 6
  101. #define USB_REQUEST_SET_DESCRIPTOR 7
  102. #define USB_REQUEST_GET_CONFIGURATION 8
  103. #define USB_REQUEST_SET_CONFIGURATION 9
  104. #define USB_REQUEST_GET_INTERFACE 10
  105. #define USB_REQUEST_SET_INTERFACE 11
  106. #define USB_REQUEST_SYNC_FRAME 12
  107. /* USB GET_STATUS Bit Values */
  108. #define USB_GETSTATUS_SELF_POWERED 0x01
  109. #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
  110. #define USB_GETSTATUS_ENDPOINT_STALL 0x01
  111. /* USB Standard Feature selectors */
  112. #define USB_FEATURE_ENDPOINT_STALL 0
  113. #define USB_FEATURE_REMOTE_WAKEUP 1
  114. /* USB Default Control Pipe Setup Packet */
  115. #if defined ( __CC_ARM )
  116. typedef __packed struct _USB_SETUP_PACKET {
  117. #elif defined ( __GNUC__ )
  118. typedef struct __packed _USB_SETUP_PACKET {
  119. #elif defined ( __IAR_SYSTEMS_ICC__ )
  120. #pragma pack(1)
  121. typedef struct _USB_SETUP_PACKET {
  122. #endif
  123. REQUEST_TYPE bmRequestType;
  124. uint8_t bRequest;
  125. WORD_BYTE wValue;
  126. WORD_BYTE wIndex;
  127. uint16_t wLength;
  128. } USB_SETUP_PACKET;
  129. #ifdef __IAR_SYSTEMS_ICC__
  130. #pragma pack()
  131. #endif
  132. /* USB Descriptor Types */
  133. #define USB_DEVICE_DESCRIPTOR_TYPE 1
  134. #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
  135. #define USB_STRING_DESCRIPTOR_TYPE 3
  136. #define USB_INTERFACE_DESCRIPTOR_TYPE 4
  137. #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
  138. #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
  139. #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
  140. #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
  141. #define USB_OTG_DESCRIPTOR_TYPE 9
  142. #define USB_DEBUG_DESCRIPTOR_TYPE 10
  143. #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
  144. /* USB Device Classes */
  145. #define USB_DEVICE_CLASS_RESERVED 0x00
  146. #define USB_DEVICE_CLASS_AUDIO 0x01
  147. #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
  148. #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
  149. #define USB_DEVICE_CLASS_MONITOR 0x04
  150. #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
  151. #define USB_DEVICE_CLASS_POWER 0x06
  152. #define USB_DEVICE_CLASS_PRINTER 0x07
  153. #define USB_DEVICE_CLASS_STORAGE 0x08
  154. #define USB_DEVICE_CLASS_HUB 0x09
  155. #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
  156. #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
  157. /* bmAttributes in Configuration Descriptor */
  158. #define USB_CONFIG_POWERED_MASK 0x40
  159. #define USB_CONFIG_BUS_POWERED 0x80
  160. #define USB_CONFIG_SELF_POWERED 0xC0
  161. #define USB_CONFIG_REMOTE_WAKEUP 0x20
  162. /* bMaxPower in Configuration Descriptor */
  163. #define USB_CONFIG_POWER_MA(mA) ((mA)/2)
  164. /* bEndpointAddress in Endpoint Descriptor */
  165. #define USB_ENDPOINT_DIRECTION_MASK 0x80
  166. #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
  167. #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
  168. /* bmAttributes in Endpoint Descriptor */
  169. #define USB_ENDPOINT_TYPE_MASK 0x03
  170. #define USB_ENDPOINT_TYPE_CONTROL 0x00
  171. #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
  172. #define USB_ENDPOINT_TYPE_BULK 0x02
  173. #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
  174. #define USB_ENDPOINT_SYNC_MASK 0x0C
  175. #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
  176. #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
  177. #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
  178. #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
  179. #define USB_ENDPOINT_USAGE_MASK 0x30
  180. #define USB_ENDPOINT_USAGE_DATA 0x00
  181. #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
  182. #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
  183. #define USB_ENDPOINT_USAGE_RESERVED 0x30
  184. /* USB Standard Device Descriptor */
  185. #if defined ( __CC_ARM )
  186. typedef __packed struct _USB_DEVICE_DESCRIPTOR {
  187. #elif defined ( __GNUC__ )
  188. typedef struct __packed _USB_DEVICE_DESCRIPTOR {
  189. #elif defined ( __IAR_SYSTEMS_ICC__ )
  190. #pragma pack(1)
  191. typedef struct _USB_DEVICE_DESCRIPTOR {
  192. #endif
  193. uint8_t bLength;
  194. uint8_t bDescriptorType;
  195. uint16_t bcdUSB;
  196. uint8_t bDeviceClass;
  197. uint8_t bDeviceSubClass;
  198. uint8_t bDeviceProtocol;
  199. uint8_t bMaxPacketSize0;
  200. uint16_t idVendor;
  201. uint16_t idProduct;
  202. uint16_t bcdDevice;
  203. uint8_t iManufacturer;
  204. uint8_t iProduct;
  205. uint8_t iSerialNumber;
  206. uint8_t bNumConfigurations;
  207. } USB_DEVICE_DESCRIPTOR;
  208. #ifdef __IAR_SYSTEMS_ICC__
  209. #pragma pack()
  210. #endif
  211. /* USB 2.0 Device Qualifier Descriptor */
  212. #if defined ( __CC_ARM )
  213. typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
  214. #elif defined ( __GNUC__ )
  215. typedef struct __packed _USB_DEVICE_QUALIFIER_DESCRIPTOR {
  216. #elif defined ( __IAR_SYSTEMS_ICC__ )
  217. #pragma pack(1)
  218. typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
  219. #endif
  220. uint8_t bLength;
  221. uint8_t bDescriptorType;
  222. uint16_t bcdUSB;
  223. uint8_t bDeviceClass;
  224. uint8_t bDeviceSubClass;
  225. uint8_t bDeviceProtocol;
  226. uint8_t bMaxPacketSize0;
  227. uint8_t bNumConfigurations;
  228. uint8_t bReserved;
  229. } USB_DEVICE_QUALIFIER_DESCRIPTOR;
  230. #ifdef __IAR_SYSTEMS_ICC__
  231. #pragma pack()
  232. #endif
  233. #if defined ( __CC_ARM )
  234. typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR {
  235. #elif defined ( __GNUC__ )
  236. typedef struct __packed _USB_CONFIGURATION_DESCRIPTOR {
  237. #elif defined ( __IAR_SYSTEMS_ICC__ )
  238. #pragma pack(1)
  239. typedef struct _USB_CONFIGURATION_DESCRIPTOR {
  240. #endif
  241. uint8_t bLength;
  242. uint8_t bDescriptorType;
  243. uint16_t wTotalLength;
  244. uint8_t bNumInterfaces;
  245. uint8_t bConfigurationValue;
  246. uint8_t iConfiguration;
  247. uint8_t bmAttributes;
  248. uint8_t bMaxPower;
  249. } USB_CONFIGURATION_DESCRIPTOR;
  250. #ifdef __IAR_SYSTEMS_ICC__
  251. #pragma pack()
  252. #endif
  253. /* USB Standard Interface Descriptor */
  254. #if defined ( __CC_ARM )
  255. typedef __packed struct _USB_INTERFACE_DESCRIPTOR {
  256. #elif defined ( __GNUC__ )
  257. typedef struct __packed _USB_INTERFACE_DESCRIPTOR {
  258. #elif defined ( __IAR_SYSTEMS_ICC__ )
  259. #pragma pack(1)
  260. typedef struct _USB_INTERFACE_DESCRIPTOR {
  261. #endif
  262. uint8_t bLength;
  263. uint8_t bDescriptorType;
  264. uint8_t bInterfaceNumber;
  265. uint8_t bAlternateSetting;
  266. uint8_t bNumEndpoints;
  267. uint8_t bInterfaceClass;
  268. uint8_t bInterfaceSubClass;
  269. uint8_t bInterfaceProtocol;
  270. uint8_t iInterface;
  271. } USB_INTERFACE_DESCRIPTOR;
  272. #ifdef __IAR_SYSTEMS_ICC__
  273. #pragma pack()
  274. #endif
  275. /* USB Standard Endpoint Descriptor */
  276. #if defined ( __CC_ARM )
  277. typedef __packed struct _USB_ENDPOINT_DESCRIPTOR {
  278. #elif defined ( __GNUC__ )
  279. typedef struct __packed _USB_ENDPOINT_DESCRIPTOR {
  280. #elif defined ( __IAR_SYSTEMS_ICC__ )
  281. #pragma pack(1)
  282. typedef struct _USB_ENDPOINT_DESCRIPTOR {
  283. #endif
  284. uint8_t bLength;
  285. uint8_t bDescriptorType;
  286. uint8_t bEndpointAddress;
  287. uint8_t bmAttributes;
  288. uint16_t wMaxPacketSize;
  289. uint8_t bInterval;
  290. } USB_ENDPOINT_DESCRIPTOR;
  291. #ifdef __IAR_SYSTEMS_ICC__
  292. #pragma pack()
  293. #endif
  294. /* USB String Descriptor */
  295. #if defined ( __CC_ARM )
  296. typedef __packed struct _USB_STRING_DESCRIPTOR {
  297. #elif defined ( __GNUC__ )
  298. typedef struct __packed _USB_STRING_DESCRIPTOR {
  299. #elif defined ( __IAR_SYSTEMS_ICC__ )
  300. #pragma pack(1)
  301. typedef struct _USB_STRING_DESCRIPTOR {
  302. #endif
  303. uint8_t bLength;
  304. uint8_t bDescriptorType;
  305. uint16_t bString/*[]*/;
  306. } USB_STRING_DESCRIPTOR;
  307. #ifdef __IAR_SYSTEMS_ICC__
  308. #pragma pack()
  309. #endif
  310. /* USB Common Descriptor */
  311. #if defined ( __CC_ARM )
  312. typedef __packed struct _USB_COMMON_DESCRIPTOR {
  313. #elif defined ( __GNUC__ )
  314. typedef struct __packed _USB_COMMON_DESCRIPTOR {
  315. #elif defined ( __IAR_SYSTEMS_ICC__ )
  316. #pragma pack(1)
  317. typedef struct _USB_COMMON_DESCRIPTOR {
  318. #endif
  319. uint8_t bLength;
  320. uint8_t bDescriptorType;
  321. } USB_COMMON_DESCRIPTOR;
  322. #ifdef __IAR_SYSTEMS_ICC__
  323. #pragma pack()
  324. #endif
  325. #endif /* __USB_H__ */