From d3fb6273aa59c60f2d3f41de321c35ff08ef8feb Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sun, 19 Jul 2009 09:36:16 +0000 Subject: Fix PrinterHost demo so that it will only enumerate printers with Bidirectional protocol encapsulation. Change enumeration code to automatically select the correct alternate setting for the printer interface to select the bidirectional protocol. --- Demos/Host/Incomplete/PrinterHost/PrinterHost.c | 33 +++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'Demos/Host/Incomplete/PrinterHost/PrinterHost.c') diff --git a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c index 80fca259c..643f919c9 100644 --- a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c +++ b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c @@ -36,8 +36,6 @@ #include "PrinterHost.h" -uint8_t PrinterProtocol; - int main(void) { @@ -150,12 +148,37 @@ void USB_Printer_Host(void) USB_HostState = HOST_STATE_WaitForDeviceRemoval; break; } - + + /* Some printers use alternate settings to determine the communication protocol used - if so, send a SetInterface + * request to switch to the interface alternate setting with the Bidirection protocol */ + if (PrinterAltSetting) + { + USB_ControlRequest = (USB_Request_Header_t) + { + bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE), + bRequest: REQ_SetInterface, + wValue: PrinterAltSetting, + wIndex: PrinterInterfaceNumber, + wLength: 0, + }; + + if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) + { + puts_P(PSTR("Control Error (Set Interface).\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 */ + USB_HostState = HOST_STATE_WaitForDeviceRemoval; + break; + } + } + USB_HostState = HOST_STATE_Configured; break; case HOST_STATE_Configured: - printf_P(PSTR("Printer Protocol: %d\r\n"), PrinterProtocol); - puts_P(PSTR("Retrieving Device ID...\r\n")); Device_ID_String_t DeviceIDString; -- cgit v1.2.3