Saturday, April 6, 2013

MIDI USB Class for the Maple board



I got myself an OpenPipe breakout board and want to use a Maple board to connect it to a soft synth on my computer or a hardware synth. For this I want the Maple to implement a MIDI USB class device.

The Maple has as standard a USB serial device that gets setup and loaded as part of building a sketch and its then available as SerialUSB object. The MIDI USB will replace the Serial USB, and register the device as a MIDI class compliant device. The Maple bootloader is not affected, but the remote reset into bootloader is not implemented, so a manual reset is needed to get into the bootloader, I can live with that.

The MIDI USB needs a few things to setup

  • USB Setup and handling of Control Requests
  • A MIDI USB device descriptor to present itself to a host computer as a MIDI USB device
  • Bulk IN and OUT endpoints for MIDI USB packets, 32 bit/4 byte blocks of data
  • Code that interprets the MIDI USB packets as standard MIDI events.

Building the MIDI USB class as a variant of the existing USB serial code, the first and third parts are almost identical for MIDI and Serial, actually easier for MIDI since no modem control line handling is necessary and no management endpoint is needed.
The device descriptor is bit harder, but its a static datastructure and just following the MIDI USB documentation carefully will get you through this.
The USB MIDI package handling is standard MIDI code, and does not depend on the details of the USB transport layer.  

The code has been tested and registers as a MIDI device both under OSX and Android, and seems to be working.

A git repository can be found at    https://github.com/mlu/maple-ide

The MIDI USB is built from the following files:
High level device object, Wirish style, replaces usb_serial.cpp
  • usb_midi.cpp
  • include/wirish/usb_midi.h
Low level USB driver, replaces usb_cdcacm.c
  • stm32f1/usb_midi_device.c
  • include/libmaple/usb_midi_device.h
The process of setting up a sketch to use MIDI instead of Serial is still clumsy and needs some manual editing of the boards.h file.

The development is done on a modified Maple-IDE that uses a current arm toolchain and a libmaple layout that is closer to the present libmaple layout so the files are placed in different locations than the standard Maple-IDE file layout.

UPDATE 2013/0412

The descriptor definitions have been factored out of usb_midi_device and placed into usb_midi_descr.c/h . A working copy of the libmaple git repository with the midi usb files placed in their proper place in the hierarchy can be found at https://github.com/mlu/libmaple .


      

No comments: