Jump to content

PIC usb - midi in from computer - cv out to synthesizers


Knas

Recommended Posts

Hi, sorry if this post has nothing really to do with uCapps's stuff, but i'm quite desperate for information;

I'm doing a USB module that's supposed to take MIDIStream data as input from a computer, when connected the device is enumerated but no midi ports show up. It's a classic, i've found the same problem all over the internet but i'm yet to find a sollution. Does anyone have any hints about how to solve this?? I'm currently using WinXP and have tried to use the MBHP USB descriptors but without success.

(note! i'm *not* going to try and do a midi-out so no silicon-bug problems here.. )

Thanks

Knas

Link to comment
Share on other sites

Hi Knas,

maybe it's related to the buffer size of your endpoints?

Here the descriptors that I used for the PIC18F4550 (it's written for the C18 compiler)


/* Device Descriptor */
rom USB_DEV_DSC device_dsc=
{   
    sizeof(USB_DEV_DSC),    // Size of this descriptor in bytes
    DSC_DEV,                // DEVICE descriptor type
    0x0200,                // USB Spec Release Number in BCD format
    CDC_DEVICE,            // Class Code
    0x00,                  // Subclass code
    0x00,                  // Protocol code
    EP0_BUFF_SIZE,          // Max packet size for EP0, see usbcfg.h
    0x16C0,                // Vendor ID --- sponsored by voti.nl! see http://www.voti.nl/pids
    1020,                  // Product ID: CDC RS-232 Emulation Demo
    0x0000,                // Device release number in BCD format
    0x01,                  // Manufacturer string index
    0x02,                  // Product string index
    0x00,                  // Device serial number string index
    0x01                    // Number of possible configurations
};

/* Configuration 1 Descriptor */
CFG01=
{
    /* Configuration Descriptor */
9, // Size of this descriptor in bytes
    0x02,                  // CONFIGURATION descriptor type
    9+ 9+9 +9+7+ 6+6+ 9+9+ 9+5+9+5, 0x00,          // Total length of data for this cfg
    0x02,                  // Number of interfaces in this cfg
    0x01,                  // Interface number
    0x00,                  // Configuration string index
    0x80,                  // Attributes, see usbdefs_std_dsc.h
    50,                    // Max power consumption (2X mA)


    /* Descriptor of Audio Control Interface */
    9, // Size of this descriptor in bytes
    0x04,                  // INTERFACE descriptor type
    0x00,                  // Interface Number
    0x00,                  // Alternate Setting Number
    0x00,                  // Number of endpoints in this intf
    0x01, // Class code (AUDIO)
    0x01, // Sub Class (AUDIO_CONTROL)
    0x00, // Sub Sub Class
    0x00,                  // Interface string index
   
    /* Class Specific Audio Control Interface Descriptor */
    9,     // Size of this descriptor in bytes
    0x24,                  // descriptor type
0x01, // Header subtype
0x00, 0x01, // Revision of class specification - 1.0
9, 0x00, // total size of class-specific descriptors
0x01, // number of streaming interfaces
0x01, // MIDI Streaming Interface 1 belongs to this AudioControl Interface



    /* Descriptor of MIDI Stream Interface */
    9, // Size of this descriptor in bytes
    0x04,                  // INTERFACE descriptor type
    0x01,                  // Interface Number
    0x00,                  // Alternate Setting Number
    0x02,                  // Number of endpoints in this intf
    0x01, // Class code (AUDIO)
    0x03, // Sub Class (MIDISTREAMING)
    0x00, // Sub Sub Class
    0x00,                  // Interface string index
   
    /* Class Specific MIDI Stream Interface Descriptor */
    7,     // Size of this descriptor in bytes
    0x24,                  // descriptor type
0x01, // Header subtype
0x00, 0x01, // Revision of class specification - 1.0
7+ 6+6+ 9+9+ 9+5+9+5,0x00, // total size of class-specific descriptors


    /* MIDI In Descriptor (Embedded) */
    6,     // Size of this descriptor in bytes
    0x24,                 // descriptor type
    0x02,                 // MIDI_IN_JACK subtype
0x01, // EMBEDDED
0x01, // ID of this jack
0x00, // unused

    /* MIDI In Descriptor (External) */
    6,     // Size of this descriptor in bytes
    0x24,                 // descriptor type
    0x02,                 // MIDI_IN_JACK subtype
0x02, // EXTERNAL
0x02, // ID of this jack
0x00, // unused

    /* MIDI Out Descriptor (Embedded) */
    9,     // Size of this descriptor in bytes
    0x24,                 // descriptor type
    0x03,                 // MIDI_OUT_JACK subtype
0x01, // EMBEDDED
0x03, // ID of this jack
0x01, // number of input pins of this jack
0x02, // ID of the entity to which this pin is connected
0x01, // Output Pin number of the entity to which this input pin is connected
0x00, // unused

    /* MIDI Out Descriptor (External) */
    9,     // Size of this descriptor in bytes
    0x24,                 // descriptor type
    0x03,                 // MIDI_OUT_JACK subtype
0x02, // EXTERNAL
0x04, // ID of this jack
0x01, // number of input pins of this jack
0x01, // ID of the entity to which this pin is connected
0x01, // Output Pin number of the entity to which this input pin is connected
0x00, // unused

    /* EP2 Out */
    9,     // Size of this descriptor in bytes
    0x05,                 // descriptor type (ENDPOINT)
    0x01,                 // Out Endpoint 1
0x02, // Bulk, not shared
0x40, 0x00, // 64 bytes per packet
0x00, // ignore for bulk
0x00, // unused
0x00, // unused

    5,     // Size of this descriptor in bytes
    0x25,                 // descriptor type (CS_ENDPOINT)
    0x01,                 // MS_GENERAL
0x01, // number of embedded MIDI INs
0x01, // ID of embedded MIDI In Jack

    /* EP2 In */
    9,     // Size of this descriptor in bytes
    0x05,                 // descriptor type (ENDPOINT)
    0x81,                 // In Endpoint 1
0x02, // Bulk, not shared
0x40, 0x00, // 64 bytes per packet
0x00, // ignore for bulk
0x00, // unused
0x00, // unused

    5,     // Size of this descriptor in bytes
    0x25,                 // descriptor type (CS_ENDPOINT)
    0x01,                 // MS_GENERAL
0x01, // number of embedded MIDI OUTs
0x03, // ID of embedded MIDI Out Jack
};

rom struct{byte bLength;byte bDscType;word string[1];}sd000={
sizeof(sd000),DSC_STR,0x0409};

rom struct{byte bLength;byte bDscType;word string[25];}sd001={
sizeof(sd001),DSC_STR,
'T','h','o','r','s','t','e','n',' ','K','l','o','s','e',
' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};

rom struct{byte bLength;byte bDscType;word string[25];}sd002={
sizeof(sd002),DSC_STR,
'M','B','H','P',' ','U','S','B',' ','P','I','C',
'E','m','u','l','a','t','i','o','n',' ','D',' '};
[/code]

Best Regards, Thorsten.

Link to comment
Share on other sites

maybe it's related to the buffer size of your endpoints?

Here the descriptors that I used for the PIC18F4550 (it's written for the C18 compiler)

Thanks Thorsten, i finally got to try and implement the code, still no midi ports though at least this doesn't appear as a "composite device" which - as i've understood - is part of the problem. I'm thinking that i've done something seriously wrong here since none of the code i've tried so far has worked - even though they've apparently worked for other people. I'm wondering if i need to get a class-specific request (which i never get as far as i can see) before windows decides to install the midiports. Maybe the buffersize is incorrect, though i've tried changing the size in the descriptor so far without luck.

Okay, this is the only changes i've made to the HID example to make it go midi:

* Changing descriptor

* Adding typedefs for calculating the descriptor size microchip-style

* Changed the ClassReqHandler[1] to point at a function of my own (USBCheckMIDIStreamRequest)

* Changed the initializationroutine for the endpoints

* Changed ProcessIO to look for incoming events

* Changed EP0_BUFF_SIZE to 64 (i tried 8 as well, but i guess it should be 64 with this descriptor, right?)

Right now i'm just looking for some kind of request that is not directed to an interface, or a request that

is not a STANDARD_REQUEST type deal. Just anything. Here's a piece of the code i've changed, it might not be fully functioning, just a brief explanation of what i'm trying to do:

#define MIDI_UEP                  UEP1
#define MIDI_BD_OUT          ep1Bo
#define MIDI_BD_IN              ep1Bi
#define MIDI_BD_OUT          ep1Bo
#define MIDI_BD_IN              ep1Bi

//Called when we get Set Config Handler request and Configured State
void MIDIInitEP(void) { 
    MIDI_UEP = EP_OUT_IN|HSHK_EN;                // Enable 2 data pipes  
    MIDI_BD_OUT.Cnt = sizeof(midi_out);    // Set buffer size
    MIDI_BD_OUT.ADR = (byte*)&midi_out;    // Set buffer address
    MIDI_BD_OUT.Stat._byte = _USIE|_DAT0|_DTSEN; // Set status
    MIDI_BD_IN.Cnt = sizeof(midi_in);    // Set buffer size
    MIDI_BD_IN.ADR = (byte*)&midi_in;    // Set buffer address
    MIDI_BD_IN.Stat._byte = _UCPU|_DAT1; // Set status
}

void USBCheckMIDIStreamRequest(void) {

    if(SetupPkt.Recipient != RCPT_INTF) return;
    /* Use debug functions here to show that we've got something that is *not* directed to an interface
        for once. I also tried if(SetupPkt.RequestType == STANDARD) return; just to see if i could get
        *anything*
    */
}

#define mMIDITxIsBusy()              MIDI_BD_IN.Stat.UOWN
#define mMIDIRxIsBusy()              MIDI_BD_OUT.Stat.UOWN

void ProcessIO(void) {   
    if((usb_device_state < CONFIGURED_STATE)||(UCONbits.SUSPND==1)) return;
    if(usb_device_state == DETACHED_STATE) return;
    if(UCONbits.SUSPND==1) return; 
    if (!MIDI_BD_OUT.Stat.UOWN) { // == 0) { hdebug('R','x',' ',' ') }
    if (!MIDI_BD_IN.Stat.UOWN) { //== 1) {	hdebug('T','x',' ',' ') }
}

A few things are a little unclear to me, for one i can't quite wrap my head around how to monitor the

UOWN bit, also the whole buffer deal is a little uncertain for me now. I might have forgot to add something

in the code, but hopefully not. Oh, also, i'm using the pic18f2455 but that shouldn't be a problem i guess.

Thanks

Knas

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...