Commit b9dd51cd authored by Dean Camera's avatar Dean Camera
Browse files

Collapse configuration descriptor size retrieval and size testing into a...

Collapse configuration descriptor size retrieval and size testing into a single if statement within the new host mode class driver demos for clarity.
parent 84c3c4a3
...@@ -77,17 +77,10 @@ int main(void) ...@@ -77,17 +77,10 @@ int main(void)
uint16_t ConfigDescriptorSize; uint16_t ConfigDescriptorSize;
uint8_t ConfigDescriptorData[512]; uint8_t ConfigDescriptorData[512];
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||
(ConfigDescriptorSize > sizeof(ConfigDescriptorData)))
{ {
printf("Error Retrieving Device Descriptor.\r\n"); printf("Error Retrieving Configuration Descriptor.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
if (ConfigDescriptorSize > 512)
{
printf("Device Descriptor Too Large To Process.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR); LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval; USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break; break;
......
...@@ -79,22 +79,15 @@ int main(void) ...@@ -79,22 +79,15 @@ int main(void)
uint16_t ConfigDescriptorSize; uint16_t ConfigDescriptorSize;
uint8_t ConfigDescriptorData[512]; uint8_t ConfigDescriptorData[512];
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||
(ConfigDescriptorSize > sizeof(ConfigDescriptorData)))
{ {
printf("Error Retrieving Device Descriptor.\r\n"); printf("Error Retrieving Configuration Descriptor.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR); LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval; USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break; break;
} }
if (ConfigDescriptorSize > 512)
{
printf("Device Descriptor Too Large To Process.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData); USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
if (HID_Host_ConfigurePipes(&Mouse_HID_Interface, if (HID_Host_ConfigurePipes(&Mouse_HID_Interface,
......
...@@ -66,8 +66,13 @@ ...@@ -66,8 +66,13 @@
uint8_t DataINPipeNumber; /**< Pipe number of the HID interface's IN data pipe */ uint8_t DataINPipeNumber; /**< Pipe number of the HID interface's IN data pipe */
uint8_t DataOUTPipeNumber; /**< Pipe number of the HID interface's OUT data pipe */ uint8_t DataOUTPipeNumber; /**< Pipe number of the HID interface's OUT data pipe */
bool MatchInterfaceProtocol; bool MatchInterfaceProtocol; /**< Indicates whether the driver should match the device's
uint8_t HIDInterfaceProtocol; * HID interface protocol's value to the \ref HIDInterfaceProtocol
* suppled (otherwise just accept all HID class devices)
*/
uint8_t HIDInterfaceProtocol; /**< HID interface protocol value to match against if the
* \ref MatchInterfaceProtocol is set to true (ignored otherwise)
*/
} Config; /**< Config data for the USB class interface within the device. All elements in this section } Config; /**< Config data for the USB class interface within the device. All elements in this section
* <b>must</b> be set or the interface will fail to enumerate and operate correctly. * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
*/ */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment