vusb.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Copyright 2011 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #include "host_driver.h"
  16. #include <usbdrv/usbdrv.h>
  17. typedef struct usbDescriptorHeader {
  18. uchar bLength;
  19. uchar bDescriptorType;
  20. } __attribute__((packed)) usbDescriptorHeader_t;
  21. typedef struct usbDeviceDescriptor {
  22. usbDescriptorHeader_t header;
  23. unsigned bcdUSB;
  24. uchar bDeviceClass;
  25. uchar bDeviceSubClass;
  26. uchar bDeviceProtocol;
  27. uchar bMaxPacketSize0;
  28. unsigned idVendor;
  29. unsigned idProduct;
  30. unsigned bcdDevice;
  31. uchar iManufacturer;
  32. uchar iProduct;
  33. uchar iSerialNumber;
  34. uchar bNumConfigurations;
  35. } __attribute__((packed)) usbDeviceDescriptor_t;
  36. typedef struct usbConfigurationDescriptorHeader {
  37. usbDescriptorHeader_t header;
  38. unsigned wTotalLength;
  39. uchar bNumInterfaces;
  40. uchar bConfigurationValue;
  41. uchar iConfiguration;
  42. uchar bmAttributes;
  43. uchar bMaxPower;
  44. } __attribute__((packed)) usbConfigurationDescriptorHeader_t;
  45. typedef struct usbStringDescriptor {
  46. usbDescriptorHeader_t header;
  47. int bString[];
  48. } __attribute__((packed)) usbStringDescriptor_t;
  49. typedef struct usbInterfaceDescriptor {
  50. usbDescriptorHeader_t header;
  51. uchar bInterfaceNumber;
  52. uchar bAlternateSetting;
  53. uchar bNumEndpoints;
  54. uchar bInterfaceClass;
  55. uchar bInterfaceSubClass;
  56. uchar bInterfaceProtocol;
  57. uchar iInterface;
  58. } __attribute__((packed)) usbInterfaceDescriptor_t;
  59. typedef struct usbEndpointDescriptor {
  60. usbDescriptorHeader_t header;
  61. uchar bEndpointAddress;
  62. uchar bmAttributes;
  63. unsigned wMaxPacketSize;
  64. uchar bInterval;
  65. } __attribute__((packed)) usbEndpointDescriptor_t;
  66. typedef struct usbHIDDescriptor {
  67. usbDescriptorHeader_t header;
  68. unsigned bcdHID;
  69. uchar bCountryCode;
  70. uchar bNumDescriptors;
  71. uchar bDescriptorType;
  72. unsigned wDescriptorLength;
  73. } __attribute__((packed)) usbHIDDescriptor_t;
  74. typedef struct usbConfigurationDescriptor {
  75. usbConfigurationDescriptorHeader_t header;
  76. #ifndef KEYBOARD_SHARED_EP
  77. usbInterfaceDescriptor_t keyboardInterface;
  78. usbHIDDescriptor_t keyboardHID;
  79. usbEndpointDescriptor_t keyboardINEndpoint;
  80. #else
  81. usbInterfaceDescriptor_t sharedInterface;
  82. usbHIDDescriptor_t sharedHID;
  83. usbEndpointDescriptor_t sharedINEndpoint;
  84. #endif
  85. #if defined(RAW_ENABLE)
  86. usbInterfaceDescriptor_t rawInterface;
  87. usbHIDDescriptor_t rawHID;
  88. usbEndpointDescriptor_t rawINEndpoint;
  89. usbEndpointDescriptor_t rawOUTEndpoint;
  90. #endif
  91. #if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
  92. usbInterfaceDescriptor_t sharedInterface;
  93. usbHIDDescriptor_t sharedHID;
  94. usbEndpointDescriptor_t sharedINEndpoint;
  95. #endif
  96. #if defined(CONSOLE_ENABLE)
  97. usbInterfaceDescriptor_t consoleInterface;
  98. usbHIDDescriptor_t consoleHID;
  99. usbEndpointDescriptor_t consoleINEndpoint;
  100. usbEndpointDescriptor_t consoleOUTEndpoint;
  101. #endif
  102. } __attribute__((packed)) usbConfigurationDescriptor_t;
  103. #define USB_STRING_LEN(s) (sizeof(usbDescriptorHeader_t) + ((s) << 1))
  104. extern bool vusb_suspended;
  105. host_driver_t *vusb_driver(void);
  106. void vusb_transfer_keyboard(void);