This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Expanding In/Out Reports on Keil USB HID example code

I'm implementing an HID class device and have based my program on the HID USB program supplied by Keil. I'm new to USB but am a fairly experienced programmer otherwise.

I have got a basic program working fine bit with single byte input and output reports. I've tested the functionality using a client called SimpleHIDWrite.exe

I need to expand both in and out reports to 8 bytes each to communicate with the host. Has anybody successfully modified this example program or does anyone have any advice on how to do it properly?

My guess is that I need to edit the report descriptor and also set up the inreport and outreport as arrays. Is there anything I need to watch out for?

My target is the LPC2141.

Any advice or information would be much appreciated!

Thanks,
Gareth.

Parents
  • hiduser.h
    
    /* HID report size (count) */
    #define HID_INPUT_REPORT_BYTES       64             /* size of report in Bytes */
    #define HID_OUTPUT_REPORT_BYTES      64             /* size of report in Bytes */
    #define HID_FEATURE_REPORT_BYTES     64             /* size of report in Bytes */
    
    /* HID In/Out Endpoint Address */
    #define HID_EP_OUT      0x01
    #define HID_EP_IN       0x81
    

    hiduser.c
    
    #include <string.h>
    
    BOOL HID_GetReport (void) {
    
      /* ReportID = SetupPacket.wValue.WB.L; */
      switch (SetupPacket.wValue.WB.H) {
        case HID_REPORT_INPUT:
          GetInReport();
    //      EP0Buf[0] = InReport;
          memcpy( EP0Buf, InReport, SetupPacket.wLength );
          break;
        case HID_REPORT_OUTPUT:
          return (__FALSE);        /* Not Supported */
        case HID_REPORT_FEATURE:
          GetFeatureReport();
          memcpy( EP0Buf, FeatureReport, SetupPacket.wLength );
          break;
      }
      return (__TRUE);
    }
    
    BOOL HID_SetReport (void) {
    
      /* ReportID = SetupPacket.wValue.WB.L; */
      switch (SetupPacket.wValue.WB.H) {
        case HID_REPORT_INPUT:
          return (__FALSE);        /* Not Supported */
        case HID_REPORT_OUTPUT:
    //      OutReport = EP0Buf[0];
          memcpy( OutReport, EP0Buf, SetupPacket.wLength );
          SetOutReport();
          break;
        case HID_REPORT_FEATURE:
          memcpy( FeatureReport, EP0Buf, SetupPacket.wLength );
          SetFeatureReport();
          break;
      }
      return (__TRUE);
    }
    

    demo.h
    
    
    /* HID Demo Variables */ extern U8 InReport[ HID_INPUT_REPORT_BYTES ]; extern U8 OutReport[ HID_OUTPUT_REPORT_BYTES ]; extern U8 FeatureReport[ HID_FEATURE_REPORT_BYTES ];
    /* HID Demo Functions */ extern void GetInReport (void); extern void SetOutReport (void); extern void GetFeatureReport (void); extern void SetFeatureReport (void);

    demo.c
    
    #include "hiduser.h"
    #include "demo.h"
    
    U8 InReport[ HID_INPUT_REPORT_BYTES ];           /* HID Input Report    */
    U8 OutReport[ HID_OUTPUT_REPORT_BYTES ];         /* HID Out Report      */
    U8 FeatureReport[ HID_FEATURE_REPORT_BYTES ];    /* HID Feature Report  */
    
    /*------------------------------------------------------------------------------
      Get HID Input Report -> InReport
     *------------------------------------------------------------------------------*/
    void GetInReport (void) {
        // this function is called just when Get_Report( input ) request comes
        // fill InReport[] with an input report, here
    
    //  if ((FIO2PIN & PB_INT0) == 0) {           /* Check if PBINT is pressed */
    //    InReport = 0x01;
    //  } else {
    //    InReport = 0x00;
    //  }
    }
    
    /*------------------------------------------------------------------------------
      Set HID Output Report <- OutReport
     *------------------------------------------------------------------------------*/
    void SetOutReport (void) {
        // this function is called just when Set_Report( output ) request comes
        // At the entry of this function, OutReport[] holds an output report from the host
    
    //    IOPIN1 = (IOPIN1 & ~LED_MSK) | (OutReport << 16);
    }
    
    /*------------------------------------------------------------------------------
      Get HID Feature Report -> FeatureReport
     *------------------------------------------------------------------------------*/
    void GetFeatureReport (void) {
        // this function is called just when Get_Report( feature ) request comes
        // fill FeatureReport[] with an input report, here
    }
    
    /*------------------------------------------------------------------------------
      Set HID Feature Report <- FeatureReport
     *------------------------------------------------------------------------------*/
    void SetFeatureReport (void) {
        // this function is called just when Set_Report( feature ) request comes
        // At the entry of this function, FeatureReport[] holds an feature report from the host
    }
    

    Tsuneo

Reply
  • hiduser.h
    
    /* HID report size (count) */
    #define HID_INPUT_REPORT_BYTES       64             /* size of report in Bytes */
    #define HID_OUTPUT_REPORT_BYTES      64             /* size of report in Bytes */
    #define HID_FEATURE_REPORT_BYTES     64             /* size of report in Bytes */
    
    /* HID In/Out Endpoint Address */
    #define HID_EP_OUT      0x01
    #define HID_EP_IN       0x81
    

    hiduser.c
    
    #include <string.h>
    
    BOOL HID_GetReport (void) {
    
      /* ReportID = SetupPacket.wValue.WB.L; */
      switch (SetupPacket.wValue.WB.H) {
        case HID_REPORT_INPUT:
          GetInReport();
    //      EP0Buf[0] = InReport;
          memcpy( EP0Buf, InReport, SetupPacket.wLength );
          break;
        case HID_REPORT_OUTPUT:
          return (__FALSE);        /* Not Supported */
        case HID_REPORT_FEATURE:
          GetFeatureReport();
          memcpy( EP0Buf, FeatureReport, SetupPacket.wLength );
          break;
      }
      return (__TRUE);
    }
    
    BOOL HID_SetReport (void) {
    
      /* ReportID = SetupPacket.wValue.WB.L; */
      switch (SetupPacket.wValue.WB.H) {
        case HID_REPORT_INPUT:
          return (__FALSE);        /* Not Supported */
        case HID_REPORT_OUTPUT:
    //      OutReport = EP0Buf[0];
          memcpy( OutReport, EP0Buf, SetupPacket.wLength );
          SetOutReport();
          break;
        case HID_REPORT_FEATURE:
          memcpy( FeatureReport, EP0Buf, SetupPacket.wLength );
          SetFeatureReport();
          break;
      }
      return (__TRUE);
    }
    

    demo.h
    
    
    /* HID Demo Variables */ extern U8 InReport[ HID_INPUT_REPORT_BYTES ]; extern U8 OutReport[ HID_OUTPUT_REPORT_BYTES ]; extern U8 FeatureReport[ HID_FEATURE_REPORT_BYTES ];
    /* HID Demo Functions */ extern void GetInReport (void); extern void SetOutReport (void); extern void GetFeatureReport (void); extern void SetFeatureReport (void);

    demo.c
    
    #include "hiduser.h"
    #include "demo.h"
    
    U8 InReport[ HID_INPUT_REPORT_BYTES ];           /* HID Input Report    */
    U8 OutReport[ HID_OUTPUT_REPORT_BYTES ];         /* HID Out Report      */
    U8 FeatureReport[ HID_FEATURE_REPORT_BYTES ];    /* HID Feature Report  */
    
    /*------------------------------------------------------------------------------
      Get HID Input Report -> InReport
     *------------------------------------------------------------------------------*/
    void GetInReport (void) {
        // this function is called just when Get_Report( input ) request comes
        // fill InReport[] with an input report, here
    
    //  if ((FIO2PIN & PB_INT0) == 0) {           /* Check if PBINT is pressed */
    //    InReport = 0x01;
    //  } else {
    //    InReport = 0x00;
    //  }
    }
    
    /*------------------------------------------------------------------------------
      Set HID Output Report <- OutReport
     *------------------------------------------------------------------------------*/
    void SetOutReport (void) {
        // this function is called just when Set_Report( output ) request comes
        // At the entry of this function, OutReport[] holds an output report from the host
    
    //    IOPIN1 = (IOPIN1 & ~LED_MSK) | (OutReport << 16);
    }
    
    /*------------------------------------------------------------------------------
      Get HID Feature Report -> FeatureReport
     *------------------------------------------------------------------------------*/
    void GetFeatureReport (void) {
        // this function is called just when Get_Report( feature ) request comes
        // fill FeatureReport[] with an input report, here
    }
    
    /*------------------------------------------------------------------------------
      Set HID Feature Report <- FeatureReport
     *------------------------------------------------------------------------------*/
    void SetFeatureReport (void) {
        // this function is called just when Set_Report( feature ) request comes
        // At the entry of this function, FeatureReport[] holds an feature report from the host
    }
    

    Tsuneo

Children
No data