usb.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2008 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef __HW_USB_H
  24. #define __HW_USB_H
  25. #include <sys/types.h>
  26. #include <compiler.h>
  27. /* GLOBAL STATUS VALUES */
  28. #define STD_COMMAND 0x00
  29. #define SETUP_COMMAND_PHASE 0x40
  30. #define FUNCTION_ERROR 0x7F /* Used when we are stalling the function EP0 */
  31. #define HUB_ERROR 0xFF /* Used when we are stalling the HUB EP0 */
  32. /* Request Types */
  33. #define DIR_OUT (0 << 7)
  34. #define DIR_IN (1 << 7)
  35. #define DIR_MASK (1 << 7)
  36. #define TYPE_STANDARD (0 << 5)
  37. #define TYPE_CLASS (1 << 5)
  38. #define TYPE_VENDOR (2 << 5)
  39. #define TYPE_MASK (3 << 5)
  40. #define RECIP_DEVICE (0 << 0)
  41. #define RECIP_INTERFACE (1 << 0)
  42. #define RECIP_ENDPOINT (2 << 0)
  43. #define RECIP_OTHER (3 << 0)
  44. #define RECIP_MASK (0x1f << 0)
  45. /* 1.0 Request Values */
  46. #define GET_STATUS 0x00
  47. #define CLEAR_FEATURE 0x01
  48. #define SET_FEATURE 0x03
  49. #define SET_ADDRESS 0x05
  50. #define GET_DESCRIPTOR 0x06
  51. #define SET_DESCRIPTOR 0x07
  52. #define GET_CONFIGURATION 0x08
  53. #define SET_CONFIGURATION 0x09
  54. #define GET_INTERFACE 0x0A
  55. #define SET_INTERFACE 0x0B
  56. #define SYNCH_FRAME 0x0C
  57. /* Mass storage requests */
  58. #define MASS_STORAGE_GET_MAX_LUN 0xfe
  59. #define MASS_STORAGE_RESET 0xff
  60. /* DFU requests */
  61. #define DFU_DETACH 0x00
  62. #define DFU_DNLOAD 0x01
  63. #define DFU_UPLOAD 0x02
  64. #define DFU_GETSTATUS 0x03
  65. #define DFU_CLRSTATUS 0x04
  66. #define DFU_GETSTATE 0x05
  67. #define DFU_ABORT 0x06
  68. /* HID Request Values */
  69. #define GET_REPORT 0x01
  70. #define GET_IDLE 0x02
  71. #define GET_PROTOCOL 0x03
  72. #define SET_REPORT 0x09
  73. #define SET_IDLE 0x0A
  74. #define SET_PROTOCOL 0x0B
  75. /* Descriptor Types */
  76. #define DEVICE 0x01
  77. #define CONFIGURATION 0x02
  78. #define STRING 0x03
  79. #define INTERFACE 0x04
  80. #define ENDPOINT 0x05
  81. #define DEVICE_QUALIFIER 0x06
  82. #define OTHER_SPEED_CONFIGURATION 0x07
  83. #define INTERFACE_POWER 0x08
  84. #define HID 0x21
  85. #define HIDREPORT 0x22
  86. #define HIDPHYSICAL 0x23
  87. /* general USB defines */
  88. struct usb_setup {
  89. uint8_t request_type;
  90. uint8_t request;
  91. uint16_t value;
  92. uint16_t index;
  93. uint16_t length;
  94. } __PACKED;
  95. #endif