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.

This commit is contained in:
Dean Camera 2009-06-18 10:31:55 +00:00
parent e338cb6f32
commit f896c00c48
58 changed files with 912 additions and 3594 deletions

View file

@ -40,12 +40,20 @@
* passed to all Audio Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_Audio_t Microphone_Audio_Interface =
USB_ClassInfo_Audio_Device_t Microphone_Audio_Interface =
{
.StreamingInterfaceNumber = 1,
.Config =
{
.StreamingInterfaceNumber = 1,
.DataINEndpointNumber = AUDIO_STREAM_EPNUM,
.DataINEndpointSize = AUDIO_STREAM_EPSIZE,
.DataINEndpointNumber = AUDIO_STREAM_EPNUM,
.DataINEndpointSize = AUDIO_STREAM_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -59,7 +67,7 @@ int main(void)
for (;;)
{
if (Microphone_Audio_Interface.InterfaceEnabled)
if (Microphone_Audio_Interface.State.InterfaceEnabled)
ProcessNextSample();
Audio_Device_USBTask(&Microphone_Audio_Interface);

View file

@ -40,12 +40,20 @@
* passed to all Audio Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_Audio_t Speaker_Audio_Interface =
USB_ClassInfo_Audio_Device_t Speaker_Audio_Interface =
{
.StreamingInterfaceNumber = 1,
.Config =
{
.StreamingInterfaceNumber = 1,
.DataOUTEndpointNumber = AUDIO_STREAM_EPNUM,
.DataOUTEndpointSize = AUDIO_STREAM_EPSIZE,
.DataINEndpointNumber = AUDIO_STREAM_EPNUM,
.DataINEndpointSize = AUDIO_STREAM_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -59,7 +67,7 @@ int main(void)
for (;;)
{
if (Speaker_Audio_Interface.InterfaceEnabled)
if (Speaker_Audio_Interface.State.InterfaceEnabled)
ProcessNextSample();
Audio_Device_USBTask(&Speaker_Audio_Interface);

View file

@ -40,18 +40,26 @@
* passed to all CDC Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_CDC_t VirtualSerial_CDC_Interface =
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
{
.ControlInterfaceNumber = 0,
.Config =
{
.ControlInterfaceNumber = 0,
.DataINEndpointNumber = CDC_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataINEndpointNumber = CDC_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial

View file

@ -41,18 +41,26 @@
* within a device can be differentiated from one another. This is for the first CDC interface,
* which sends strings to the host for each joystick movement.
*/
USB_ClassInfo_CDC_t VirtualSerial1_CDC_Interface =
USB_ClassInfo_CDC_Device_t VirtualSerial1_CDC_Interface =
{
.ControlInterfaceNumber = 0,
.Config =
{
.ControlInterfaceNumber = 0,
.DataINEndpointNumber = CDC1_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataINEndpointNumber = CDC1_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC1_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC1_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.NotificationEndpointNumber = CDC1_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
.NotificationEndpointNumber = CDC1_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** LUFA CDC Class driver interface configuration and state information. This structure is
@ -60,18 +68,26 @@ USB_ClassInfo_CDC_t VirtualSerial1_CDC_Interface =
* within a device can be differentiated from one another. This is for the second CDC interface,
* which echos back all received data from the host.
*/
USB_ClassInfo_CDC_t VirtualSerial2_CDC_Interface =
USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface =
{
.ControlInterfaceNumber = 2,
.Config =
{
.ControlInterfaceNumber = 2,
.DataINEndpointNumber = CDC2_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataINEndpointNumber = CDC2_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC2_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC2_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
.NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial

View file

@ -40,16 +40,22 @@
* passed to all HID Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_HID_t Generic_HID_Interface =
USB_ClassInfo_HID_Device_t Generic_HID_Interface =
{
.InterfaceNumber = 0,
.Config =
{
.InterfaceNumber = 0,
.ReportINEndpointNumber = GENERIC_IN_EPNUM,
.ReportINEndpointSize = GENERIC_EPSIZE,
.ReportINBufferSize = GENERIC_REPORT_SIZE,
.ReportINEndpointNumber = GENERIC_IN_EPNUM,
.ReportINEndpointSize = GENERIC_EPSIZE,
.ReportINBufferSize = GENERIC_REPORT_SIZE,
},
.UsingReportProtocol = true,
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -119,8 +125,8 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Generic_HID_Interface.IdleMSRemaining)
Generic_HID_Interface.IdleMSRemaining--;
if (Generic_HID_Interface.State.IdleMSRemaining)
Generic_HID_Interface.State.IdleMSRemaining--;
}
/** HID class driver callback function for the creation of HID reports to the host.
@ -131,7 +137,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
*
* \return Number of bytes written in the 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)
{
// Create generic HID report here
@ -145,7 +151,7 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceIn
* \param ReportData Pointer to a buffer where the created report has been stored
* \param ReportSize Size in bytes of the received HID report
*/
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID,
void* ReportData, uint16_t ReportSize)
{
// Process received generic HID report here

View file

@ -72,8 +72,9 @@
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_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);
#endif

View file

@ -40,16 +40,22 @@
* passed to all HID Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_HID_t Joystick_HID_Interface =
USB_ClassInfo_HID_Device_t Joystick_HID_Interface =
{
.InterfaceNumber = 0,
.Config =
{
.InterfaceNumber = 0,
.ReportINEndpointNumber = JOYSTICK_EPNUM,
.ReportINEndpointSize = JOYSTICK_EPSIZE,
.ReportINBufferSize = sizeof(USB_JoystickReport_Data_t),
.UsingReportProtocol = true,
.ReportINEndpointNumber = JOYSTICK_EPNUM,
.ReportINEndpointSize = JOYSTICK_EPSIZE,
.ReportINBufferSize = sizeof(USB_JoystickReport_Data_t),
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -121,8 +127,8 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Joystick_HID_Interface.IdleMSRemaining)
Joystick_HID_Interface.IdleMSRemaining--;
if (Joystick_HID_Interface.State.IdleMSRemaining)
Joystick_HID_Interface.State.IdleMSRemaining--;
}
/** HID class driver callback function for the creation of HID reports to the host.
@ -133,7 +139,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
*
* \return Number of bytes written in the 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)
{
USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData;
@ -166,7 +172,7 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceIn
* \param ReportData Pointer to a buffer where the created report has been stored
* \param ReportSize Size in bytes of the received HID report
*/
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID,
void* ReportData, uint16_t ReportSize)
{
// Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports

View file

@ -83,8 +83,9 @@
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
uint16_t CALLBACK_HID_Device_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
void CALLBACK_HID_Device_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
uint16_t CALLBACK_HID_Device_CreateNextHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t* ReportID,
void* ReportData);
void CALLBACK_HID_Device_ProcessReceivedHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID,
void* ReportData, uint16_t ReportSize);
#endif

View file

@ -41,16 +41,22 @@
* passed to all HID Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_HID_t Keyboard_HID_Interface =
{
.InterfaceNumber = 0,
USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
{
.Config =
{
.InterfaceNumber = 0,
.ReportINEndpointNumber = KEYBOARD_EPNUM,
.ReportINEndpointSize = KEYBOARD_EPSIZE,
.ReportINEndpointNumber = KEYBOARD_EPNUM,
.ReportINEndpointSize = KEYBOARD_EPSIZE,
.ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t),
.IdleCount = 500,
.ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t),
},
.State =
{
.IdleCount = 500,
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -122,8 +128,8 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Keyboard_HID_Interface.IdleMSRemaining)
Keyboard_HID_Interface.IdleMSRemaining--;
if (Keyboard_HID_Interface.State.IdleMSRemaining)
Keyboard_HID_Interface.State.IdleMSRemaining--;
}
/** HID class driver callback function for the creation of HID reports to the host.
@ -134,7 +140,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
*
* \return Number of bytes written in the 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)
{
USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;
@ -167,7 +173,7 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceIn
* \param ReportData Pointer to a buffer where the created report has been stored
* \param ReportSize Size in bytes of the received HID report
*/
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID,
void* ReportData, uint16_t ReportSize)
{
uint8_t LEDMask = LEDS_NO_LEDS;

View file

@ -86,8 +86,9 @@
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_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);
#endif

View file

@ -42,16 +42,22 @@
* within a device can be differentiated from one another. This is for the keyboard HID
* interface within the device.
*/
USB_ClassInfo_HID_t Keyboard_HID_Interface =
USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
{
.InterfaceNumber = 0,
.Config =
{
.InterfaceNumber = 0,
.ReportINEndpointNumber = KEYBOARD_IN_EPNUM,
.ReportINEndpointSize = HID_EPSIZE,
.ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t),
.ReportINEndpointNumber = KEYBOARD_IN_EPNUM,
.ReportINEndpointSize = HID_EPSIZE,
.ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t),
},
.IdleCount = 500,
.State =
{
.IdleCount = 500,
}
};
/** LUFA HID Class driver interface configuration and state information. This structure is
@ -59,14 +65,22 @@ USB_ClassInfo_HID_t Keyboard_HID_Interface =
* within a device can be differentiated from one another. This is for the mouse HID
* interface within the device.
*/
USB_ClassInfo_HID_t Mouse_HID_Interface =
USB_ClassInfo_HID_Device_t Mouse_HID_Interface =
{
.InterfaceNumber = 0,
.Config =
{
.InterfaceNumber = 0,
.ReportINEndpointNumber = MOUSE_IN_EPNUM,
.ReportINEndpointSize = HID_EPSIZE,
.ReportINEndpointNumber = MOUSE_IN_EPNUM,
.ReportINEndpointSize = HID_EPSIZE,
.ReportINBufferSize = sizeof(USB_MouseReport_Data_t),
.ReportINBufferSize = sizeof(USB_MouseReport_Data_t),
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -142,11 +156,11 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Keyboard_HID_Interface.IdleMSRemaining)
Keyboard_HID_Interface.IdleMSRemaining--;
if (Keyboard_HID_Interface.State.IdleMSRemaining)
Keyboard_HID_Interface.State.IdleMSRemaining--;
if (Mouse_HID_Interface.IdleMSRemaining)
Mouse_HID_Interface.IdleMSRemaining--;
if (Mouse_HID_Interface.State.IdleMSRemaining)
Mouse_HID_Interface.State.IdleMSRemaining--;
}
/** HID class driver callback function for the creation of HID reports to the host.
@ -157,7 +171,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
*
* \return Number of bytes written in the 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)
{
uint8_t JoyStatus_LCL = Joystick_GetStatus();
uint8_t ButtonStatus_LCL = Buttons_GetStatus();
@ -217,7 +231,7 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceIn
* \param ReportData Pointer to a buffer where the created report has been stored
* \param ReportSize Size in bytes of the received HID report
*/
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID,
void* ReportData, uint16_t ReportSize)
{
if (HIDInterfaceInfo == &Keyboard_HID_Interface)

View file

@ -90,8 +90,9 @@
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_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);
#endif

View file

@ -40,15 +40,23 @@
* passed to all MIDI Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_MIDI_t Keyboard_MIDI_Interface =
USB_ClassInfo_MIDI_Device_t Keyboard_MIDI_Interface =
{
.StreamingInterfaceNumber = 1,
.Config =
{
.StreamingInterfaceNumber = 1,
.DataINEndpointNumber = MIDI_STREAM_IN_EPNUM,
.DataINEndpointSize = MIDI_STREAM_EPSIZE,
.DataINEndpointNumber = MIDI_STREAM_IN_EPNUM,
.DataINEndpointSize = MIDI_STREAM_EPSIZE,
.DataOUTEndpointNumber = MIDI_STREAM_OUT_EPNUM,
.DataOUTEndpointSize = MIDI_STREAM_EPSIZE,
.DataOUTEndpointNumber = MIDI_STREAM_OUT_EPNUM,
.DataOUTEndpointSize = MIDI_STREAM_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial

View file

@ -47,7 +47,7 @@
* \param BlockAddress Data block starting address for the write sequence
* \param TotalBlocks Number of blocks of data to write
*/
void DataflashManager_WriteBlocks(USB_ClassInfo_MS_t* MSInterfaceInfo, const uint32_t BlockAddress, uint16_t TotalBlocks)
void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const uint32_t BlockAddress, uint16_t TotalBlocks)
{
uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE);
uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE);
@ -143,7 +143,7 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_t* MSInterfaceInfo, const uin
BytesInBlockDiv16++;
/* Check if the current command is being aborted by the host */
if (MSInterfaceInfo->IsMassStoreReset)
if (MSInterfaceInfo->State.IsMassStoreReset)
return;
}
@ -173,7 +173,7 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_t* MSInterfaceInfo, const uin
* \param BlockAddress Data block starting address for the read sequence
* \param TotalBlocks Number of blocks of data to read
*/
void DataflashManager_ReadBlocks(USB_ClassInfo_MS_t* MSInterfaceInfo, const uint32_t BlockAddress, uint16_t TotalBlocks)
void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const uint32_t BlockAddress, uint16_t TotalBlocks)
{
uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE);
uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE);
@ -252,7 +252,7 @@ void DataflashManager_ReadBlocks(USB_ClassInfo_MS_t* MSInterfaceInfo, const uint
BytesInBlockDiv16++;
/* Check if the current command is being aborted by the host */
if (MSInterfaceInfo->IsMassStoreReset)
if (MSInterfaceInfo->State.IsMassStoreReset)
return;
}

View file

@ -64,9 +64,9 @@
#define VIRTUAL_MEMORY_BLOCKS (VIRTUAL_MEMORY_BYTES / VIRTUAL_MEMORY_BLOCK_SIZE)
/* Function Prototypes: */
void DataflashManager_WriteBlocks(USB_ClassInfo_MS_t* MSInterfaceInfo, const uint32_t BlockAddress,
void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const uint32_t BlockAddress,
uint16_t TotalBlocks);
void DataflashManager_ReadBlocks(USB_ClassInfo_MS_t* MSInterfaceInfo, const uint32_t BlockAddress,
void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const uint32_t BlockAddress,
uint16_t TotalBlocks);
void DataflashManager_WriteBlocks_RAM(const uint32_t BlockAddress, uint16_t TotalBlocks,
uint8_t* BufferPtr) ATTR_NON_NULL_PTR_ARG(3);

View file

@ -86,12 +86,12 @@ SCSI_Request_Sense_Response_t SenseData =
*
* \param MSInterfaceInfo Pointer to the Mass Storage class interface structure that the command is associated with
*/
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_t* MSInterfaceInfo)
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
bool CommandSuccess = false;
/* Run the appropriate SCSI command hander function based on the passed command */
switch (MSInterfaceInfo->CommandBlock.SCSICommandData[0])
switch (MSInterfaceInfo->State.CommandBlock.SCSICommandData[0])
{
case SCSI_CMD_INQUIRY:
CommandSuccess = SCSI_Command_Inquiry(MSInterfaceInfo);
@ -116,7 +116,7 @@ bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_t* MSInterfaceInfo)
case SCSI_CMD_VERIFY_10:
/* These commands should just succeed, no handling required */
CommandSuccess = true;
MSInterfaceInfo->CommandBlock.DataTransferLength = 0;
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
break;
default:
/* Update the SENSE key to reflect the invalid command */
@ -146,16 +146,16 @@ bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_t* MSInterfaceInfo)
*
* \return Boolean true if the command completed successfully, false otherwise.
*/
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_t* MSInterfaceInfo)
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
uint16_t AllocationLength = (((uint16_t)MSInterfaceInfo->CommandBlock.SCSICommandData[3] << 8) |
MSInterfaceInfo->CommandBlock.SCSICommandData[4]);
uint16_t AllocationLength = (((uint16_t)MSInterfaceInfo->State.CommandBlock.SCSICommandData[3] << 8) |
MSInterfaceInfo->State.CommandBlock.SCSICommandData[4]);
uint16_t BytesTransferred = (AllocationLength < sizeof(InquiryData))? AllocationLength :
sizeof(InquiryData);
/* Only the standard INQUIRY data is supported, check if any optional INQUIRY bits set */
if ((MSInterfaceInfo->CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) ||
MSInterfaceInfo->CommandBlock.SCSICommandData[2])
if ((MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) ||
MSInterfaceInfo->State.CommandBlock.SCSICommandData[2])
{
/* Optional but unsupported bits set - update the SENSE key and fail the request */
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
@ -176,7 +176,7 @@ static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_t* MSInterfaceInfo)
Endpoint_ClearIN();
/* Succeed the command and update the bytes transferred counter */
MSInterfaceInfo->CommandBlock.DataTransferLength -= BytesTransferred;
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;
return true;
}
@ -188,9 +188,9 @@ static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_t* MSInterfaceInfo)
*
* \return Boolean true if the command completed successfully, false otherwise.
*/
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_t* MSInterfaceInfo)
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
uint8_t AllocationLength = MSInterfaceInfo->CommandBlock.SCSICommandData[4];
uint8_t AllocationLength = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];
uint8_t BytesTransferred = (AllocationLength < sizeof(SenseData))? AllocationLength : sizeof(SenseData);
uint8_t PadBytes[AllocationLength - BytesTransferred];
@ -200,7 +200,7 @@ static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_t* MSInterfaceInfo)
Endpoint_ClearIN();
/* Succeed the command and update the bytes transferred counter */
MSInterfaceInfo->CommandBlock.DataTransferLength -= BytesTransferred;
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= BytesTransferred;
return true;
}
@ -212,7 +212,7 @@ static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_t* MSInterfaceInfo)
*
* \return Boolean true if the command completed successfully, false otherwise.
*/
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_t* MSInterfaceInfo)
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
uint32_t TotalLUNs = (LUN_MEDIA_BLOCKS - 1);
uint32_t MediaBlockSize = VIRTUAL_MEMORY_BLOCK_SIZE;
@ -222,7 +222,7 @@ static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_t* MSInterfaceInfo)
Endpoint_ClearIN();
/* Succeed the command and update the bytes transferred counter */
MSInterfaceInfo->CommandBlock.DataTransferLength -= 8;
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 8;
return true;
}
@ -235,12 +235,12 @@ static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_t* MSInterfaceInfo)
*
* \return Boolean true if the command completed successfully, false otherwise.
*/
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_t* MSInterfaceInfo)
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
uint8_t ReturnByte;
/* Check to see if the SELF TEST bit is not set */
if (!(MSInterfaceInfo->CommandBlock.SCSICommandData[1] & (1 << 2)))
if (!(MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & (1 << 2)))
{
/* Only self-test supported - update SENSE key and fail the command */
SCSI_SET_SENSE(SCSI_SENSE_KEY_ILLEGAL_REQUEST,
@ -287,7 +287,7 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_t* MSInterfaceInfo)
#endif
/* Succeed the command and update the bytes transferred counter */
MSInterfaceInfo->CommandBlock.DataTransferLength = 0;
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
return true;
}
@ -301,20 +301,20 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_t* MSInterfaceInfo)
*
* \return Boolean true if the command completed successfully, false otherwise.
*/
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_t* MSInterfaceInfo, const bool IsDataRead)
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const bool IsDataRead)
{
uint32_t BlockAddress;
uint16_t TotalBlocks;
/* Load in the 32-bit block address (SCSI uses big-endian, so have to do it byte-by-byte) */
((uint8_t*)&BlockAddress)[3] = MSInterfaceInfo->CommandBlock.SCSICommandData[2];
((uint8_t*)&BlockAddress)[2] = MSInterfaceInfo->CommandBlock.SCSICommandData[3];
((uint8_t*)&BlockAddress)[1] = MSInterfaceInfo->CommandBlock.SCSICommandData[4];
((uint8_t*)&BlockAddress)[0] = MSInterfaceInfo->CommandBlock.SCSICommandData[5];
((uint8_t*)&BlockAddress)[3] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[2];
((uint8_t*)&BlockAddress)[2] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[3];
((uint8_t*)&BlockAddress)[1] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];
((uint8_t*)&BlockAddress)[0] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[5];
/* Load in the 16-bit total blocks (SCSI uses big-endian, so have to do it byte-by-byte) */
((uint8_t*)&TotalBlocks)[1] = MSInterfaceInfo->CommandBlock.SCSICommandData[7];
((uint8_t*)&TotalBlocks)[0] = MSInterfaceInfo->CommandBlock.SCSICommandData[8];
((uint8_t*)&TotalBlocks)[1] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[7];
((uint8_t*)&TotalBlocks)[0] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[8];
/* Check if the block address is outside the maximum allowable value for the LUN */
if (BlockAddress >= LUN_MEDIA_BLOCKS)
@ -329,7 +329,7 @@ static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_t* MSInterfaceInfo, const
#if (TOTAL_LUNS > 1)
/* Adjust the given block address to the real media address based on the selected LUN */
BlockAddress += ((uint32_t)MSInterfaceInfo->CommandBlock.LUN * LUN_MEDIA_BLOCKS);
BlockAddress += ((uint32_t)MSInterfaceInfo->State.CommandBlock.LUN * LUN_MEDIA_BLOCKS);
#endif
/* Determine if the packet is a READ (10) or WRITE (10) command, call appropriate function */
@ -339,7 +339,7 @@ static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_t* MSInterfaceInfo, const
DataflashManager_WriteBlocks(MSInterfaceInfo, BlockAddress, TotalBlocks);
/* Update the bytes transferred counter and succeed the command */
MSInterfaceInfo->CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);
return true;
}

View file

@ -135,14 +135,14 @@
} SCSI_Request_Sense_Response_t;
/* Function Prototypes: */
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_t* MSInterfaceInfo);
bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
#if defined(INCLUDE_FROM_SCSI_C)
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_t* MSInterfaceInfo);
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_t* MSInterfaceInfo);
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_t* MSInterfaceInfo);
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_t* MSInterfaceInfo);
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_t* MSInterfaceInfo, const bool IsDataRead);
static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, const bool IsDataRead);
#endif
#endif

View file

@ -40,17 +40,25 @@
* passed to all Mass Storage Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_MS_t Disk_MS_Interface =
USB_ClassInfo_MS_Device_t Disk_MS_Interface =
{
.InterfaceNumber = 0,
.Config =
{
.InterfaceNumber = 0,
.DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
.DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
.DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
.DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
.DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
.DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
.DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
.DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
.TotalLUNs = TOTAL_LUNS,
.TotalLUNs = TOTAL_LUNS,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -119,7 +127,7 @@ void EVENT_USB_UnhandledControlPacket(void)
*
* \param MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
*/
bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_t* MSInterfaceInfo)
bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
bool CommandSuccess;

View file

@ -83,6 +83,6 @@
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_t* MSInterfaceInfo);
bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* MSInterfaceInfo);
#endif

View file

@ -40,14 +40,22 @@
* passed to all HID Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_HID_t Mouse_HID_Interface =
USB_ClassInfo_HID_Device_t Mouse_HID_Interface =
{
.InterfaceNumber = 0,
.Config =
{
.InterfaceNumber = 0,
.ReportINEndpointNumber = MOUSE_EPNUM,
.ReportINEndpointSize = MOUSE_EPSIZE,
.ReportINEndpointNumber = MOUSE_EPNUM,
.ReportINEndpointSize = MOUSE_EPSIZE,
.ReportINBufferSize = sizeof(USB_MouseReport_Data_t),
.ReportINBufferSize = sizeof(USB_MouseReport_Data_t),
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -119,8 +127,8 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Mouse_HID_Interface.IdleMSRemaining)
Mouse_HID_Interface.IdleMSRemaining--;
if (Mouse_HID_Interface.State.IdleMSRemaining)
Mouse_HID_Interface.State.IdleMSRemaining--;
}
/** HID class driver callback function for the creation of HID reports to the host.
@ -131,7 +139,7 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
*
* \return Number of bytes written in the 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)
{
USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData;
@ -164,7 +172,7 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceIn
* \param ReportData Pointer to a buffer where the created report has been stored
* \param ReportSize Size in bytes of the received HID report
*/
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t ReportID,
void* ReportData, uint16_t ReportSize)
{
// Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports

View file

@ -85,8 +85,9 @@
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, uint8_t ReportID,
uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_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);
#endif

View file

@ -56,7 +56,7 @@ TCP_ConnectionState_t ConnectionStateTable[MAX_TCP_CONNECTIONS];
* level. If an application produces a response, this task constructs the appropriate Ethernet frame and places it into the Ethernet OUT
* buffer for later transmission.
*/
void TCP_TCPTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo)
{
/* Task to hand off TCP packets to and from the listening applications. */
@ -76,7 +76,7 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
}
/* Bail out early if there is already a frame waiting to be sent in the Ethernet OUT buffer */
if (RNDISInterfaceInfo->FrameOUT.FrameInBuffer)
if (RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer)
return;
/* Send response packets from each application as the TCP packet buffers are filled by the applications */
@ -86,11 +86,11 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
if ((ConnectionStateTable[CSTableEntry].Info.Buffer.Direction == TCP_PACKETDIR_OUT) &&
(ConnectionStateTable[CSTableEntry].Info.Buffer.Ready))
{
Ethernet_Frame_Header_t* FrameOUTHeader = (Ethernet_Frame_Header_t*)&RNDISInterfaceInfo->FrameOUT.FrameData;
IP_Header_t* IPHeaderOUT = (IP_Header_t*)&RNDISInterfaceInfo->FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t)];
TCP_Header_t* TCPHeaderOUT = (TCP_Header_t*)&RNDISInterfaceInfo->FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t) +
Ethernet_Frame_Header_t* FrameOUTHeader = (Ethernet_Frame_Header_t*)&RNDISInterfaceInfo->State.FrameOUT.FrameData;
IP_Header_t* IPHeaderOUT = (IP_Header_t*)&RNDISInterfaceInfo->State.FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t)];
TCP_Header_t* TCPHeaderOUT = (TCP_Header_t*)&RNDISInterfaceInfo->State.FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t) +
sizeof(IP_Header_t)];
void* TCPDataOUT = &RNDISInterfaceInfo->FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t) +
void* TCPDataOUT = &RNDISInterfaceInfo->State.FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t) +
sizeof(IP_Header_t) +
sizeof(TCP_Header_t)];
@ -145,8 +145,8 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo)
PacketSize += sizeof(Ethernet_Frame_Header_t);
/* Set the response length in the buffer and indicate that a response is ready to be sent */
RNDISInterfaceInfo->FrameOUT.FrameLength = PacketSize;
RNDISInterfaceInfo->FrameOUT.FrameInBuffer = true;
RNDISInterfaceInfo->State.FrameOUT.FrameLength = PacketSize;
RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer = true;
ConnectionStateTable[CSTableEntry].Info.Buffer.Ready = false;

View file

@ -232,7 +232,7 @@
TCP_PortState_t PortStateTable[MAX_OPEN_TCP_PORTS];
/* Function Prototypes: */
void TCP_TCPTask(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo);
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo);
void TCP_Init(void);
bool TCP_SetPortState(uint16_t Port, uint8_t State, void (*Handler)(TCP_ConnectionState_t*, TCP_ConnectionBuffer_t*));
uint8_t TCP_GetPortState(uint16_t Port);

View file

@ -40,21 +40,29 @@
* passed to all RNDIS Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_RNDIS_t Ethernet_RNDIS_Interface =
USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface =
{
.ControlInterfaceNumber = 0,
.Config =
{
.ControlInterfaceNumber = 0,
.DataINEndpointNumber = CDC_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataINEndpointNumber = CDC_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
.AdapterVendorDescription = "LUFA RNDIS Demo Adapter",
.AdapterMACAddress = {ADAPTER_MAC_ADDRESS},
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
.AdapterVendorDescription = "LUFA RNDIS Demo Adapter",
.AdapterMACAddress = {ADAPTER_MAC_ADDRESS},
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -73,10 +81,10 @@ int main(void)
for (;;)
{
if (Ethernet_RNDIS_Interface.FrameIN.FrameInBuffer)
if (Ethernet_RNDIS_Interface.State.FrameIN.FrameInBuffer)
{
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.FrameIN, &Ethernet_RNDIS_Interface.FrameOUT);
Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.State.FrameIN, &Ethernet_RNDIS_Interface.State.FrameOUT);
LEDs_SetAllLEDs(LEDMASK_USB_READY);
}

View file

@ -46,18 +46,26 @@ RingBuff_t Tx_Buffer;
* passed to all CDC Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_CDC_t VirtualSerial_CDC_Interface =
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
{
.ControlInterfaceNumber = 0,
.Config =
{
.ControlInterfaceNumber = 0,
.DataINEndpointNumber = CDC_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataINEndpointNumber = CDC_TX_EPNUM,
.DataINEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.DataOUTEndpointNumber = CDC_RX_EPNUM,
.DataOUTEndpointSize = CDC_TXRX_EPSIZE,
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
.NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -152,27 +160,38 @@ ISR(USART1_RX_vect, ISR_BLOCK)
*
* \param CDCInterfaceInfo Pointer to the CDC class interface configuration structure being referenced
*/
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
{
uint8_t ConfigMask = 0;
if (CDCInterfaceInfo->LineEncoding.ParityType == CDC_PARITY_Odd)
ConfigMask = ((1 << UPM11) | (1 << UPM10));
else if (CDCInterfaceInfo->LineEncoding.ParityType == CDC_PARITY_Even)
ConfigMask = (1 << UPM11);
switch (CDCInterfaceInfo->State.LineEncoding.ParityType)
{
case CDC_PARITY_Odd:
ConfigMask = ((1 << UPM11) | (1 << UPM10));
break;
case CDC_PARITY_Even:
ConfigMask = (1 << UPM11);
break;
}
if (CDCInterfaceInfo->LineEncoding.CharFormat == CDC_LINEENCODING_TwoStopBits)
if (CDCInterfaceInfo->State.LineEncoding.CharFormat == CDC_LINEENCODING_TwoStopBits)
ConfigMask |= (1 << USBS1);
if (CDCInterfaceInfo->LineEncoding.DataBits == 6)
ConfigMask |= (1 << UCSZ10);
else if (CDCInterfaceInfo->LineEncoding.DataBits == 7)
ConfigMask |= (1 << UCSZ11);
else if (CDCInterfaceInfo->LineEncoding.DataBits == 8)
ConfigMask |= ((1 << UCSZ11) | (1 << UCSZ10));
switch (CDCInterfaceInfo->State.LineEncoding.DataBits)
{
case 6:
ConfigMask |= (1 << UCSZ10);
break;
case 7:
ConfigMask |= (1 << UCSZ11);
break;
case 8:
ConfigMask |= ((1 << UCSZ11) | (1 << UCSZ10));
break;
}
UCSR1A = (1 << U2X1);
UCSR1B = ((1 << RXCIE1) | (1 << TXEN1) | (1 << RXEN1));
UCSR1C = ConfigMask;
UBRR1 = SERIAL_2X_UBBRVAL((uint16_t)CDCInterfaceInfo->LineEncoding.BaudRateBPS);
UBRR1 = SERIAL_2X_UBBRVAL((uint16_t)CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
}

View file

@ -74,6 +74,6 @@
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo);
#endif