[alsa-devel] How to add a new MIDI device to the usbaudio driver

Clemens Ladisch clemens at ladisch.de
Wed Aug 24 21:51:34 CEST 2011


Daniel Mack wrote:
> Ok, then let's try the attached patch.

> +		/* reset the port */
> +		err = snd_usbmidi_ftdi_command(umidi, 0, 0);
> +		if (err < 0)
> +			break;
> +
> +		/* set mctrl */
> +		err = snd_usbmidi_ftdi_command(umidi, 1, 0x303);
> +		if (err < 0)
> +			break;

The chip reads its initial configuration from the EEPROM, so these
commands might not be necessary.

> +		/* set baud rate */
> +		err = snd_usbmidi_ftdi_command(umidi, 3, 0xc04e);

Replace 0xc04e with 0x60 to get exactly 31250 baud.

Furthermore, the FT232RL chip sends two modem status bytes in its
packets, so we need something like this to prevent them from being
interpreted as MIDI:

--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -791,7 +791,8 @@ static struct usb_protocol_ops snd_usbmidi_novation_ops = {
 static void snd_usbmidi_raw_input(struct snd_usb_midi_in_endpoint* ep,
 				  uint8_t* buffer, int buffer_length)
 {
-	snd_usbmidi_input_data(ep, 0, buffer, buffer_length);
+	if (buffer_length > 2)
+		snd_usbmidi_input_data(ep, 0, buffer + 2, buffer_length - 2);
 }

 static void snd_usbmidi_raw_output(struct snd_usb_midi_out_endpoint* ep,


Regards,
Clemens


More information about the Alsa-devel mailing list