abcminiuser / lufa

LUFA - the Lightweight USB Framework for AVRs.
http://www.lufa-lib.org
1.04k stars 325 forks source link

OUT endpoint for the XMega devices #29

Open peetervois opened 10 years ago

peetervois commented 10 years ago

I was reading from forums that making OUT endpint for HID class devices is a burden. I have XMega project where I am using generic HID device for sending and receiving up to 20 bytes of data telegrams. My controller is composite device including 3 different USB HID logical devices and using 4 endpoints. One of the logical devices needs OUT endpoint. So, I invested some time to implement possibility to have also OUT endpoint available fro HID class device.

The feature can be turned on in Config/LUFAConfig.h with

    #elif (ARCH == ARCH_XMEGA)
        #define HID_HAVE_OUT_ENDPOINT

It is implemented only for XMEGA in this diff. Without the define it works as before.

The xmega controller USB hardware is haveing register for reading out how many bytes was sent in the OUT transfer, the mega ones seem not to have it. When dealing with telegrams and not with streams, the amount of bytes is not a big problem, as telegram needs to have protocol for reading and handling of the contents.

It seems I can not attach the patch but must include in this description, UPS and it seems to be reverse.

diff -r 8e76cf8ff108 -r 5b1ce1d1573c Drivers/USB/Class/Device/HIDClassDevice.c
--- a/Drivers/USB/Class/Device/HIDClassDevice.c Mon May 12 16:00:37 2014 +0300
+++ b/Drivers/USB/Class/Device/HIDClassDevice.c Thu May 01 20:16:51 2014 +0300
@@ -145,10 +145,6 @@

    if (!(Endpoint_ConfigureEndpointTable(&HIDInterfaceInfo->Config.ReportINEndpoint, 1)))
      return false;
-#ifdef HID_HAVE_OUT_ENDPOINT
-   if (!(Endpoint_ConfigureEndpointTable(&HIDInterfaceInfo->Config.ReportOUTEndpoint, 1)))
-     return false;
-#endif

    return true;
 }
@@ -205,41 +201,6 @@

        HIDInterfaceInfo->State.PrevFrameNum = USB_Device_GetFrameNumber();
    }
-
-#ifdef HID_HAVE_OUT_ENDPOINT
-   bool CALLBACK_HID_Device_ProcessHIDoutReport( USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
-           const void* ReportData,
-           const uint16_t ReportSize );
-
-   if( HIDInterfaceInfo->Config.ReportOUTEndpoint.Address != 0 )
-   {
-       Endpoint_SelectEndpoint(HIDInterfaceInfo->Config.ReportOUTEndpoint.Address);
-
-       /* Check to see if a packet has been sent from the host */
-       if (Endpoint_IsOUTReceived())
-       {
-           uint8_t* ReportData = HIDInterfaceInfo->Config.ReportOUTBuffer;
-           uint16_t ReportSize = 0;
-
-           while ( Endpoint_IsReadWriteAllowed()  )
-           {
-               uint8_t b = Endpoint_Read_8();
-               if( ReportSize < HIDInterfaceInfo->Config.ReportOUTBufferSize )
-               {
-                   // avoid over filling of the buffer
-                   *ReportData = b;
-                   ReportSize++;
-                   ReportData++;
-               }
-           }
-
-           /* Process Report Data */
-           if( CALLBACK_HID_Device_ProcessHIDoutReport( HIDInterfaceInfo, ReportData, ReportSize ) )
-               Endpoint_ClearOUT();
-       }
-   }
-
-#endif
 }

 #endif
diff -r 8e76cf8ff108 -r 5b1ce1d1573c Drivers/USB/Class/Device/HIDClassDevice.h
--- a/Drivers/USB/Class/Device/HIDClassDevice.h Mon May 12 16:00:37 2014 +0300
+++ b/Drivers/USB/Class/Device/HIDClassDevice.h Thu May 01 20:16:51 2014 +0300
@@ -86,11 +86,6 @@
                    uint8_t  InterfaceNumber; /**< Interface number of the HID interface within the device. */

                    USB_Endpoint_Table_t ReportINEndpoint; /**< Data IN HID report endpoint configuration table. */
-#ifdef HID_HAVE_OUT_ENDPOINT
-                   USB_Endpoint_Table_t ReportOUTEndpoint; /**< Data OUT HID report endpoint configuration table. */
-                   void*    ReportOUTBuffer;     /**< Pointer to the reserved memory for out report buffer */
-                   uint8_t  ReportOUTBufferSize; /**< Size of the out report buffer. This amount of bytes will be filled from USB device */
-#endif // HID_HAVE_OUT_ENDPOINT

                    void*    PrevReportINBuffer; /**< Pointer to a buffer where the previously created HID input report can be
                                                  *  stored by the driver, for comparison purposes to detect report changes that