USBconstant.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #include "USBconstant.h"
  2. // Device descriptor
  3. __code USB_Descriptor_Device_t DeviceDescriptor = {
  4. .Header = { .Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device },
  5. .USBSpecification = VERSION_BCD(1, 1, 0),
  6. .Class = 0x00,
  7. .SubClass = 0x00,
  8. .Protocol = 0x00,
  9. .Endpoint0Size = DEFAULT_ENDP0_SIZE,
  10. .VendorID = 0x1209,
  11. .ProductID = 0xc55D,
  12. .ReleaseNumber = VERSION_BCD(1, 0, 0),
  13. .ManufacturerStrIndex = 1,
  14. .ProductStrIndex = 2,
  15. .SerialNumStrIndex = 3,
  16. .NumberOfConfigurations = 1
  17. };
  18. /** Configuration descriptor structure. This descriptor, located in FLASH
  19. * memory, describes the usage of the device in one of its supported
  20. * configurations, including information about any device interfaces and
  21. * endpoints. The descriptor is read out by the USB host during the enumeration
  22. * process when selecting a configuration so that the host may correctly
  23. * communicate with the USB device.
  24. */
  25. __code USB_Descriptor_Configuration_t ConfigurationDescriptor = {
  26. .Config = { .Header = { .Size = sizeof(USB_Descriptor_Configuration_Header_t),
  27. .Type = DTYPE_Configuration },
  28. .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
  29. .TotalInterfaces = 1,
  30. .ConfigurationNumber = 1,
  31. .ConfigurationStrIndex = NO_DESCRIPTOR,
  32. .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED),
  33. .MaxPowerConsumption = USB_CONFIG_POWER_MA(200) },
  34. .HID_Interface = { .Header = { .Size = sizeof(USB_Descriptor_Interface_t),
  35. .Type = DTYPE_Interface },
  36. .InterfaceNumber = 0,
  37. .AlternateSetting = 0x00,
  38. .TotalEndpoints = 2,
  39. .Class = HID_CSCP_HIDClass,
  40. .SubClass = HID_CSCP_BootSubclass,
  41. .Protocol = HID_CSCP_KeyboardBootProtocol,
  42. .InterfaceStrIndex = NO_DESCRIPTOR },
  43. .HID_KeyboardHID = { .Header = { .Size = sizeof(USB_HID_Descriptor_HID_t),
  44. .Type = HID_DTYPE_HID },
  45. .HIDSpec = VERSION_BCD(1, 1, 0),
  46. .CountryCode = 0x00,
  47. .TotalReportDescriptors = 1,
  48. .HIDReportType = HID_DTYPE_Report,
  49. .HIDReportLength = sizeof(ReportDescriptor) },
  50. .HID_ReportINEndpoint = { .Header = { .Size =
  51. sizeof(USB_Descriptor_Endpoint_t),
  52. .Type = DTYPE_Endpoint },
  53. .EndpointAddress = KEYBOARD_EPADDR,
  54. .Attributes =
  55. (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  56. .EndpointSize = KEYBOARD_MOUSE_EPSIZE,
  57. .PollingIntervalMS = 10 },
  58. .HID_ReportOUTEndpoint = { .Header = { .Size =
  59. sizeof(USB_Descriptor_Endpoint_t),
  60. .Type = DTYPE_Endpoint },
  61. .EndpointAddress = KEYBOARD_LED_EPADDR,
  62. .Attributes =
  63. (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
  64. .EndpointSize = KEYBOARD_MOUSE_EPSIZE,
  65. .PollingIntervalMS = 10 },
  66. };
  67. __code uint8_t ReportDescriptor[] = {
  68. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  69. 0x09, 0x06, // USAGE (Keyboard)
  70. 0xa1, 0x01, // COLLECTION (Application)
  71. 0x85, 0x01, // REPORT_ID (1)
  72. 0x05, 0x07, // USAGE_PAGE (Keyboard)
  73. 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
  74. 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
  75. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  76. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  77. 0x95, 0x08, // REPORT_COUNT (8)
  78. 0x75, 0x01, // REPORT_SIZE (1)
  79. 0x81, 0x02, // INPUT (Data,Var,Abs)
  80. 0x95, 0x01, // REPORT_COUNT (1)
  81. 0x75, 0x08, // REPORT_SIZE (8)
  82. 0x81, 0x03, // INPUT (Cnst,Var,Abs)
  83. 0x95, 0x06, // REPORT_COUNT (6)
  84. 0x75, 0x08, // REPORT_SIZE (8)
  85. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  86. 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
  87. 0x05, 0x07, // USAGE_PAGE (Keyboard)
  88. 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
  89. 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
  90. 0x81, 0x00, // INPUT (Data,Ary,Abs)
  91. 0x05, 0x08, // USAGE_PAGE (LEDs)
  92. 0x19, 0x01, // USAGE_MINIMUM (Num Lock)
  93. 0x29, 0x05, // USAGE_MAXIMUM (Kana)
  94. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  95. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  96. 0x95, 0x05, // REPORT_COUNT (5)
  97. 0x75, 0x01, // REPORT_SIZE (1)
  98. 0x91, 0x02, // OUTPUT (Data,Var,Abs)
  99. 0x95, 0x01, // REPORT_COUNT (1)
  100. 0x75, 0x03, // REPORT_SIZE (3)
  101. 0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
  102. 0xc0, // END_COLLECTION
  103. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  104. 0x09, 0x02, // USAGE (Mouse)
  105. 0xa1, 0x01, // COLLECTION (Application)
  106. 0x09, 0x01, // USAGE (Pointer)
  107. 0xa1, 0x00, // COLLECTION (Physical)
  108. 0x85, 0x02, // REPORT_ID (2)
  109. 0x05, 0x09, // USAGE_PAGE (Button)
  110. 0x19, 0x01, // USAGE_MINIMUM (Button 1)
  111. 0x29, 0x03, // USAGE_MAXIMUM (Button 3)
  112. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  113. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
  114. 0x95, 0x03, // REPORT_COUNT (3)
  115. 0x75, 0x01, // REPORT_SIZE (1)
  116. 0x81, 0x02, // INPUT (Data,Var,Abs)
  117. 0x95, 0x01, // REPORT_COUNT (1)
  118. 0x75, 0x05, // REPORT_SIZE (5)
  119. 0x81, 0x03, // INPUT (Cnst,Var,Abs)
  120. 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
  121. 0x09, 0x30, // USAGE (X)
  122. 0x09, 0x31, // USAGE (Y)
  123. 0x09, 0x38, // USAGE (Wheel)
  124. 0x15, 0x81, // LOGICAL_MINIMUM (-127)
  125. 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
  126. 0x75, 0x08, // REPORT_SIZE (8)
  127. 0x95, 0x03, // REPORT_COUNT (3)
  128. 0x81, 0x06, // INPUT (Data,Var,Rel)
  129. 0xc0, // END_COLLECTION
  130. 0xc0 // END_COLLECTION
  131. };
  132. // String Descriptors
  133. __code uint8_t LanguageDescriptor[] = { 0x04, 0x03, 0x09,
  134. 0x04 }; // Language Descriptor
  135. __code uint16_t SerialDescriptor[] = {
  136. // Serial String Descriptor
  137. (((13 + 1) * 2) | (DTYPE_String << 8)),
  138. 'R',
  139. 'e',
  140. 'm',
  141. 'd',
  142. 'e',
  143. 's',
  144. '_',
  145. 'U',
  146. 'S',
  147. 'B',
  148. 'K',
  149. 'V',
  150. 'M',
  151. };
  152. __code uint16_t ProductDescriptor[] = {
  153. // Produce String Descriptor
  154. (((9 + 1) * 2) | (DTYPE_String << 8)),
  155. 'R',
  156. 'E',
  157. 'M',
  158. 'D',
  159. 'E',
  160. 'S',
  161. 'K',
  162. 'V',
  163. 'M',
  164. };
  165. __code uint16_t ManufacturerDescriptor[] = {
  166. // SDCC is little endian
  167. (((7 + 1) * 2) | (DTYPE_String << 8)),
  168. 'I',
  169. 'M',
  170. 'U',
  171. 'S',
  172. 'L',
  173. 'A',
  174. 'B',
  175. };