Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIDI device class #11

Open
kisielk opened this issue Jan 2, 2018 · 8 comments
Open

Add MIDI device class #11

kisielk opened this issue Jan 2, 2018 · 8 comments

Comments

@kisielk
Copy link

kisielk commented Jan 2, 2018

I'm mostly doing USB-MIDI on STM32 devices and would like to switch to this library. Unless someone else is already working on it or has a functional implementation I will contribute mine when I have it ready.

Spec is here: http://www.usb.org/developers/docs/devclass_docs/midi10.pdf

@xcvista
Copy link
Contributor

xcvista commented Jan 2, 2018

Another common class I would suggest is mass storage.

@dmitrystu
Copy link
Owner

The MSC class definitions are partially done.

@kisielk
Copy link
Author

kisielk commented Jan 2, 2018

That should probably be tracked in a separate issue ;)

@kisielk
Copy link
Author

kisielk commented Jan 2, 2018

I already have a functional MIDI implementation using ST's Device Library for the F072, F373 and F746, so I should be able to port it over to this lib when I have some time..

@WojtaCZ
Copy link

WojtaCZ commented Sep 30, 2020

I know this is a old one, but has anyone made any progress on the MIDI class?

@dmitrystu
Copy link
Owner

No one but me. :)
But it's yet not completed nor tested. See this branch.

@GrantMTG
Copy link

GrantMTG commented Jan 18, 2022

We need to add another struct to usb_midi.h (there might be other things I discover as I go through this as well):

// Class-Specific AC (Audio Control) Interface Descriptor
struct usb_midi_ac_interface_desc {
   uint8_t  bLength;              /**<\brief Size of this descriptor in bytes. */
   uint8_t  bDescriptorType;      /**<\brief CS_INTERFACE descriptor type.     */
   uint8_t  bDescriptorSubType;   /**<\brief MIDI_HEADER descriptor subtype.  */
   uint16_t bcdADC;               /**<\brief AC SubClass Specification Release Number. */
   uint16_t wTotalLength;         /**<\brief Total size of class specific descriptors. */
   uint8_t  bInCollection;        /**<\brief Number of streaming interfaces.   */
   uint8_t  bInterfaceNumber;     /**<\brief Index of the current interface.   */
} __attribute__ ((packed));

@GrantMTG
Copy link

GrantMTG commented Feb 1, 2022

The only other things that I think are missing from usb_midi.h are,

(a) adding the definition for USB_MIDI_SUBCLASS_STREAM

#define USB_CLASS_MIDI              0x01U   /**<\brief MIDI Device class */
#define USB_MIDI_SUBCLASS_CONTROL   0x01U   /**<\brief Data Interface class */
#define USB_MIDI_SUBCLASS_STREAM    0x03U   /**<\brief MIDI Streaming */

(b) Preferred spelling of USB_MIDI_JACK_EXTERNAL

//#define USB_MIDI_JACK_EXTERNL       0x02U   /**<\brief Declares external Jack */ 
#define USB_MIDI_JACK_EXTERNAL      0x02U   /**<\brief Declares external Jack */ 

(c) Correction of baAssocJackID in usb_midi_class_ep_descriptor

struct usb_midi_class_ep_descriptor {
    uint8_t     bLength;                /**<\brief Size of the descriptor, in bytes.*/
    uint8_t     bDescriptorType;        /**<\brief CS_ENDPOINT descriptor.*/
    uint8_t     bDescriptorSubType;     /**<\brief USB_DTYPE_MIDI_EP_GENERAL subtype.*/
    uint8_t     bNumEmbMIDIJack;        /**<\brief Number of Embedded MIDI Jacks.*/
//    uint8_t     baAssocJackID[];        /**<\brief Embedded jacks ID's */ 
    uint8_t     baAssocJackID;          /**<\brief Embedded jacks ID's */ 
} __attribute__((packed));

(d) and finally, if it is not elsewhere (I didn't see it), the 9-byte version of the bulk endpoints. This one I am not 100% sure of yet since I have not run the USB Compliance Suite and both endpoint versions for USB MIDI.

struct usb_bulk_endpoint_desc {
    uint8_t  bLength;             /**<\brief Size of the descriptor, in bytes. */
    uint8_t  bDescriptorType;     /**<\brief Endpoint descriptor.*/
    uint8_t  bEndpointAddress;    /**<\brief Logical address of the endpoint within the device for
                                   * the current configuration, including direction mask. */
    uint8_t  bmAttributes;        /**<\brief Endpoint attributes, \ref USB_ENDPOINT_DEF.  */
    uint16_t wMaxPacketSize;      /**<\brief Size of the endpoint bank, in bytes. This indicates the
                                   * maximum packet size that the endpoint can receive at a time. */
    uint8_t  bInterval;           /**<\brief Ignored for bulk.   */
    uint8_t  bRefresh;            /**<\brief               */
    uint8_t  bSynchAddress;       /**<\brief               */
} __attribute__((packed));

See:
Example: https://github.com/kshoji/USB-MIDI-Link/blob/master/firmware/main.c
Discussion elsewhere: libopencm3/libopencm3#1130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants