Hi MaximLiadov
you are coming close to it.
intercepting the Vendor request inside the endpoint0.c is simple as putting these lignes inside the switch:
Code: Select all
#if defined( VENDOR_AUDIO_REQS )
case USB_BMREQ_H2D_VENDOR_DEV:
case USB_BMREQ_D2H_VENDOR_DEV:
{
result = vendorAudioRequests(ep0_out, ep0_in, &sp, vendorIF );
} break;
#endif
in my case I have added an interface parameter because I want to call routines running which will be on tile0 (for example read-write in flash).
now your vendorrequest.xc should be as simple as that:
Code: Select all
// executed from within endpoint0 upon usb commands arriving in ep0
int vendorAudioRequests(XUD_ep ep0_out, XUD_ep ep0_in,
USB_SetupPacket_t &sp ,
client VENDOR_IF(vIF) // to access information available on tile 0
) {
unsigned char buffer[512];
XUD_Result_t result = XUD_RES_ERR;
unsigned datalength;
xprintf("VendorRequest 0x%X, wValue=0x%X, wIndex=0x%X, length=%d, dir=%d, type=%X\n",
sp.bRequest, sp.wValue, sp.wIndex, sp.wLength, sp.bmRequestType.Direction, sp.bmRequestType.Type);
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) {
// Host to device
// get buffer associated with request
if (sp.wLength)
if (XUD_GetBuffer(ep0_out, buffer, datalength) != XUD_RES_OKAY) return XUD_RES_ERR;
} else datalength = 0;
// treat requests
switch( sp.bRequest ) {
case 0x48: {
xprintf("bRequest = 0x48\n");
xprintf("Host to Device with 4data\n");
xprintf("buffer[0..3] = %X %X %X %X\n",buffer[0],buffer[1],buffer[2],buffer[3]);
result = XUD_RES_OKAY;
} break;
case 0x49: {
xprintf("bRequest = 0x49\n");
xprintf("Device to Host with 2 data\n");
datalength = 2;
buffer[0] = 0x34; buffer[1] = 0x12;
result = XUD_RES_OKAY;
} break;
default: break;
} // switch brequest
if (result == XUD_RES_OKAY){
if (sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H && sp.wLength != 0) {
// send back expected data to the host
result = XUD_DoGetRequest(ep0_out, ep0_in, buffer, datalength, sp.wLength);
} else {
// acknoledge command treatment
result = XUD_DoSetRequestStatus(ep0_in); }
}
return result;
}
in this example there are only 2 vendor requests. 0x48 is receiving information from host (H2D) and 0x49 is sending information from host upon request.
this works great for setting parameters or pulling information.
if you need to push infromation from device to host asynchronously then you will need to implement an 'interrupt' endpoint, like the feedback clock or the hid report but I have no example for this.
br/fabriceo