Commit 7c5444b8 authored by Dean Camera's avatar Dean Camera
Browse files

Removed new Start of Frame event from the library; performance suffered far...

Removed new Start of Frame event from the library; performance suffered far too much and it was only useful in one of the standard classes (HID). Altered HID demos to use the previous method of tracking millisecond periods via a hardware timer rather than the SOF events.

Fixed MIDI class driver blocking on unread events to the host.
parent 74b7c07e
......@@ -64,6 +64,5 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
#endif
......@@ -64,6 +64,5 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
#endif
......@@ -40,7 +40,7 @@ USB_ClassInfo_HID_t Generic_HID_Interface =
.ReportOUTEndpointNumber = GENERIC_OUT_EPNUM,
.ReportOUTEndpointSize = GENERIC_EPSIZE,
.ReportBufferSize = GENERIC_REPORT_SIZE,
.ReportINBufferSize = GENERIC_REPORT_SIZE,
.UsingReportProtocol = true,
};
......@@ -70,6 +70,12 @@ void SetupHardware(void)
/* Hardware Initialization */
LEDs_Init();
USB_Init();
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00));
TIMSK0 = (1 << OCIE0A);
}
void EVENT_USB_Connect(void)
......@@ -95,9 +101,10 @@ void EVENT_USB_UnhandledControlPacket(void)
USB_HID_ProcessControlPacket(&Generic_HID_Interface);
}
void EVENT_USB_StartOfFrame(void)
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
USB_HID_RegisterStartOfFrame(&Generic_HID_Interface);
if (Generic_HID_Interface.IdleMSRemaining)
Generic_HID_Interface.IdleMSRemaining--;
}
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData)
......
......@@ -64,7 +64,6 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo,
......
......@@ -37,7 +37,7 @@ USB_ClassInfo_HID_t Joystick_HID_Interface =
.ReportINEndpointNumber = JOYSTICK_EPNUM,
.ReportINEndpointSize = JOYSTICK_EPSIZE,
.ReportBufferSize = sizeof(USB_JoystickReport_Data_t),
.ReportINBufferSize = sizeof(USB_JoystickReport_Data_t),
.UsingReportProtocol = true,
};
......@@ -69,6 +69,12 @@ void SetupHardware(void)
LEDs_Init();
Buttons_Init();
USB_Init();
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00));
TIMSK0 = (1 << OCIE0A);
}
void EVENT_USB_Connect(void)
......@@ -94,9 +100,10 @@ void EVENT_USB_UnhandledControlPacket(void)
USB_HID_ProcessControlPacket(&Joystick_HID_Interface);
}
void EVENT_USB_StartOfFrame(void)
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
USB_HID_RegisterStartOfFrame(&Joystick_HID_Interface);
if (Joystick_HID_Interface.IdleMSRemaining)
Joystick_HID_Interface.IdleMSRemaining--;
}
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData)
......
......@@ -75,7 +75,6 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo,
......
......@@ -41,7 +41,7 @@ USB_ClassInfo_HID_t Keyboard_HID_Interface =
.ReportOUTEndpointNumber = KEYBOARD_LEDS_EPNUM,
.ReportOUTEndpointSize = KEYBOARD_EPSIZE,
.ReportBufferSize = sizeof(USB_KeyboardReport_Data_t),
.ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t),
.IdleCount = 500,
};
......@@ -73,6 +73,12 @@ void SetupHardware()
LEDs_Init();
Buttons_Init();
USB_Init();
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00));
TIMSK0 = (1 << OCIE0A);
}
void EVENT_USB_Connect(void)
......@@ -98,9 +104,10 @@ void EVENT_USB_UnhandledControlPacket(void)
USB_HID_ProcessControlPacket(&Keyboard_HID_Interface);
}
void EVENT_USB_StartOfFrame(void)
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
USB_HID_RegisterStartOfFrame(&Keyboard_HID_Interface);
if (Keyboard_HID_Interface.IdleMSRemaining)
Keyboard_HID_Interface.IdleMSRemaining--;
}
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData)
......
......@@ -78,7 +78,6 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo,
......
......@@ -41,7 +41,7 @@ USB_ClassInfo_HID_t Keyboard_HID_Interface =
.ReportOUTEndpointNumber = KEYBOARD_OUT_EPNUM,
.ReportOUTEndpointSize = HID_EPSIZE,
.ReportBufferSize = sizeof(USB_KeyboardReport_Data_t),
.ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t),
.IdleCount = 500,
};
......@@ -53,7 +53,7 @@ USB_ClassInfo_HID_t Mouse_HID_Interface =
.ReportINEndpointNumber = MOUSE_IN_EPNUM,
.ReportINEndpointSize = HID_EPSIZE,
.ReportBufferSize = sizeof(USB_MouseReport_Data_t),
.ReportINBufferSize = sizeof(USB_MouseReport_Data_t),
.ReportOUTEndpointNumber = 0,
.ReportOUTEndpointSize = 0,
......@@ -85,7 +85,13 @@ void SetupHardware()
/* Hardware Initialization */
Joystick_Init();
LEDs_Init();
USB_Init();
USB_Init();
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00));
TIMSK0 = (1 << OCIE0A);
}
void EVENT_USB_Connect(void)
......@@ -115,10 +121,13 @@ void EVENT_USB_UnhandledControlPacket(void)
USB_HID_ProcessControlPacket(&Mouse_HID_Interface);
}
void EVENT_USB_StartOfFrame(void)
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
USB_HID_RegisterStartOfFrame(&Keyboard_HID_Interface);
USB_HID_RegisterStartOfFrame(&Mouse_HID_Interface);
if (Keyboard_HID_Interface.IdleMSRemaining)
Keyboard_HID_Interface.IdleMSRemaining--;
if (Mouse_HID_Interface.IdleMSRemaining)
Mouse_HID_Interface.IdleMSRemaining--;
}
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData)
......
......@@ -82,7 +82,6 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo,
......
......@@ -37,7 +37,7 @@ USB_ClassInfo_HID_t Mouse_HID_Interface =
.ReportINEndpointNumber = MOUSE_EPNUM,
.ReportINEndpointSize = MOUSE_EPSIZE,
.ReportBufferSize = sizeof(USB_MouseReport_Data_t),
.ReportINBufferSize = sizeof(USB_MouseReport_Data_t),
};
int main(void)
......@@ -67,6 +67,12 @@ void SetupHardware(void)
LEDs_Init();
Buttons_Init();
USB_Init();
/* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00));
TIMSK0 = (1 << OCIE0A);
}
void EVENT_USB_Connect(void)
......@@ -92,9 +98,10 @@ void EVENT_USB_UnhandledControlPacket(void)
USB_HID_ProcessControlPacket(&Mouse_HID_Interface);
}
void EVENT_USB_StartOfFrame(void)
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
USB_HID_RegisterStartOfFrame(&Mouse_HID_Interface);
if (Mouse_HID_Interface.IdleMSRemaining)
Mouse_HID_Interface.IdleMSRemaining--;
}
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData)
......
......@@ -77,7 +77,6 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo,
......
......@@ -71,7 +71,6 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
void CALLBACK_USB_RNDIS_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t* RNDISInterfaceInfo);
......
......@@ -66,7 +66,6 @@
void EVENT_USB_Disconnect(void);
void EVENT_USB_ConfigurationChanged(void);
void EVENT_USB_UnhandledControlPacket(void);
void EVENT_USB_StartOfFrame(void);
void EVENT_USB_CDC_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
......
......@@ -38,7 +38,6 @@
* LUFA/Drivers/USB/Class/ directory to LUFA/Drivers/USB/HighLevel/ in preperation for the new USB class APIs
* - Moved out each demos' functionality library files (e.g. Ring Buffer library) to /Lib directories for a better directory structure
* - Removed Tx interrupt from the USBtoSerial demo; now sends characters via polling to ensure more time for the Rx interrupt
* - Added new EVENT_USB_StartOfFrame event in the library to indicate the start of each USB frame (when generated)
* - Removed psuedo-scheduler, dynamic memory block allocator from the library (no longer needed and not used respectively)
*
*
......
......@@ -45,7 +45,7 @@ void USB_HID_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
Endpoint_ClearSETUP();
uint8_t ReportINData[HIDInterfaceInfo->ReportBufferSize];
uint8_t ReportINData[HIDInterfaceInfo->ReportINBufferSize];
uint16_t ReportINSize;
memset(ReportINData, 0, sizeof(ReportINData));
......@@ -146,12 +146,6 @@ bool USB_HID_ConfigureEndpoints(USB_ClassInfo_HID_t* HIDInterfaceInfo)
return true;
}
void USB_HID_RegisterStartOfFrame(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
if (HIDInterfaceInfo->IdleMSRemaining)
HIDInterfaceInfo->IdleMSRemaining--;
}
void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo)
{
......@@ -166,7 +160,7 @@ void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo)
if (HIDInterfaceInfo->IdleCount && !(HIDInterfaceInfo->IdleMSRemaining))
HIDInterfaceInfo->IdleMSRemaining = HIDInterfaceInfo->IdleCount;
uint8_t ReportINData[HIDInterfaceInfo->ReportBufferSize];
uint8_t ReportINData[HIDInterfaceInfo->ReportINBufferSize];
uint16_t ReportINSize;
memset(ReportINData, 0, sizeof(ReportINData));
......@@ -174,13 +168,7 @@ void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo)
ReportINSize = CALLBACK_USB_HID_CreateNextHIDReport(HIDInterfaceInfo, ReportINData);
if (ReportINSize)
{
Endpoint_Write_Stream_LE(ReportINData, ReportINSize
#if !defined(NO_STREAM_CALLBACKS)
, NO_STREAM_CALLBACK
#endif
);
}
Endpoint_Write_Stream_LE(ReportINData, ReportINSize, NO_STREAM_CALLBACK);
Endpoint_ClearIN();
}
......@@ -195,13 +183,7 @@ void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo)
uint8_t ReportOUTData[ReportOUTSize];
if (ReportOUTSize)
{
Endpoint_Read_Stream_LE(ReportOUTData, ReportOUTSize
#if !defined(NO_STREAM_CALLBACKS)
, NO_STREAM_CALLBACK
#endif
);
}
Endpoint_Read_Stream_LE(ReportOUTData, ReportOUTSize, NO_STREAM_CALLBACK);
CALLBACK_USB_HID_ProcessReceivedHIDReport(HIDInterfaceInfo, ReportOUTData, ReportOUTSize);
......
......@@ -96,7 +96,7 @@
uint8_t ReportOUTEndpointNumber; /**< Endpoint number of the HID interface's OUT report endpoint, if used */
uint16_t ReportOUTEndpointSize; /**< Size in bytes of the HID interface's OUT report endpoint, if used */
uint8_t ReportBufferSize;
uint8_t ReportINBufferSize;
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 */
......@@ -106,7 +106,6 @@
/* Function Prototypes: */
bool USB_HID_ConfigureEndpoints(USB_ClassInfo_HID_t* HIDInterfaceInfo);
void USB_HID_ProcessControlPacket(USB_ClassInfo_HID_t* HIDInterfaceInfo);
void USB_HID_RegisterStartOfFrame(USB_ClassInfo_HID_t* HIDInterfaceInfo);
void USB_HID_USBTask(USB_ClassInfo_HID_t* HIDInterfaceInfo);
uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData);
......
......@@ -55,36 +55,18 @@ bool USB_MIDI_ConfigureEndpoints(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo)
return true;
}
void USB_MIDI_SendNoteChange(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, const uint8_t Pitch, const bool OnOff,
const uint8_t CableID, const uint8_t Channel)
{
if (!(USB_IsConnected))
return;
Endpoint_SelectEndpoint(MIDIInterfaceInfo->DataINEndpointNumber);
while (!(Endpoint_IsReadWriteAllowed()));
uint8_t Command = ((OnOff)? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF);
Endpoint_Write_Byte((CableID << 4) | (Command >> 4));
Endpoint_Write_Byte(Command | Channel);
Endpoint_Write_Byte(Pitch);
Endpoint_Write_Byte(MIDI_STANDARD_VELOCITY);
Endpoint_ClearIN();
}
void USB_MIDI_SendEventPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event)
{
if (!(USB_IsConnected))
return;
Endpoint_SelectEndpoint(MIDIInterfaceInfo->DataINEndpointNumber);
while (!(Endpoint_IsReadWriteAllowed()));
Endpoint_Write_Stream_LE(Event, sizeof(USB_MIDI_EventPacket_t), NO_STREAM_CALLBACK);
Endpoint_ClearIN();
if (Endpoint_IsReadWriteAllowed());
{
Endpoint_Write_Stream_LE(Event, sizeof(USB_MIDI_EventPacket_t), NO_STREAM_CALLBACK);
Endpoint_ClearIN();
}
}
bool USB_MIDI_ReceiveEventPacket(USB_ClassInfo_MIDI_t* MIDIInterfaceInfo, USB_MIDI_EventPacket_t* Event)
......
......@@ -267,11 +267,6 @@
* \ref Group_USBManagement documentation).
*/
void EVENT_USB_Reset(void);
/** Event for the USB start of frame interrupt, firing once each millisecond in either device or host
* mode, while USB frames are being generated or recieved.
*/
void EVENT_USB_StartOfFrame(void);
#endif
/* Private Interface - For use in library only: */
......@@ -308,7 +303,6 @@
void EVENT_USB_Suspend(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_WakeUp(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Reset(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_StartOfFrame(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
#endif
#endif
......
......@@ -180,15 +180,6 @@ ISR(USB_GEN_vect, ISR_BLOCK)
EVENT_USB_Reset();
}
if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
{
USB_INT_Clear(USB_INT_SOFI);
FrameElapsed = true;
EVENT_USB_StartOfFrame();
}
#endif
#if defined(USB_CAN_BE_HOST)
......@@ -241,15 +232,6 @@ ISR(USB_GEN_vect, ISR_BLOCK)
USB_ResetInterface();
}
if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
{
USB_INT_Clear(USB_INT_HSOFI);
FrameElapsed = true;
EVENT_USB_StartOfFrame();
}
#endif
#if defined(USB_CAN_BE_BOTH)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment