Spell check library source code files.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / HID.c
index c387665..992f7b3 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
+     Copyright (C) Dean Camera, 2011.
 
   dean [at] fourwalledcubicle [dot] com
 
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -29,7 +29,8 @@
 */
 
 #define  __INCLUDE_FROM_USB_DRIVER
 */
 
 #define  __INCLUDE_FROM_USB_DRIVER
-#include "../../HighLevel/USBMode.h"
+#include "../../Core/USBMode.h"
+
 #if defined(USB_CAN_BE_HOST)
 
 #define  __INCLUDE_FROM_HID_DRIVER
 #if defined(USB_CAN_BE_HOST)
 
 #define  __INCLUDE_FROM_HID_DRIVER
@@ -88,37 +89,64 @@ uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo
                USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);
 
                if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
                USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);
 
                if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
-                 DataINEndpoint = EndpointData;
+                 DataINEndpoint  = EndpointData;
                else
                  DataOUTEndpoint = EndpointData;
        }
 
        for (uint8_t PipeNum = 1; PipeNum < PIPE_TOTAL_PIPES; PipeNum++)
        {
                else
                  DataOUTEndpoint = EndpointData;
        }
 
        for (uint8_t PipeNum = 1; PipeNum < PIPE_TOTAL_PIPES; PipeNum++)
        {
+               uint16_t Size;
+               uint8_t  Type;
+               uint8_t  Token;
+               uint8_t  EndpointAddress;
+               uint8_t  InterruptPeriod;
+               bool     DoubleBanked;
+
                if (PipeNum == HIDInterfaceInfo->Config.DataINPipeNumber)
                {
                if (PipeNum == HIDInterfaceInfo->Config.DataINPipeNumber)
                {
-                       Pipe_ConfigurePipe(PipeNum, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,
-                                          DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize,
-                                          HIDInterfaceInfo->Config.DataINPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE);
-                       Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS);
-
-                       HIDInterfaceInfo->State.DataINPipeSize = DataINEndpoint->EndpointSize;
+                       Size            = DataINEndpoint->EndpointSize;
+                       EndpointAddress = DataINEndpoint->EndpointAddress;
+                       Token           = PIPE_TOKEN_IN;
+                       Type            = EP_TYPE_INTERRUPT;
+                       DoubleBanked    = HIDInterfaceInfo->Config.DataINPipeDoubleBank;
+                       InterruptPeriod = DataINEndpoint->PollingIntervalMS;
+
+                       HIDInterfaceInfo->State.DataINPipeSize   = DataINEndpoint->EndpointSize;
                }
                else if (PipeNum == HIDInterfaceInfo->Config.DataOUTPipeNumber)
                {
                }
                else if (PipeNum == HIDInterfaceInfo->Config.DataOUTPipeNumber)
                {
-                       Pipe_ConfigurePipe(PipeNum, EP_TYPE_INTERRUPT, PIPE_TOKEN_OUT,
-                                          DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize,
-                                          HIDInterfaceInfo->Config.DataOUTPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE);
-                       Pipe_SetInterruptPeriod(DataOUTEndpoint->PollingIntervalMS);
-
-                       HIDInterfaceInfo->State.DataOUTPipeSize = DataOUTEndpoint->EndpointSize;
+                       if (DataOUTEndpoint == NULL)
+                         continue;
+               
+                       Size            = DataOUTEndpoint->EndpointSize;
+                       EndpointAddress = DataOUTEndpoint->EndpointAddress;
+                       Token           = PIPE_TOKEN_OUT;
+                       Type            = EP_TYPE_INTERRUPT;
+                       DoubleBanked    = HIDInterfaceInfo->Config.DataOUTPipeDoubleBank;
+                       InterruptPeriod = DataOUTEndpoint->PollingIntervalMS;
+
+                       HIDInterfaceInfo->State.DataOUTPipeSize   = DataOUTEndpoint->EndpointSize;
                        HIDInterfaceInfo->State.DeviceUsesOUTPipe = true;
                }
                        HIDInterfaceInfo->State.DeviceUsesOUTPipe = true;
                }
+               else
+               {
+                       continue;
+               }
+
+               if (!(Pipe_ConfigurePipe(PipeNum, Type, Token, EndpointAddress, Size,
+                                        DoubleBanked ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE)))
+               {
+                       return HID_ENUMERROR_PipeConfigurationFailed;
+               }
+               
+               if (InterruptPeriod)
+                 Pipe_SetInterruptPeriod(InterruptPeriod);
        }
 
        }
 
-       HIDInterfaceInfo->State.InterfaceNumber = HIDInterface->InterfaceNumber;
-       HIDInterfaceInfo->State.HIDReportSize   = HIDDescriptor->HIDReportLength;
-       HIDInterfaceInfo->State.SupportsBootProtocol = (HIDInterface->SubClass != HID_BOOTP_NonBootProtocol);
+       HIDInterfaceInfo->State.InterfaceNumber      = HIDInterface->InterfaceNumber;
+       HIDInterfaceInfo->State.HIDReportSize        = HIDDescriptor->HIDReportLength;
+       HIDInterfaceInfo->State.SupportsBootProtocol = (HIDInterface->SubClass != HID_CSCP_NonBootProtocol);
        HIDInterfaceInfo->State.LargestReportSize    = 8;
        HIDInterfaceInfo->State.IsActive = true;
 
        HIDInterfaceInfo->State.LargestReportSize    = 8;
        HIDInterfaceInfo->State.IsActive = true;
 
@@ -127,12 +155,13 @@ uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo
 
 static uint8_t DCOMP_HID_Host_NextHIDInterface(void* const CurrentDescriptor)
 {
 
 static uint8_t DCOMP_HID_Host_NextHIDInterface(void* const CurrentDescriptor)
 {
-       if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
+       USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
+
+       if (Header->Type == DTYPE_Interface)
        {
        {
-               USB_Descriptor_Interface_t* CurrentInterface = DESCRIPTOR_PCAST(CurrentDescriptor,
-                                                                               USB_Descriptor_Interface_t);
+               USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
 
 
-               if (CurrentInterface->Class == HID_INTERFACE_CLASS)
+               if (Interface->Class == HID_CSCP_HIDClass)
                  return DESCRIPTOR_SEARCH_Found;
        }
 
                  return DESCRIPTOR_SEARCH_Found;
        }
 
@@ -141,9 +170,11 @@ static uint8_t DCOMP_HID_Host_NextHIDInterface(void* const CurrentDescriptor)
 
 static uint8_t DCOMP_HID_Host_NextHID(void* const CurrentDescriptor)
 {
 
 static uint8_t DCOMP_HID_Host_NextHID(void* const CurrentDescriptor)
 {
-       if (DESCRIPTOR_TYPE(CurrentDescriptor) == HID_DTYPE_HID)
+       USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
+
+       if (Header->Type == HID_DTYPE_HID)
          return DESCRIPTOR_SEARCH_Found;
          return DESCRIPTOR_SEARCH_Found;
-       else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
+       else if (Header->Type == DTYPE_Interface)
          return DESCRIPTOR_SEARCH_Fail;
        else
          return DESCRIPTOR_SEARCH_NotFound;
          return DESCRIPTOR_SEARCH_Fail;
        else
          return DESCRIPTOR_SEARCH_NotFound;
@@ -151,15 +182,16 @@ static uint8_t DCOMP_HID_Host_NextHID(void* const CurrentDescriptor)
 
 static uint8_t DCOMP_HID_Host_NextHIDInterfaceEndpoint(void* const CurrentDescriptor)
 {
 
 static uint8_t DCOMP_HID_Host_NextHIDInterfaceEndpoint(void* const CurrentDescriptor)
 {
-       if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
+       USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
+
+       if (Header->Type == DTYPE_Endpoint)
        {
        {
-               USB_Descriptor_Endpoint_t* CurrentEndpoint = DESCRIPTOR_PCAST(CurrentDescriptor,
-                                                                             USB_Descriptor_Endpoint_t);
+               USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
 
 
-               if (!(Pipe_IsEndpointBound(CurrentEndpoint->EndpointAddress)))
+               if (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress)))
                  return DESCRIPTOR_SEARCH_Found;
        }
                  return DESCRIPTOR_SEARCH_Found;
        }
-       else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
+       else if (Header->Type == DTYPE_Interface)
        {
                return DESCRIPTOR_SEARCH_Fail;
        }
        {
                return DESCRIPTOR_SEARCH_Fail;
        }
@@ -208,7 +240,7 @@ uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo,
 
                if (HIDInterfaceInfo->Config.HIDParserData->UsingReportIDs)
                {
 
                if (HIDInterfaceInfo->Config.HIDParserData->UsingReportIDs)
                {
-                       ReportID = Pipe_Read_Byte();
+                       ReportID = Pipe_Read_8();
                        *(BufferPos++) = ReportID;
                }
 
                        *(BufferPos++) = ReportID;
                }
 
@@ -220,7 +252,7 @@ uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo,
                ReportSize = Pipe_BytesInPipe();
        }
 
                ReportSize = Pipe_BytesInPipe();
        }
 
-       if ((ErrorCode = Pipe_Read_Stream_LE(BufferPos, ReportSize, NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError)
+       if ((ErrorCode = Pipe_Read_Stream_LE(BufferPos, ReportSize, NULL)) != PIPE_RWSTREAM_NoError)
          return ErrorCode;
 
        Pipe_ClearIN();
          return ErrorCode;
 
        Pipe_ClearIN();
@@ -249,9 +281,9 @@ uint8_t HID_Host_SendReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo
                Pipe_Unfreeze();
 
                if (ReportID)
                Pipe_Unfreeze();
 
                if (ReportID)
-                 Pipe_Write_Stream_LE(&ReportID, sizeof(ReportID), NO_STREAM_CALLBACK);
+                 Pipe_Write_Stream_LE(&ReportID, sizeof(ReportID), NULL);
 
 
-               if ((ErrorCode = Pipe_Write_Stream_LE(Buffer, ReportSize, NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError)
+               if ((ErrorCode = Pipe_Write_Stream_LE(Buffer, ReportSize, NULL)) != PIPE_RWSTREAM_NoError)
                  return ErrorCode;
 
                Pipe_ClearOUT();
                  return ErrorCode;
 
                Pipe_ClearOUT();