cm3_usb_midi.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /** @defgroup usb_audio_defines USB MIDI Type Definitions
  2. @brief <b>Defined Constants and Types for the USB MIDI Type Definitions</b>
  3. @ingroup USB_defines
  4. @version 1.0.0
  5. @author @htmlonly &copy; @endhtmlonly 2014
  6. Daniel Thompson <daniel@redfelineninja.org.uk>
  7. @date 19 April 2014
  8. LGPL License Terms @ref lgpl_license
  9. */
  10. /*
  11. * This file is part of the libopencm3 project.
  12. *
  13. * Copyright (C) 2014 Daniel Thompson <daniel@redfelineninja.org.uk>
  14. *
  15. * This library is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Lesser General Public License as published by
  17. * the Free Software Foundation, either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This library is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Lesser General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Lesser General Public License
  26. * along with this library. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /**@{*/
  29. #ifndef LIBOPENCM3_USB_MIDI_H
  30. #define LIBOPENCM3_USB_MIDI_H
  31. #include <stdint.h>
  32. /*
  33. * Definitions from the USB_MIDI_ or usb_midi_ namespace come from:
  34. * "Universal Serial Bus Class Definitions for MIDI Devices, Revision 1.0"
  35. */
  36. /* Appendix A.1: MS Class-Specific Interface Descriptor Subtypes */
  37. #define USB_MIDI_SUBTYPE_MS_DESCRIPTOR_UNDEFINED 0x00
  38. #define USB_MIDI_SUBTYPE_MS_HEADER 0x01
  39. #define USB_MIDI_SUBTYPE_MIDI_IN_JACK 0x02
  40. #define USB_MIDI_SUBTYPE_MIDI_OUT_JACK 0x03
  41. #define USB_MIDI_SUBTYPE_MIDI_ELEMENT 0x04
  42. /* Appendix A.2: MS Class-Specific Endpoint Descriptor Subtypes */
  43. #define USB_MIDI_SUBTYPE_DESCRIPTOR_UNDEFINED 0x00
  44. #define USB_MIDI_SUBTYPE_MS_GENERAL 0x01
  45. /* Appendix A.3: MS MIDI IN and OUT Jack types */
  46. #define USB_MIDI_JACK_TYPE_UNDEFINED 0x00
  47. #define USB_MIDI_JACK_TYPE_EMBEDDED 0x01
  48. #define USB_MIDI_JACK_TYPE_EXTERNAL 0x02
  49. /* Appendix A.5.1 Endpoint Control Selectors */
  50. #define USB_MIDI_EP_CONTROL_UNDEFINED 0x00
  51. #define USB_MIDI_ASSOCIATION_CONTROL 0x01
  52. /* Table 6-2: Class-Specific MS Interface Header Descriptor */
  53. struct usb_midi_header_descriptor {
  54. uint8_t bLength;
  55. uint8_t bDescriptorType;
  56. uint8_t bDescriptorSubtype;
  57. uint16_t bcdMSC;
  58. uint16_t wTotalLength;
  59. } __attribute__((packed));
  60. /* Table 6-3: MIDI IN Jack Descriptor */
  61. struct usb_midi_in_jack_descriptor {
  62. uint8_t bLength;
  63. uint8_t bDescriptorType;
  64. uint8_t bDescriptorSubtype;
  65. uint8_t bJackType;
  66. uint8_t bJackID;
  67. uint8_t iJack;
  68. } __attribute__((packed));
  69. /* Table 6-4: MIDI OUT Jack Descriptor (head) */
  70. struct usb_midi_out_jack_descriptor_head {
  71. uint8_t bLength;
  72. uint8_t bDescriptorType;
  73. uint8_t bDescriptorSubtype;
  74. uint8_t bJackType;
  75. uint8_t bJackID;
  76. uint8_t bNrInputPins;
  77. /* ... */
  78. } __attribute__((packed));
  79. /* Table 6.4: MIDI OUT Jack Descriptor (body) */
  80. struct usb_midi_out_jack_descriptor_body {
  81. /* ... */
  82. uint8_t baSourceID;
  83. uint8_t baSourcePin;
  84. /* ... */
  85. } __attribute__((packed));
  86. /* Table 6.4: MIDI OUT Jack Descriptor (tail) */
  87. struct usb_midi_out_jack_descriptor_tail {
  88. /* ... */
  89. uint8_t iJack;
  90. } __attribute__((packed));
  91. /* Table 6.4: MIDI OUT Jack Descriptor (single)
  92. *
  93. * This structure is a convenience covering the (normal) case where
  94. * there is only one input pin.
  95. */
  96. struct usb_midi_out_jack_descriptor {
  97. struct usb_midi_out_jack_descriptor_head head;
  98. struct usb_midi_out_jack_descriptor_body source[1];
  99. struct usb_midi_out_jack_descriptor_tail tail;
  100. } __attribute__((packed));
  101. /* Table 6-5: MIDI Element Descriptor (head) */
  102. struct usb_midi_element_descriptor_head {
  103. uint8_t bLength;
  104. uint8_t bDescriptorType;
  105. uint8_t bDescriptorSubtype;
  106. uint8_t bElementID;
  107. uint8_t bNrInputPins;
  108. /* ... */
  109. } __attribute__((packed));
  110. /* Table 6-5: MIDI Element Descriptor (body) */
  111. struct usb_midi_element_descriptor_body {
  112. /* ... */
  113. uint8_t baSourceID;
  114. uint8_t baSourcePin;
  115. /* ... */
  116. } __attribute__((packed));
  117. /* Table 6-5: MIDI Element Descriptor (tail) */
  118. struct usb_midi_element_descriptor_tail {
  119. /* ... */
  120. uint8_t bNrOutputPins;
  121. uint8_t bInTerminalLink;
  122. uint8_t bOutTerminalLink;
  123. uint8_t bElCapsSize;
  124. uint16_t bmElementCaps; /* host cannot assume this is 16-bit but device
  125. can (since highest defined bitmap value in
  126. v1.0 is bit 11) */
  127. uint8_t iElement;
  128. } __attribute__((packed));
  129. /* Table 6-5: MIDI Element Descriptor (single)
  130. *
  131. * This structure is a convenience covering the (common) case where
  132. * there is only one input pin.
  133. */
  134. struct usb_midi_element_descriptor {
  135. struct usb_midi_element_descriptor_head head;
  136. struct usb_midi_element_descriptor_body source[1];
  137. struct usb_midi_element_descriptor_tail tail;
  138. } __attribute__((packed));
  139. /* Table 6-7: Class-specific MS Bulk Data Endpoint Descriptor (head) */
  140. struct usb_midi_endpoint_descriptor_head {
  141. uint8_t bLength;
  142. uint8_t bDescriptorType;
  143. uint8_t bDescriptorSubType;
  144. uint8_t bNumEmbMIDIJack;
  145. } __attribute__((packed));
  146. /* Table 6-7: Class-specific MS Bulk Data Endpoint Descriptor (body) */
  147. struct usb_midi_endpoint_descriptor_body {
  148. uint8_t baAssocJackID;
  149. } __attribute__((packed));
  150. /* Table 6.7: Class-specific MS Bulk Data Endpoint Descriptor (single)
  151. *
  152. * This structure is a convenience covering the (normal) case where
  153. * there is only one input pin.
  154. */
  155. struct usb_midi_endpoint_descriptor {
  156. struct usb_midi_endpoint_descriptor_head head;
  157. struct usb_midi_endpoint_descriptor_body jack[1];
  158. } __attribute__((packed));
  159. #endif
  160. /**@}*/