aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-06-18 10:31:55 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-06-18 10:31:55 +0000
commitf896c00c48f04fb9273555ab8d9b1af99f865d25 (patch)
treeb76827a0467c77ddeb30e11748c02a4f53779a14 /LUFA
parente338cb6f329d6bf948abad88637f81436ee90daf (diff)
downloadlufa-f896c00c48f04fb9273555ab8d9b1af99f865d25.tar.gz
lufa-f896c00c48f04fb9273555ab8d9b1af99f865d25.tar.bz2
lufa-f896c00c48f04fb9273555ab8d9b1af99f865d25.zip
Break device mode class driver interfaces into seperate config and state structs which are then combined, for clarity. Move device mode class driver interfaces back into the device mode class driver headers from the common class headers to make room for host class interfaces.
Diffstat (limited to 'LUFA')
-rw-r--r--LUFA/Drivers/USB/Class/Common/Audio.h22
-rw-r--r--LUFA/Drivers/USB/Class/Common/CDC.h34
-rw-r--r--LUFA/Drivers/USB/Class/Common/HID.h34
-rw-r--r--LUFA/Drivers/USB/Class/Common/MIDI.h16
-rw-r--r--LUFA/Drivers/USB/Class/Common/MassStorage.h30
-rw-r--r--LUFA/Drivers/USB/Class/Common/RNDIS.h35
-rw-r--r--LUFA/Drivers/USB/Class/Device/Audio.c30
-rw-r--r--LUFA/Drivers/USB/Class/Device/Audio.h61
-rw-r--r--LUFA/Drivers/USB/Class/Device/CDC.c48
-rw-r--r--LUFA/Drivers/USB/Class/Device/CDC.h78
-rw-r--r--LUFA/Drivers/USB/Class/Device/HID.c34
-rw-r--r--LUFA/Drivers/USB/Class/Device/HID.h52
-rw-r--r--LUFA/Drivers/USB/Class/Device/MIDI.c26
-rw-r--r--LUFA/Drivers/USB/Class/Device/MIDI.h49
-rw-r--r--LUFA/Drivers/USB/Class/Device/MassStorage.c95
-rw-r--r--LUFA/Drivers/USB/Class/Device/MassStorage.h62
-rw-r--r--LUFA/Drivers/USB/Class/Device/RNDIS.c121
-rw-r--r--LUFA/Drivers/USB/Class/Device/RNDIS.h68
-rw-r--r--LUFA/Drivers/USB/Class/Host/CDC.c38
-rw-r--r--LUFA/Drivers/USB/Class/Host/CDC.h19
-rw-r--r--LUFA/ManPages/FutureChanges.txt3
21 files changed, 546 insertions, 409 deletions
diff --git a/LUFA/Drivers/USB/Class/Common/Audio.h b/LUFA/Drivers/USB/Class/Common/Audio.h
index 51cdfc6f4..07667a5e1 100644
--- a/LUFA/Drivers/USB/Class/Common/Audio.h
+++ b/LUFA/Drivers/USB/Class/Common/Audio.h
@@ -349,27 +349,7 @@
uint8_t LockDelayUnits; /**< Units used for the LockDelay field, see Audio class specification */
uint16_t LockDelay; /**< Time required to internally lock endpoint's internal clock recovery circuitry */
- } USB_AudioStreamEndpoint_Spc_t;
-
- /** Class state structure. An instance of this structure should be made for each Audio interface
- * within the user application, and passed to each of the Audio class driver functions as the
- * AudioInterfaceInfo parameter. The contents of this structure should be set to their correct
- * values when used, or ommitted to force the library to use default values.
- */
- typedef struct
- {
- uint8_t StreamingInterfaceNumber; /**< Index of the Audio Streaming interface within the device this structure controls */
-
- uint8_t DataINEndpointNumber; /**< Endpoint number of the incomming Audio Streaming data, if available (zero if unused) */
- uint16_t DataINEndpointSize; /**< Size in bytes of the incomming Audio Streaming data endpoint, if available (zero if unused) */
-
- uint8_t DataOUTEndpointNumber; /**< Endpoint number of the outgoing Audio Streaming data, if available (zero if unused) */
- uint16_t DataOUTEndpointSize; /**< Size in bytes of the outgoing Audio Streaming data endpoint, if available (zero if unused) */
-
- bool InterfaceEnabled; /**< Set and cleared by the class driver to indicate if the host has enabled the streaming endpoints
- * of the Audio Streaming interface
- */
- } USB_ClassInfo_Audio_t;
+ } USB_AudioStreamEndpoint_Spc_t;
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
diff --git a/LUFA/Drivers/USB/Class/Common/CDC.h b/LUFA/Drivers/USB/Class/Common/CDC.h
index 12f8b8381..ccc32683b 100644
--- a/LUFA/Drivers/USB/Class/Common/CDC.h
+++ b/LUFA/Drivers/USB/Class/Common/CDC.h
@@ -140,40 +140,6 @@
CDC_PARITY_Space = 4, /**< Space parity bit mode on each frame */
};
- /* Type Defines: */
- /** Class state structure. An instance of this structure should be made for each CDC interface
- * within the user application, and passed to each of the CDC class driver functions as the
- * CDCInterfaceInfo parameter. The contents of this structure should be set to their correct
- * values when used, or ommitted to force the library to use default values.
- */
- typedef struct
- {
- uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
-
- uint8_t DataINEndpointNumber; /**< Endpoint number of the CDC interface's IN data endpoint */
- uint16_t DataINEndpointSize; /**< Size in bytes of the CDC interface's IN data endpoint */
-
- uint8_t DataOUTEndpointNumber; /**< Endpoint number of the CDC interface's OUT data endpoint */
- uint16_t DataOUTEndpointSize; /**< Size in bytes of the CDC interface's OUT data endpoint */
-
- uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
- uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
-
- uint8_t ControlLineState; /**< Current control line states, as set by the host */
-
- struct
- {
- uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */
- uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the
- * CDCDevice_CDC_LineCodingFormats_t enum
- */
- uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the
- * CDCDevice_LineCodingParity_t enum
- */
- uint8_t DataBits; /**< Bits of data per character of the virtual serial port */
- } LineEncoding;
- } USB_ClassInfo_CDC_t;
-
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
diff --git a/LUFA/Drivers/USB/Class/Common/HID.h b/LUFA/Drivers/USB/Class/Common/HID.h
index 07ed94b56..54403d4c8 100644
--- a/LUFA/Drivers/USB/Class/Common/HID.h
+++ b/LUFA/Drivers/USB/Class/Common/HID.h
@@ -71,42 +71,20 @@
*/
typedef struct
{
- USB_Descriptor_Header_t Header;
+ USB_Descriptor_Header_t Header;
- uint16_t HIDSpec;
- uint8_t CountryCode;
+ uint16_t HIDSpec;
+ uint8_t CountryCode;
- uint8_t TotalReportDescriptors;
+ uint8_t TotalReportDescriptors;
- uint8_t HIDReportType;
- uint16_t HIDReportLength;
+ uint8_t HIDReportType;
+ uint16_t HIDReportLength;
} USB_Descriptor_HID_t;
/** Type define for the data type used to store HID report descriptor elements. */
typedef uint8_t USB_Descriptor_HIDReport_Datatype_t;
- /** Class state structure. An instance of this structure should be made for each HID interface
- * within the user application, and passed to each of the HID class driver functions as the
- * HIDInterfaceInfo parameter. The contents of this structure should be set to their correct
- * values when used, or ommitted to force the library to use default values.
- *
- * Note that for the HID class driver, host-to-device reports are received via HID class requests
- * rather than a dedicated endpoint to simplify the driver and its interface.
- */
- typedef struct
- {
- uint8_t InterfaceNumber; /**< Interface number of the HID interface within the device */
-
- uint8_t ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */
- uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */
-
- uint8_t ReportINBufferSize; /**< Size of the largest possible report to send to the host, for buffer allocation purposes */
-
- bool UsingReportProtocol; /**< Indicates if the HID interface is set to Boot or Report protocol mode */
- uint16_t IdleCount; /**< Report idle period, in ms, set by the host */
- uint16_t IdleMSRemaining; /**< Total number of ms remaining before the idle period elapses */
- } USB_ClassInfo_HID_t;
-
#endif
/** @} */
diff --git a/LUFA/Drivers/USB/Class/Common/MIDI.h b/LUFA/Drivers/USB/Class/Common/MIDI.h
index f768ba238..fad7ad89d 100644
--- a/LUFA/Drivers/USB/Class/Common/MIDI.h
+++ b/LUFA/Drivers/USB/Class/Common/MIDI.h
@@ -145,22 +145,6 @@
uint8_t Data3; /**< Third byte of data in the MIDI event */
} USB_MIDI_EventPacket_t;
- /** Class state structure. An instance of this structure should be made for each MIDI interface
- * within the user application, and passed to each of the MIDI class driver functions as the
- * MIDIInterfaceInfo parameter. The contents of this structure should be set to their correct
- * values when used, or ommitted to force the library to use default values.
- */
- typedef struct
- {
- uint8_t StreamingInterfaceNumber; /**< Index of the Audio Streaming interface within the device this structure controls */
-
- uint8_t DataINEndpointNumber; /**< Endpoint number of the incomming MIDI data, if available (zero if unused) */
- uint16_t DataINEndpointSize; /**< Size in bytes of the incomming MIDI data endpoint, if available (zero if unused) */
-
- uint8_t DataOUTEndpointNumber; /**< Endpoint number of the outgoing MIDI data, if available (zero if unused) */
- uint16_t DataOUTEndpointSize; /**< Size in bytes of the outgoing MIDI data endpoint, if available (zero if unused) */
- } USB_ClassInfo_MIDI_t;
-
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
diff --git a/LUFA/Drivers/USB/Class/Common/MassStorage.h b/LUFA/Drivers/USB/Class/Common/MassStorage.h
index b4ba0908f..d00f371a0 100644
--- a/LUFA/Drivers/USB/Class/Common/MassStorage.h
+++ b/LUFA/Drivers/USB/Class/Common/MassStorage.h
@@ -94,36 +94,6 @@
SCSI_Command_Fail = 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */
SCSI_Phase_Error = 2 /**< Command failed due to being invalid in the current phase */
};
-
- /* Type Defines: */
- /** Class state structure. An instance of this structure should be made for each Mass Storage interface
- * within the user application, and passed to each of the Mass Storage class driver functions as the
- * MSInterfaceInfo parameter. The contents of this structure should be set to their correct
- * values when used, or ommitted to force the library to use default values.
- */
- typedef struct
- {
- uint8_t InterfaceNumber; /**< Interface number of the Mass Storage interface within the device */
-
- uint8_t DataINEndpointNumber; /**< Endpoint number of the Mass Storage interface's IN data endpoint */
- uint16_t DataINEndpointSize; /**< Size in bytes of the Mass Storage interface's IN data endpoint */
-
- uint8_t DataOUTEndpointNumber; /**< Endpoint number of the Mass Storage interface's OUT data endpoint */
- uint16_t DataOUTEndpointSize; /**< Size in bytes of the Mass Storage interface's OUT data endpoint */
-
- uint8_t TotalLUNs; /**< Total number of logical drives in the Mass Storage interface */
-
- CommandBlockWrapper_t CommandBlock; /**< Mass Storage class command block structure, used internally
- * by the class driver
- */
- CommandStatusWrapper_t CommandStatus; /**< Mass Storage class command status structure, used internally
- * by the class driver
- */
-
- bool IsMassStoreReset; /**< Flag indicating that the host has requested that the Mass Storage interface be reset
- * and that all current Mass Storage operations should immediately abort
- */
- } USB_ClassInfo_MS_t;
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
diff --git a/LUFA/Drivers/USB/Class/Common/RNDIS.h b/LUFA/Drivers/USB/Class/Common/RNDIS.h
index abc17334a..157fff359 100644
--- a/LUFA/Drivers/USB/Class/Common/RNDIS.h
+++ b/LUFA/Drivers/USB/Class/Common/RNDIS.h
@@ -228,41 +228,6 @@
uint32_t InformationBufferLength;
uint32_t InformationBufferOffset;
} RNDIS_QUERY_CMPLT_t;
-
- /** Class state structure. An instance of this structure should be made for each RNDIS interface
- * within the user application, and passed to each of the RNDIS class driver functions as the
- * RNDISInterfaceInfo parameter. The contents of this structure should be set to their correct
- * values when used, or ommitted to force the library to use default values.
- */
- typedef struct
- {
- uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
-
- uint8_t DataINEndpointNumber; /**< Endpoint number of the CDC interface's IN data endpoint */
- uint16_t DataINEndpointSize; /**< Size in bytes of the CDC interface's IN data endpoint */
-
- uint8_t DataOUTEndpointNumber; /**< Endpoint number of the CDC interface's OUT data endpoint */
- uint16_t DataOUTEndpointSize; /**< Size in bytes of the CDC interface's OUT data endpoint */
-
- uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
- uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
-
- char* AdapterVendorDescription; /**< String description of the adapter vendor */
- MAC_Address_t AdapterMACAddress; /**< MAC address of the adapter */
-
- uint8_t RNDISMessageBuffer[RNDIS_MESSAGE_BUFFER_SIZE]; /**< Buffer to hold RNDIS messages to and from the host,
- * managed by the class driver
- */
- bool ResponseReady; /**< Internal flag indicating if a RNDIS message is waiting to be returned to the host */
- uint8_t CurrRNDISState; /**< Current RNDIS state of the adapter, a value from the RNDIS_States_t enum */
- uint32_t CurrPacketFilter; /**< Current packet filter mode, used internally by the class driver */
- Ethernet_Frame_Info_t FrameIN; /**< Structure holding the last received Ethernet frame from the host, for user
- * processing
- */
- Ethernet_Frame_Info_t FrameOUT; /**< Structure holding the next Ethernet frame to send to the host, populated by the
- * user application
- */
- } USB_ClassInfo_RNDIS_t;
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
diff --git a/LUFA/Drivers/USB/Class/Device/Audio.c b/LUFA/Drivers/USB/Class/Device/Audio.c
index 108bf9495..e398f1c0e 100644
--- a/LUFA/Drivers/USB/Class/Device/Audio.c
+++ b/LUFA/Drivers/USB/Class/Device/Audio.c
@@ -33,12 +33,12 @@
#include "Audio.h"
-void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_t* AudioInterfaceInfo)
+void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo)
{
if (!(Endpoint_IsSETUPReceived()))
return;
- if (USB_ControlRequest.wIndex != AudioInterfaceInfo->StreamingInterfaceNumber)
+ if (USB_ControlRequest.wIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber)
return;
switch (USB_ControlRequest.bRequest)
@@ -48,7 +48,7 @@ void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_t* AudioInterfaceInfo
{
Endpoint_ClearSETUP();
- AudioInterfaceInfo->InterfaceEnabled = (USB_ControlRequest.wValue != 0);
+ AudioInterfaceInfo->State.InterfaceEnabled = (USB_ControlRequest.wValue != 0);
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
@@ -58,22 +58,22 @@ void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_t* AudioInterfaceInfo
}
}
-bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_t* AudioInterfaceInfo)
+bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo)
{
- if (AudioInterfaceInfo->DataINEndpointNumber)
+ if (AudioInterfaceInfo->Config.DataINEndpointNumber)
{
- if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->DataINEndpointNumber, EP_TYPE_ISOCHRONOUS,
- ENDPOINT_DIR_IN, AudioInterfaceInfo->DataINEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_ISOCHRONOUS,
+ ENDPOINT_DIR_IN, AudioInterfaceInfo->Config.DataINEndpointSize,
ENDPOINT_BANK_DOUBLE)))
{
return false;
}
}
- if (AudioInterfaceInfo->DataOUTEndpointNumber)
+ if (AudioInterfaceInfo->Config.DataOUTEndpointNumber)
{
- if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->DataOUTEndpointNumber, EP_TYPE_ISOCHRONOUS,
- ENDPOINT_DIR_OUT, AudioInterfaceInfo->DataOUTEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_ISOCHRONOUS,
+ ENDPOINT_DIR_OUT, AudioInterfaceInfo->Config.DataOUTEndpointSize,
ENDPOINT_BANK_DOUBLE)))
{
return false;
@@ -83,7 +83,7 @@ bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_t* AudioInterfaceInfo)
return true;
}
-void Audio_Device_USBTask(USB_ClassInfo_Audio_t* AudioInterfaceInfo)
+void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo)
{
}
@@ -149,15 +149,15 @@ void Audio_Device_WriteSample24(int32_t Sample)
Endpoint_ClearIN();
}
-bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_t* AudioInterfaceInfo)
+bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo)
{
- Endpoint_SelectEndpoint(AudioInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber);
return Endpoint_IsOUTReceived();
}
-bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_t* AudioInterfaceInfo)
+bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo)
{
- Endpoint_SelectEndpoint(AudioInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber);
return Endpoint_IsINReady();
}
diff --git a/LUFA/Drivers/USB/Class/Device/Audio.h b/LUFA/Drivers/USB/Class/Device/Audio.h
index 3591358f9..cc3e98419 100644
--- a/LUFA/Drivers/USB/Class/Device/Audio.h
+++ b/LUFA/Drivers/USB/Class/Device/Audio.h
@@ -52,6 +52,57 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Type Defines: */
+ /** Configuration information structure for \ref USB_ClassInfo_Audio_Device_t Audio device interface structures. */
+ typedef struct
+ {
+ uint8_t StreamingInterfaceNumber; /**< Index of the Audio Streaming interface within the device this
+ * structure controls.
+ */
+
+ uint8_t DataINEndpointNumber; /**< Endpoint number of the incomming Audio Streaming data, if available
+ * (zero if unused).
+ */
+ uint16_t DataINEndpointSize; /**< Size in bytes of the incomming Audio Streaming data endpoint, if available
+ * (zero if unused).
+ */
+
+ uint8_t DataOUTEndpointNumber; /**< Endpoint number of the outgoing Audio Streaming data, if available
+ * (zero if unused).
+ */
+ uint16_t DataOUTEndpointSize; /**< Size in bytes of the outgoing Audio Streaming data endpoint, if available
+ * (zero if unused).
+ */
+ } USB_ClassInfo_Audio_Device_Config_t;
+
+ /** Current State information structure for \ref USB_ClassInfo_Audio_Device_t Audio device interface structures. */
+ typedef struct
+ {
+ bool InterfaceEnabled; /**< Set and cleared by the class driver to indicate if the host has enabled the streaming endpoints
+ * of the Audio Streaming interface.
+ */
+ } USB_ClassInfo_Audio_Device_State_t;
+
+ /** Class state structure. An instance of this structure should be made for each Audio interface
+ * within the user application, and passed to each of the Audio class driver functions as the
+ * AudioInterfaceInfo parameter. This stores each Audio interface's configuration and state information.
+ */
+ typedef struct
+ {
+ const USB_ClassInfo_Audio_Device_Config_t Config; /**< Config data for the USB class interface within
+ * the device. All elements in this section
+ * <b>must</b> be set or the interface will fail
+ * to enumerate and operate correctly.
+ */
+
+ USB_ClassInfo_Audio_Device_State_t State; /**< State data for the USB class interface within
+ * the device. All elements in this section
+ * <b>may</b> be set to initial values, but may
+ * also be ignored to default to sane values when
+ * the interface is enumerated.
+ */
+ } USB_ClassInfo_Audio_Device_t;
+
/* Function Prototypes: */
/** Configures the endpoints of a given Audio interface, ready for use. This should be linked to the library
* \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration containing the
@@ -61,21 +112,21 @@
*
* \return Boolean true if the endpoints were sucessfully configured, false otherwise
*/
- bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_t* AudioInterfaceInfo);
+ bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
/** Processes incomming control requests from the host, that are directed to the given Audio class interface. This should be
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
*
* \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
*/
- void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_t* AudioInterfaceInfo);
+ void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
/** General management task for a given Audio class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
*/
- void Audio_Device_USBTask(USB_ClassInfo_Audio_t* AudioInterfaceInfo);
+ void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
/** Reads the next 8-bit audio sample from the current audio interface.
*
@@ -137,7 +188,7 @@
*
* \return Boolean true if the given Audio interface has a sample to be read, false otherwise
*/
- bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_t* AudioInterfaceInfo);
+ bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
/** Determines if the given audio interface is ready to accept the next sample to be written to it.
*
@@ -145,7 +196,7 @@
*
* \return Boolean true if the given Audio interface is ready to accept the next sample, false otherwise
*/
- bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_t* AudioInterfaceInfo);
+ bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
diff --git a/LUFA/Drivers/USB/Class/Device/CDC.c b/LUFA/Drivers/USB/Class/Device/CDC.c
index 2cc0f941a..cc8161e0b 100644
--- a/LUFA/Drivers/USB/Class/Device/CDC.c
+++ b/LUFA/Drivers/USB/Class/Device/CDC.c
@@ -39,12 +39,12 @@ void CDC_Device_Event_Stub(void)
}
-void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
+void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
{
if (!(Endpoint_IsSETUPReceived()))
return;
- if (USB_ControlRequest.wIndex != CDCInterfaceInfo->ControlInterfaceNumber)
+ if (USB_ControlRequest.wIndex != CDCInterfaceInfo->Config.ControlInterfaceNumber)
return;
switch (USB_ControlRequest.bRequest)
@@ -53,7 +53,7 @@ void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
- Endpoint_Write_Control_Stream_LE(&CDCInterfaceInfo->LineEncoding, sizeof(CDCInterfaceInfo->LineEncoding));
+ Endpoint_Write_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));
Endpoint_ClearOUT();
}
@@ -62,7 +62,7 @@ void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
- Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->LineEncoding, sizeof(CDCInterfaceInfo->LineEncoding));
+ Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));
Endpoint_ClearIN();
EVENT_CDC_Device_LineEncodingChanged(CDCInterfaceInfo);
@@ -74,7 +74,7 @@ void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
{
Endpoint_ClearSETUP();
- CDCInterfaceInfo->ControlLineState = USB_ControlRequest.wValue;
+ CDCInterfaceInfo->State.ControlLineState = USB_ControlRequest.wValue;
EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo);
@@ -86,24 +86,24 @@ void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
}
}
-bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
+bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
{
- if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->DataINEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_IN, CDCInterfaceInfo->DataINEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_IN, CDCInterfaceInfo->Config.DataINEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
}
- if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->DataOUTEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_OUT, CDCInterfaceInfo->DataOUTEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_OUT, CDCInterfaceInfo->Config.DataOUTEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
}
- if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->NotificationEndpointNumber, EP_TYPE_INTERRUPT,
- ENDPOINT_DIR_IN, CDCInterfaceInfo->NotificationEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->Config.NotificationEndpointNumber, EP_TYPE_INTERRUPT,
+ ENDPOINT_DIR_IN, CDCInterfaceInfo->Config.NotificationEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
@@ -112,12 +112,12 @@ bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
return true;
}
-void CDC_Device_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
+void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
{
if (!(USB_IsConnected))
return;
- Endpoint_SelectEndpoint(CDCInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
if (!(Endpoint_BytesInEndpoint()))
return;
@@ -131,21 +131,21 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
Endpoint_ClearIN();
}
-void CDC_Device_SendString(USB_ClassInfo_CDC_t* CDCInterfaceInfo, char* Data, uint16_t Length)
+void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, char* Data, uint16_t Length)
{
if (!(USB_IsConnected))
return;
- Endpoint_SelectEndpoint(CDCInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
Endpoint_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK);
}
-void CDC_Device_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data)
+void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, uint8_t Data)
{
if (!(USB_IsConnected))
return;
- Endpoint_SelectEndpoint(CDCInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
if (!(Endpoint_IsReadWriteAllowed()))
{
@@ -156,19 +156,19 @@ void CDC_Device_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data)
Endpoint_Write_Byte(Data);
}
-uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
+uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
{
- Endpoint_SelectEndpoint(CDCInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
return Endpoint_BytesInEndpoint();
}
-uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
+uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
{
if (!(USB_IsConnected))
return 0;
- Endpoint_SelectEndpoint(CDCInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
uint8_t DataByte = Endpoint_Read_Byte();
@@ -178,12 +178,12 @@ uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
return DataByte;
}
-void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask)
+void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, uint16_t LineStateMask)
{
if (!(USB_IsConnected))
return;
- Endpoint_SelectEndpoint(CDCInterfaceInfo->NotificationEndpointNumber);
+ Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.NotificationEndpointNumber);
USB_Request_Header_t Notification = (USB_Request_Header_t)
{
diff --git a/LUFA/Drivers/USB/Class/Device/CDC.h b/LUFA/Drivers/USB/Class/Device/CDC.h
index 2306cdfb1..13fa8d3b7 100644
--- a/LUFA/Drivers/USB/Class/Device/CDC.h
+++ b/LUFA/Drivers/USB/Class/Device/CDC.h
@@ -52,6 +52,60 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Type Defines: */
+ /** Configuration information structure for \ref USB_ClassInfo_CDC_Device_t CDC device interface structures. */
+ typedef struct
+ {
+ uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
+
+ uint8_t DataINEndpointNumber; /**< Endpoint number of the CDC interface's IN data endpoint */
+ uint16_t DataINEndpointSize; /**< Size in bytes of the CDC interface's IN data endpoint */
+
+ uint8_t DataOUTEndpointNumber; /**< Endpoint number of the CDC interface's OUT data endpoint */
+ uint16_t DataOUTEndpointSize; /**< Size in bytes of the CDC interface's OUT data endpoint */
+
+ uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
+ uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
+ } USB_ClassInfo_CDC_Device_Config_t;
+
+ /** Current State information structure for \ref USB_ClassInfo_CDC_Device_t CDC device interface structures. */
+ typedef struct
+ {
+ uint8_t ControlLineState; /**< Current control line states, as set by the host */
+
+ struct
+ {
+ uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */
+ uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the
+ * CDCDevice_CDC_LineCodingFormats_t enum
+ */
+ uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the
+ * CDCDevice_LineCodingParity_t enum
+ */
+ uint8_t DataBits; /**< Bits of data per character of the virtual serial port */
+ } LineEncoding;
+ } USB_ClassInfo_CDC_Device_State_t;
+
+ /** Class state structure. An instance of this structure should be made for each CDC interface
+ * within the user application, and passed to each of the CDC class driver functions as the
+ * CDCInterfaceInfo parameter. This stores each CDC interface's configuration and state information.
+ */
+ typedef struct
+ {
+ const USB_ClassInfo_CDC_Device_Config_t Config; /**< Config data for the USB class interface within
+ * the device. All elements in this section
+ * <b>must</b> be set or the interface will fail
+ * to enumerate and operate correctly.
+ */
+
+ USB_ClassInfo_CDC_Device_State_t State; /**< State data for the USB class interface within
+ * the device. All elements in this section
+ * <b>may</b> be set to initial values, but may
+ * also be ignored to default to sane values when
+ * the interface is enumerated.
+ */
+ } USB_ClassInfo_CDC_Device_t;
+
/* Function Prototypes: */
/** Configures the endpoints of a given CDC interface, ready for use. This should be linked to the library
* \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration containing the
@@ -61,21 +115,21 @@
*
* \return Boolean true if the endpoints were sucessfully configured, false otherwise
*/
- bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
+ bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
/** Processes incomming control requests from the host, that are directed to the given CDC class interface. This should be
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
*
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
- void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
+ void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
/** General management task for a given CDC class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
- void CDC_Device_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
+ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
/** CDC class driver event for a line encoding change on a CDC interface. This event fires each time the host requests a
* line encoding change (containing the serial parity, baud and other configuration information) and may be hooked in the
@@ -84,7 +138,7 @@
*
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
- void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
+ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
/** CDC class driver event for a control line state change on a CDC interface. This event fires each time the host requests a
* control line state change (containing the virtual serial control line states, such as DTR) and may be hooked in the
@@ -94,7 +148,7 @@
*
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
- void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
+ void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
/** Sends a given string to the attached USB host, if connected. If a host is not connected when the function is called, the
* string is discarded.
@@ -103,7 +157,7 @@
* \param Data Pointer to the string to send to the host
* \param Length Size in bytes of the string to send to the host
*/
- void CDC_Device_SendString(USB_ClassInfo_CDC_t* CDCInterfaceInfo, char* Data, uint16_t Length);
+ void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, char* Data, uint16_t Length);
/** Sends a given byte to the attached USB host, if connected. If a host is not connected when the function is called, the
* byte is discarded.
@@ -111,7 +165,7 @@
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param Data Byte of data to send to the host
*/
- void CDC_Device_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data);
+ void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, uint8_t Data);
/** Determines the number of bytes received by the CDC interface from the host, waiting to be read.
*
@@ -119,7 +173,7 @@
*
* \return Total number of buffered bytes received from the host
*/
- uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
+ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
/** Reads a byte of data from the host. If no data is waiting to be read of if a USB host is not connected, the function
* returns 0. The USB_CDC_BytesReceived() function should be queried before data is recieved to ensure that no data
@@ -129,7 +183,7 @@
*
* \return Next received byte from the host, or 0 if no data received
*/
- uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
+ uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
/** Sends a Serial Control Line State Change notification to the host. This should be called when the virtual serial control
* lines (DCD, DSR, etc.) have changed states, or to give BREAK notfications to the host. Line states persist until they are
@@ -138,16 +192,16 @@
* \param CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param LineStateMask Mask of CDC_CONTROL_LINE_IN_* masks giving the current control line states
*/
- void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask);
+ void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, uint16_t LineStateMask);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
#if defined(INCLUDE_FROM_CDC_CLASS_DEVICE_C)
void CDC_Device_Event_Stub(void);
- void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
+ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
ATTR_WEAK ATTR_ALIAS(CDC_Device_Event_Stub);
- void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
+ void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
ATTR_WEAK ATTR_ALIAS(CDC_Device_Event_Stub);
#endif
diff --git a/LUFA/Drivers/USB/Class/Device/HID.c b/LUFA/Drivers/USB/Class/Device/HID.c
index 54bef47e2..c37dc5d5c 100644
--- a/LUFA/Drivers/USB/Class/Device/HID.c
+++ b/LUFA/Drivers/USB/Class/Device/HID.c
@@ -33,12 +33,12 @@
#include "HID.h"
-void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
+void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo)
{
if (!(Endpoint_IsSETUPReceived()))
return;
- if (USB_ControlRequest.wIndex != HIDInterfaceInfo->InterfaceNumber)
+ if (USB_ControlRequest.wIndex != HIDInterfaceInfo->Config.InterfaceNumber)
return;
switch (USB_ControlRequest.bRequest)
@@ -48,7 +48,7 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
Endpoint_ClearSETUP();
- uint8_t ReportINData[HIDInterfaceInfo->ReportINBufferSize];
+ uint8_t ReportINData[HIDInterfaceInfo->Config.ReportINBufferSize];
uint16_t ReportINSize;
uint8_t ReportID = (USB_ControlRequest.wValue & 0xFF);
@@ -82,7 +82,7 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
Endpoint_ClearSETUP();
- Endpoint_Write_Byte(HIDInterfaceInfo->UsingReportProtocol);
+ Endpoint_Write_Byte(HIDInterfaceInfo->State.UsingReportProtocol);
Endpoint_ClearIN();
while (!(Endpoint_IsOUTReceived()));
@@ -95,7 +95,7 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
Endpoint_ClearSETUP();
- HIDInterfaceInfo->UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);
+ HIDInterfaceInfo->State.UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
@@ -107,7 +107,7 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
Endpoint_ClearSETUP();
- HIDInterfaceInfo->IdleCount = ((USB_ControlRequest.wValue >> 8) << 2);
+ HIDInterfaceInfo->State.IdleCount = ((USB_ControlRequest.wValue >> 8) << 2);
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
@@ -119,7 +119,7 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
Endpoint_ClearSETUP();
- Endpoint_Write_Byte(HIDInterfaceInfo->IdleCount >> 2);
+ Endpoint_Write_Byte(HIDInterfaceInfo->State.IdleCount >> 2);
Endpoint_ClearIN();
while (!(Endpoint_IsOUTReceived()));
@@ -130,12 +130,12 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
}
}
-bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_t* HIDInterfaceInfo)
+bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo)
{
- HIDInterfaceInfo->UsingReportProtocol = true;
+ HIDInterfaceInfo->State.UsingReportProtocol = true;
- if (!(Endpoint_ConfigureEndpoint(HIDInterfaceInfo->ReportINEndpointNumber, EP_TYPE_INTERRUPT,
- ENDPOINT_DIR_IN, HIDInterfaceInfo->ReportINEndpointSize, ENDPOINT_BANK_SINGLE)))
+ if (!(Endpoint_ConfigureEndpoint(HIDInterfaceInfo->Config.ReportINEndpointNumber, EP_TYPE_INTERRUPT,
+ ENDPOINT_DIR_IN, HIDInterfaceInfo->Config.ReportINEndpointSize, ENDPOINT_BANK_SINGLE)))
{
return false;
}
@@ -143,20 +143,20 @@ bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_t* HIDInterfaceInfo)
return true;
}
-void HID_Device_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo)
+void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo)
{
if (!(USB_IsConnected))
return;
- Endpoint_SelectEndpoint(HIDInterfaceInfo->ReportINEndpointNumber);
+ Endpoint_SelectEndpoint(HIDInterfaceInfo->Config.ReportINEndpointNumber);
if (Endpoint_IsReadWriteAllowed() &&
- !(HIDInterfaceInfo->IdleCount && HIDInterfaceInfo->IdleMSRemaining))
+ !(HIDInterfaceInfo->State.IdleCount && HIDInterfaceInfo->State.IdleMSRemaining))
{
- if (HIDInterfaceInfo->IdleCount && !(HIDInterfaceInfo->IdleMSRemaining))
- HIDInterfaceInfo->IdleMSRemaining = HIDInterfaceInfo->IdleCount;
+ if (HIDInterfaceInfo->State.IdleCount && !(HIDInterfaceInfo->State.IdleMSRemaining))
+ HIDInterfaceInfo->State.IdleMSRemaining = HIDInterfaceInfo->State.IdleCount;
- uint8_t ReportINData[HIDInterfaceInfo->ReportINBufferSize];
+ uint8_t ReportINData[HIDInterfaceInfo->Config.ReportINBufferSize];
uint16_t ReportINSize;
uint8_t ReportID = 0;
diff --git a/LUFA/Drivers/USB/Class/Device/HID.h b/LUFA/Drivers/USB/Class/Device/HID.h
index 6ed6b3892..b4c400f05 100644
--- a/LUFA/Drivers/USB/Class/Device/HID.h
+++ b/LUFA/Drivers/USB/Class/Device/HID.h
@@ -52,6 +52,48 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Type Defines: */
+ /** Configuration information structure for \ref USB_ClassInfo_HID_Device_t HID device interface structures. */
+ typedef struct
+ {
+ uint8_t InterfaceNumber; /**< Interface number of the HID interface within the device */
+
+ uint8_t ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */
+ uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */
+
+ uint8_t ReportINBufferSize; /**< Size of the largest possible report to send to the host, for
+ * buffer allocation purposes
+ */
+ } USB_ClassInfo_HID_Device_Config_t;
+
+ /** Current State information structure for \ref USB_ClassInfo_HID_Device_t HID device interface structures. */
+ typedef struct
+ {
+ bool UsingReportProtocol; /**< Indicates if the HID interface is set to Boot or Report protocol mode */
+ uint16_t IdleCount; /**< Report idle period, in ms, set by the host */
+ uint16_t IdleMSRemaining; /**< Total number of ms remaining before the idle period elapses */
+ } USB_ClassInfo_HID_Device_State_t;
+
+ /** Class state structure. An instance of this structure should be made for each HID interface
+ * within the user application, and passed to each of the HID class driver functions as the
+ * HIDInterfaceInfo parameter. This stores each HID interface's configuration and state information.
+ */
+ typedef struct
+ {
+ const USB_ClassInfo_HID_Device_Config_t Config; /**< Config data for the USB class interface within
+ * the device. All elements in this section
+ * <b>must</b> be set or the interface will fail
+ * to enumerate and operate correctly.
+ */
+
+ USB_ClassInfo_HID_Device_State_t State; /**< State data for the USB class interface within
+ * the device. All elements in this section
+ * <b>may</b> be set to initial values, but may
+ * also be ignored to default to sane values when
+ * the interface is enumerated.
+ */
+ } USB_ClassInfo_HID_Device_t;
+
/* Function Prototypes: */
/** Configures the endpoints of a given HID interface, ready for use. This should be linked to the library
* \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration
@@ -61,21 +103,21 @@
*
* \return Boolean true if the endpoints were sucessfully configured, false otherwise
*/
- bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_t* HIDInterfaceInfo);
+ bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
/** Processes incomming control requests from the host, that are directed to the given HID class interface. This should be
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
*
* \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
*/
- void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo);
+ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
/** General management task for a given HID class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
*/
- void HID_Device_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo);
+ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
/** HID class driver callback for the user creation of a HID input report. This callback may fire in response to either
* HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback the
@@ -89,7 +131,7 @@
*
* \return Number of bytes in the generated input report, or zero if no report is to be sent
*/
- uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
+ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
/** HID class driver callback for the user processing of a received HID input report. This callback may fire in response to
* either HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback
@@ -101,7 +143,7 @@
* \param ReportData Pointer to a buffer where the received HID report is stored.
* \param ReportSize Size in bytes of the received report from the host.
*/
- void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID, void* ReportData,
+ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID, void* ReportData,
uint16_t ReportSize);
/* Disable C linkage for C++ Compilers: */
diff --git a/LUFA/Drivers/USB/Class/Device/MIDI.c b/LUFA/Drivers/USB/Class/Device/MIDI.c
index a2ab0beb4..1d342f5ce 100644
--- a/LUFA/Drivers/USB/Class/Device/MIDI.c
+++ b/LUFA/Drivers/USB/Class/Device/MIDI.c
@@ -33,27 +33,27 @@
#include "MIDI.h"
-void MIDI_Device_ProcessControlPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo)
+void MIDI_Device_ProcessControlPacket(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo)
{
}
-bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo)
+bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo)
{
- if (MIDIInterfaceInfo->DataINEndpointNumber)
+ if (MIDIInterfaceInfo->Config.DataINEndpointNumber)
{
- if (!(Endpoint_ConfigureEndpoint(MIDIInterfaceInfo->DataINEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_IN, MIDIInterfaceInfo->DataINEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(MIDIInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_IN, MIDIInterfaceInfo->Config.DataINEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
}
}
- if (MIDIInterfaceInfo->DataOUTEndpointNumber)
+ if (MIDIInterfaceInfo->Config.DataOUTEndpointNumber)
{
- if (!(Endpoint_ConfigureEndpoint(MIDIInterfaceInfo->DataOUTEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_OUT, MIDIInterfaceInfo->DataOUTEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(MIDIInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_OUT, MIDIInterfaceInfo->Config.DataOUTEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
@@ -63,17 +63,17 @@ bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo)
return true;
}
-void MIDI_Device_USBTask(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo)
+void MIDI_Device_USBTask(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo)
{
}
-void MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event)
+void MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event)
{
if (!(USB_IsConnected))
return;
- Endpoint_SelectEndpoint(MIDIInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataINEndpointNumber);
if (Endpoint_IsReadWriteAllowed());
{
@@ -82,12 +82,12 @@ void MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, USB_MI
}
}
-bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event)
+bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event)
{
if (!(USB_IsConnected))
return false;
- Endpoint_SelectEndpoint(MIDIInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataOUTEndpointNumber);
if (!(Endpoint_IsReadWriteAllowed()))
return false;
diff --git a/LUFA/Drivers/USB/Class/Device/MIDI.h b/LUFA/Drivers/USB/Class/Device/MIDI.h
index 87aabe1c5..e2e06b635 100644
--- a/LUFA/Drivers/USB/Class/Device/MIDI.h
+++ b/LUFA/Drivers/USB/Class/Device/MIDI.h
@@ -53,6 +53,45 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Type Define: */
+ /** Configuration information structure for \ref USB_ClassInfo_MIDI_Device_t MIDI device interface structures. */
+ typedef struct
+ {
+ uint8_t StreamingInterfaceNumber; /**< Index of the Audio Streaming interface within the device this structure controls */
+
+ uint8_t DataINEndpointNumber; /**< Endpoint number of the incomming MIDI data, if available (zero if unused) */
+ uint16_t DataINEndpointSize; /**< Size in bytes of the incomming MIDI data endpoint, if available (zero if unused) */
+
+ uint8_t DataOUTEndpointNumber; /**< Endpoint number of the outgoing MIDI data, if available (zero if unused) */
+ uint16_t DataOUTEndpointSize; /**< Size in bytes of the outgoing MIDI data endpoint, if available (zero if unused) */
+ } USB_ClassInfo_MIDI_Device_Config_t;
+
+ /** Current State information structure for \ref USB_ClassInfo_MIDI_Device_t MIDI device interface structures. */
+ typedef struct
+ {
+
+ } USB_ClassInfo_MIDI_Device_State_t;
+
+ /** Class state structure. An instance of this structure should be made for each MIDI interface
+ * within the user application, and passed to each of the MIDI class driver functions as the
+ * MIDIInterfaceInfo parameter. This stores each MIDI interface's configuration and state information.
+ */
+ typedef struct
+ {
+ const USB_ClassInfo_MIDI_Device_Config_t Config; /**< Config data for the USB class interface within
+ * the device. All elements in this section
+ * <b>must</b> be set or the interface will fail
+ * to enumerate and operate correctly.
+ */
+
+ USB_ClassInfo_MIDI_Device_State_t State; /**< State data for the USB class interface within
+ * the device. All elements in this section
+ * <b>may</b> be set to initial values, but may
+ * also be ignored to default to sane values when
+ * the interface is enumerated.
+ */
+ } USB_ClassInfo_MIDI_Device_t;
+
/* Function Prototypes: */
/** Configures the endpoints of a given MIDI interface, ready for use. This should be linked to the library
* \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration
@@ -62,28 +101,28 @@
*
* \return Boolean true if the endpoints were sucessfully configured, false otherwise
*/
- bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo);
+ bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo);
/** Processes incomming control requests from the host, that are directed to the given MIDI class interface. This should be
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
*
* \param MIDIInterfaceInfo Pointer to a structure containing a MIDI Class configuration and state.
*/
- void MIDI_Device_ProcessControlPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo);
+ void MIDI_Device_ProcessControlPacket(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo);
/** General management task for a given MIDI class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param MIDIInterfaceInfo Pointer to a structure containing a MIDI Class configuration and state.
*/
- void MIDI_Device_USBTask(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo);
+ void MIDI_Device_USBTask(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo);
/** Sends a MIDI event packet to the host. If no host is connected, the event packet is discarded.
*
* \param MIDIInterfaceInfo Pointer to a structure containing a MIDI Class configuration and state.
* \param Event Pointer to a populated USB_MIDI_EventPacket_t structure containing the MIDI event to send
*/
- void MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event);
+ void MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event);
/** Receives a MIDI event packet from the host.
*
@@ -92,7 +131,7 @@
*
* \return Boolean true if a MIDI event packet was received, false otherwise
*/
- bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event);
+ bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event);
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
diff --git a/LUFA/Drivers/USB/Class/Device/MassStorage.c b/LUFA/Drivers/USB/Class/Device/MassStorage.c
index 1dc6d600c..a70ed68ce 100644
--- a/LUFA/Drivers/USB/Class/Device/MassStorage.c
+++ b/LUFA/Drivers/USB/Class/Device/MassStorage.c
@@ -34,14 +34,14 @@
#define INCLUDE_FROM_MS_CLASS_DEVICE_C
#include "MassStorage.h"
-static USB_ClassInfo_MS_t* CallbackMSInterfaceInfo;
+static USB_ClassInfo_MS_Device_t* CallbackMSInterfaceInfo;
-void MS_Device_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo)
+void MS_Device_ProcessControlPacket(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
if (!(Endpoint_IsSETUPReceived()))
return;
- if (USB_ControlRequest.wIndex != MSInterfaceInfo->InterfaceNumber)
+ if (USB_ControlRequest.wIndex != MSInterfaceInfo->Config.InterfaceNumber)
return;
switch (USB_ControlRequest.bRequest)
@@ -51,7 +51,7 @@ void MS_Device_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo)
{
Endpoint_ClearSETUP();
- MSInterfaceInfo->IsMassStoreReset = true;
+ MSInterfaceInfo->State.IsMassStoreReset = true;
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
@@ -63,7 +63,7 @@ void MS_Device_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo)
{
Endpoint_ClearSETUP();
- Endpoint_Write_Byte(MSInterfaceInfo->TotalLUNs - 1);
+ Endpoint_Write_Byte(MSInterfaceInfo->Config.TotalLUNs - 1);
Endpoint_ClearIN();
@@ -75,17 +75,17 @@ void MS_Device_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo)
}
}
-bool MS_Device_ConfigureEndpoints(USB_ClassInfo_MS_t* MSInterfaceInfo)
+bool MS_Device_ConfigureEndpoints(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
- if (!(Endpoint_ConfigureEndpoint(MSInterfaceInfo->DataINEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_IN, MSInterfaceInfo->DataINEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_IN, MSInterfaceInfo->Config.DataINEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
}
- if (!(Endpoint_ConfigureEndpoint(MSInterfaceInfo->DataOUTEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_OUT, MSInterfaceInfo->DataOUTEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_OUT, MSInterfaceInfo->Config.DataOUTEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
@@ -94,109 +94,112 @@ bool MS_Device_ConfigureEndpoints(USB_ClassInfo_MS_t* MSInterfaceInfo)
return true;
}
-void MS_Device_USBTask(USB_ClassInfo_MS_t* MSInterfaceInfo)
+void MS_Device_USBTask(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
if (!(USB_IsConnected))
return;
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
if (Endpoint_IsReadWriteAllowed())
{
if (MS_Device_ReadInCommandBlock(MSInterfaceInfo))
{
- if (MSInterfaceInfo->CommandBlock.Flags & MS_COMMAND_DIR_DATA_IN)
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataINEndpointNumber);
+ if (MSInterfaceInfo->State.CommandBlock.Flags & MS_COMMAND_DIR_DATA_IN)
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
- MSInterfaceInfo->CommandStatus.Status = CALLBACK_MS_Device_SCSICommandReceived(MSInterfaceInfo) ?
- SCSI_Command_Pass : SCSI_Command_Fail;
- MSInterfaceInfo->CommandStatus.Signature = MS_CSW_SIGNATURE;
- MSInterfaceInfo->CommandStatus.Tag = MSInterfaceInfo->CommandBlock.Tag;
- MSInterfaceInfo->CommandStatus.DataTransferResidue = MSInterfaceInfo->CommandBlock.DataTransferLength;
-
- if ((MSInterfaceInfo->CommandStatus.Status == SCSI_Command_Fail) && (MSInterfaceInfo->CommandStatus.DataTransferResidue))
- Endpoint_StallTransaction();
+ MSInterfaceInfo->State.CommandStatus.Status = CALLBACK_MS_Device_SCSICommandReceived(MSInterfaceInfo) ?
+ SCSI_Command_Pass : SCSI_Command_Fail;
+ MSInterfaceInfo->State.CommandStatus.Signature = MS_CSW_SIGNATURE;
+ MSInterfaceInfo->State.CommandStatus.Tag = MSInterfaceInfo->State.CommandBlock.Tag;
+ MSInterfaceInfo->State.CommandStatus.DataTransferResidue = MSInterfaceInfo->State.CommandBlock.DataTransferLength;
+
+ if ((MSInterfaceInfo->State.CommandStatus.Status == SCSI_Command_Fail) &&
+ (MSInterfaceInfo->State.CommandStatus.DataTransferResidue))
+ {
+ Endpoint_StallTransaction();
+ }
MS_Device_ReturnCommandStatus(MSInterfaceInfo);
- if (MSInterfaceInfo->IsMassStoreReset)
+ if (MSInterfaceInfo->State.IsMassStoreReset)
{
- Endpoint_ResetFIFO(MSInterfaceInfo->DataOUTEndpointNumber);
- Endpoint_ResetFIFO(MSInterfaceInfo->DataINEndpointNumber);
+ Endpoint_ResetFIFO(MSInterfaceInfo->Config.DataOUTEndpointNumber);
+ Endpoint_ResetFIFO(MSInterfaceInfo->Config.DataINEndpointNumber);
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
Endpoint_ClearStall();
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
Endpoint_ClearStall();
- MSInterfaceInfo->IsMassStoreReset = false;
+ MSInterfaceInfo->State.IsMassStoreReset = false;
}
}
}
}
-static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_t* MSInterfaceInfo)
+static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
CallbackMSInterfaceInfo = MSInterfaceInfo;
- Endpoint_Read_Stream_LE(&MSInterfaceInfo->CommandBlock,
+ Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock,
(sizeof(CommandBlockWrapper_t) - 16),
StreamCallback_MS_Device_AbortOnMassStoreReset);
- if ((MSInterfaceInfo->CommandBlock.Signature != MS_CBW_SIGNATURE) ||
- (MSInterfaceInfo->CommandBlock.LUN >= MSInterfaceInfo->TotalLUNs) ||
- (MSInterfaceInfo->CommandBlock.SCSICommandLength > 16))
+ if ((MSInterfaceInfo->State.CommandBlock.Signature != MS_CBW_SIGNATURE) ||
+ (MSInterfaceInfo->State.CommandBlock.LUN >= MSInterfaceInfo->Config.TotalLUNs) ||
+ (MSInterfaceInfo->State.CommandBlock.SCSICommandLength > 16))
{
Endpoint_StallTransaction();
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
Endpoint_StallTransaction();
return false;
}
CallbackMSInterfaceInfo = MSInterfaceInfo;
- Endpoint_Read_Stream_LE(&MSInterfaceInfo->CommandBlock.SCSICommandData,
- MSInterfaceInfo->CommandBlock.SCSICommandLength,
+ Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock.SCSICommandData,
+ MSInterfaceInfo->State.CommandBlock.SCSICommandLength,
StreamCallback_MS_Device_AbortOnMassStoreReset);
Endpoint_ClearOUT();
- if (MSInterfaceInfo->IsMassStoreReset)
+ if (MSInterfaceInfo->State.IsMassStoreReset)
return false;
return true;
}
-static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_t* MSInterfaceInfo)
+static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
while (Endpoint_IsStalled())
{
USB_USBTask();
- if (MSInterfaceInfo->IsMassStoreReset)
+ if (MSInterfaceInfo->State.IsMassStoreReset)
return;
}
- Endpoint_SelectEndpoint(MSInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
while (Endpoint_IsStalled())
{
USB_USBTask();
- if (MSInterfaceInfo->IsMassStoreReset)
+ if (MSInterfaceInfo->State.IsMassStoreReset)
return;
}
CallbackMSInterfaceInfo = MSInterfaceInfo;
- Endpoint_Write_Stream_LE(&MSInterfaceInfo->CommandStatus, sizeof(CommandStatusWrapper_t),
+ Endpoint_Write_Stream_LE(&MSInterfaceInfo->State.CommandStatus, sizeof(CommandStatusWrapper_t),
StreamCallback_MS_Device_AbortOnMassStoreReset);
Endpoint_ClearIN();
- if (MSInterfaceInfo->IsMassStoreReset)
+ if (MSInterfaceInfo->State.IsMassStoreReset)
return;
}
@@ -204,7 +207,7 @@ static uint8_t StreamCallback_MS_Device_AbortOnMassStoreReset(void)
{
MS_Device_USBTask(CallbackMSInterfaceInfo);
- if (CallbackMSInterfaceInfo->IsMassStoreReset)
+ if (CallbackMSInterfaceInfo->State.IsMassStoreReset)
return STREAMCALLBACK_Abort;
else
return STREAMCALLBACK_Continue;
diff --git a/LUFA/Drivers/USB/Class/Device/MassStorage.h b/LUFA/Drivers/USB/Class/Device/MassStorage.h
index feaebcca4..2616bd871 100644
--- a/LUFA/Drivers/USB/Class/Device/MassStorage.h
+++ b/LUFA/Drivers/USB/Class/Device/MassStorage.h
@@ -52,6 +52,56 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Type Defines: */
+ /** Configuration information structure for \ref USB_ClassInfo_MS_Device_t Mass Storage device interface structures. */
+ typedef struct
+ {
+ uint8_t InterfaceNumber; /**< Interface number of the Mass Storage interface within the device */
+
+ uint8_t DataINEndpointNumber; /**< Endpoint number of the Mass Storage interface's IN data endpoint */
+ uint16_t DataINEndpointSize; /**< Size in bytes of the Mass Storage interface's IN data endpoint */
+
+ uint8_t DataOUTEndpointNumber; /**< Endpoint number of the Mass Storage interface's OUT data endpoint */
+ uint16_t DataOUTEndpointSize; /**< Size in bytes of the Mass Storage interface's OUT data endpoint */
+
+ uint8_t TotalLUNs; /**< Total number of logical drives in the Mass Storage interface */
+ } USB_ClassInfo_MS_Device_Config_t;
+
+ /** Current State information structure for \ref USB_ClassInfo_MS_Device_t Mass Storage device interface structures. */
+ typedef struct
+ {
+ CommandBlockWrapper_t CommandBlock; /**< Mass Storage class command block structure, used internally
+ * by the class driver
+ */
+ CommandStatusWrapper_t CommandStatus; /**< Mass Storage class command status structure, used internally
+ * by the class driver
+ */
+
+ bool IsMassStoreReset; /**< Flag indicating that the host has requested that the Mass Storage interface be reset
+ * and that all current Mass Storage operations should immediately abort
+ */
+ } USB_ClassInfo_MS_Device_State_t;
+
+ /** Class state structure. An instance of this structure should be made for each Mass Storage interface
+ * within the user application, and passed to each of the Mass Storage class driver functions as the
+ * MSInterfaceInfo parameter. This stores each Mass Storage interface's configuration and state information.
+ */
+ typedef struct
+ {
+ const USB_ClassInfo_MS_Device_Config_t Config; /**< Config data for the USB class interface within
+ * the device. All elements in this section
+ * <b>must</b> be set or the interface will fail
+ * to enumerate and operate correctly.
+ */
+
+ USB_ClassInfo_MS_Device_State_t State; /**< State data for the USB class interface within
+ * the device. All elements in this section
+ * <b>may</b> be set to initial values, but may
+ * also be ignored to default to sane values when
+ * the interface is enumerated.
+ */
+ } USB_ClassInfo_MS_Device_t;
+
/* Function Prototypes: */
/** Configures the endpoints of a given Mass Storage interface, ready for use. This should be linked to the library
* \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration
@@ -61,21 +111,21 @@
*
* \return Boolean true if the endpoints were sucessfully configured, false otherwise
*/
- bool MS_Device_ConfigureEndpoints(USB_ClassInfo_MS_t* MSInterfaceInfo);
+ bool MS_Device_ConfigureEndpoints(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
/** Processes incomming control requests from the host, that are directed to the given Mass Storage class interface. This should be
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
*
* \param MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state.
*/
- void MS_Device_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo);
+ void MS_Device_ProcessControlPacket(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
/** General management task for a given Mass Storage class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param MSInterfaceInfo Pointer to a structure containing a Mass Storage configuration and state.
*/
- void MS_Device_USBTask(USB_ClassInfo_MS_t* MSInterfaceInfo);
+ void MS_Device_USBTask(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
/** Mass Storage class driver callback for the user processing of a received SCSI command. This callback will fire each time the
* host sends a SCSI command which requires processing by the user application. Inside this callback the user is responsible
@@ -86,14 +136,14 @@
*
* \return Boolean true if the SCSI command was successfully processed, false otherwise
*/
- bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_t* MSInterfaceInfo);
+ bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
#if defined(INCLUDE_FROM_MS_CLASS_DEVICE_C)
- static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_t* MSInterfaceInfo);
- static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_t* MSInterfaceInfo);
+ static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
+ static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
static uint8_t StreamCallback_MS_Device_AbortOnMassStoreReset(void);
#endif
diff --git a/LUFA/Drivers/USB/Class/Device/RNDIS.c b/LUFA/Drivers/USB/Class/Device/RNDIS.c
index 08efcde4b..7ac84709b 100644
--- a/LUFA/Drivers/USB/Class/Device/RNDIS.c
+++ b/LUFA/Drivers/USB/Class/Device/RNDIS.c
@@ -65,12 +65,12 @@ static const uint32_t PROGMEM AdapterSupportedOIDList[] =
OID_802_3_XMIT_MORE_COLLISIONS,
};
-void RNDIS_Device_ProcessControlPacket(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
+void RNDIS_Device_ProcessControlPacket(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo)
{
if (!(Endpoint_IsSETUPReceived()))
return;
- if (USB_ControlRequest.wIndex != RNDISInterfaceInfo->ControlInterfaceNumber)
+ if (USB_ControlRequest.wIndex != RNDISInterfaceInfo->Config.ControlInterfaceNumber)
return;
switch (USB_ControlRequest.bRequest)
@@ -80,7 +80,7 @@ void RNDIS_Device_ProcessControlPacket(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo
{
Endpoint_ClearSETUP();
- Endpoint_Read_Control_Stream_LE(RNDISInterfaceInfo->RNDISMessageBuffer, USB_ControlRequest.wLength);
+ Endpoint_Read_Control_Stream_LE(RNDISInterfaceInfo->State.RNDISMessageBuffer, USB_ControlRequest.wLength);
Endpoint_ClearIN();
RNDIS_Device_ProcessRNDISControlMessage(RNDISInterfaceInfo);
@@ -92,15 +92,15 @@ void RNDIS_Device_ProcessControlPacket(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo
{
Endpoint_ClearSETUP();
- RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
if (!(MessageHeader->MessageLength))
{
- RNDISInterfaceInfo->RNDISMessageBuffer[0] = 0;
+ RNDISInterfaceInfo->State.RNDISMessageBuffer[0] = 0;
MessageHeader->MessageLength = 1;
}
- Endpoint_Write_Control_Stream_LE(RNDISInterfaceInfo->RNDISMessageBuffer, MessageHeader->MessageLength);
+ Endpoint_Write_Control_Stream_LE(RNDISInterfaceInfo->State.RNDISMessageBuffer, MessageHeader->MessageLength);
Endpoint_ClearOUT();
MessageHeader->MessageLength = 0;
@@ -110,24 +110,24 @@ void RNDIS_Device_ProcessControlPacket(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo
}
}
-bool RNDIS_Device_ConfigureEndpoints(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
+bool RNDIS_Device_ConfigureEndpoints(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo)
{
- if (!(Endpoint_ConfigureEndpoint(RNDISInterfaceInfo->DataINEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_IN, RNDISInterfaceInfo->DataINEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(RNDISInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_IN, RNDISInterfaceInfo->Config.DataINEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
}
- if (!(Endpoint_ConfigureEndpoint(RNDISInterfaceInfo->DataOUTEndpointNumber, EP_TYPE_BULK,
- ENDPOINT_DIR_OUT, RNDISInterfaceInfo->DataOUTEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_BULK,
+ ENDPOINT_DIR_OUT, RNDISInterfaceInfo->Config.DataOUTEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
}
- if (!(Endpoint_ConfigureEndpoint(RNDISInterfaceInfo->NotificationEndpointNumber, EP_TYPE_INTERRUPT,
- ENDPOINT_DIR_IN, RNDISInterfaceInfo->NotificationEndpointSize,
+ if (!(Endpoint_ConfigureEndpoint(RNDISInterfaceInfo->Config.NotificationEndpointNumber, EP_TYPE_INTERRUPT,
+ ENDPOINT_DIR_IN, RNDISInterfaceInfo->Config.NotificationEndpointSize,
ENDPOINT_BANK_SINGLE)))
{
return false;
@@ -136,16 +136,16 @@ bool RNDIS_Device_ConfigureEndpoints(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
return true;
}
-void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
+void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo)
{
if (!(USB_IsConnected))
return;
- RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
- Endpoint_SelectEndpoint(RNDISInterfaceInfo->NotificationEndpointNumber);
+ Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.NotificationEndpointNumber);
- if (Endpoint_IsINReady() && RNDISInterfaceInfo->ResponseReady)
+ if (Endpoint_IsINReady() && RNDISInterfaceInfo->State.ResponseReady)
{
USB_Request_Header_t Notification = (USB_Request_Header_t)
{
@@ -160,16 +160,16 @@ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
Endpoint_ClearIN();
- RNDISInterfaceInfo->ResponseReady = false;
+ RNDISInterfaceInfo->State.ResponseReady = false;
}
- if ((RNDISInterfaceInfo->CurrRNDISState == RNDIS_Data_Initialized) && !(MessageHeader->MessageLength))
+ if ((RNDISInterfaceInfo->State.CurrRNDISState == RNDIS_Data_Initialized) && !(MessageHeader->MessageLength))
{
RNDIS_PACKET_MSG_t RNDISPacketHeader;
- Endpoint_SelectEndpoint(RNDISInterfaceInfo->DataOUTEndpointNumber);
+ Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber);
- if (Endpoint_IsOUTReceived() && !(RNDISInterfaceInfo->FrameIN.FrameInBuffer))
+ if (Endpoint_IsOUTReceived() && !(RNDISInterfaceInfo->State.FrameIN.FrameInBuffer))
{
Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_PACKET_MSG_t), NO_STREAM_CALLBACK);
@@ -179,49 +179,49 @@ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
return;
}
- Endpoint_Read_Stream_LE(RNDISInterfaceInfo->FrameIN.FrameData, RNDISPacketHeader.DataLength, NO_STREAM_CALLBACK);
+ Endpoint_Read_Stream_LE(RNDISInterfaceInfo->State.FrameIN.FrameData, RNDISPacketHeader.DataLength, NO_STREAM_CALLBACK);
Endpoint_ClearOUT();
- RNDISInterfaceInfo->FrameIN.FrameLength = RNDISPacketHeader.DataLength;
+ RNDISInterfaceInfo->State.FrameIN.FrameLength = RNDISPacketHeader.DataLength;
- RNDISInterfaceInfo->FrameIN.FrameInBuffer = true;
+ RNDISInterfaceInfo->State.FrameIN.FrameInBuffer = true;
}
- Endpoint_SelectEndpoint(RNDISInterfaceInfo->DataINEndpointNumber);
+ Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataINEndpointNumber);
- if (Endpoint_IsINReady() && RNDISInterfaceInfo->FrameOUT.FrameInBuffer)
+ if (Endpoint_IsINReady() && RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer)
{
memset(&RNDISPacketHeader, 0, sizeof(RNDIS_PACKET_MSG_t));
RNDISPacketHeader.MessageType = REMOTE_NDIS_PACKET_MSG;
- RNDISPacketHeader.MessageLength = (sizeof(RNDIS_PACKET_MSG_t) + RNDISInterfaceInfo->FrameOUT.FrameLength);
+ RNDISPacketHeader.MessageLength = (sizeof(RNDIS_PACKET_MSG_t) + RNDISInterfaceInfo->State.FrameOUT.FrameLength);
RNDISPacketHeader.DataOffset = (sizeof(RNDIS_PACKET_MSG_t) - sizeof(RNDIS_Message_Header_t));
- RNDISPacketHeader.DataLength = RNDISInterfaceInfo->FrameOUT.FrameLength;
+ RNDISPacketHeader.DataLength = RNDISInterfaceInfo->State.FrameOUT.FrameLength;
Endpoint_Write_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_PACKET_MSG_t), NO_STREAM_CALLBACK);
- Endpoint_Write_Stream_LE(RNDISInterfaceInfo->FrameOUT.FrameData, RNDISPacketHeader.DataLength, NO_STREAM_CALLBACK);
+ Endpoint_Write_Stream_LE(RNDISInterfaceInfo->State.FrameOUT.FrameData, RNDISPacketHeader.DataLength, NO_STREAM_CALLBACK);
Endpoint_ClearIN();
- RNDISInterfaceInfo->FrameOUT.FrameInBuffer = false;
+ RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer = false;
}
}
}
-void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
+void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo)
{
/* Note: Only a single buffer is used for both the received message and its response to save SRAM. Because of
this, response bytes should be filled in order so that they do not clobber unread data in the buffer. */
- RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
switch (MessageHeader->MessageType)
{
case REMOTE_NDIS_INITIALIZE_MSG:
- RNDISInterfaceInfo->ResponseReady = true;
+ RNDISInterfaceInfo->State.ResponseReady = true;
- RNDIS_INITIALIZE_MSG_t* INITIALIZE_Message = (RNDIS_INITIALIZE_MSG_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
- RNDIS_INITIALIZE_CMPLT_t* INITIALIZE_Response = (RNDIS_INITIALIZE_CMPLT_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_INITIALIZE_MSG_t* INITIALIZE_Message = (RNDIS_INITIALIZE_MSG_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
+ RNDIS_INITIALIZE_CMPLT_t* INITIALIZE_Response = (RNDIS_INITIALIZE_CMPLT_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
INITIALIZE_Response->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT;
INITIALIZE_Response->MessageLength = sizeof(RNDIS_INITIALIZE_CMPLT_t);
@@ -238,26 +238,26 @@ void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfa
INITIALIZE_Response->AFListOffset = 0;
INITIALIZE_Response->AFListSize = 0;
- RNDISInterfaceInfo->CurrRNDISState = RNDIS_Initialized;
+ RNDISInterfaceInfo->State.CurrRNDISState = RNDIS_Initialized;
break;
case REMOTE_NDIS_HALT_MSG:
- RNDISInterfaceInfo->ResponseReady = false;
+ RNDISInterfaceInfo->State.ResponseReady = false;
MessageHeader->MessageLength = 0;
- RNDISInterfaceInfo->CurrRNDISState = RNDIS_Uninitialized;
+ RNDISInterfaceInfo->State.CurrRNDISState = RNDIS_Uninitialized;
break;
case REMOTE_NDIS_QUERY_MSG:
- RNDISInterfaceInfo->ResponseReady = true;
+ RNDISInterfaceInfo->State.ResponseReady = true;
- RNDIS_QUERY_MSG_t* QUERY_Message = (RNDIS_QUERY_MSG_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
- RNDIS_QUERY_CMPLT_t* QUERY_Response = (RNDIS_QUERY_CMPLT_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_QUERY_MSG_t* QUERY_Message = (RNDIS_QUERY_MSG_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
+ RNDIS_QUERY_CMPLT_t* QUERY_Response = (RNDIS_QUERY_CMPLT_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
uint32_t Query_Oid = QUERY_Message->Oid;
- void* QueryData = &RNDISInterfaceInfo->RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) +
+ void* QueryData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) +
QUERY_Message->InformationBufferOffset];
- void* ResponseData = &RNDISInterfaceInfo->RNDISMessageBuffer[sizeof(RNDIS_QUERY_CMPLT_t)];
+ void* ResponseData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_QUERY_CMPLT_t)];
uint16_t ResponseSize;
QUERY_Response->MessageType = REMOTE_NDIS_QUERY_CMPLT;
@@ -282,17 +282,17 @@ void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfa
break;
case REMOTE_NDIS_SET_MSG:
- RNDISInterfaceInfo->ResponseReady = true;
+ RNDISInterfaceInfo->State.ResponseReady = true;
- RNDIS_SET_MSG_t* SET_Message = (RNDIS_SET_MSG_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
- RNDIS_SET_CMPLT_t* SET_Response = (RNDIS_SET_CMPLT_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_SET_MSG_t* SET_Message = (RNDIS_SET_MSG_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
+ RNDIS_SET_CMPLT_t* SET_Response = (RNDIS_SET_CMPLT_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
uint32_t SET_Oid = SET_Message->Oid;
SET_Response->MessageType = REMOTE_NDIS_SET_CMPLT;
SET_Response->MessageLength = sizeof(RNDIS_SET_CMPLT_t);
SET_Response->RequestId = SET_Message->RequestId;
- void* SetData = &RNDISInterfaceInfo->RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) +
+ void* SetData = &RNDISInterfaceInfo->State.RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) +
SET_Message->InformationBufferOffset];
if (RNDIS_Device_ProcessNDISSet(RNDISInterfaceInfo, SET_Oid, SetData, SET_Message->InformationBufferLength))
@@ -302,9 +302,9 @@ void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfa
break;
case REMOTE_NDIS_RESET_MSG:
- RNDISInterfaceInfo->ResponseReady = true;
+ RNDISInterfaceInfo->State.ResponseReady = true;
- RNDIS_RESET_CMPLT_t* RESET_Response = (RNDIS_RESET_CMPLT_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_RESET_CMPLT_t* RESET_Response = (RNDIS_RESET_CMPLT_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
RESET_Response->MessageType = REMOTE_NDIS_RESET_CMPLT;
RESET_Response->MessageLength = sizeof(RNDIS_RESET_CMPLT_t);
@@ -313,10 +313,10 @@ void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfa
break;
case REMOTE_NDIS_KEEPALIVE_MSG:
- RNDISInterfaceInfo->ResponseReady = true;
+ RNDISInterfaceInfo->State.ResponseReady = true;
- RNDIS_KEEPALIVE_MSG_t* KEEPALIVE_Message = (RNDIS_KEEPALIVE_MSG_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
- RNDIS_KEEPALIVE_CMPLT_t* KEEPALIVE_Response = (RNDIS_KEEPALIVE_CMPLT_t*)&RNDISInterfaceInfo->RNDISMessageBuffer;
+ RNDIS_KEEPALIVE_MSG_t* KEEPALIVE_Message = (RNDIS_KEEPALIVE_MSG_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
+ RNDIS_KEEPALIVE_CMPLT_t* KEEPALIVE_Response = (RNDIS_KEEPALIVE_CMPLT_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
KEEPALIVE_Response->MessageType = REMOTE_NDIS_KEEPALIVE_CMPLT;
KEEPALIVE_Response->MessageLength = sizeof(RNDIS_KEEPALIVE_CMPLT_t);
@@ -327,7 +327,7 @@ void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfa
}
}
-static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo,
+static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo,
uint32_t OId, void* QueryData, uint16_t QuerySize,
void* ResponseData, uint16_t* ResponseSize)
{
@@ -375,9 +375,9 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_t* RNDISInterfaceI
return true;
case OID_GEN_VENDOR_DESCRIPTION:
- *ResponseSize = (strlen(RNDISInterfaceInfo->AdapterVendorDescription) + 1);
+ *ResponseSize = (strlen(RNDISInterfaceInfo->Config.AdapterVendorDescription) + 1);
- memcpy(ResponseData, RNDISInterfaceInfo->AdapterVendorDescription, *ResponseSize);
+ memcpy(ResponseData, RNDISInterfaceInfo->Config.AdapterVendorDescription, *ResponseSize);
return true;
case OID_GEN_MEDIA_CONNECT_STATUS:
@@ -397,7 +397,7 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_t* RNDISInterfaceI
case OID_802_3_CURRENT_ADDRESS:
*ResponseSize = sizeof(MAC_Address_t);
- memcpy(ResponseData, &RNDISInterfaceInfo->AdapterMACAddress, sizeof(MAC_Address_t));
+ memcpy(ResponseData, &RNDISInterfaceInfo->Config.AdapterMACAddress, sizeof(MAC_Address_t));
return true;
case OID_802_3_MAXIMUM_LIST_SIZE:
@@ -410,7 +410,7 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_t* RNDISInterfaceI
case OID_GEN_CURRENT_PACKET_FILTER:
*ResponseSize = sizeof(uint32_t);
- *((uint32_t*)ResponseData) = RNDISInterfaceInfo->CurrPacketFilter;
+ *((uint32_t*)ResponseData) = RNDISInterfaceInfo->State.CurrPacketFilter;
return true;
case OID_GEN_XMIT_OK:
@@ -439,13 +439,14 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_t* RNDISInterfaceI
}
}
-static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo, uint32_t OId, void* SetData, uint16_t SetSize)
+static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo, uint32_t OId, void* SetData,
+ uint16_t SetSize)
{
switch (OId)
{
case OID_GEN_CURRENT_PACKET_FILTER:
- RNDISInterfaceInfo->CurrPacketFilter = *((uint32_t*)SetData);
- RNDISInterfaceInfo->CurrRNDISState = ((RNDISInterfaceInfo->CurrPacketFilter) ?
+ RNDISInterfaceInfo->State.CurrPacketFilter = *((uint32_t*)SetData);
+ RNDISInterfaceInfo->State.CurrRNDISState = ((RNDISInterfaceInfo->State.CurrPacketFilter) ?
RNDIS_Data_Initialized : RNDIS_Data_Initialized);
return true;
diff --git a/LUFA/Drivers/USB/Class/Device/RNDIS.h b/LUFA/Drivers/USB/Class/Device/RNDIS.h
index 93e4ebb41..49700a1b2 100644
--- a/LUFA/Drivers/USB/Class/Device/RNDIS.h
+++ b/LUFA/Drivers/USB/Class/Device/RNDIS.h
@@ -53,6 +53,62 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Type Defines: */
+ /** Configuration information structure for \ref USB_ClassInfo_RNDIS_Device_t RNDIS device interface structures. */
+ typedef struct
+ {
+ uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
+
+ uint8_t DataINEndpointNumber; /**< Endpoint number of the CDC interface's IN data endpoint */
+ uint16_t DataINEndpointSize; /**< Size in bytes of the CDC interface's IN data endpoint */
+
+ uint8_t DataOUTEndpointNumber; /**< Endpoint number of the CDC interface's OUT data endpoint */
+ uint16_t DataOUTEndpointSize; /**< Size in bytes of the CDC interface's OUT data endpoint */
+
+ uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
+ uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
+
+ char* AdapterVendorDescription; /**< String description of the adapter vendor */
+ MAC_Address_t AdapterMACAddress; /**< MAC address of the adapter */
+ } USB_ClassInfo_MS_Device_Config_t;
+
+ /** Current State information structure for \ref USB_ClassInfo_RNDIS_Device_t RNDIS device interface structures. */
+ typedef struct
+ {
+ uint8_t RNDISMessageBuffer[RNDIS_MESSAGE_BUFFER_SIZE]; /**< Buffer to hold RNDIS messages to and from the host,
+ * managed by the class driver
+ */
+ bool ResponseReady; /**< Internal flag indicating if a RNDIS message is waiting to be returned to the host */
+ uint8_t CurrRNDISState; /**< Current RNDIS state of the adapter, a value from the RNDIS_States_t enum */
+ uint32_t CurrPacketFilter; /**< Current packet filter mode, used internally by the class driver */
+ Ethernet_Frame_Info_t FrameIN; /**< Structure holding the last received Ethernet frame from the host, for user
+ * processing
+ */
+ Ethernet_Frame_Info_t FrameOUT; /**< Structure holding the next Ethernet frame to send to the host, populated by the
+ * user application
+ */
+ } USB_ClassInfo_MS_Device_State_t;
+
+ /** Class state structure. An instance of this structure should be made for each RNDIS interface
+ * within the user application, and passed to each of the RNDIS class driver functions as the
+ * RNDISInterfaceInfo parameter. This stores each RNDIS interface's configuration and state information.
+ */
+ typedef struct
+ {
+ const USB_ClassInfo_MS_Device_Config_t Config; /**< Config data for the USB class interface within
+ * the device. All elements in this section
+ * <b>must</b> be set or the interface will fail
+ * to enumerate and operate correctly.
+ */
+
+ USB_ClassInfo_MS_Device_State_t State; /**< State data for the USB class interface within
+ * the device. All elements in this section
+ * <b>may</b> be set to initial values, but may
+ * also be ignored to default to sane values when
+ * the interface is enumerated.
+ */
+ } USB_ClassInfo_RNDIS_Device_t;
+
/* Function Prototypes: */
/** Configures the endpoints of a given RNDIS interface, ready for use. This should be linked to the library
* \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration
@@ -62,31 +118,31 @@
*
* \return Boolean true if the endpoints were sucessfully configured, false otherwise
*/
- bool RNDIS_Device_ConfigureEndpoints(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo);
+ bool RNDIS_Device_ConfigureEndpoints(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo);
/** Processes incomming control requests from the host, that are directed to the given RNDIS class interface. This should be
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
*
* \param RNDISInterfaceInfo Pointer to a structure containing a RNDIS Class configuration and state.
*/
- void RNDIS_Device_ProcessControlPacket(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo);
+ void RNDIS_Device_ProcessControlPacket(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo);
/** General management task for a given HID class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param RNDISInterfaceInfo Pointer to a structure containing a RNDIS Class configuration and state.
*/
- void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo);
+ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
#if defined(INCLUDE_FROM_RNDIS_CLASS_DEVICE_C)
- static void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo);
- static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo,
+ static void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo);
+ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo,
uint32_t OId, void* QueryData, uint16_t QuerySize,
void* ResponseData, uint16_t* ResponseSize);
- static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo, uint32_t OId,
+ static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo, uint32_t OId,
void* SetData, uint16_t SetSize);
#endif
diff --git a/LUFA/Drivers/USB/Class/Host/CDC.c b/LUFA/Drivers/USB/Class/Host/CDC.c
index 32cc9e6eb..6eca8ae67 100644
--- a/LUFA/Drivers/USB/Class/Host/CDC.c
+++ b/LUFA/Drivers/USB/Class/Host/CDC.c
@@ -41,22 +41,22 @@ static uint8_t CDC_Host_ProcessConfigDescriptor(void)
uint8_t FoundEndpoints = 0;
if (USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
- return ControlError;
+ return CDC_ENUMERROR_ControlError;
if (ConfigDescriptorSize > 512)
- return DescriptorTooLarge;
+ return CDC_ENUMERROR_DescriptorTooLarge;
ConfigDescriptorData = alloca(ConfigDescriptorSize);
USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, ConfigDescriptorData);
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
- return InvalidConfigDataReturned;
+ return CDC_ENUMERROR_InvalidConfigDataReturned;
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
DComp_CDC_Host_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
{
- return NoCDCInterfaceFound;
+ return CDC_ENUMERROR_NoCDCInterfaceFound;
}
while (FoundEndpoints != ((1 << CDC_NOTIFICATIONPIPE) | (1 << CDC_DATAPIPE_IN) | (1 << CDC_DATAPIPE_OUT)))
@@ -72,7 +72,7 @@ static uint8_t CDC_Host_ProcessConfigDescriptor(void)
DComp_CDC_Host_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
{
/* Descriptor not found, error out */
- return NoCDCInterfaceFound;
+ return CDC_ENUMERROR_NoCDCInterfaceFound;
}
}
else
@@ -89,14 +89,14 @@ static uint8_t CDC_Host_ProcessConfigDescriptor(void)
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
DComp_CDC_Host_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
{
- return NoCDCInterfaceFound;
+ return CDC_ENUMERROR_NoCDCInterfaceFound;
}
}
if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
DComp_CDC_Host_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{
- return NoEndpointFound;
+ return CDC_ENUMERROR_NoEndpointFound;
}
}
@@ -139,7 +139,7 @@ static uint8_t CDC_Host_ProcessConfigDescriptor(void)
}
}
- return SuccessfulConfigRead;
+ return CDC_ENUMERROR_NoError;
}
static uint8_t DComp_CDC_Host_NextCDCControlInterface(void* CurrentDescriptor)
@@ -192,25 +192,19 @@ static uint8_t DComp_CDC_Host_NextInterfaceCDCDataEndpoint(void* CurrentDescript
return DESCRIPTOR_SEARCH_NotFound;
}
-void CDC_Host_Task(void)
+void CDC_Host_USBTask(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo)
{
uint8_t ErrorCode;
switch (USB_HostState)
{
case HOST_STATE_Addressed:
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_SetConfiguration,
- .wValue = 1,
- .wIndex = 0,
- .wLength = 0,
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
+ if ((ErrorCode = CDC_Host_ProcessConfigDescriptor()) != SuccessfulConfigRead)
+ {
+ USB_HostState = HOST_STATE_Unattached;
+ }
- if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
+ if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
USB_HostState = HOST_STATE_Unattached;
}
@@ -218,10 +212,6 @@ void CDC_Host_Task(void)
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
- if ((ErrorCode = CDC_Host_ProcessConfigDescriptor()) != SuccessfulConfigRead)
- {
- USB_HostState = HOST_STATE_Unattached;
- }
USB_HostState = HOST_STATE_Ready;
break;
diff --git a/LUFA/Drivers/USB/Class/Host/CDC.h b/LUFA/Drivers/USB/Class/Host/CDC.h
index 3bc814daf..e39333ee8 100644
--- a/LUFA/Drivers/USB/Class/Host/CDC.h
+++ b/LUFA/Drivers/USB/Class/Host/CDC.h
@@ -53,8 +53,6 @@
/* Type Defines: */
typedef struct
{
- bool IsActive; /**< Indicates if this class driver is currently attached to the device */
-
uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
uint8_t DataINPipeNumber; /**< Pipe number of the CDC interface's IN data pipe */
@@ -63,8 +61,8 @@
uint8_t DataOUTPipeNumber; /**< Pipe number of the CDC interface's OUT data pipe */
uint16_t DataOUTPipeSize; /**< Size in bytes of the CDC interface's OUT data pipe */
- uint8_t NotificationEndpointNumber; /**< Pipe number of the CDC interface's IN notification endpoint, if used */
- uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
+ uint8_t NotificationPipeNumber; /**< Pipe number of the CDC interface's IN notification endpoint, if used */
+ uint16_t NotificationPipeSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
uint8_t ControlLineState; /**< Current control line states */
@@ -80,9 +78,20 @@
uint8_t DataBits; /**< Bits of data per character of the virtual serial port */
} LineEncoding;
} USB_ClassInfo_CDC_Host_t;
+
+ /* Enums: */
+ typedef enum
+ {
+ CDC_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully */
+ CDC_ENUMERROR_ControlError = 1, /**< A control request to the device failed to complete successfully */
+ CDC_ENUMERROR_DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */
+ CDC_ENUMERROR_InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */
+ CDC_ENUMERROR_NoCDCInterfaceFound = 4, /**< A compatible CDC interface was not found in the device's Configuration Descriptor */
+ CDC_ENUMERROR_NoEndpointFound = 5, /**< Compatible CDC endpoints were not found in the device's CDC interface */
+ } CDCHost_EnumerationFailure_ErrorCodes_t;
/* Function Prototypes: */
- void CDC_Host_Task(void);
+ void CDC_Host_USBTask(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
diff --git a/LUFA/ManPages/FutureChanges.txt b/LUFA/ManPages/FutureChanges.txt
index 2a714f720..35411f2ab 100644
--- a/LUFA/ManPages/FutureChanges.txt
+++ b/LUFA/ManPages/FutureChanges.txt
@@ -22,6 +22,5 @@
* - Remake AVRStudio project files
* - Master LUFA include file
* - Debug mode for pipe/endpoint calls
- * - Device descriptor get routines
- * - Add ClearPipeStall host function
+ * - Add hub support to match Atmel's stack (thanks to the Atmel engineer who said it wasn't possible :P)
*/