• AVR Freaks

Hot!USB Host MIDI

Author
Soulnafein
Starting Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/08/15 03:26:04
  • Location: 0
  • Status: offline
2020/09/24 08:41:45 (permalink)
4.5 (2)

USB Host MIDI

Hello there,
I'm trying to connect a MIDI Keyboard to a PIC24FJ64GB002.
I've successfully managed to compile and run the example in the MLA that allows to connect a Computer Keyboard.
I've been trying to understand how to connect the USB Keyboard now. I've noticed that there is a "driver" for it under framework/usb. I can see a file usb_host_midi.c but that file requires a usb_host_midi.h that is missing from the installation.
Do you have any idea why is missing? Are you aware of any example of USB Host MIDI?
Cheers,
#1

3 Replies Related Threads

    aurelienalbert
    Starting Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/10/26 00:07:35
    • Location: 0
    • Status: offline
    Re: USB Host MIDI 2020/11/17 11:15:05 (permalink)
    2 (1)
    Hi Soulnafein!
     
    Are you still struggling with this problem?
     
    This is what you are looking for: https://github.com/MicrochipTech/mla_usb . Take a look at the the inc/ directory.
     
    Well, I'm actually trying to do the exact same thing as you, which is getting midi info from a midi keyboard (mine is an akai mpk mini mk2) and output a gate from the PIC, to trigger anything that needs gate (like an envelope for a synth).
     
    I've been searching for a long time example of how to use that code to make a ush midi host that actually works but there's no way I can find an existing example.
     
    I'm new to microcontroller programming so this task is actually a huge challenge to me. What about sharing our progress in this journey?
     
    My roadmap to reach the goal "Parsing midi data from usb midi keyboard" is the following:
    1. [OK] Blink LEDs with a PIC
    2. [WIP] Connecting an HID mouse to the PIC and blink an LED when pressing the left button.
    3. [NOK] Connecting a midi keyboard to the PIC and blink an LED when pressing a pad of the keyboard.
     
    I'm trying to understand if there's some kind of midi parser within the usb_host_midi.c file but no result yet.
     
    Cheers and hope you've not abandoned this project. If the two of us work on it, we could get this thing done.
    #2
    Soulnafein
    Starting Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2020/08/15 03:26:04
    • Location: 0
    • Status: offline
    Re: USB Host MIDI 2020/11/26 10:11:33 (permalink)
    4.5 (2)
    Hello there. I've managed to make my project work.  You can find the code here: https://github.com/soulnafein/midi-to-cv
    I'm not a PIC expert, nor an electronics expert, nor a C expert, so use it at your own risk.
    I'm in the process of adding a schematic to the repository but you should be able to understand what's going on easily.
    Most of the application specific usb code is in the keyboard module.
    I'm using an external 16mhz crystal with 18pF capacitors.
    I've followed this schematic to setup the USB related circuits: https://www.hobbytronics.co.uk/datasheets/usb-host-v2-basic-IC.pdf
    In my program you'll find some example of how to read a note from a  midi keyboard, and how to light up an LED when a key is pressed.
     
     
    #3
    aurelienalbert
    Starting Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/10/26 00:07:35
    • Location: 0
    • Status: offline
    Re: USB Host MIDI 2020/11/27 00:22:21 (permalink)
    4 (1)
    Hey Soulnafein!

    Glad to hear you got it working. Good job! And thanks a lot for sharing your contribution.
     
    On my side, my midi keyboard is enumerated by the PIC and the PIC detects when the keyboard is attached or detached (not that amazing but still a step forward).
     
    I'm struggling with sending request from the host to the IN endpoint to read midi data. The endpoint is busy untill I detach the keyboard from the PIC, which is not very interesting.
     
    Here below is my piece app tasks method which is called in the main function. If someone sees a mistake, I'll take any advice.
     

    void APP_HostMIDIKeyboardTasks()
    {    
        if (midi_keyboard.device == NULL)
            midi_keyboard.device = USBHostMIDIDeviceDetect();
        
        switch(midi_keyboard.state)
        {            
            case DEVICE_NOT_CONNECTED:
                if (midi_keyboard.device != NULL)
                {
                    SYSTEM_Initialize(SYSTEM_STATE_USB_HOST_MIDI_KEYBOARD);
                    midi_keyboard.state = DEVICE_CONNECTED;
                    TIMER_RequestTick(&APP_HostTimerHandler, 10);
                }
                break;
                
            case DEVICE_CONNECTED:
                break;

            case GET_INPUT_REPORT:
                if (USBHostMIDIRead(midi_keyboard.device,
                                    MIDI_KEYBOARD_ENDPOINT_IN,
                                    &midi_keyboard.buffer,
                                    sizeof(&midi_keyboard.buffer))!=USB_SUCCESS)
                {
                    // Host may be busy/error -- keep trying
                }
                else
                {
                    // USB_SUCCESS received, waiting for TRANSFER_DONE
                    midi_keyboard.state = INPUT_REPORT_PENDING;
                }
                break;

            case INPUT_REPORT_PENDING:
                if(!USBHostMIDITransferIsBusy(midi_keyboard.device, MIDI_KEYBOARD_ENDPOINT_IN))
                {
                    LED_On(LED_USB_HOST_MIDI_KEYBOARD_DEVICE_READY);
                    midi_keyboard.state = DEVICE_CONNECTED;
                    App_ProcessInputReport();
                }
                break;

            case ERROR_REPORTED:
                break;

            default:
                break;

        }
    }

     
    I'll take a look at your code to see what you've done for that.
     
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5