Page 1 of 1

libusb & 128 bytes data transfer

Posted: Wed Oct 07, 2009 5:14 pm
by Urvin
Hi!
Now I'm trying to transfer data between my device and PC using libusb and custom requests.

I can send 128 bytes from the device to computer already, but I'm in doubt about sending this array of data back to AVR.

Would it be right if I use this construction to receieve data (avr-side)?

Code: Select all

#define CUSTOM_RQ_SET_ALL 2                     // request to set data array
#define USB_BUFFER_REPORT_LEN 128               // data array len
static uchar wholeData[USB_BUFFER_REPORT_LEN]   // this array should be filled with data

uchar   usbFunctionSetup(uchar data[8])
{
    usbRequest_t    *rq = (void *)data;

    if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR)
    {
        // Trying to get data from PC
        if(rq->bRequest == CUSTOM_RQ_SET_ALL)
        {
            uchar i;
         
            for (i=0; i<USB_BUFFER_REPORT_LEN; i++)
            {
                wholeData[i] = rq->wValue.bytes[i];
            }
        }
    }

    return 0;
}


What code should I use in the host application?

Re: libusb & 128 bytes data transfer

Posted: Thu Oct 08, 2009 1:17 pm
by Urvin
I tried to use this code in the host software (with the upper avr code):

Code: Select all

char usbReportBuffer[128];
//...
usb_control_msg(usbHandle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
                              CUSTOM_RQ_SET_ALL, 1, 0,usbReportBuffer, sizeof(usbReportBuffer), 5000);


I always get "1" at first position of wholeData array, other elements are trash-filled.
What do I need to change to receive data from array, but not wValue parameter, in microcontroller?

Re: libusb & 128 bytes data transfer

Posted: Thu Oct 08, 2009 6:41 pm
by Urvin
A little trip around usbRequest_t shows that I'm wrong with rq->wValue.bytes[i] cause of there are only two bytes spreading into integer type.
I see that there must be a pointer do data send from PC with size of rq->wLength.
And it's not usbMsgPtr :(

Re: libusb & 128 bytes data transfer

Posted: Fri Oct 09, 2009 12:43 am
by maxi
You need to implement function write, see usbconfig.h. There is an example in the documentation wiki http://vusb.wikidot.com/driver-api
For the host-side, example code can also be found in the wiki here http://vusb.wikidot.com/host-software

Re: libusb & 128 bytes data transfer

Posted: Fri Oct 09, 2009 7:51 am
by Urvin
Thanks!
I was afraid of using usbFunctionWrite just because of there's no such function in requests example of v-usb :roll: