Does USB HID support USB MIDI?

Posted on
  • Hi,

    I'm trying to work out if it's possible to use the new Pico USB HID support to get the Pico to work as a USB-MIDI controller.

    I want to be able to plug a Pico into the USB port of a computer and have the Pico send MIDI messages without any USB to MIDI adaptors in between.

    The Teensy 3 USB library seems to support this and HIDUINO does similar for the Arduino Uno.

    I've dug into the code to try and figure out how it's done. The Teensy 3 source has the Keyboard, Mouse, Joystick and MIDI descriptors in the same file, usb_desc.c.

    Mouse descriptors:
    https://github.com/PaulStoffregen/cores/­blob/master/teensy3/usb_desc.c#L159-L198­

    MIDI descriptors:
    https://github.com/PaulStoffregen/cores/­blob/master/teensy3/usb_desc.c#L482-L563­

    Is it possible to use the MIDI descriptors in the same way as the Espruino Keyboard, Mouse and Tablet examples? Or is the USB-MIDI interface different to the HID interface?

    I'm going to have a go at this but I thought it would be worth asking first as my USB knowledge is non-existent.

    Thanks for any help!
    Andrew

  • Hi Andrew,

    There was actually a question about this here too: http://forum.espruino.com/conversations/­268671/?offset=25#comment12401332

    It looks (to me at least - I'm not exactly a USB guru :) like MIDI devices aren't actually HID devices, which means that you have to specify a configuration descriptor (not just the report descriptor like you do for HID).

    Now I can change Espruino to allow that, but it's all getting quite low-level then, as if you want to be able to use Espruino's serial port as well your descriptor has to include a USB CDC descriptor as well - and you have to make sure you've got the right endpoint numbers.

    I just wonder how many people would be up for fiddling with that - however it looks like there are at least 2 so far, so I might end up putting it in :)

  • @andrewn: I am trying to get enough facts together to convince Gordon that USB-Midi is a 'must have' feature. :-) But he is right. Not too many users asked for it and its not so easy to implement. I would definitely use the pico for my USB-Midi projects because i like the nodejs / closures / events / modules - concept.

    A alternative to USB-Midi could be OSC over USB/Serial/SLIP. It is supported by pd, Max, Ableton Live, Native Instruments and many others. But i don't know if that's easier to implement?

    http://cnmat.berkeley.edu/oscuino
    https://github.com/CNMAT/OSC
    https://forum.pjrc.com/threads/18849-Ope­n-Sound-Control

  • As always I'll add my vote for better general USB support.
    BTW, I am still having problems with the Keyboard HID implementation on all of our macs, which triggers some mouse events in addition to the keystrokes (unfortunately also mouse button events, which trigger the context menu, which in return keeps the keystrokes from being handled...). I don't have that problem on windows.

    As far as I understand there might be more descriptors needed than the report descriptor.

    Concerning MIDI, I would think that it's another thing beyond getting HID right, as it seems to need an even more general implementation. I also see that this feels like a huge amount of study and implementation.

    Still, I would like to encourage any work on the USB client implementation as it seems a pretty obvious application area for the pico to me. I would have gone Teensy (LC) if I hadn't that stubborn believe in Espruino's programming model (combined with that low footprint of this projects HW implementation). I'd really like to see USB being a No. 1 citizen on this project.

    -Stev

  • USB features would definitely be a great thing to build on for espruino, especially with the pico being USB stick shaped. Being able to just stick it into a computer and program and debug it without extra cables, circuits or development environments is awesome, so adding things like USB HID really builds on that, as you can build devices that don't need their own networking hardware or special pc software to work.

  • Well, it is all Open Source if anyone feels motivated... It'd be nice if this graph was looking a little less one-sided ;)

    It'd also be nice to see a few projects that actually use USB HID as it is before I spend yet more time on it.

    I just had a quick go at letting other types of descriptor be specified, but no luck yet... It's one of those things that works perfectly when you attach the debugger, and then breaks when you try and run it normally.

    I'll try and get that fixed at some point, and then potentially getting something like MIDI should be easier (as it'd just be a matter of allowing the endpoint type to be specified).

    @Stev there's a possibility that the Mac is a bit stubborn about the config descriptor (which currently reports back that it's a mouse). I've just set it to 'none', so if you use this build when it's compiled, you may have more luck? Let me know how you get on.

  • @Gordon It's only so one-sided because you keep adding so many awesome features!

    I understand that USB HID isn't a high priority right now, I'm just voicing support for it. I know that you put a lot of time into things like stability of core functions and basic modules for common components/boards/sensors, and its really paying off with helping people get straight into Espruino.

    USB mass storage for Espruino is something I'd like to tackle myself... if I ever slow down on pcb design and getting the kinks out of my home automation...

  • We definitively need another graph for good advice, opinion and complains. It's just a question of pushing the right values...

    Other than that, the None config descriptor works well on my mac, eliminating the probs with ghost mousing while typing (Edit: I also assumed the scaling prob for tablet mode being gone, but I was testing on the wrong machine...).

    Very cool.
    Stev

  • Phew, great! Glad that's sorted then! :)

    Yes - all feedback is great - the worst thing is not having anyone suggest anything or tell me when they're having problems. I've just got to make sure I spend my time working on the right stuff :)

    At the moment the priority is getting a proper 1v80 release out with reliable USB HID support. After that I'll definitely look at expanding the capabilities though - actually allowing people to make MIDI instruments is really cool, and something I definitely want to allow.

  • I already was holding still :) When I read over the HID pdfs and found the config descriptor with its mouse and keyboard entries after our last chat, I didn't ask since setUSBHID already has that keyed list as a parameter that allows for more than the reportDescriptor entry...

    I am personally looking forward to 1v80 and anything USB related (an "intelligent" mass storage device?). I just wanted to voice that opinion again, like others, that your idea of adding USB was cool and fits the product well and should no be seen as a annoying step child just because it comes with all those funny new demands from the implementation and from the forum once you opened that box.

    I see the forum's interest as a good sign for the Pico and Espruino, actually.

    And what did you expect when adding that USB connector right to the board :)

    -Stev

  • :) yeah, USB mass storage is an option. Micro Python does it - although the flash memory is a bit more limited on the Pico, so it's possible that we'd actually end up having the option to use Mass Storage to store your code or the option to do it as we do at the moment (storing the interpreter state), but not both.

  • Thanks for the swift reply Gordon. I hadn't seen the developments on that thread!

  • The reason I prefer MIDI over OSC support is because of the recent WebMIDI standard (some demo). I'm imagining some cool instruments/interfaces created with Pico that can be plugged into the USB port and then interact via a web page.

    I'm keen to see if this is possible so I'll try to find time to follow Gordon's suggestions for getting a custom firmware built. Not that I know what I'm doing.

    @loopMasta, let me know if you make any progress or if you fancy collaborating on it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Does USB HID support USB MIDI?

Posted by Avatar for andrewn @andrewn

Actions