Corrections, improvements and additions to the incomplete RNDISHost demo.

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.
pull/1469/head
Dean Camera 15 years ago
parent e625fd6df3
commit 588886878e

@ -210,10 +210,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
else if (JoyStatus_LCL & JOY_DOWN)
MouseReport->Y = 1;
if (JoyStatus_LCL & JOY_RIGHT)
MouseReport->X = 1;
else if (JoyStatus_LCL & JOY_LEFT)
if (JoyStatus_LCL & JOY_LEFT)
MouseReport->X = -1;
else if (JoyStatus_LCL & JOY_RIGHT)
MouseReport->X = 1;
if (JoyStatus_LCL & JOY_PRESS)
MouseReport->Button = (1 << 0);

@ -148,10 +148,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
else if (JoyStatus_LCL & JOY_DOWN)
JoystickReport->Y = 100;
if (JoyStatus_LCL & JOY_RIGHT)
JoystickReport->X = 100;
else if (JoyStatus_LCL & JOY_LEFT)
if (JoyStatus_LCL & JOY_LEFT)
JoystickReport->X = -100;
else if (JoyStatus_LCL & JOY_RIGHT)
JoystickReport->X = 100;
if (JoyStatus_LCL & JOY_PRESS)
JoystickReport->Button = (1 << 1);

@ -170,6 +170,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
uint8_t JoyStatus_LCL = Joystick_GetStatus();
uint8_t ButtonStatus_LCL = Buttons_GetStatus();
/* Determine which interface must have its report generated */
if (HIDInterfaceInfo == &Keyboard_HID_Interface)
{
USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;
@ -207,10 +208,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
else if (JoyStatus_LCL & JOY_DOWN)
MouseReport->Y = 1;
if (JoyStatus_LCL & JOY_RIGHT)
MouseReport->X = 1;
else if (JoyStatus_LCL & JOY_LEFT)
if (JoyStatus_LCL & JOY_LEFT)
MouseReport->X = -1;
else if (JoyStatus_LCL & JOY_RIGHT)
MouseReport->X = 1;
if (JoyStatus_LCL & JOY_PRESS)
MouseReport->Button = (1 << 0);

@ -148,10 +148,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
else if (JoyStatus_LCL & JOY_DOWN)
MouseReport->Y = 1;
if (JoyStatus_LCL & JOY_RIGHT)
MouseReport->X = 1;
else if (JoyStatus_LCL & JOY_LEFT)
if (JoyStatus_LCL & JOY_LEFT)
MouseReport->X = -1;
else if (JoyStatus_LCL & JOY_RIGHT)
MouseReport->X = 1;
if (JoyStatus_LCL & JOY_PRESS)
MouseReport->Button = (1 << 0);

@ -156,10 +156,10 @@ bool GetNextReport(USB_JoystickReport_Data_t* ReportData)
else if (JoyStatus_LCL & JOY_DOWN)
ReportData->Y = 100;
if (JoyStatus_LCL & JOY_RIGHT)
ReportData->X = 100;
else if (JoyStatus_LCL & JOY_LEFT)
if (JoyStatus_LCL & JOY_LEFT)
ReportData->X = -100;
else if (JoyStatus_LCL & JOY_RIGHT)
ReportData->X = 100;
if (JoyStatus_LCL & JOY_PRESS)
ReportData->Button = (1 << 1);

@ -238,10 +238,10 @@ void CreateMouseReport(USB_MouseReport_Data_t* ReportData)
else if (JoyStatus_LCL & JOY_DOWN)
ReportData->Y = 1;
if (JoyStatus_LCL & JOY_RIGHT)
ReportData->X = 1;
else if (JoyStatus_LCL & JOY_LEFT)
if (JoyStatus_LCL & JOY_LEFT)
ReportData->X = -1;
else if (JoyStatus_LCL & JOY_RIGHT)
ReportData->X = 1;
if (JoyStatus_LCL & JOY_PRESS)
ReportData->Button = (1 << 0);

@ -98,18 +98,20 @@ uint8_t RNDIS_KeepAlive(void)
return HOST_SENDCONTROL_Successful;
}
uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize, RNDIS_Initialize_Complete_t* InitMessageResponse)
uint8_t RNDIS_InitializeDevice(uint16_t HostMaxPacketSize, uint16_t* DeviceMaxPacketSize)
{
uint8_t ErrorCode;
RNDIS_Initialize_Message_t InitMessage;
RNDIS_Initialize_Complete_t InitMessageResponse;
InitMessage.MessageType = REMOTE_NDIS_INITIALIZE_MSG;
InitMessage.MessageLength = sizeof(RNDIS_Initialize_Message_t);
InitMessage.RequestId = RequestID++;
InitMessage.MajorVersion = REMOTE_NDIS_VERSION_MAJOR;
InitMessage.MinorVersion = REMOTE_NDIS_VERSION_MINOR;
InitMessage.MaxTransferSize = sizeof(RNDIS_Packet_Message_t) + MaxPacketSize;
InitMessage.MaxTransferSize = HostMaxPacketSize;
if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&InitMessage,
sizeof(RNDIS_Initialize_Message_t))) != HOST_SENDCONTROL_Successful)
@ -117,12 +119,17 @@ uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize, RNDIS_Initialize_Complete
return ErrorCode;
}
if ((ErrorCode = RNDIS_GetEncapsulatedResponse(InitMessageResponse,
if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&InitMessageResponse,
sizeof(RNDIS_Initialize_Complete_t))) != HOST_SENDCONTROL_Successful)
{
return ErrorCode;
}
if (InitMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
return RNDIS_COMMAND_FAILED;
*DeviceMaxPacketSize = InitMessageResponse.MaxTransferSize;
return HOST_SENDCONTROL_Successful;
}
@ -144,7 +151,7 @@ uint8_t RNDIS_SetRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
SetMessageData.SetMessage.Oid = Oid;
SetMessageData.SetMessage.InformationBufferLength = Length;
SetMessageData.SetMessage.InformationBufferOffset = 0;
SetMessageData.SetMessage.InformationBufferOffset = (sizeof(RNDIS_Set_Message_t) - sizeof(RNDIS_Message_Header_t));
SetMessageData.SetMessage.DeviceVcHandle = 0;
memcpy(&SetMessageData.ContigiousBuffer, Buffer, Length);
@ -161,10 +168,13 @@ uint8_t RNDIS_SetRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
return ErrorCode;
}
if (SetMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
return RNDIS_COMMAND_FAILED;
return HOST_SENDCONTROL_Successful;
}
uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t MaxLength)
{
uint8_t ErrorCode;
@ -173,7 +183,7 @@ uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
struct
{
RNDIS_Query_Complete_t QueryMessageResponse;
uint8_t ContigiousBuffer[Length];
uint8_t ContigiousBuffer[MaxLength];
} QueryMessageResponseData;
QueryMessage.MessageType = REMOTE_NDIS_QUERY_MSG;
@ -181,7 +191,7 @@ uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
QueryMessage.RequestId = RequestID++;
QueryMessage.Oid = Oid;
QueryMessage.InformationBufferLength = Length;
QueryMessage.InformationBufferLength = 0;
QueryMessage.InformationBufferOffset = 0;
QueryMessage.DeviceVcHandle = 0;
@ -197,12 +207,15 @@ uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)
return ErrorCode;
}
memcpy(Buffer, &QueryMessageResponseData.ContigiousBuffer, Length);
if (QueryMessageResponseData.QueryMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
return RNDIS_COMMAND_FAILED;
memcpy(Buffer, &QueryMessageResponseData.ContigiousBuffer, MaxLength);
return HOST_SENDCONTROL_Successful;
}
uint8_t RNDIS_GetPacketSize(uint16_t* PacketSize)
uint8_t RNDIS_GetPacketLength(uint16_t* PacketLength)
{
uint8_t ErrorCode;
@ -213,7 +226,9 @@ uint8_t RNDIS_GetPacketSize(uint16_t* PacketSize)
return ErrorCode;
}
*PacketSize = (uint16_t)DeviceMessage.DataLength;
*PacketLength = (uint16_t)DeviceMessage.DataLength;
Pipe_Discard_Stream(DeviceMessage.DataOffset - (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)));
return PIPE_RWSTREAM_NoError;
}

@ -196,14 +196,17 @@
/** Pipe number for the RNDIS notification pipe */
#define RNDIS_NOTIFICATIONPIPE 3
/** Additional error code for RNDIS functions when a device returns a logical command failure */
#define RNDIS_COMMAND_FAILED 0xC0
/* Function Prototypes: */
uint8_t RNDIS_SendEncapsulatedCommand(void* Buffer, uint16_t Length);
uint8_t RNDIS_GetEncapsulatedResponse(void* Buffer, uint16_t Length);
uint8_t RNDIS_KeepAlive(void);
uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize, RNDIS_Initialize_Complete_t* InitMessageResponse);
uint8_t RNDIS_InitializeDevice(uint16_t HostMaxPacketSize, uint16_t* DeviceMaxPacketSize);
uint8_t RNDIS_SetRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length);
uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length);
uint8_t RNDIS_GetPacketSize(uint16_t* PacketSize);
uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t MaxLength);
uint8_t RNDIS_GetPacketLength(uint16_t* PacketLength);
#endif

@ -138,30 +138,32 @@ void PrintIncommingPackets(void)
puts_P(PSTR("DATA IN\r\n"));
uint16_t PacketSize;
if ((ErrorCode = RNDIS_GetPacketSize(&PacketSize)) != HOST_SENDCONTROL_Successful)
uint16_t PacketLength;
if ((ErrorCode = RNDIS_GetPacketLength(&PacketLength)) != HOST_SENDCONTROL_Successful)
{
printf_P(PSTR(ESC_FG_RED "Packet Reception Error.\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
return;
}
else if (PacketSize > 2048)
printf_P(PSTR("***PACKET (Size %d)***\r\n"), PacketLength);
if (PacketLength > 1024)
{
printf_P(PSTR(ESC_FG_RED "Packet of Size %d Too Large.\r\n" ESC_FG_WHITE), PacketSize);
Pipe_Discard_Stream(PacketSize);
puts_P(PSTR(ESC_FG_RED "Packet too large.\r\n" ESC_FG_WHITE));
Pipe_Discard_Stream(PacketLength);
}
else
{
uint8_t PacketBuffer[PacketSize];
uint8_t PacketBuffer[PacketLength];
Pipe_Read_Stream_LE(&PacketBuffer, PacketSize);
Pipe_Read_Stream_LE(&PacketBuffer, PacketLength);
printf("***PACKET (Size %d)***\r\n", PacketSize);
for (uint16_t i = 0; i < PacketSize; i++)
{
for (uint16_t i = 0; i < PacketLength; i++)
printf("%02x ", PacketBuffer[i]);
}
printf("\r\n\r\n");
}
LEDs_SetAllLEDs(LEDMASK_USB_READY);
@ -213,8 +215,8 @@ void RNDIS_Host_Task(void)
break;
}
RNDIS_Initialize_Complete_t InitMessageResponse;
if ((ErrorCode = RNDIS_InitializeDevice(1024, &InitMessageResponse)) != HOST_SENDCONTROL_Successful)
uint16_t DeviceMaxPacketSize;
if ((ErrorCode = RNDIS_InitializeDevice(1024, &DeviceMaxPacketSize)) != HOST_SENDCONTROL_Successful)
{
printf_P(PSTR(ESC_FG_RED "Error Initializing Device.\r\n"
" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
@ -227,7 +229,7 @@ void RNDIS_Host_Task(void)
break;
}
printf_P(PSTR("Device Max Transfer Size: %lu bytes.\r\n"), InitMessageResponse.MaxTransferSize);
printf_P(PSTR("Device Max Transfer Size: %lu bytes.\r\n"), DeviceMaxPacketSize);
/* We set the default filter to only receive packets we would be interested in */
uint32_t PacketFilter = (RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST | RNDIS_PACKET_TYPE_ALL_MULTICAST);

@ -29,7 +29,7 @@
*/
/** \ingroup Group_USB
* @defgroup Group_OTGManagement USB On The Go (OTG) Management
* @defgroup Group_OTG USB On The Go (OTG) Management
*
* This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role
* exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host

@ -54,6 +54,15 @@
* Driver and framework for the USB controller hardware on the USB series of AVR microcontrollers. This module
* consists of many submodules, and is designed to provide an easy way to configure and control USB host, device
* or OTG mode USB applications.
*
* The USB stack requires the sole control over the USB controller in the microcontroller only; i.e. it does not
* require any additional AVR timers, etc. to operate. This ensures that the USB stack requires as few resources
* as possible.
*
* The USB stack can be used in Device Mode for connections to USB Hosts (see \ref Group_Device), in Host mode for
* hosting of other USB devices (see \ref Group_Host), or as a dual role device which can either act as a USB host
* or device depending on what peripheral is connected (see \ref Group_OTG). Both modes also require a common set
* of USB management functions found \ref Group_USBManagement.
*/
/** \ingroup Group_USB

@ -33,6 +33,7 @@
* item's attributes, to expose more information on the item (including it's type, collection path, etc.)
* - Changed MouseHostWithParser demos to check that the report items have a Mouse usage collection as a parent at some point,
* to prevent Joysticks from enumerating with the demo
* - Corrected the name of the misnamed USB_GetDeviceConfigDescriptor() function to USB_Host_GetDeviceConfigDescriptor().
*
* <b>Fixed:</b>
* - Fixed PrinterHost demo returning invalid Device ID data when the attached device does not have a

@ -177,5 +177,5 @@
* <b>INTERRUPT_CONTROL_ENDPOINT</b> - ( \ref Group_USBManagement ) \n
* Some applications prefer to not call the USB_USBTask() management task reguarly while in device mode, as it can complicate code significantly.
* 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
* endpoint entirely via interrupts asynchronously to the user application.
* endpoint entirely via USB controller interrupts asynchronously to the user application.
*/

Loading…
Cancel
Save