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.

116 lines
4.0 KiB

  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. typedef struct usbDescriptorHeader {
  17. uchar bLength;
  18. uchar bDescriptorType;
  19. } __attribute__((packed)) usbDescriptorHeader_t;
  20. typedef struct usbDeviceDescriptor {
  21. usbDescriptorHeader_t header;
  22. unsigned bcdUSB;
  23. uchar bDeviceClass;
  24. uchar bDeviceSubClass;
  25. uchar bDeviceProtocol;
  26. uchar bMaxPacketSize0;
  27. unsigned idVendor;
  28. unsigned idProduct;
  29. unsigned bcdDevice;
  30. uchar iManufacturer;
  31. uchar iProduct;
  32. uchar iSerialNumber;
  33. uchar bNumConfigurations;
  34. } __attribute__((packed)) usbDeviceDescriptor_t;
  35. typedef struct usbConfigurationDescriptorHeader {
  36. usbDescriptorHeader_t header;
  37. unsigned wTotalLength;
  38. uchar bNumInterfaces;
  39. uchar bConfigurationValue;
  40. uchar iConfiguration;
  41. uchar bmAttributes;
  42. uchar bMaxPower;
  43. } __attribute__((packed)) usbConfigurationDescriptorHeader_t;
  44. typedef struct usbStringDescriptor {
  45. usbDescriptorHeader_t header;
  46. int bString[];
  47. } __attribute__((packed)) usbStringDescriptor_t;
  48. typedef struct usbInterfaceDescriptor {
  49. usbDescriptorHeader_t header;
  50. uchar bInterfaceNumber;
  51. uchar bAlternateSetting;
  52. uchar bNumEndpoints;
  53. uchar bInterfaceClass;
  54. uchar bInterfaceSubClass;
  55. uchar bInterfaceProtocol;
  56. uchar iInterface;
  57. } __attribute__((packed)) usbInterfaceDescriptor_t;
  58. typedef struct usbEndpointDescriptor {
  59. usbDescriptorHeader_t header;
  60. uchar bEndpointAddress;
  61. uchar bmAttributes;
  62. unsigned wMaxPacketSize;
  63. uchar bInterval;
  64. } __attribute__((packed)) usbEndpointDescriptor_t;
  65. typedef struct usbHIDDescriptor {
  66. usbDescriptorHeader_t header;
  67. unsigned bcdHID;
  68. uchar bCountryCode;
  69. uchar bNumDescriptors;
  70. uchar bDescriptorType;
  71. unsigned wDescriptorLength;
  72. } __attribute__((packed)) usbHIDDescriptor_t;
  73. typedef struct usbConfigurationDescriptor {
  74. usbConfigurationDescriptorHeader_t header;
  75. usbInterfaceDescriptor_t keyboardInterface;
  76. usbHIDDescriptor_t keyboardHID;
  77. usbEndpointDescriptor_t keyboardINEndpoint;
  78. #if defined(RAW_ENABLE)
  79. usbInterfaceDescriptor_t rawInterface;
  80. usbHIDDescriptor_t rawHID;
  81. usbEndpointDescriptor_t rawINEndpoint;
  82. usbEndpointDescriptor_t rawOUTEndpoint;
  83. #endif
  84. #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
  85. usbInterfaceDescriptor_t mouseExtraInterface;
  86. usbHIDDescriptor_t mouseExtraHID;
  87. usbEndpointDescriptor_t mouseExtraINEndpoint;
  88. #endif
  89. #if defined(CONSOLE_ENABLE)
  90. usbInterfaceDescriptor_t consoleInterface;
  91. usbHIDDescriptor_t consoleHID;
  92. usbEndpointDescriptor_t consoleINEndpoint;
  93. usbEndpointDescriptor_t consoleOUTEndpoint;
  94. #endif
  95. } __attribute__((packed)) usbConfigurationDescriptor_t;
  96. #define USB_STRING_LEN(s) (sizeof(usbDescriptorHeader_t) + ((s) << 1))
  97. host_driver_t *vusb_driver(void);
  98. void vusb_transfer_keyboard(void);