X-Git-Url: http://git.linex4red.de/pub/lufa.git/blobdiff_plain/ac70ddd0a1c412bb54def48e53caaebd0b5c9c61..23f3c3deee8bd153d59f2ac4e659c71ee75915f7:/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c diff --git a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c index 6810320e8..2f84d0fb8 100644 --- a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c +++ b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c @@ -74,6 +74,7 @@ void SetupHardware(void) SerialStream_Init(9600, false); LEDs_Init(); Buttons_Init(); + USB_Init(); } /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and @@ -137,36 +138,6 @@ void MassStorage_Task(void) switch (USB_HostState) { case HOST_STATE_Addressed: - /* Standard request to set the device configuration to configuration 1 */ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), - .bRequest = REQ_SetConfiguration, - .wValue = 1, - .wIndex = 0, - .wLength = 0, - }; - - /* Select the control pipe for the request transfer */ - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - /* Send the request, display error and wait for device detach if request fails */ - if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) - { - puts_P(PSTR("Control Error (Set Configuration).\r\n")); - printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode); - - /* Indicate error via status LEDs */ - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - - /* Wait until USB device disconnected */ - while (USB_IsConnected); - break; - } - - USB_HostState = HOST_STATE_Configured; - break; - case HOST_STATE_Configured: puts_P(PSTR("Getting Config Data.\r\n")); /* Get and process the configuration descriptor data */ @@ -187,6 +158,23 @@ void MassStorage_Task(void) break; } + /* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */ + if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful) + { + puts_P(PSTR("Control Error (Set Configuration).\r\n")); + printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode); + + /* Indicate error via status LEDs */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + /* Wait until USB device disconnected */ + while (USB_IsConnected); + break; + } + + USB_HostState = HOST_STATE_Configured; + break; + case HOST_STATE_Configured: puts_P(PSTR("Mass Storage Disk Enumerated.\r\n")); USB_HostState = HOST_STATE_Ready; @@ -203,7 +191,7 @@ void MassStorage_Task(void) } /* Print number of LUNs detected in the attached device */ - printf_P(PSTR("Total LUNs: %d.\r\n"), (MassStore_MaxLUNIndex + 1)); + printf_P(PSTR("Total LUNs: %d - Using first LUN in device.\r\n"), (MassStore_MaxLUNIndex + 1)); /* Reset the Mass Storage device interface, ready for use */ if ((ErrorCode = MassStore_MassStorageReset()) != HOST_SENDCONTROL_Successful) @@ -228,9 +216,20 @@ void MassStorage_Task(void) break; } - puts_P(PSTR("Waiting until ready..")); - + /* Get inquiry data from the device */ + SCSI_Inquiry_Response_t InquiryData; + if (((ErrorCode = MassStore_Inquiry(0, &InquiryData)) != 0) || (SCSICommandStatus.Status != Command_Pass)) + { + ShowDiskReadError(PSTR("Inquiry"), (SCSICommandStatus.Status != Command_Pass), ErrorCode); + break; + } + + /* Print vendor and product names of attached device */ + printf_P(PSTR("Vendor \"%.8s\", Product \"%.16s\"\r\n"), InquiryData.VendorID, InquiryData.ProductID); + /* Wait until disk ready */ + puts_P(PSTR("Waiting until ready..")); + do { Serial_TxByte('.'); @@ -350,9 +349,9 @@ void MassStorage_Task(void) * printing error codes to the serial port and waiting until the device is removed before * continuing. * - * \param CommandString ASCII string located in PROGMEM space indicating what operation failed - * \param FailedAtSCSILayer Indicates if the command failed at the (logical) SCSI layer or at the physical USB layer - * \param ErrorCode Error code of the function which failed to complete successfully + * \param[in] CommandString ASCII string located in PROGMEM space indicating what operation failed + * \param[in] FailedAtSCSILayer Indicates if the command failed at the (logical) SCSI layer or at the physical USB layer + * \param[in] ErrorCode Error code of the function which failed to complete successfully */ void ShowDiskReadError(char* CommandString, bool FailedAtSCSILayer, uint8_t ErrorCode) {