libusb & 128 bytes data transfer

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Urvin
Posts: 16
Joined: Wed Sep 16, 2009 3:26 pm

libusb & 128 bytes data transfer

Post by Urvin » Wed Oct 07, 2009 5:14 pm

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?

Urvin
Posts: 16
Joined: Wed Sep 16, 2009 3:26 pm

Re: libusb & 128 bytes data transfer

Post by Urvin » Thu Oct 08, 2009 1:17 pm

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?

Urvin
Posts: 16
Joined: Wed Sep 16, 2009 3:26 pm

Re: libusb & 128 bytes data transfer

Post by Urvin » Thu Oct 08, 2009 6:41 pm

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 :(

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: libusb & 128 bytes data transfer

Post by maxi » Fri Oct 09, 2009 12:43 am

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

Urvin
Posts: 16
Joined: Wed Sep 16, 2009 3:26 pm

Re: libusb & 128 bytes data transfer

Post by Urvin » Fri Oct 09, 2009 7:51 am

Thanks!
I was afraid of using usbFunctionWrite just because of there's no such function in requests example of v-usb :roll:

Post Reply