aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Host
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-07-19 09:36:16 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-07-19 09:36:16 +0000
commitd3fb6273aa59c60f2d3f41de321c35ff08ef8feb (patch)
treefc27c982e19dbae0ee230d2df89708621b529d63 /Demos/Host
parent9d2613d90868b59ac48ccce8b652819d5cd388d5 (diff)
downloadlufa-d3fb6273aa59c60f2d3f41de321c35ff08ef8feb.tar.gz
lufa-d3fb6273aa59c60f2d3f41de321c35ff08ef8feb.tar.bz2
lufa-d3fb6273aa59c60f2d3f41de321c35ff08ef8feb.zip
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.
Diffstat (limited to 'Demos/Host')
-rw-r--r--Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.c34
-rw-r--r--Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.h6
-rw-r--r--Demos/Host/Incomplete/PrinterHost/PrinterHost.c33
-rw-r--r--Demos/Host/Incomplete/PrinterHost/PrinterHost.h3
4 files changed, 45 insertions, 31 deletions
diff --git a/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.c b/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.c
index ed4bdb994..67a0fa76e 100644
--- a/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.c
+++ b/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.c
@@ -30,13 +30,16 @@
#include "ConfigDescriptor.h"
+uint8_t PrinterInterfaceNumber;
+uint8_t PrinterAltSetting;
+
+
uint8_t ProcessConfigurationDescriptor(void)
{
uint8_t* ConfigDescriptorData;
uint16_t ConfigDescriptorSize;
uint8_t ErrorCode;
uint8_t FoundEndpoints = 0;
- uint8_t FoundEndpointMask;
/* Get Configuration Descriptor size from the device */
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
@@ -58,31 +61,17 @@ uint8_t ProcessConfigurationDescriptor(void)
/* Get the printer interface from the configuration descriptor */
if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
- NextPrinterInterface)))
+ NextBidirectionalPrinterInterface)))
{
/* Descriptor not found, error out */
return NoInterfaceFound;
}
-
- /* Get the printer's communication protocol */
- PrinterProtocol = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).Protocol;
- /* Determine what endpoints to look for from the protocol */
- switch (PrinterProtocol)
- {
- case PROTOCOL_UNIDIRECTIONAL:
- FoundEndpointMask = (1 << PRINTER_DATA_OUT_PIPE);
- break;
- case PROTOCOL_BIDIRECTIONAL:
- case PROTOCOL_IEEE1284:
- FoundEndpointMask = ((1 << PRINTER_DATA_OUT_PIPE) | (1 << PRINTER_DATA_IN_PIPE));
- break;
- default:
- return NoInterfaceFound;
- }
+ PrinterInterfaceNumber = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).InterfaceNumber;
+ PrinterAltSetting = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).AlternateSetting;
/* Get the IN and OUT data endpoints for the mass storage interface */
- while (FoundEndpoints != FoundEndpointMask)
+ while (FoundEndpoints != ((1 << PRINTER_DATA_OUT_PIPE) | (1 << PRINTER_DATA_IN_PIPE)))
{
/* Fetch the next bulk endpoint from the current printer interface */
if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
@@ -123,15 +112,16 @@ uint8_t ProcessConfigurationDescriptor(void)
return SuccessfulConfigRead;
}
-uint8_t NextPrinterInterface(void* CurrentDescriptor)
+uint8_t NextBidirectionalPrinterInterface(void* CurrentDescriptor)
{
- /* PURPOSE: Find next mass storage class interface descriptor */
+ /* PURPOSE: Find next Bidirectional protocol printer class interface descriptor */
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
/* Check the descriptor class and protocol, break out if correct class/protocol interface found */
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == PRINTER_CLASS) &&
- (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == PRINTER_SUBCLASS))
+ (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == PRINTER_SUBCLASS) &&
+ (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == PROTOCOL_BIDIRECTIONAL))
{
return DESCRIPTOR_SEARCH_Found;
}
diff --git a/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.h b/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.h
index 0a8dbe931..bbe23725c 100644
--- a/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.h
+++ b/Demos/Host/Incomplete/PrinterHost/ConfigDescriptor.h
@@ -55,11 +55,15 @@
NoInterfaceFound = 4,
NoEndpointFound = 5,
};
+
+ /* External Variables: */
+ uint8_t PrinterInterfaceNumber;
+ uint8_t PrinterAltSetting;
/* Function Prototypes: */
uint8_t ProcessConfigurationDescriptor(void);
- uint8_t NextPrinterInterface(void* CurrentDescriptor);
+ uint8_t NextBidirectionalPrinterInterface(void* CurrentDescriptor);
uint8_t NextInterfaceBulkDataEndpoint(void* CurrentDescriptor);
#endif
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;
diff --git a/Demos/Host/Incomplete/PrinterHost/PrinterHost.h b/Demos/Host/Incomplete/PrinterHost/PrinterHost.h
index 46427b300..c0bbebfe3 100644
--- a/Demos/Host/Incomplete/PrinterHost/PrinterHost.h
+++ b/Demos/Host/Incomplete/PrinterHost/PrinterHost.h
@@ -62,9 +62,6 @@
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
#define LEDMASK_USB_BUSY (LEDS_LED2)
-
- /* External Variables: */
- extern uint8_t PrinterProtocol;
/* Function Prototypes: */
void EVENT_USB_DeviceAttached(void);