Adding MIDI interface

The next step is to add MIDI interface. Algoriddim Djay did not recognized my device as Reloop Beatpad after cloning VID and PID. Maybe after cloning the MIDI interface it will.

I cloned the MIDI descriptor part from Beatpad. I added EP1 IN and EP2 OUT Bulk endpoints. The addresses are different from the Beatpad endpoint addresses, but as I mentioned earlier I cannot set the endpoint addresses in the FS USB core. I hope the software is not too picky about addresses.

I modified USBD_AUDIO_Init to initialize the new endpoints, and also DeInit. For MIDI there are no class specific Setup request, so it is nothing to do with the Setup part fortunatelly.

I modified USBD_AUDIO_DataOut to read data from the MIDI endpoint.

Another important thing is to set a TX FIFO for the EP1 IN endpoint in usbd_conf.c file. HAL_PCD_SetTxFiFo(&hpcd, 1, 0x40);

The FS USB core has 320 word FIFO for all in and out endpoints, so we have to devide maximum this amount between our FIFOs. The size parameter needs to be the number of words, not bytes.

I am going to use my MIOS MIDI port to this project, because there is no support in the ST libraries. For now, I only want to test the interface, so I didn’t add the MIOS stack. I only made the MIDI_Periodic_Task() which sends and (receives) in MIOS and invoked in every microseconds. My task sends a hardcoded note on event if the device is configured. I fill the buffer from the push button external interrupt. So the code sends a note on event on every buttonpush.

void MIDI_Periodic_Task(void)
{
     if(USBD_Device.dev_state ==USBD_STATE_CONFIGURED)
     {
            USBD_LL_Transmit (&USBD_Device,
                            MIDI_IN_EP,
                            &txbuff[0],
                            4);
     }
}

I used midi-ox to test the functionality, and it worked. Yeah!

midi-ox

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s