midi_template.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include "usbd_core.h"
  2. #include "usb_midi.h"
  3. USB_DESC_SECTION const uint8_t midi_descriptor[] = {
  4. USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0100, 0x01),
  5. USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
  6. // Standard AC Interface Descriptor
  7. 0x09,
  8. 0x04,
  9. 0x00,
  10. 0x00,
  11. 0x00,
  12. 0x01,
  13. 0x01,
  14. 0x00,
  15. 0x00,
  16. // Class-specific AC Interface Descriptor
  17. 0x09,
  18. 0x24,
  19. 0x01,
  20. 0x00,
  21. 0x01,
  22. 0x09,
  23. 0x00,
  24. 0x01,
  25. 0x01,
  26. // MIDIStreaming Interface Descriptors
  27. 0x09,
  28. 0x04,
  29. 0x01,
  30. 0x00,
  31. 0x02,
  32. 0x01,
  33. 0x03,
  34. 0x00,
  35. 0x00,
  36. // Class-Specific MS Interface Header Descriptor
  37. 0x07,
  38. 0x24,
  39. 0x01,
  40. 0x00,
  41. 0x01,
  42. WBVAL(65),
  43. // MIDI_IN_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EMBEDDED, 0x01),
  44. // MIDI_IN_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EXTERNAL, 0x02),
  45. // MIDI_OUT_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EMBEDDED, 0x03, 0x02),
  46. // MIDI_OUT_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EXTERNAL, 0x04, 0x01),
  47. MIDI_JACK_DESCRIPTOR_INIT(0x01),
  48. // OUT endpoint descriptor
  49. 0x09, 0x05, 0x02, 0x02, WBVAL(64), 0x00, 0x00, 0x00,
  50. 0x05, 0x25, 0x01, 0x01, 0x01,
  51. // IN endpoint descriptor
  52. 0x09, 0x05, 0x81, 0x02, WBVAL(64), 0x00, 0x00, 0x00,
  53. 0x05, 0x25, 0x01, 0x01, 0x03,
  54. ///////////////////////////////////////
  55. /// string0 descriptor
  56. ///////////////////////////////////////
  57. USB_LANGID_INIT(USBD_LANGID_STRING),
  58. ///////////////////////////////////////
  59. /// string1 descriptor
  60. ///////////////////////////////////////
  61. 0x14, /* bLength */
  62. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  63. 'C', 0x00, /* wcChar0 */
  64. 'h', 0x00, /* wcChar1 */
  65. 'e', 0x00, /* wcChar2 */
  66. 'r', 0x00, /* wcChar3 */
  67. 'r', 0x00, /* wcChar4 */
  68. 'y', 0x00, /* wcChar5 */
  69. 'U', 0x00, /* wcChar6 */
  70. 'S', 0x00, /* wcChar7 */
  71. 'B', 0x00, /* wcChar8 */
  72. ///////////////////////////////////////
  73. /// string2 descriptor
  74. ///////////////////////////////////////
  75. 0x28, /* bLength */
  76. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  77. 'C', 0x00, /* wcChar0 */
  78. 'h', 0x00, /* wcChar1 */
  79. 'e', 0x00, /* wcChar2 */
  80. 'r', 0x00, /* wcChar3 */
  81. 'r', 0x00, /* wcChar4 */
  82. 'y', 0x00, /* wcChar5 */
  83. 'U', 0x00, /* wcChar6 */
  84. 'S', 0x00, /* wcChar7 */
  85. 'B', 0x00, /* wcChar8 */
  86. ' ', 0x00, /* wcChar9 */
  87. 'M', 0x00, /* wcChar10 */
  88. 'I', 0x00, /* wcChar11 */
  89. 'D', 0x00, /* wcChar12 */
  90. 'I', 0x00, /* wcChar13 */
  91. ' ', 0x00, /* wcChar14 */
  92. 'D', 0x00, /* wcChar15 */
  93. 'E', 0x00, /* wcChar16 */
  94. 'M', 0x00, /* wcChar17 */
  95. 'O', 0x00, /* wcChar18 */
  96. ///////////////////////////////////////
  97. /// string3 descriptor
  98. ///////////////////////////////////////
  99. 0x16, /* bLength */
  100. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
  101. '2', 0x00, /* wcChar0 */
  102. '0', 0x00, /* wcChar1 */
  103. '2', 0x00, /* wcChar2 */
  104. '1', 0x00, /* wcChar3 */
  105. '0', 0x00, /* wcChar4 */
  106. '3', 0x00, /* wcChar5 */
  107. '1', 0x00, /* wcChar6 */
  108. '0', 0x00, /* wcChar7 */
  109. '0', 0x00, /* wcChar8 */
  110. '0', 0x00, /* wcChar9 */
  111. #ifdef CONFIG_USB_HS
  112. ///////////////////////////////////////
  113. /// device qualifier descriptor
  114. ///////////////////////////////////////
  115. 0x0a,
  116. USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
  117. 0x00,
  118. 0x02,
  119. 0x02,
  120. 0x02,
  121. 0x01,
  122. 0x40,
  123. 0x01,
  124. 0x00,
  125. #endif
  126. 0x00
  127. };
  128. void usbd_midi_bulk_out(uint8_t ep)
  129. {
  130. }
  131. void usbd_midi_bulk_in(uint8_t ep)
  132. {
  133. }
  134. usbd_class_t midi_class;
  135. usbd_interface_t midi_cmd_intf;
  136. usbd_interface_t midi_data_intf;
  137. usbd_endpoint_t midi_out_ep = {
  138. .ep_addr = MIDI_OUT_EP,
  139. .ep_cb = usbd_midi_bulk_out
  140. };
  141. usbd_endpoint_t midi_in_ep = {
  142. .ep_addr = MIDI_IN_EP,
  143. .ep_cb = usbd_midi_bulk_in
  144. };
  145. void midi_init(void)
  146. {
  147. usbd_desc_register(midi_descriptor);
  148. usbd_class_add_interface(&midi_class, &midi_cmd_intf);
  149. usbd_class_add_interface(&midi_class, &midi_data_intf);
  150. usbd_interface_add_endpoint(&midi_data_intf, &midi_out_ep);
  151. usbd_interface_add_endpoint(&midi_data_intf, &midi_in_ep);
  152. usbd_initialize();
  153. }