From: Xiaofan C. <xia...@gm...> - 2010-04-08 22:59:28
|
On Thu, Apr 8, 2010 at 11:15 PM, Pete Batard <pb...@gm...> wrote: > On 2010.04.08 15:47, Xiaofan Chen wrote: >> Actually it should be ( (SetupPkt.W_Value.byte.HB == 0x00) || >> (SetupPkt.W_Value.byte.LB == 0x01) ). > > Unless I'm missing something, I don't thing this is what we want. Sorry I made a mistake here. > My understanding is that the Low Byte is the report ID we filter against > and originally, the code was: > > if (SetupPkt.W_Value.byte.LB == 0x00) // => only handle report ID 0 > > Thus, if we want to also handle report ID 1, which we have set as the > report ID for the input descriptor, we need to have: > > if ( (SetupPkt.W_Value.byte.HB == 0x00) || (SetupPkt.W_Value.byte.LB > == 0x01) ) My change is if ( (SetupPkt.W_Value.byte.HB == 0x01). I think we can only handle report ID 1, there is no report ID 0 now. I made similar changes for the Output report (only handle Report ID 2) and feature report (only handle Report ID 3). >> There are other places to change in the firmware. > > Yes, but these don't seem to be called, at least when using xusb (I > checked that with serial debug statements). > The following are my modifications to main.c. void mySetReportHandler(void) { BYTE count = 0; // Get the report type from the Setup packet. switch (MSB(SetupPkt.W_Value)) { case 0x02: // Output report { switch(LSB(SetupPkt.W_Value)) { case 2: // Report ID 2 // This example application copies the Output report data // to ToSendDataBuffer. // Assumes Input and Output reports are the same length. // A "real" application would do something more useful with the data. // wCount holds the number of bytes read in the Data stage. // This example assumes the report fits in one transaction. for(count=0; count <= HID_OUTPUT_REPORT_BYTES - 1; count++) { hid_report_in[count] = hid_report_out[count] ; } break; } // end switch(LSB(SetupPkt.W_Value)) break; } case 0x03: // Feature report { // Get the report ID from the Setup packet. switch(LSB(SetupPkt.W_Value)) { case 3: // Report ID 3 // The Feature report data is in hid_report_feature. // This example application just sends the data back in the next // Get_Report request for a Feature report. // wCount holds the number of bytes read in the Data stage. // This example assumes the report fits in one transaction. // The Feature report uses a single buffer so to send the same data back // in the next IN Feature report, there is nothing to copy. // The data is in hid_report_feature[HID_FEATURE_REPORT_BYTES] break; } // end switch(LSB(SetupPkt.W_Value)) break; } } // end switch(MSB(SetupPkt.W_Value)) } // end mySetReportHandler BYTE ReportSupported(void) { //USBDeviceTasks(); switch (MSB(SetupPkt.W_Value)) { case 0x02: // Output report { switch(LSB(SetupPkt.W_Value)) { case 0x02: // Report ID 2 { return 2; } default: { // Other report IDs not supported. return 0; } } // end switch(LSB(SetupPkt.W_Value)) } case 0x03: // Feature report { switch(LSB(SetupPkt.W_Value)) { case 0x03: // Report ID 3 { return 3; } default: { // Other report IDs not supported. return 0; } } // end switch(LSB(SetupPkt.W_Value)) } default: { return 0; } } // end switch(MSB(SetupPkt.W_Value)) } // end ReportSupported void User_Get_Report_Handler(void) { #if defined(USER_GET_REPORT_HANDLER) if ((SetupPkt.W_Value.byte.HB) == 0x01) { // Input report if (SetupPkt.W_Value.byte.LB == 0x01) { // Report ID = 1, supported USBEP0SendRAMPtr((BYTE*)&hid_report_out[0],HID_INPUT_REPORT_BYTES,USB_EP0_INCLUDE_ZERO); } } else if (SetupPkt.W_Value.byte.HB == 0x03) { // Feature report if (SetupPkt.W_Value.byte.LB == 0x03) { // Report ID = 3, supported USBEP0SendRAMPtr((BYTE*)&hid_report_feature[0],HID_FEATURE_REPORT_BYTES,USB_EP0_INCLUDE_ZERO); } } #endif }//end User_Get_Report_Handler1 /******************************************************************** * Function: void User_Set_Report_Handler1(void) * * PreCondition: A Setup packet with a HID Set_Report request * has been received. * * Input: None * * Output: None * * Side Effects: None * * Overview: If the HID supports the report the host is requesting * to send, prepares to receive the report in the * Data stage of the control transfer. * Otherwise the endpoint returns STALL. * This code is similar to the code for SET_LINE_CODING in * usb_function_cdc.c, USBCheckCDCRequest() function. * * Note: None *******************************************************************/ void User_Set_Report_Handler(void) { #if defined(USER_SET_REPORT_HANDLER) switch (ReportSupported()) { case 0x02: // Output report { if (SetupPkt.W_Value.byte.LB == 0x02) { // Report ID = 3, supported outPipes[0].wCount.Val = SetupPkt.wLength; outPipes[0].pDst.bRam = (BYTE*)OUTPUT_REPORT; outPipes[0].pFunc = SET_REPORT_PFUNC; outPipes[0].info.bits.busy = 1; } break; } case 0x03: // Feature report { if (SetupPkt.W_Value.byte.LB == 0x03) { // Report ID = 3, supported outPipes[0].wCount.Val = SetupPkt.wLength; outPipes[0].pDst.bRam = (BYTE*)FEATURE_REPORT; outPipes[0].pFunc = SET_REPORT_PFUNC; outPipes[0].info.bits.busy = 1; } break; } } #endif }//end User_Set_Report_Handler1 -- Xiaofan http://mcuee.blogspot.com |