diff options
Diffstat (limited to 'Demos')
83 files changed, 641 insertions, 602 deletions
diff --git a/Demos/Device/ClassDriver/AudioInput/Descriptors.c b/Demos/Device/ClassDriver/AudioInput/Descriptors.c index b89c97f73..c01e10129 100644 --- a/Demos/Device/ClassDriver/AudioInput/Descriptors.c +++ b/Demos/Device/ClassDriver/AudioInput/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2047, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/AudioOutput/Descriptors.c b/Demos/Device/ClassDriver/AudioOutput/Descriptors.c index 7db75609d..b82d5ab22 100644 --- a/Demos/Device/ClassDriver/AudioOutput/Descriptors.c +++ b/Demos/Device/ClassDriver/AudioOutput/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2046, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/Descriptors.c b/Demos/Device/ClassDriver/DualVirtualSerial/Descriptors.c index 20ba4936c..592f488b9 100644 --- a/Demos/Device/ClassDriver/DualVirtualSerial/Descriptors.c +++ b/Demos/Device/ClassDriver/DualVirtualSerial/Descriptors.c @@ -67,7 +67,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204E, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/GenericHID/Descriptors.c b/Demos/Device/ClassDriver/GenericHID/Descriptors.c index 1964d533c..2d9ec83a8 100644 --- a/Demos/Device/ClassDriver/GenericHID/Descriptors.c +++ b/Demos/Device/ClassDriver/GenericHID/Descriptors.c @@ -81,7 +81,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204F, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/Joystick/Descriptors.c b/Demos/Device/ClassDriver/Joystick/Descriptors.c index 8696e207e..6000e0e20 100644 --- a/Demos/Device/ClassDriver/Joystick/Descriptors.c +++ b/Demos/Device/ClassDriver/Joystick/Descriptors.c @@ -91,7 +91,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2043, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/Keyboard/Descriptors.c b/Demos/Device/ClassDriver/Keyboard/Descriptors.c index ed2cb6c49..3b2acdd7f 100644 --- a/Demos/Device/ClassDriver/Keyboard/Descriptors.c +++ b/Demos/Device/ClassDriver/Keyboard/Descriptors.c @@ -97,7 +97,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2042, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/KeyboardMouse/Descriptors.c b/Demos/Device/ClassDriver/KeyboardMouse/Descriptors.c index bba7ca20d..1f2411662 100644 --- a/Demos/Device/ClassDriver/KeyboardMouse/Descriptors.c +++ b/Demos/Device/ClassDriver/KeyboardMouse/Descriptors.c @@ -130,7 +130,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204D, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/MIDI/Descriptors.c b/Demos/Device/ClassDriver/MIDI/Descriptors.c index b842bd27e..98e6ae508 100644 --- a/Demos/Device/ClassDriver/MIDI/Descriptors.c +++ b/Demos/Device/ClassDriver/MIDI/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2048, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/MassStorage/Descriptors.c b/Demos/Device/ClassDriver/MassStorage/Descriptors.c index b7c21a269..b6e03a359 100644 --- a/Demos/Device/ClassDriver/MassStorage/Descriptors.c +++ b/Demos/Device/ClassDriver/MassStorage/Descriptors.c @@ -67,7 +67,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2045, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c b/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c index 12422ad13..7be7bed92 100644 --- a/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c +++ b/Demos/Device/ClassDriver/MassStorageKeyboard/Descriptors.c @@ -110,7 +110,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2061, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/Mouse/Descriptors.c b/Demos/Device/ClassDriver/Mouse/Descriptors.c index 6a699b03d..02066ba93 100644 --- a/Demos/Device/ClassDriver/Mouse/Descriptors.c +++ b/Demos/Device/ClassDriver/Mouse/Descriptors.c @@ -91,7 +91,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2041, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/RNDISEthernet/Descriptors.c b/Demos/Device/ClassDriver/RNDISEthernet/Descriptors.c index d259390c3..2eaa1eb5b 100644 --- a/Demos/Device/ClassDriver/RNDISEthernet/Descriptors.c +++ b/Demos/Device/ClassDriver/RNDISEthernet/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204C, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/VirtualSerial/Descriptors.c b/Demos/Device/ClassDriver/VirtualSerial/Descriptors.c index 2e47069fd..ac45d0f64 100644 --- a/Demos/Device/ClassDriver/VirtualSerial/Descriptors.c +++ b/Demos/Device/ClassDriver/VirtualSerial/Descriptors.c @@ -67,7 +67,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2044, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/Descriptors.c b/Demos/Device/ClassDriver/VirtualSerialMouse/Descriptors.c index 72e89ef27..2a52edcd4 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/Descriptors.c +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/Descriptors.c @@ -103,7 +103,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2062, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/Incomplete/Sideshow/Descriptors.c b/Demos/Device/Incomplete/Sideshow/Descriptors.c index 4e3983c22..6860ac459 100644 --- a/Demos/Device/Incomplete/Sideshow/Descriptors.c +++ b/Demos/Device/Incomplete/Sideshow/Descriptors.c @@ -43,7 +43,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = VendorID: 0x03EB, ProductID: 0x2040, - ReleaseNumber: 0x0001, + ReleaseNumber: VERSION_BCD(00.01), ManufacturerStrIndex: 0x01, ProductStrIndex: 0x02, diff --git a/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.c b/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.c index 0cb7852ab..aac16909d 100644 --- a/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.c +++ b/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.c @@ -68,7 +68,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2065, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h b/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h index 975ca10f7..fefb6b555 100644 --- a/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h +++ b/Demos/Device/Incomplete/TestAndMeasurement/Descriptors.h @@ -43,15 +43,15 @@ #include <LUFA/Drivers/USB/USB.h>
/* Macros: */
+ /** Endpoint number of the TMC notification IN endpoint. */
+ #define TMC_NOTIFICATION_EPNUM 2
+
/** Endpoint number of the TMC device-to-host data IN endpoint. */
#define TMC_IN_EPNUM 3
/** Endpoint number of the TMC host-to-device data OUT endpoint. */
#define TMC_OUT_EPNUM 4
- /** Endpoint number of the TMC notification IN endpoint. */
- #define TMC_NOTIFICATION_EPNUM 2
-
/** Size in bytes of the TMC data endpoints. */
#define TMC_IO_EPSIZE 64
diff --git a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c index 55e17bcc6..7949a7ebd 100644 --- a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c +++ b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c @@ -121,12 +121,12 @@ void EVENT_USB_Device_ConfigurationChanged(void) bool ConfigSuccess = true;
/* Setup TMC In, Out and Notification Endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
+ TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(TMC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
- TMC_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
diff --git a/Demos/Device/LowLevel/AudioInput/Descriptors.c b/Demos/Device/LowLevel/AudioInput/Descriptors.c index ddcac155a..150fb3367 100644 --- a/Demos/Device/LowLevel/AudioInput/Descriptors.c +++ b/Demos/Device/LowLevel/AudioInput/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2047, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/AudioOutput/Descriptors.c b/Demos/Device/LowLevel/AudioOutput/Descriptors.c index d6e8ef632..1194568ad 100644 --- a/Demos/Device/LowLevel/AudioOutput/Descriptors.c +++ b/Demos/Device/LowLevel/AudioOutput/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2046, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.c b/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.c index 45f1d4eb4..ac9739fd7 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.c +++ b/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.c @@ -67,7 +67,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204E, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.h b/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.h index aa1a8beaa..90091ea22 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.h +++ b/Demos/Device/LowLevel/DualVirtualSerial/Descriptors.h @@ -42,23 +42,23 @@ #include <avr/pgmspace.h> /* Macros: */ - /** Endpoint number of the first CDC interface's device-to-host notification IN endpoint. */ - #define CDC1_NOTIFICATION_EPNUM 3 - /** Endpoint number of the first CDC interface's device-to-host data IN endpoint. */ #define CDC1_TX_EPNUM 1 /** Endpoint number of the first CDC interface's host-to-device data OUT endpoint. */ #define CDC1_RX_EPNUM 2 - /** Endpoint number of the second CDC interface's device-to-host notification IN endpoint. */ - #define CDC2_NOTIFICATION_EPNUM 4 + /** Endpoint number of the first CDC interface's device-to-host notification IN endpoint. */ + #define CDC1_NOTIFICATION_EPNUM 3 /** Endpoint number of the second CDC interface's device-to-host data IN endpoint. */ - #define CDC2_TX_EPNUM 5 + #define CDC2_TX_EPNUM 4 /** Endpoint number of the second CDC interface's host-to-device data OUT endpoint. */ - #define CDC2_RX_EPNUM 6 + #define CDC2_RX_EPNUM 5 + + /** Endpoint number of the second CDC interface's device-to-host notification IN endpoint. */ + #define CDC2_NOTIFICATION_EPNUM 6 /** Size in bytes of the CDC device-to-host notification IN endpoints. */ #define CDC_NOTIFICATION_EPSIZE 8 diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c index 11f6cda0d..67463084e 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c +++ b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c @@ -123,20 +123,20 @@ void EVENT_USB_Device_ConfigurationChanged(void) bool ConfigSuccess = true; /* Setup first CDC Interface's Endpoints */ - ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, - CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_TX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE); ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_RX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE); + ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, + CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); /* Setup second CDC Interface's Endpoints */ - ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, - CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_TX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE); ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_RX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE); + ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, + CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); /* Reset line encoding baud rates so that the host knows to send new values */ LineEncoding1.BaudRateBPS = 0; diff --git a/Demos/Device/LowLevel/GenericHID/Descriptors.c b/Demos/Device/LowLevel/GenericHID/Descriptors.c index 7a670f70a..88388e641 100644 --- a/Demos/Device/LowLevel/GenericHID/Descriptors.c +++ b/Demos/Device/LowLevel/GenericHID/Descriptors.c @@ -81,7 +81,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204F, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/Joystick/Descriptors.c b/Demos/Device/LowLevel/Joystick/Descriptors.c index b32ffebf9..19925a9c9 100644 --- a/Demos/Device/LowLevel/Joystick/Descriptors.c +++ b/Demos/Device/LowLevel/Joystick/Descriptors.c @@ -91,7 +91,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2043, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/Joystick/Descriptors.h b/Demos/Device/LowLevel/Joystick/Descriptors.h index 02906999c..ee828fd4c 100644 --- a/Demos/Device/LowLevel/Joystick/Descriptors.h +++ b/Demos/Device/LowLevel/Joystick/Descriptors.h @@ -75,10 +75,10 @@ /* Macros: */ /** Endpoint number of the Joystick HID reporting IN endpoint. */ - #define JOYSTICK_EPNUM 1 + #define JOYSTICK_EPNUM 1 /** Size in bytes of the Joystick HID reporting IN endpoint. */ - #define JOYSTICK_EPSIZE 8 + #define JOYSTICK_EPSIZE 8 /** Descriptor header type value, to indicate a HID class HID descriptor. */ #define DTYPE_HID 0x21 diff --git a/Demos/Device/LowLevel/Keyboard/Descriptors.c b/Demos/Device/LowLevel/Keyboard/Descriptors.c index 6827cb890..69265cba9 100644 --- a/Demos/Device/LowLevel/Keyboard/Descriptors.c +++ b/Demos/Device/LowLevel/Keyboard/Descriptors.c @@ -98,7 +98,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2042, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/KeyboardMouse/Descriptors.c b/Demos/Device/LowLevel/KeyboardMouse/Descriptors.c index 9a2f69c4f..642b8e904 100644 --- a/Demos/Device/LowLevel/KeyboardMouse/Descriptors.c +++ b/Demos/Device/LowLevel/KeyboardMouse/Descriptors.c @@ -131,7 +131,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204D, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/MIDI/Descriptors.c b/Demos/Device/LowLevel/MIDI/Descriptors.c index 2d2b365aa..8e8746aa2 100644 --- a/Demos/Device/LowLevel/MIDI/Descriptors.c +++ b/Demos/Device/LowLevel/MIDI/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2048, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01),, .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/MIDI/Descriptors.h b/Demos/Device/LowLevel/MIDI/Descriptors.h index b364c1b62..e110cc2e6 100644 --- a/Demos/Device/LowLevel/MIDI/Descriptors.h +++ b/Demos/Device/LowLevel/MIDI/Descriptors.h @@ -60,11 +60,11 @@ /** Audio class descriptor jack type value for an external (physical) MIDI input or output jack. */ #define JACKTYPE_EXTERNAL 0x02 - /** Endpoint number of the MIDI streaming data OUT endpoint, for host-to-device data transfers. */ - #define MIDI_STREAM_OUT_EPNUM 1 - /** Endpoint number of the MIDI streaming data IN endpoint, for device-to-host data transfers. */ - #define MIDI_STREAM_IN_EPNUM 2 + #define MIDI_STREAM_IN_EPNUM 1 + + /** Endpoint number of the MIDI streaming data OUT endpoint, for host-to-device data transfers. */ + #define MIDI_STREAM_OUT_EPNUM 2 /** Endpoint size in bytes of the Audio isochronous streaming data IN and OUT endpoints. */ #define MIDI_STREAM_EPSIZE 64 diff --git a/Demos/Device/LowLevel/MIDI/MIDI.c b/Demos/Device/LowLevel/MIDI/MIDI.c index 5570dd16e..87ecbd4d0 100644 --- a/Demos/Device/LowLevel/MIDI/MIDI.c +++ b/Demos/Device/LowLevel/MIDI/MIDI.c @@ -94,10 +94,10 @@ void EVENT_USB_Device_ConfigurationChanged(void) bool ConfigSuccess = true; /* Setup MIDI Data Endpoints */ - ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT, - MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); + ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT, + MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); /* Indicate endpoint configuration success or failure */ LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); diff --git a/Demos/Device/LowLevel/MassStorage/Descriptors.c b/Demos/Device/LowLevel/MassStorage/Descriptors.c index b7c21a269..b6e03a359 100644 --- a/Demos/Device/LowLevel/MassStorage/Descriptors.c +++ b/Demos/Device/LowLevel/MassStorage/Descriptors.c @@ -67,7 +67,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2045, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/Mouse/Descriptors.c b/Demos/Device/LowLevel/Mouse/Descriptors.c index f85ff61eb..1d3708f60 100644 --- a/Demos/Device/LowLevel/Mouse/Descriptors.c +++ b/Demos/Device/LowLevel/Mouse/Descriptors.c @@ -91,7 +91,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2041, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/RNDISEthernet/Descriptors.c b/Demos/Device/LowLevel/RNDISEthernet/Descriptors.c index d6e79e1e4..362406887 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Descriptors.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204C, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Device/LowLevel/RNDISEthernet/Descriptors.h b/Demos/Device/LowLevel/RNDISEthernet/Descriptors.h index 0d651c5e9..5985d3473 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Descriptors.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Descriptors.h @@ -42,21 +42,21 @@ #include <avr/pgmspace.h> /* Macros: */ - /** Endpoint number of the CDC device-to-host notification IN endpoint. */ - #define CDC_NOTIFICATION_EPNUM 3 - /** Endpoint number of the CDC device-to-host data IN endpoint. */ #define CDC_TX_EPNUM 1 /** Endpoint number of the CDC host-to-device data OUT endpoint. */ #define CDC_RX_EPNUM 2 - /** Size in bytes of the CDC device-to-host notification IN endpoint. */ - #define CDC_NOTIFICATION_EPSIZE 8 + /** Endpoint number of the CDC device-to-host notification IN endpoint. */ + #define CDC_NOTIFICATION_EPNUM 3 /** Size in bytes of the CDC data IN and OUT endpoints. */ #define CDC_TXRX_EPSIZE 64 + /** Size in bytes of the CDC device-to-host notification IN endpoint. */ + #define CDC_NOTIFICATION_EPSIZE 8 + /* Type Defines: */ /** Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device * contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration. diff --git a/Demos/Device/LowLevel/VirtualSerial/Descriptors.c b/Demos/Device/LowLevel/VirtualSerial/Descriptors.c index f0066d900..5ca446667 100644 --- a/Demos/Device/LowLevel/VirtualSerial/Descriptors.c +++ b/Demos/Device/LowLevel/VirtualSerial/Descriptors.c @@ -67,7 +67,7 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x2044, - .ReleaseNumber = 0x0000, + .ReleaseNumber = VERSION_BCD(00.01), .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, diff --git a/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c b/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c index 0fd08fb93..cc7570387 100644 --- a/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c +++ b/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.c @@ -50,7 +50,10 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* EventsEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -62,7 +65,7 @@ uint8_t ProcessConfigurationDescriptor(void) case HOST_GETCONFIG_BuffOverflow: return DescriptorTooLarge; default: - return ControlError; + return DevControlError; } /* The Bluetooth USB transport addendum mandates that the data (not streaming voice) endpoints @@ -71,63 +74,48 @@ uint8_t ProcessConfigurationDescriptor(void) /* Ensure that an interface was found, and the end of the descriptor was not reached */ if (!(CurrConfigBytesRem)) - return NoBTInterfaceFound; + return NoCompatibleInterfaceFound; - /* Get the data IN, data OUT and event notification endpoints for the Bluetooth interface */ - while (FoundEndpoints != ((1 << BLUETOOTH_DATA_IN_PIPE) | (1 << BLUETOOTH_DATA_OUT_PIPE) | - (1 << BLUETOOTH_EVENTS_PIPE))) + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Fetch the next endpoint from the current Bluetooth interface */ + /* Get the next Still Image interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextInterfaceBluetoothDataEndpoint)) + DComp_NextInterfaceBluetoothDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Data endpoints not found within the first bluetooth device interface, error out */ + return NoCompatibleInterfaceFound; } - + + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the endpoint is a bulk or interrupt type endpoint */ - if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) { - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the events IN pipe */ - Pipe_ConfigurePipe(BLUETOOTH_EVENTS_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_SINGLE); - - Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS); - - /* Set the flag indicating that the events notification pipe has been found */ - FoundEndpoints |= (1 << BLUETOOTH_EVENTS_PIPE); - } + /* Check if the found endpoint is a interrupt or bulk type descriptor */ + if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + EventsEndpoint = EndpointData; + else + DataINEndpoint = EndpointData; } else { - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(BLUETOOTH_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << BLUETOOTH_DATA_IN_PIPE); - } - else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(BLUETOOTH_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << BLUETOOTH_DATA_OUT_PIPE); - } + DataOUTEndpoint = EndpointData; } - } + + /* Configure the Bluetooth data IN pipe */ + Pipe_ConfigurePipe(BLUETOOTH_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Bluetooth data OUT pipe */ + Pipe_ConfigurePipe(BLUETOOTH_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Bluetooth events pipe */ + Pipe_ConfigurePipe(BLUETOOTH_EVENTS_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + EventsEndpoint->EndpointAddress, EventsEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(EventsEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; @@ -146,17 +134,10 @@ uint8_t DComp_NextInterfaceBluetoothDataEndpoint(void* CurrentDescriptor) { /* Determine the type of the current descriptor */ if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) - { - /* Indicate that the descriptor being searched for has been found */ - return DESCRIPTOR_SEARCH_Found; - } + return DESCRIPTOR_SEARCH_Found; else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) - { - /* Indicate that the search has failed prematurely and should be aborted */ - return DESCRIPTOR_SEARCH_Fail; - } - - /* Current descriptor does not match what this comparator is looking for */ - return DESCRIPTOR_SEARCH_NotFound; + return DESCRIPTOR_SEARCH_Fail; + else + return DESCRIPTOR_SEARCH_NotFound; } diff --git a/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.h b/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.h index 70451a6be..25442b87b 100644 --- a/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.h +++ b/Demos/Host/Incomplete/BluetoothHost/ConfigDescriptor.h @@ -39,7 +39,10 @@ /* Includes: */ #include <LUFA/Drivers/USB/USB.h> - #include "BluetoothHost.h" + /* Macros: */ + #define BLUETOOTH_DATA_IN_PIPE 1 + #define BLUETOOTH_DATA_OUT_PIPE 2 + #define BLUETOOTH_EVENTS_PIPE 3 /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ @@ -49,10 +52,7 @@ DevControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoBTInterfaceFound = 4, /**< A compatible Bluetooth interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< A compatible set of Bluetooth endpoints were not found in the - * device's Bluetooth interface - */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h index 6f1ea6742..e434e6c4f 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h @@ -39,11 +39,9 @@ /* Includes: */ #include <LUFA/Drivers/USB/USB.h> + #include "../ConfigDescriptor.h" + /* Macros: */ - #define BLUETOOTH_DATA_IN_PIPE 1 - #define BLUETOOTH_DATA_OUT_PIPE 2 - #define BLUETOOTH_EVENTS_PIPE 3 - #define BLUETOOTH_MAX_OPEN_CHANNELS 6 #define CHANNEL_PSM_SDP 0x0001 diff --git a/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c b/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c index f5d8e5cd5..40bc98e2d 100644 --- a/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c @@ -50,7 +50,9 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,15 +67,15 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the HID interface from the configuration descriptor */ + /* Get the first HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDInterfaceFound; + return NoCompatibleInterfaceFound; } - while (FoundEndpoints != ((1 << HID_DATA_IN_PIPE) | (1 << HID_DATA_OUT_PIPE))) + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { /* Get the next HID interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, @@ -81,11 +83,19 @@ uint8_t ProcessConfigurationDescriptor(void) { /* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor * but only found the mandatory IN endpoint, it's safe to continue with the device enumeration */ - if (FoundEndpoints == (1 << HID_DATA_IN_PIPE)) + if (DataINEndpoint) break; - - /* Descriptor not found, error out */ - return NoEndpointFound; + + /* Clear any found endpoints */ + DataOUTEndpoint = NULL; + + /* Get the next HID interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } } /* Retrieve the endpoint address from the endpoint descriptor */ @@ -93,22 +103,23 @@ uint8_t ProcessConfigurationDescriptor(void) /* If the endpoint is a IN type endpoint */ if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the HID data IN pipe */ - Pipe_ConfigurePipe(HID_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - FoundEndpoints |= (1 << HID_DATA_IN_PIPE); - } + DataINEndpoint = EndpointData; else - { - /* Configure the HID data OUT pipe */ - Pipe_ConfigurePipe(HID_DATA_OUT_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - FoundEndpoints |= (1 << HID_DATA_OUT_PIPE); - } + DataOUTEndpoint = EndpointData; } + + /* Configure the HID data IN pipe */ + Pipe_ConfigurePipe(HID_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); + + /* Check if the HID interface contained an optional OUT data endpoint */ + if (DataOUTEndpoint) + { + /* Configure the HID data OUT pipe */ + Pipe_ConfigurePipe(HID_DATA_OUT_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); + } /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.h b/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.h index b284b7bd8..e5a39479d 100644 --- a/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.h @@ -43,7 +43,13 @@ /* Macros: */ /** Interface Class value for the Human Interface Device class. */ - #define HID_CLASS 0x03 + #define HID_CLASS 0x03 + + /** Pipe number for the HID data IN pipe. */ + #define HID_DATA_IN_PIPE 1 + + /** Pipe number for the HID data OUT pipe. */ + #define HID_DATA_OUT_PIPE 2 /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ @@ -53,8 +59,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.h b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.h index 89ac01958..489fba896 100644 --- a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.h +++ b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.h @@ -53,12 +53,6 @@ #include "ConfigDescriptor.h" /* Macros: */ - /** Pipe number for the HID data IN pipe. */ - #define HID_DATA_IN_PIPE 1 - - /** Pipe number for the HID data OUT pipe. */ - #define HID_DATA_OUT_PIPE 2 - /** HID Class specific request to send a HID report to the device. */ #define REQ_SetReport 0x09 diff --git a/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c b/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c index 80caeb656..dfca7b407 100644 --- a/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c @@ -50,6 +50,8 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -63,41 +65,43 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the joystick interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextJoystickInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoHIDInterfaceFound; - } - /* Get the joystick interface's HID descriptor */ + /* Get the first HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) + DComp_NextJoystickInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDDescriptorFound; + return NoCompatibleInterfaceFound; } - /* Save the HID report size for later use */ - HIDReportSize = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_HID_t).HIDReportLength; - - /* Get the joystick interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextJoystickInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + while (!(DataINEndpoint)) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Get the next HID interface's data endpoint descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextJoystickInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Get the next HID interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextJoystickInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + } + + /* Retrieve the endpoint address from the endpoint descriptor */ + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); + + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) + DataINEndpoint = EndpointData; } - /* Retrieve the endpoint address from the endpoint descriptor */ - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - - /* Configure the joystick data pipe */ - Pipe_ConfigurePipe(JOYSTICK_DATAPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - + /* Configure the HID data IN pipe */ + Pipe_ConfigurePipe(JOYSTICK_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); + /* Valid data found, return success */ return SuccessfulConfigRead; } diff --git a/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.h b/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.h index 4b059dcad..58c63f9e5 100644 --- a/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.h @@ -54,6 +54,9 @@ /** Descriptor header type constant for a HID report descriptor. */ #define DTYPE_Report 0x22 + /** Pipe number for the joystick report data pipe. */ + #define JOYSTICK_DATA_IN_PIPE 1 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum JoystickHostWithParser_GetConfigDescriptorDataCodes_t @@ -64,7 +67,7 @@ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */ NoHIDDescriptorFound = 5, /**< A compatible HID descriptor was not found in the device's HID interface */ - NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.c b/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.c index cf469ffec..c7739e97f 100644 --- a/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.c +++ b/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.c @@ -211,7 +211,7 @@ void Joystick_HID_Task(void) break; case HOST_STATE_Configured: /* Select and unfreeze joystick data pipe */ - Pipe_SelectPipe(JOYSTICK_DATAPIPE); + Pipe_SelectPipe(JOYSTICK_DATA_IN_PIPE); Pipe_Unfreeze(); /* Check to see if a packet has been received */ diff --git a/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.h b/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.h index 95a0a639e..5f34dba03 100644 --- a/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.h +++ b/Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.h @@ -54,9 +54,6 @@ #include "HIDReport.h" /* Macros: */ - /** Pipe number for the joystick report data pipe. */ - #define JOYSTICK_DATAPIPE 1 - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ #define LEDMASK_USB_NOTREADY LEDS_LED1 diff --git a/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c b/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c index 0be2de18d..dbdfac9c6 100644 --- a/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c @@ -50,6 +50,8 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -64,28 +66,41 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the keyboard interface from the configuration descriptor */ + /* Get the first HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDInterfaceFound; + return NoCompatibleInterfaceFound; } - /* Get the keyboard interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + while (!(DataINEndpoint)) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Get the next HID interface's data endpoint descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Get the next HID interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + } + + /* Retrieve the endpoint address from the endpoint descriptor */ + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); + + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) + DataINEndpoint = EndpointData; } - /* Retrieve the endpoint address from the endpoint descriptor */ - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - - /* Configure the keyboard data pipe */ - Pipe_ConfigurePipe(KEYBOARD_DATAPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); + /* Configure the HID data IN pipe */ + Pipe_ConfigurePipe(KEYBOARD_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.h b/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.h index d319097f3..f8fed3e58 100644 --- a/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.h @@ -48,6 +48,9 @@ /** Interface Protocol value for a Boot Protocol Keyboard compliant device. */ #define KEYBOARD_PROTOCOL 0x01 + /** Pipe number for the keyboard data IN pipe. */ + #define KEYBOARD_DATA_IN_PIPE 1 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum KeyboardHost_GetConfigDescriptorDataCodes_t @@ -56,8 +59,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c index d98c26557..0c24bc9e2 100644 --- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c +++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c @@ -131,7 +131,7 @@ void ReadNextReport(void) USB_KeyboardReport_Data_t KeyboardReport; /* Select keyboard data pipe */ - Pipe_SelectPipe(KEYBOARD_DATAPIPE); + Pipe_SelectPipe(KEYBOARD_DATA_IN_PIPE); /* Unfreeze keyboard data pipe */ Pipe_Unfreeze(); diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.h b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.h index 91a2be534..0c6075330 100644 --- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.h +++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.h @@ -53,9 +53,6 @@ #include "ConfigDescriptor.h" /* Macros: */ - /** Pipe number for the keyboard data IN pipe. */ - #define KEYBOARD_DATAPIPE 1 - /** HID Class Specific request to set the report protocol mode. */ #define REQ_SetProtocol 0x0B diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c b/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c index 6eace565c..d397ca7ad 100644 --- a/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c @@ -50,6 +50,8 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -64,39 +66,63 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the keyboard interface from the configuration descriptor */ + /* Get the first HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDInterfaceFound; + return NoCompatibleInterfaceFound; } - - /* Get the keyboard interface's HID descriptor */ + + /* Get the HID descriptor from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDDescriptorFound; + return NoCompatibleInterfaceFound; } - + /* Save the HID report size for later use */ HIDReportSize = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_HID_t).HIDReportLength; - /* Get the keyboard interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + while (!(DataINEndpoint)) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Get the next HID interface's data endpoint descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Get the next HID interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + + /* Get the HID descriptor from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + + /* Save the HID report size for later use */ + HIDReportSize = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_HID_t).HIDReportLength; + } + + /* Retrieve the endpoint address from the endpoint descriptor */ + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); + + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) + DataINEndpoint = EndpointData; } - /* Retrieve the endpoint address from the endpoint descriptor */ - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - - /* Configure the keyboard data pipe */ - Pipe_ConfigurePipe(KEYBOARD_DATAPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); + /* Configure the HID data IN pipe */ + Pipe_ConfigurePipe(KEYBOARD_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; @@ -161,6 +187,8 @@ uint8_t DComp_NextHID(void* CurrentDescriptor) { if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_HID) return DESCRIPTOR_SEARCH_Found; + else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) + return DESCRIPTOR_SEARCH_Fail; else - return DESCRIPTOR_SEARCH_NotFound; + return DESCRIPTOR_SEARCH_NotFound; } diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h b/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h index 5a6953b12..a7bc1d34c 100644 --- a/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.h @@ -54,6 +54,9 @@ /** Descriptor header type constant for a HID report descriptor. */ #define DTYPE_Report 0x22 + /** Pipe number for the keyboard report data pipe. */ + #define KEYBOARD_DATA_IN_PIPE 1 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum KeyboardHostWithParser_GetConfigDescriptorDataCodes_t @@ -62,9 +65,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */ - NoHIDDescriptorFound = 5, /**< A compatible HID descriptor was not found in the device's HID interface */ - NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c index 94aca2fef..15bc94061 100644 --- a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c +++ b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c @@ -212,7 +212,7 @@ void Keyboard_HID_Task(void) break; case HOST_STATE_Configured: /* Select and unfreeze keyboard data pipe */ - Pipe_SelectPipe(KEYBOARD_DATAPIPE); + Pipe_SelectPipe(KEYBOARD_DATA_IN_PIPE); Pipe_Unfreeze(); /* Check to see if a packet has been received */ diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h index 76b3b49a9..4aaea382f 100644 --- a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h +++ b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h @@ -49,9 +49,6 @@ #include "HIDReport.h" /* Macros: */ - /** Pipe number for the keyboard report data pipe. */ - #define KEYBOARD_DATAPIPE 1 - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ #define LEDMASK_USB_NOTREADY LEDS_LED1 diff --git a/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c b/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c index 0c2ddfa92..3ede45778 100644 --- a/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c @@ -50,7 +50,9 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,47 +67,50 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the MIDI Audio Streaming interface from the configuration descriptor */ + /* Get the first MIDI interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMIDIStreamingInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoCDCInterfaceFound; + return NoCompatibleInterfaceFound; } - - /* Get the IN and OUT data endpoints for the MIDI interface */ - while (FoundEndpoints != ((1 << MIDI_DATAPIPE_IN) | (1 << MIDI_DATAPIPE_OUT))) + + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Fetch the next bulk endpoint from the current MIDI streaming interface */ + /* Get the next MIDI interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMIDIStreamingDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + + /* Get the next Mass Storage interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextMIDIStreamingInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } } + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the endpoint is a bulk IN or bulk OUT endpoint */ + /* If the endpoint is a IN type endpoint */ if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(MIDI_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << MIDI_DATAPIPE_IN); - } + DataINEndpoint = EndpointData; else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(MIDI_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << MIDI_DATAPIPE_OUT); - } + DataOUTEndpoint = EndpointData; } + + /* Configure the MIDI data IN pipe */ + Pipe_ConfigurePipe(MIDI_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the MIDI data OUT pipe */ + Pipe_ConfigurePipe(MIDI_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.h b/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.h index 4948b5864..80a05667d 100644 --- a/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.h @@ -51,6 +51,12 @@ /** Interface Class value for the MIDI Audio Streaming protocol. */ #define MIDI_STREAMING_PROTOCOL 0x00 + /** Pipe number for the MIDI data IN pipe. */ + #define MIDI_DATA_IN_PIPE 1 + + /** Pipe number for the MIDI data OUT pipe. */ + #define MIDI_DATA_OUT_PIPE 2 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum MIDIHost_GetConfigDescriptorDataCodes_t @@ -59,8 +65,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoCDCInterfaceFound = 4, /**< A compatible CDC interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< Compatible CDC endpoints were not found in the device's CDC interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/MIDIHost/MIDIHost.c b/Demos/Host/LowLevel/MIDIHost/MIDIHost.c index f518550b5..7725f5d8a 100644 --- a/Demos/Host/LowLevel/MIDIHost/MIDIHost.c +++ b/Demos/Host/LowLevel/MIDIHost/MIDIHost.c @@ -175,7 +175,7 @@ void MIDI_Host_Task(void) USB_HostState = HOST_STATE_Configured; break; case HOST_STATE_Configured: - Pipe_SelectPipe(MIDI_DATAPIPE_IN); + Pipe_SelectPipe(MIDI_DATA_IN_PIPE); if (Pipe_IsINReceived()) { @@ -196,7 +196,7 @@ void MIDI_Host_Task(void) Pipe_ClearIN(); } - Pipe_SelectPipe(MIDI_DATAPIPE_OUT); + Pipe_SelectPipe(MIDI_DATA_OUT_PIPE); static uint8_t PrevJoystickStatus; diff --git a/Demos/Host/LowLevel/MIDIHost/MIDIHost.h b/Demos/Host/LowLevel/MIDIHost/MIDIHost.h index ecae67c8d..507f0787c 100644 --- a/Demos/Host/LowLevel/MIDIHost/MIDIHost.h +++ b/Demos/Host/LowLevel/MIDIHost/MIDIHost.h @@ -71,12 +71,6 @@ */ #define MIDI_CHANNEL(channel) (channel - 1) - /** Pipe number for the MIDI data IN pipe. */ - #define MIDI_DATAPIPE_IN 1 - - /** Pipe number for the MIDI data OUT pipe. */ - #define MIDI_DATAPIPE_OUT 2 - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ #define LEDMASK_USB_NOTREADY LEDS_LED1 diff --git a/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c b/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c index 8a808d751..64565ac6d 100644 --- a/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c @@ -50,7 +50,9 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,49 +67,50 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the mass storage interface from the configuration descriptor */ + /* Get the first Mass Storage interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoInterfaceFound; + return NoCompatibleInterfaceFound; } - /* Get the IN and OUT data endpoints for the mass storage interface */ - while (FoundEndpoints != ((1 << MASS_STORE_DATA_IN_PIPE) | (1 << MASS_STORE_DATA_OUT_PIPE))) + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Fetch the next bulk endpoint from the current mass storage interface */ + /* Get the next Mass Storage interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMSInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + + /* Get the next Mass Storage interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } } + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the endpoint is a bulk IN or bulk OUT endpoint, set appropriate globals */ + /* If the endpoint is a IN type endpoint */ if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(MASS_STORE_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << MASS_STORE_DATA_IN_PIPE); - } + DataINEndpoint = EndpointData; else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(MASS_STORE_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << MASS_STORE_DATA_OUT_PIPE); - } + DataOUTEndpoint = EndpointData; } + + /* Configure the Mass Storage data IN pipe */ + Pipe_ConfigurePipe(MASS_STORE_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Mass Storage data OUT pipe */ + Pipe_ConfigurePipe(MASS_STORE_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.h b/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.h index fa24019ad..d75789192 100644 --- a/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.h @@ -51,6 +51,12 @@ /** Interface Protocol value for the Bulk Only transport protocol. */ #define MASS_STORE_PROTOCOL 0x50 + /** Pipe number of the Mass Storage data IN pipe. */ + #define MASS_STORE_DATA_IN_PIPE 1 + + /** Pipe number of the Mass Storage data OUT pipe. */ + #define MASS_STORE_DATA_OUT_PIPE 2 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum MassStorageHost_GetConfigDescriptorDataCodes_t @@ -59,8 +65,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoInterfaceFound = 4, /**< A compatible MSD interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< The correct MSD endpoint descriptors were not found in the device's MSD interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.h b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.h index bb038f1c5..628066363 100644 --- a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.h +++ b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.h @@ -65,12 +65,6 @@ /** Timeout period between the issuing of a CBW to a device, and the reception of the first packet. */ #define COMMAND_DATA_TIMEOUT_MS 10000 - - /** Pipe number of the Mass Storage data IN pipe. */ - #define MASS_STORE_DATA_IN_PIPE 1 - - /** Pipe number of the Mass Storage data OUT pipe. */ - #define MASS_STORE_DATA_OUT_PIPE 2 /** Additional error code for Mass Storage functions when a device returns a logical command failure. */ #define MASS_STORE_SCSI_COMMAND_FAILED 0xC0 diff --git a/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c b/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c index 816c23321..02c4cd46d 100644 --- a/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c @@ -50,6 +50,8 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -64,29 +66,42 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the mouse interface from the configuration descriptor */ + /* Get the first HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDInterfaceFound; + return NoCompatibleInterfaceFound; } - /* Get the mouse interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + while (!(DataINEndpoint)) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Get the next HID interface's data endpoint descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Get the next HID interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + } + + /* Retrieve the endpoint address from the endpoint descriptor */ + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); + + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) + DataINEndpoint = EndpointData; } - /* Retrieve the endpoint address from the endpoint descriptor */ - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - - /* Configure the mouse data pipe */ - Pipe_ConfigurePipe(MOUSE_DATAPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - + /* Configure the HID data IN pipe */ + Pipe_ConfigurePipe(MOUSE_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); + /* Valid data found, return success */ return SuccessfulConfigRead; } diff --git a/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.h b/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.h index 77ea6f2a3..71fbadedd 100644 --- a/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.h @@ -48,6 +48,9 @@ /** Interface Protocol value for a Boot Protocol Mouse compliant device. */ #define MOUSE_PROTOCOL 0x02 + /** Pipe number for the mouse data IN pipe. */ + #define MOUSE_DATA_IN_PIPE 1 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum MouseHost_GetConfigDescriptorDataCodes_t @@ -56,8 +59,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/MouseHost/MouseHost.c b/Demos/Host/LowLevel/MouseHost/MouseHost.c index bf20bca52..05efa25c5 100644 --- a/Demos/Host/LowLevel/MouseHost/MouseHost.c +++ b/Demos/Host/LowLevel/MouseHost/MouseHost.c @@ -132,7 +132,7 @@ void ReadNextReport(void) uint8_t LEDMask = LEDS_NO_LEDS; /* Select mouse data pipe */ - Pipe_SelectPipe(MOUSE_DATAPIPE); + Pipe_SelectPipe(MOUSE_DATA_IN_PIPE); /* Unfreeze keyboard data pipe */ Pipe_Unfreeze(); diff --git a/Demos/Host/LowLevel/MouseHost/MouseHost.h b/Demos/Host/LowLevel/MouseHost/MouseHost.h index b9c5aeda1..8947436e6 100644 --- a/Demos/Host/LowLevel/MouseHost/MouseHost.h +++ b/Demos/Host/LowLevel/MouseHost/MouseHost.h @@ -53,9 +53,6 @@ #include "ConfigDescriptor.h" /* Macros: */ - /** Pipe number for the mouse data IN pipe. */ - #define MOUSE_DATAPIPE 1 - /** HID Class Specific request to set the report protocol mode. */ #define REQ_SetProtocol 0x0B diff --git a/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c b/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c index 70766e9e4..f285f5a02 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c @@ -50,6 +50,8 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -63,40 +65,64 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the mouse interface from the configuration descriptor */ + + /* Get the first HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDInterfaceFound; + return NoCompatibleInterfaceFound; } - - /* Get the mouse interface's HID descriptor */ + + /* Get the HID descriptor from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoHIDDescriptorFound; + return NoCompatibleInterfaceFound; } - + /* Save the HID report size for later use */ HIDReportSize = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_HID_t).HIDReportLength; - - /* Get the mouse interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + + while (!(DataINEndpoint)) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Get the next HID interface's data endpoint descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Get the next HID interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + + /* Get the HID descriptor from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + + /* Save the HID report size for later use */ + HIDReportSize = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_HID_t).HIDReportLength; + } + + /* Retrieve the endpoint address from the endpoint descriptor */ + USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); + + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) + DataINEndpoint = EndpointData; } - /* Retrieve the endpoint address from the endpoint descriptor */ - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - - /* Configure the mouse data pipe */ - Pipe_ConfigurePipe(MOUSE_DATAPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); + /* Configure the HID data IN pipe */ + Pipe_ConfigurePipe(MOUSE_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.h b/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.h index 4b34ae683..b2a2e3890 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.h @@ -53,6 +53,9 @@ /** Descriptor header type constant for a HID report descriptor. */ #define DTYPE_Report 0x22 + + /** Pipe number for the mouse report data pipe. */ + #define MOUSE_DATA_IN_PIPE 1 /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ @@ -62,9 +65,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoHIDInterfaceFound = 4, /**< A compatible HID interface was not found in the device's Configuration Descriptor */ - NoHIDDescriptorFound = 5, /**< A compatible HID descriptor was not found in the device's HID interface */ - NoEndpointFound = 5, /**< A compatible HID IN endpoint was not found in the device's HID interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c index 5536d872b..a0240b04a 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c +++ b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c @@ -212,7 +212,7 @@ void Mouse_HID_Task(void) break; case HOST_STATE_Configured: /* Select and unfreeze mouse data pipe */ - Pipe_SelectPipe(MOUSE_DATAPIPE); + Pipe_SelectPipe(MOUSE_DATA_IN_PIPE); Pipe_Unfreeze(); /* Check to see if a packet has been received */ diff --git a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.h b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.h index 3a80c8e60..a51b7a25d 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.h +++ b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.h @@ -54,9 +54,6 @@ #include "HIDReport.h" /* Macros: */ - /** Pipe number for the mouse report data pipe. */ - #define MOUSE_DATAPIPE 1 - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ #define LEDMASK_USB_NOTREADY LEDS_LED1 diff --git a/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c b/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c index 1e0f1be74..0591aaca2 100644 --- a/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c @@ -49,7 +49,9 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -64,52 +66,58 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the printer interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextBidirectionalPrinterInterface)) + /* Get the first Printer interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextBidirectionalPrinterInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoInterfaceFound; + return NoCompatibleInterfaceFound; } - + + /* Save Printer interface details for later use */ PrinterInterfaceNumber = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_Interface_t).InterfaceNumber; PrinterAltSetting = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_Interface_t).AlternateSetting; - /* Get the IN and OUT data endpoints for the printer interface */ - while (FoundEndpoints != ((1 << PRINTER_DATA_OUT_PIPE) | (1 << PRINTER_DATA_IN_PIPE))) + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Fetch the next bulk endpoint from the current printer interface */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextPrinterInterfaceBulkDataEndpoint)) + /* Get the next Printer interface's data endpoint descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextPrinterInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + + /* Get the next Printer interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextBidirectionalPrinterInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + + /* Save Printer interface details for later use */ + PrinterInterfaceNumber = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_Interface_t).InterfaceNumber; + PrinterAltSetting = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_Interface_t).AlternateSetting; } + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the endpoint is a bulk IN or bulk OUT endpoint, set appropriate globals */ + /* If the endpoint is a IN type endpoint */ if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(PRINTER_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_SINGLE); - - Pipe_SetInfiniteINRequests(); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << PRINTER_DATA_IN_PIPE); - } + DataINEndpoint = EndpointData; else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(PRINTER_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << PRINTER_DATA_OUT_PIPE); - } + DataOUTEndpoint = EndpointData; } + + /* Configure the Printer data IN pipe */ + Pipe_ConfigurePipe(PRINTER_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Printer data OUT pipe */ + Pipe_ConfigurePipe(PRINTER_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.h b/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.h index 1b66348b9..b0cd56b19 100644 --- a/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.h @@ -47,6 +47,12 @@ /** Interface Protocol value for a Bidirectional communication encapsulation. */ #define PRINTER_PROTOCOL 0x02 + /** Pipe number of the Printer data IN pipe. */ + #define PRINTER_DATA_IN_PIPE 1 + + /** Pipe number of the Printer data OUT pipe. */ + #define PRINTER_DATA_OUT_PIPE 2 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum PrinterHost_GetConfigDescriptorDataCodes_t @@ -55,8 +61,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoInterfaceFound = 4, /**< A compatible printer interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< The printer data endpoints were not found in the device's Configuration Descriptor */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* External Variables: */ diff --git a/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.h b/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.h index 3edfe434d..9cd768efa 100644 --- a/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.h +++ b/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.h @@ -53,12 +53,6 @@ /** Printer class-specific request to soft-reset the device. */ #define REQ_SoftReset 2 - - /** Pipe number of the Printer data IN pipe. */ - #define PRINTER_DATA_IN_PIPE 1 - - /** Pipe number of the Printer data OUT pipe. */ - #define PRINTER_DATA_OUT_PIPE 2 /* Function Prototypes: */ uint8_t Printer_SendData(const void* const PrinterCommands, diff --git a/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c b/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c index 97a38b4ac..0db576f72 100644 --- a/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c @@ -50,7 +50,10 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,104 +68,80 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the CDC control interface from the configuration descriptor */ + /* Get the first RNDIS control interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoRNDISInterfaceFound; + return NoCompatibleInterfaceFound; } - /* Get the IN and OUT data and IN notification endpoints for the RNDIS interface */ - while (FoundEndpoints != ((1 << RNDIS_NOTIFICATIONPIPE) | (1 << RNDIS_DATAPIPE_IN) | (1 << RNDIS_DATAPIPE_OUT))) + while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint)) { - /* Fetch the next bulk or interrupt endpoint from the current RNDIS interface */ + /* Get the next RNDIS interface's endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Check to see if the control interface's notification pipe has been found, if so search for the data interface */ - if (FoundEndpoints & (1 << RNDIS_NOTIFICATIONPIPE)) + /* Check if we have already found the control interface's notification endpoint or not */ + if (NotificationEndpoint) { - /* Get the next CDC data interface from the configuration descriptor (RNDIS class has two CDC interfaces) */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found) + /* Get the next RNDIS data interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoRNDISInterfaceFound; - } + return NoCompatibleInterfaceFound; + } + + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; } else { - /* Clear the found endpoints mask, since any already processed endpoints aren't in the CDC interface we need */ - FoundEndpoints = 0; - - /* Disable any already configured pipes from the invalid RNDIS interfaces */ - Pipe_SelectPipe(RNDIS_NOTIFICATIONPIPE); - Pipe_DisablePipe(); - Pipe_SelectPipe(RNDIS_DATAPIPE_IN); - Pipe_DisablePipe(); - Pipe_SelectPipe(RNDIS_DATAPIPE_OUT); - Pipe_DisablePipe(); - - /* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */ + /* Get the next RNDIS control interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) + DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoRNDISInterfaceFound; + return NoCompatibleInterfaceFound; } - } - /* Fetch the next bulk or interrupt endpoint from the current CDC interface */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Clear any found endpoints */ + NotificationEndpoint = NULL; } } + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the found endpoint is a interrupt or bulk type descriptor */ - if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) { - /* If the endpoint is a IN type interrupt endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the notification pipe */ - Pipe_ConfigurePipe(RNDIS_NOTIFICATIONPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS); - - /* Set the flag indicating that the notification pipe has been found */ - FoundEndpoints |= (1 << RNDIS_NOTIFICATIONPIPE); - } + /* Check if the found endpoint is a interrupt or bulk type descriptor */ + if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + NotificationEndpoint = EndpointData; + else + DataINEndpoint = EndpointData; } else { - /* Check if the endpoint is a bulk IN or bulk OUT endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(RNDIS_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << RNDIS_DATAPIPE_IN); - } - else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(RNDIS_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << RNDIS_DATAPIPE_OUT); - } + DataOUTEndpoint = EndpointData; } } + + /* Configure the RNDIS data IN pipe */ + Pipe_ConfigurePipe(RNDIS_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the RNDIS data OUT pipe */ + Pipe_ConfigurePipe(RNDIS_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the RNDIS notification pipe */ + Pipe_ConfigurePipe(RNDIS_NOTIFICATION_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + NotificationEndpoint->EndpointAddress, NotificationEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(NotificationEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.h b/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.h index 0f8c99247..834493742 100644 --- a/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.h @@ -60,6 +60,15 @@ /** Interface Class value for the CDC data protocol. */ #define CDC_DATA_PROTOCOL 0x00 + /** Pipe number for the RNDIS data IN pipe. */ + #define RNDIS_DATA_IN_PIPE 1 + + /** Pipe number for the RNDIS data OUT pipe. */ + #define RNDIS_DATA_OUT_PIPE 2 + + /** Pipe number for the RNDIS notification pipe. */ + #define RNDIS_NOTIFICATION_PIPE 3 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum RNDISHost_GetConfigDescriptorDataCodes_t @@ -68,8 +77,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoRNDISInterfaceFound = 4, /**< A compatible RNDIS interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< Compatible RNDIS endpoints were not found in the device's RNDIS interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.c b/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.c index ec018bf3a..64cfc3ce6 100644 --- a/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.c +++ b/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.c @@ -281,7 +281,7 @@ uint8_t RNDIS_GetPacketLength(uint16_t* const PacketLength) { uint8_t ErrorCode; - Pipe_SelectPipe(RNDIS_DATAPIPE_IN); + Pipe_SelectPipe(RNDIS_DATA_IN_PIPE); Pipe_SetPipeToken(PIPE_TOKEN_IN); Pipe_Unfreeze(); diff --git a/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.h b/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.h index 0c4af3aed..56b4946e6 100644 --- a/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.h +++ b/Demos/Host/LowLevel/RNDISEthernetHost/Lib/RNDISCommands.h @@ -44,6 +44,7 @@ #include <LUFA/Drivers/USB/USB.h> #include "RNDISConstants.h" + #include "../RNDISEthernetHost.h" /* Type Defines: */ /** Type define for a RNDIS message header, sent before RNDIS messages. */ @@ -186,15 +187,6 @@ /** Implemented RNDIS Version Minor. */ #define REMOTE_NDIS_VERSION_MINOR 0x00 - - /** Pipe number for the RNDIS data IN pipe. */ - #define RNDIS_DATAPIPE_IN 1 - - /** Pipe number for the RNDIS data OUT pipe. */ - #define RNDIS_DATAPIPE_OUT 2 - - /** 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 diff --git a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c index 9f740c1f0..583df3bcc 100644 --- a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c @@ -50,7 +50,10 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* EventsEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,69 +68,64 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the Still Image interface from the configuration descriptor */ + /* Get the first Still Image interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoInterfaceFound; + return NoCompatibleInterfaceFound; } - /* Get the IN and OUT data and event endpoints for the Still Image interface */ - while (FoundEndpoints != ((1 << SIMAGE_EVENTS_PIPE) | (1 << SIMAGE_DATA_IN_PIPE) | (1 << SIMAGE_DATA_OUT_PIPE))) + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Fetch the next endpoint from the current Still Image interface */ + /* Get the next Still Image interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextStillImageInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + EventsEndpoint = NULL; + + /* Get the next Still Image interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } } - + + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the found endpoint is a interrupt or bulk type descriptor */ - if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) { - /* If the endpoint is a IN type interrupt endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the events pipe */ - Pipe_ConfigurePipe(SIMAGE_EVENTS_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS); - - /* Set the flag indicating that the events pipe has been found */ - FoundEndpoints |= (1 << SIMAGE_EVENTS_PIPE); - } + /* Check if the found endpoint is a interrupt or bulk type descriptor */ + if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + EventsEndpoint = EndpointData; + else + DataINEndpoint = EndpointData; } else { - /* Check if the endpoint is a bulk IN or bulk OUT endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(SIMAGE_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << SIMAGE_DATA_IN_PIPE); - } - else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(SIMAGE_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << SIMAGE_DATA_OUT_PIPE); - } + DataOUTEndpoint = EndpointData; } } + + /* Configure the Still Image data IN pipe */ + Pipe_ConfigurePipe(SIMAGE_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Still Image data OUT pipe */ + Pipe_ConfigurePipe(SIMAGE_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Still Image events pipe */ + Pipe_ConfigurePipe(SIMAGE_EVENTS_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + EventsEndpoint->EndpointAddress, EventsEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(EventsEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h index 631352d4f..929d658cd 100644 --- a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h @@ -51,6 +51,15 @@ /** Interface Class value for the Still Image Device protocol. */ #define SIMAGE_PROTOCOL 0x01 + /** Pipe number of the Still Image data IN pipe. */ + #define SIMAGE_DATA_IN_PIPE 1 + + /** Pipe number of the Still Image data OUT pipe. */ + #define SIMAGE_DATA_OUT_PIPE 2 + + /** Pipe number of the Still Image events pipe. */ + #define SIMAGE_EVENTS_PIPE 3 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum StillImageHost_GetConfigDescriptorDataCodes_t @@ -59,8 +68,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoInterfaceFound = 4, /**< A compatible SI interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< The correct SI endpoint descriptors were not found in the device's SI interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h index c91a80122..f2bb18953 100644 --- a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h +++ b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h @@ -40,17 +40,9 @@ #include <LUFA/Drivers/USB/USB.h> #include "PIMACodes.h" + #include "../StillImageHost.h" - /* Macros: */ - /** Pipe number of the Still Image data IN pipe. */ - #define SIMAGE_DATA_IN_PIPE 0x01 - - /** Pipe number of the Still Image data OUT pipe. */ - #define SIMAGE_DATA_OUT_PIPE 0x02 - - /** Pipe number of the Still Image events pipe. */ - #define SIMAGE_EVENTS_PIPE 0x03 - + /* Macros: */ /** Length in bytes of a given Unicode string's character length. * * \param[in] chars Total number of Unicode characters in the string diff --git a/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c b/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c index 5707308ad..c35a606cc 100644 --- a/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c @@ -50,7 +50,10 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,104 +68,80 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the CDC control interface from the configuration descriptor */ + /* Get the first CDC control interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoCDCInterfaceFound; + return NoCompatibleInterfaceFound; } - /* Get the IN and OUT data and IN notification endpoints for the CDC interface */ - while (FoundEndpoints != ((1 << CDC_NOTIFICATIONPIPE) | (1 << CDC_DATAPIPE_IN) | (1 << CDC_DATAPIPE_OUT))) + while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint)) { - /* Fetch the next bulk or interrupt endpoint from the current CDC interface */ + /* Get the next CDC interface's endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Check to see if the control interface's notification pipe has been found, if so search for the data interface */ - if (FoundEndpoints & (1 << CDC_NOTIFICATIONPIPE)) + /* Check if we have already found the control interface's notification endpoint or not */ + if (NotificationEndpoint) { - /* Get the next CDC data interface from the configuration descriptor (CDC class has two CDC interfaces) */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found) + /* Get the next CDC data interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoCDCInterfaceFound; - } + return NoCompatibleInterfaceFound; + } + + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; } else { - /* Clear the found endpoints mask, since any already processed endpoints aren't in the CDC interface we need */ - FoundEndpoints = 0; - - /* Disable any already configured pipes from the invalid CDC interfaces */ - Pipe_SelectPipe(CDC_NOTIFICATIONPIPE); - Pipe_DisablePipe(); - Pipe_SelectPipe(CDC_DATAPIPE_IN); - Pipe_DisablePipe(); - Pipe_SelectPipe(CDC_DATAPIPE_OUT); - Pipe_DisablePipe(); - - /* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */ + /* Get the next CDC control interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) + DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoCDCInterfaceFound; + return NoCompatibleInterfaceFound; } - } - /* Fetch the next bulk or interrupt endpoint from the current CDC interface */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Clear any found endpoints */ + NotificationEndpoint = NULL; } } + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the found endpoint is a interrupt or bulk type descriptor */ - if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) { - /* If the endpoint is a IN type interrupt endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the notification pipe */ - Pipe_ConfigurePipe(CDC_NOTIFICATIONPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS); - - /* Set the flag indicating that the notification pipe has been found */ - FoundEndpoints |= (1 << CDC_NOTIFICATIONPIPE); - } + /* Check if the found endpoint is a interrupt or bulk type descriptor */ + if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + NotificationEndpoint = EndpointData; + else + DataINEndpoint = EndpointData; } else { - /* Check if the endpoint is a bulk IN or bulk OUT endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(CDC_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << CDC_DATAPIPE_IN); - } - else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(CDC_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << CDC_DATAPIPE_OUT); - } + DataOUTEndpoint = EndpointData; } } + + /* Configure the CDC data IN pipe */ + Pipe_ConfigurePipe(CDC_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the CDC data OUT pipe */ + Pipe_ConfigurePipe(CDC_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the CDC notification pipe */ + Pipe_ConfigurePipe(CDC_NOTIFICATION_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + NotificationEndpoint->EndpointAddress, NotificationEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(NotificationEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.h b/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.h index a6720f2cd..2e4730c55 100644 --- a/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.h @@ -60,6 +60,15 @@ /** Interface Class value for the CDC data protocol. */ #define CDC_DATA_PROTOCOL 0x00 + /** Pipe number for the CDC data IN pipe. */ + #define CDC_DATA_IN_PIPE 1 + + /** Pipe number for the CDC data OUT pipe. */ + #define CDC_DATA_OUT_PIPE 2 + + /** Pipe number for the CDC notification pipe. */ + #define CDC_NOTIFICATION_PIPE 3 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum CDCHost_GetConfigDescriptorDataCodes_t @@ -68,8 +77,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoCDCInterfaceFound = 4, /**< A compatible CDC interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< Compatible CDC endpoints were not found in the device's CDC interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.c b/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.c index 4c250cd48..91775b7a4 100644 --- a/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.c +++ b/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.c @@ -173,7 +173,7 @@ void CDC_Host_Task(void) break; case HOST_STATE_Configured: /* Select the data IN pipe */ - Pipe_SelectPipe(CDC_DATAPIPE_IN); + Pipe_SelectPipe(CDC_DATA_IN_PIPE); Pipe_Unfreeze(); /* Check to see if a packet has been received */ @@ -205,7 +205,7 @@ void CDC_Host_Task(void) Pipe_Freeze(); /* Select and unfreeze the notification pipe */ - Pipe_SelectPipe(CDC_NOTIFICATIONPIPE); + Pipe_SelectPipe(CDC_NOTIFICATION_PIPE); Pipe_Unfreeze(); /* Check if a packet has been received */ diff --git a/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.h b/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.h index cf785e320..d55fa68af 100644 --- a/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.h +++ b/Demos/Host/LowLevel/VirtualSerialHost/VirtualSerialHost.h @@ -53,15 +53,6 @@ #include "ConfigDescriptor.h" /* Macros: */ - /** Pipe number for the CDC data IN pipe. */ - #define CDC_DATAPIPE_IN 1 - - /** Pipe number for the CDC data OUT pipe. */ - #define CDC_DATAPIPE_OUT 2 - - /** Pipe number for the CDC notification pipe. */ - #define CDC_NOTIFICATIONPIPE 3 - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ #define LEDMASK_USB_NOTREADY LEDS_LED1 |