Corrections, improvements and additions to the incomplete RNDISHost demo.
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 13 Nov 2009 13:24:04 +0000 (13:24 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 13 Nov 2009 13:24:04 +0000 (13:24 +0000)
Change device demos which use the joystick to use the natural UP, DOWN, LEFT, RIGHT ordering in all demos when checking the joystick's position.

13 files changed:
Demos/Device/ClassDriver/CDCMouse/CDCMouse.c
Demos/Device/ClassDriver/Joystick/Joystick.c
Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c
Demos/Device/ClassDriver/Mouse/Mouse.c
Demos/Device/LowLevel/Joystick/Joystick.c
Demos/Device/LowLevel/Mouse/Mouse.c
Demos/Host/Incomplete/RNDISEthernetHost/Lib/RNDISCommands.c
Demos/Host/Incomplete/RNDISEthernetHost/Lib/RNDISCommands.h
Demos/Host/Incomplete/RNDISEthernetHost/RNDISEthernetHost.c
LUFA/Drivers/USB/LowLevel/OTG.h
LUFA/Drivers/USB/USB.h
LUFA/ManPages/ChangeLog.txt
LUFA/ManPages/CompileTimeTokens.txt

index b625327..e21e0bc 100644 (file)
@@ -210,10 +210,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
        else if (JoyStatus_LCL & JOY_DOWN)\r
          MouseReport->Y =  1;\r
 \r
-       if (JoyStatus_LCL & JOY_RIGHT)\r
-         MouseReport->X =  1;\r
-       else if (JoyStatus_LCL & JOY_LEFT)\r
+       if (JoyStatus_LCL & JOY_LEFT)\r
          MouseReport->X = -1;\r
+       else if (JoyStatus_LCL & JOY_RIGHT)\r
+         MouseReport->X =  1;\r
 \r
        if (JoyStatus_LCL & JOY_PRESS)\r
          MouseReport->Button  = (1 << 0);\r
index 36a74a2..00bcb6f 100644 (file)
@@ -148,10 +148,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
        else if (JoyStatus_LCL & JOY_DOWN)\r
          JoystickReport->Y =  100;\r
 \r
-       if (JoyStatus_LCL & JOY_RIGHT)\r
-         JoystickReport->X =  100;\r
-       else if (JoyStatus_LCL & JOY_LEFT)\r
+       if (JoyStatus_LCL & JOY_LEFT)\r
          JoystickReport->X = -100;\r
+       else if (JoyStatus_LCL & JOY_RIGHT)\r
+         JoystickReport->X =  100;\r
 \r
        if (JoyStatus_LCL & JOY_PRESS)\r
          JoystickReport->Button  = (1 << 1);\r
index 77aa2a9..caa33f9 100644 (file)
@@ -170,6 +170,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
        uint8_t JoyStatus_LCL    = Joystick_GetStatus();\r
        uint8_t ButtonStatus_LCL = Buttons_GetStatus();\r
 \r
+       /* Determine which interface must have its report generated */\r
        if (HIDInterfaceInfo == &Keyboard_HID_Interface)\r
        {\r
                USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;\r
@@ -207,10 +208,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
                else if (JoyStatus_LCL & JOY_DOWN)\r
                  MouseReport->Y =  1;\r
 \r
-               if (JoyStatus_LCL & JOY_RIGHT)\r
-                 MouseReport->X =  1;\r
-               else if (JoyStatus_LCL & JOY_LEFT)\r
+               if (JoyStatus_LCL & JOY_LEFT)\r
                  MouseReport->X = -1;\r
+               else if (JoyStatus_LCL & JOY_RIGHT)\r
+                 MouseReport->X =  1;\r
 \r
                if (JoyStatus_LCL & JOY_PRESS)\r
                  MouseReport->Button  = (1 << 0);\r
index c53d429..c29cc15 100644 (file)
@@ -148,10 +148,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
        else if (JoyStatus_LCL & JOY_DOWN)\r
          MouseReport->Y =  1;\r
 \r
-       if (JoyStatus_LCL & JOY_RIGHT)\r
-         MouseReport->X =  1;\r
-       else if (JoyStatus_LCL & JOY_LEFT)\r
+       if (JoyStatus_LCL & JOY_LEFT)\r
          MouseReport->X = -1;\r
+       else if (JoyStatus_LCL & JOY_RIGHT)\r
+         MouseReport->X =  1;\r
 \r
        if (JoyStatus_LCL & JOY_PRESS)\r
          MouseReport->Button  = (1 << 0);\r
index 6d04c8f..aa5244c 100644 (file)
@@ -156,10 +156,10 @@ bool GetNextReport(USB_JoystickReport_Data_t* ReportData)
        else if (JoyStatus_LCL & JOY_DOWN)\r
          ReportData->Y =  100;\r
 \r
-       if (JoyStatus_LCL & JOY_RIGHT)\r
-         ReportData->X =  100;\r
-       else if (JoyStatus_LCL & JOY_LEFT)\r
+       if (JoyStatus_LCL & JOY_LEFT)\r
          ReportData->X = -100;\r
+       else if (JoyStatus_LCL & JOY_RIGHT)\r
+         ReportData->X =  100;\r
 \r
        if (JoyStatus_LCL & JOY_PRESS)\r
          ReportData->Button  = (1 << 1);\r
index 2f7a63f..4b318e3 100644 (file)
@@ -238,10 +238,10 @@ void CreateMouseReport(USB_MouseReport_Data_t* ReportData)
        else if (JoyStatus_LCL & JOY_DOWN)\r
          ReportData->Y =  1;\r
 \r
-       if (JoyStatus_LCL & JOY_RIGHT)\r
-         ReportData->X =  1;\r
-       else if (JoyStatus_LCL & JOY_LEFT)\r
+       if (JoyStatus_LCL & JOY_LEFT)\r
          ReportData->X = -1;\r
+       else if (JoyStatus_LCL & JOY_RIGHT)\r
+         ReportData->X = 1;\r
 \r
        if (JoyStatus_LCL & JOY_PRESS)\r
          ReportData->Button  = (1 << 0);\r
index e248b18..4802bed 100644 (file)
@@ -98,18 +98,20 @@ uint8_t RNDIS_KeepAlive(void)
        return HOST_SENDCONTROL_Successful;\r
 }\r
 \r
-uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize, RNDIS_Initialize_Complete_t* InitMessageResponse)\r
+uint8_t RNDIS_InitializeDevice(uint16_t HostMaxPacketSize, uint16_t* DeviceMaxPacketSize)\r
 {\r
        uint8_t ErrorCode;\r
 \r
-       RNDIS_Initialize_Message_t InitMessage;\r
+       RNDIS_Initialize_Message_t  InitMessage;\r
+       RNDIS_Initialize_Complete_t InitMessageResponse;\r
 \r
        InitMessage.MessageType     = REMOTE_NDIS_INITIALIZE_MSG;\r
        InitMessage.MessageLength   = sizeof(RNDIS_Initialize_Message_t);\r
        InitMessage.RequestId       = RequestID++;\r
+\r
        InitMessage.MajorVersion    = REMOTE_NDIS_VERSION_MAJOR;\r
        InitMessage.MinorVersion    = REMOTE_NDIS_VERSION_MINOR;\r
-       InitMessage.MaxTransferSize = sizeof(RNDIS_Packet_Message_t) + MaxPacketSize;\r
+       InitMessage.MaxTransferSize = HostMaxPacketSize;\r
        \r
        if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&InitMessage,\r
                                                       sizeof(RNDIS_Initialize_Message_t))) != HOST_SENDCONTROL_Successful)\r
@@ -117,11 +119,16 @@ uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize, RNDIS_Initialize_Complete
                return ErrorCode;\r
        }\r
        \r
-       if ((ErrorCode = RNDIS_GetEncapsulatedResponse(InitMessageResponse,\r
+       if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&InitMessageResponse,\r
                                                       sizeof(RNDIS_Initialize_Complete_t))) != HOST_SENDCONTROL_Successful)\r
        {\r
                return ErrorCode;\r
        }\r
+\r
+       if (InitMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)\r
+         return RNDIS_COMMAND_FAILED;\r
+         \r
+       *DeviceMaxPacketSize = InitMessageResponse.MaxTransferSize;\r
        \r
        return HOST_SENDCONTROL_Successful;\r
 }\r
@@ -138,13 +145,13 @@ uint8_t RNDIS_SetRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
        \r
        RNDIS_Set_Complete_t SetMessageResponse;\r
        \r
-       SetMessageData.SetMessage.MessageType   = REMOTE_NDIS_SET_MSG;\r
-       SetMessageData.SetMessage.MessageLength = sizeof(RNDIS_Set_Message_t) + Length;\r
-       SetMessageData.SetMessage.RequestId     = RequestID++;\r
+       SetMessageData.SetMessage.MessageType    = REMOTE_NDIS_SET_MSG;\r
+       SetMessageData.SetMessage.MessageLength  = sizeof(RNDIS_Set_Message_t) + Length;\r
+       SetMessageData.SetMessage.RequestId      = RequestID++;\r
                        \r
-       SetMessageData.SetMessage.Oid           = Oid;\r
+       SetMessageData.SetMessage.Oid            = Oid;\r
        SetMessageData.SetMessage.InformationBufferLength = Length;\r
-       SetMessageData.SetMessage.InformationBufferOffset = 0;\r
+       SetMessageData.SetMessage.InformationBufferOffset = (sizeof(RNDIS_Set_Message_t) - sizeof(RNDIS_Message_Header_t));\r
        SetMessageData.SetMessage.DeviceVcHandle = 0;\r
        \r
        memcpy(&SetMessageData.ContigiousBuffer, Buffer, Length);\r
@@ -161,19 +168,22 @@ uint8_t RNDIS_SetRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
                return ErrorCode;\r
        }\r
 \r
+       if (SetMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)\r
+         return RNDIS_COMMAND_FAILED;\r
+         \r
        return HOST_SENDCONTROL_Successful;\r
 }\r
 \r
-uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)\r
+uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t MaxLength)\r
 {\r
        uint8_t ErrorCode;\r
 \r
-       RNDIS_Query_Message_t  QueryMessage;\r
+       RNDIS_Query_Message_t QueryMessage;\r
 \r
        struct\r
        {\r
                RNDIS_Query_Complete_t QueryMessageResponse;\r
-               uint8_t              ContigiousBuffer[Length];\r
+               uint8_t                ContigiousBuffer[MaxLength];\r
        } QueryMessageResponseData;\r
 \r
        QueryMessage.MessageType    = REMOTE_NDIS_QUERY_MSG;\r
@@ -181,7 +191,7 @@ uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
        QueryMessage.RequestId      = RequestID++;\r
                        \r
        QueryMessage.Oid            = Oid;\r
-       QueryMessage.InformationBufferLength = Length;\r
+       QueryMessage.InformationBufferLength = 0;\r
        QueryMessage.InformationBufferOffset = 0;\r
        QueryMessage.DeviceVcHandle = 0;\r
 \r
@@ -197,12 +207,15 @@ uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
                return ErrorCode;\r
        }\r
 \r
-       memcpy(Buffer, &QueryMessageResponseData.ContigiousBuffer, Length);\r
+       if (QueryMessageResponseData.QueryMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)\r
+         return RNDIS_COMMAND_FAILED;\r
+\r
+       memcpy(Buffer, &QueryMessageResponseData.ContigiousBuffer, MaxLength);\r
 \r
        return HOST_SENDCONTROL_Successful;\r
 }\r
 \r
-uint8_t RNDIS_GetPacketSize(uint16_t* PacketSize)\r
+uint8_t RNDIS_GetPacketLength(uint16_t* PacketLength)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -213,7 +226,9 @@ uint8_t RNDIS_GetPacketSize(uint16_t* PacketSize)
                return ErrorCode;\r
        }\r
 \r
-       *PacketSize = (uint16_t)DeviceMessage.DataLength;\r
+       *PacketLength = (uint16_t)DeviceMessage.DataLength;\r
+       \r
+       Pipe_Discard_Stream(DeviceMessage.DataOffset - (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)));\r
        \r
        return PIPE_RWSTREAM_NoError;\r
 }\r
index 55f848b..af3e7cc 100644 (file)
                #define REMOTE_NDIS_VERSION_MINOR             0x00\r
 \r
                /** Pipe number for the RNDIS data IN pipe */\r
-               #define RNDIS_DATAPIPE_IN         1\r
+               #define RNDIS_DATAPIPE_IN                     1\r
 \r
                /** Pipe number for the RNDIS data OUT pipe */\r
-               #define RNDIS_DATAPIPE_OUT        2\r
+               #define RNDIS_DATAPIPE_OUT                    2\r
 \r
                /** Pipe number for the RNDIS notification pipe */\r
-               #define RNDIS_NOTIFICATIONPIPE    3\r
+               #define RNDIS_NOTIFICATIONPIPE                3\r
                \r
+               /** Additional error code for RNDIS functions when a device returns a logical command failure */\r
+               #define RNDIS_COMMAND_FAILED                  0xC0\r
+\r
        /* Function Prototypes: */\r
                uint8_t RNDIS_SendEncapsulatedCommand(void* Buffer, uint16_t Length);\r
                uint8_t RNDIS_GetEncapsulatedResponse(void* Buffer, uint16_t Length);\r
 \r
                uint8_t RNDIS_KeepAlive(void);\r
-               uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize, RNDIS_Initialize_Complete_t* InitMessageResponse);\r
+               uint8_t RNDIS_InitializeDevice(uint16_t HostMaxPacketSize, uint16_t* DeviceMaxPacketSize);\r
                uint8_t RNDIS_SetRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length);\r
-               uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length);\r
-               uint8_t RNDIS_GetPacketSize(uint16_t* PacketSize);\r
+               uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t MaxLength);\r
+               uint8_t RNDIS_GetPacketLength(uint16_t* PacketLength);\r
 \r
 #endif\r
index a64dfbd..c84f0c0 100644 (file)
@@ -138,31 +138,33 @@ void PrintIncommingPackets(void)
        \r
        puts_P(PSTR("DATA IN\r\n"));\r
 \r
-       uint16_t PacketSize;\r
-       if ((ErrorCode = RNDIS_GetPacketSize(&PacketSize)) != HOST_SENDCONTROL_Successful)\r
+       uint16_t PacketLength;\r
+       if ((ErrorCode = RNDIS_GetPacketLength(&PacketLength)) != HOST_SENDCONTROL_Successful)\r
        {\r
                printf_P(PSTR(ESC_FG_RED "Packet Reception Error.\r\n"\r
-                                                                " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
+                                                                " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);            \r
+               return;\r
        }\r
-       else if (PacketSize > 2048)\r
+\r
+       printf_P(PSTR("***PACKET (Size %d)***\r\n"), PacketLength);\r
+\r
+       if (PacketLength > 1024)\r
        {\r
-               printf_P(PSTR(ESC_FG_RED "Packet of Size %d Too Large.\r\n" ESC_FG_WHITE), PacketSize);\r
-               Pipe_Discard_Stream(PacketSize);\r
+               puts_P(PSTR(ESC_FG_RED "Packet too large.\r\n" ESC_FG_WHITE));\r
+               Pipe_Discard_Stream(PacketLength);\r
        }\r
        else\r
        {\r
-               uint8_t PacketBuffer[PacketSize];\r
+               uint8_t PacketBuffer[PacketLength];\r
                \r
-               Pipe_Read_Stream_LE(&PacketBuffer, PacketSize);\r
+               Pipe_Read_Stream_LE(&PacketBuffer, PacketLength);\r
                \r
-               printf("***PACKET (Size %d)***\r\n", PacketSize);\r
-               for (uint16_t i = 0; i < PacketSize; i++)\r
-               {\r
-                       printf("%02x ", PacketBuffer[i]);\r
-               }\r
-               printf("\r\n\r\n");\r
+               for (uint16_t i = 0; i < PacketLength; i++)\r
+                 printf("%02x ", PacketBuffer[i]);\r
        }\r
        \r
+       printf("\r\n\r\n");\r
+\r
        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 \r
        Pipe_ClearIN();\r
@@ -213,8 +215,8 @@ void RNDIS_Host_Task(void)
                                break;\r
                        }\r
                        \r
-                       RNDIS_Initialize_Complete_t InitMessageResponse;\r
-                       if ((ErrorCode = RNDIS_InitializeDevice(1024, &InitMessageResponse)) != HOST_SENDCONTROL_Successful)\r
+                       uint16_t DeviceMaxPacketSize;\r
+                       if ((ErrorCode = RNDIS_InitializeDevice(1024, &DeviceMaxPacketSize)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                                printf_P(PSTR(ESC_FG_RED "Error Initializing Device.\r\n"\r
                                                         " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
@@ -227,7 +229,7 @@ void RNDIS_Host_Task(void)
                                break;                  \r
                        }\r
                        \r
-                       printf_P(PSTR("Device Max Transfer Size: %lu bytes.\r\n"), InitMessageResponse.MaxTransferSize);\r
+                       printf_P(PSTR("Device Max Transfer Size: %lu bytes.\r\n"), DeviceMaxPacketSize);\r
                        \r
                        /* We set the default filter to only receive packets we would be interested in */\r
                        uint32_t PacketFilter = (RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST | RNDIS_PACKET_TYPE_ALL_MULTICAST);\r
index a5ad6ba..9420799 100644 (file)
@@ -29,7 +29,7 @@
 */\r
  \r
 /** \ingroup Group_USB\r
- *  @defgroup Group_OTGManagement USB On The Go (OTG) Management\r
+ *  @defgroup Group_OTG USB On The Go (OTG) Management\r
  *\r
  *  This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role\r
  *  exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host\r
index b9b506f..2239670 100644 (file)
  *  Driver and framework for the USB controller hardware on the USB series of AVR microcontrollers. This module\r
  *  consists of many submodules, and is designed to provide an easy way to configure and control USB host, device\r
  *  or OTG mode USB applications.\r
+ *\r
+ *  The USB stack requires the sole control over the USB controller in the microcontroller only; i.e. it does not\r
+ *  require any additional AVR timers, etc. to operate. This ensures that the USB stack requires as few resources\r
+ *  as possible.\r
+ *\r
+ *  The USB stack can be used in Device Mode for connections to USB Hosts (see \ref Group_Device), in Host mode for\r
+ *  hosting of other USB devices (see \ref Group_Host), or as a dual role device which can either act as a USB host\r
+ *  or device depending on what peripheral is connected (see \ref Group_OTG). Both modes also require a common set\r
+ *  of USB management functions found \ref Group_USBManagement.\r
  */\r
 \r
 /** \ingroup Group_USB\r
index b3a3d92..d58a070 100644 (file)
@@ -33,6 +33,7 @@
   *    item's attributes, to expose more information on the item (including it's type, collection path, etc.)\r
   *  - Changed MouseHostWithParser demos to check that the report items have a Mouse usage collection as a parent at some point,\r
   *    to prevent Joysticks from enumerating with the demo\r
+  *  - Corrected the name of the misnamed USB_GetDeviceConfigDescriptor() function to USB_Host_GetDeviceConfigDescriptor().\r
   *\r
   *  <b>Fixed:</b>\r
   *  - Fixed PrinterHost demo returning invalid Device ID data when the attached device does not have a\r
index f41c196..d8d4edb 100644 (file)
  *  <b>INTERRUPT_CONTROL_ENDPOINT</b> - ( \ref Group_USBManagement ) \n\r
  *  Some applications prefer to not call the USB_USBTask() management task reguarly while in device mode, as it can complicate code significantly.\r
  *  Instead, when device mode is used this token can be passed to the library via the -D switch to allow the library to manage the USB control\r
- *  endpoint entirely via interrupts asynchronously to the user application.\r
+ *  endpoint entirely via USB controller interrupts asynchronously to the user application.\r
  */\r