diff --git a/Demos/Device/CDC/CDC.h b/Demos/Device/CDC/CDC.h index b487813b0820d4bad9bde67d142f49acadb5b305..dc4033448f88e64a143311d6ef0663dd732fb1bf 100644 --- a/Demos/Device/CDC/CDC.h +++ b/Demos/Device/CDC/CDC.h @@ -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 diff --git a/Demos/Device/DualCDC/DualCDC.h b/Demos/Device/DualCDC/DualCDC.h index 3c1e29612304d10d71f69daa73db6289d44e6469..fc782ee5ad93d775cd7c4f3fb9422bf22bac0765 100644 --- a/Demos/Device/DualCDC/DualCDC.h +++ b/Demos/Device/DualCDC/DualCDC.h @@ -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 diff --git a/Demos/Device/GenericHID/GenericHID.c b/Demos/Device/GenericHID/GenericHID.c index 4dfb8e45571c044773f7f1d9976726f06e79f702..9c8023a5c917f7ab0650f7837d16d901c50c366b 100644 --- a/Demos/Device/GenericHID/GenericHID.c +++ b/Demos/Device/GenericHID/GenericHID.c @@ -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) diff --git a/Demos/Device/GenericHID/GenericHID.h b/Demos/Device/GenericHID/GenericHID.h index 27426431c988455db56651aa32a7dda8cc1ce17a..94a09af93260ce665b9d9c6dc5fd6b876cff9065 100644 --- a/Demos/Device/GenericHID/GenericHID.h +++ b/Demos/Device/GenericHID/GenericHID.h @@ -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, diff --git a/Demos/Device/Joystick/Joystick.c b/Demos/Device/Joystick/Joystick.c index e073a87fddc913562f16787ea04b5cbe4d37f197..d5c20737d9747cd0ad2704040ee04a87bbfa01df 100644 --- a/Demos/Device/Joystick/Joystick.c +++ b/Demos/Device/Joystick/Joystick.c @@ -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) diff --git a/Demos/Device/Joystick/Joystick.h b/Demos/Device/Joystick/Joystick.h index 461d0d0ccc7454336459f4a25c2d242449a51560..164c58ea25824f9c5f3ce04e412270688233757f 100644 --- a/Demos/Device/Joystick/Joystick.h +++ b/Demos/Device/Joystick/Joystick.h @@ -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, diff --git a/Demos/Device/Keyboard/Keyboard.c b/Demos/Device/Keyboard/Keyboard.c index d8893bfaaee9a2e68068f879f454cd259852c26f..d506657a63e721ad5df9797ca455cf9a21ed9daa 100644 --- a/Demos/Device/Keyboard/Keyboard.c +++ b/Demos/Device/Keyboard/Keyboard.c @@ -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) diff --git a/Demos/Device/Keyboard/Keyboard.h b/Demos/Device/Keyboard/Keyboard.h index eeb7be9b74aca79784d45afd03124def8a2a76a7..9cfc9aba42e44962211804d35fac3c4f525421d2 100644 --- a/Demos/Device/Keyboard/Keyboard.h +++ b/Demos/Device/Keyboard/Keyboard.h @@ -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, diff --git a/Demos/Device/KeyboardMouse/KeyboardMouse.c b/Demos/Device/KeyboardMouse/KeyboardMouse.c index 8f6a573a67289d41e1a79a360f52b0504edbcb37..71a8375aa654f6708ae512de0c23f485531baeab 100644 --- a/Demos/Device/KeyboardMouse/KeyboardMouse.c +++ b/Demos/Device/KeyboardMouse/KeyboardMouse.c @@ -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) diff --git a/Demos/Device/KeyboardMouse/KeyboardMouse.h b/Demos/Device/KeyboardMouse/KeyboardMouse.h index a5c3c5db2b0e9343d87d6a9191233fe5e82867f5..c18c6e1af48ef6593782ab578dd26b29982df0e4 100644 --- a/Demos/Device/KeyboardMouse/KeyboardMouse.h +++ b/Demos/Device/KeyboardMouse/KeyboardMouse.h @@ -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, diff --git a/Demos/Device/Mouse/Mouse.c b/Demos/Device/Mouse/Mouse.c index 57c1aa114271f88e6a2f9317afc9e9ecf575a997..01ead0012ddceb7c5cad2f7e21bc089003b45a95 100644 --- a/Demos/Device/Mouse/Mouse.c +++ b/Demos/Device/Mouse/Mouse.c @@ -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) diff --git a/Demos/Device/Mouse/Mouse.h b/Demos/Device/Mouse/Mouse.h index 5c8049590bb820116e461fd918cf63cdcb9550d0..9134e6772a85a391c019af684b84022b11b0608b 100644 --- a/Demos/Device/Mouse/Mouse.h +++ b/Demos/Device/Mouse/Mouse.h @@ -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, diff --git a/Demos/Device/RNDISEthernet/RNDISEthernet.h b/Demos/Device/RNDISEthernet/RNDISEthernet.h index bc5004205bc4c3ea8228bce1027461507e976b46..f0247ce81068a891e826ac7a8deeb5a6fc1e8cc7 100644 --- a/Demos/Device/RNDISEthernet/RNDISEthernet.h +++ b/Demos/Device/RNDISEthernet/RNDISEthernet.h @@ -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); diff --git a/Demos/Device/USBtoSerial/USBtoSerial.h b/Demos/Device/USBtoSerial/USBtoSerial.h index 7ff796e7082c754d109244613ea0d465f4c4664e..bc8d983988745b57a4b7e76ad9f31765550a0660 100644 --- a/Demos/Device/USBtoSerial/USBtoSerial.h +++ b/Demos/Device/USBtoSerial/USBtoSerial.h @@ -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); diff --git a/LUFA/ChangeLog.txt b/LUFA/ChangeLog.txt index fe3b6336093bec5db74d93c029066307b6d9d56f..67f88b9a3cefef27e4b6db04c11d373b718567cd 100644 --- a/LUFA/ChangeLog.txt +++ b/LUFA/ChangeLog.txt @@ -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) * * diff --git a/LUFA/Drivers/USB/Class/Device/HID.c b/LUFA/Drivers/USB/Class/Device/HID.c index fbc5e3a5c94c9346ca16cc4e19c1b14fbf88792e..5f8ccfbaef16e7410b714c26afc8bf65329b6c0e 100644 --- a/LUFA/Drivers/USB/Class/Device/HID.c +++ b/LUFA/Drivers/USB/Class/Device/HID.c @@ -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); diff --git a/LUFA/Drivers/USB/Class/Device/HID.h b/LUFA/Drivers/USB/Class/Device/HID.h index 8fdeb064a0a1ac2cd8bcdcd84fb612cc37ca5df5..4501fcb1c68fee983e1d3effeaed3671b1a92fa4 100644 --- a/LUFA/Drivers/USB/Class/Device/HID.h +++ b/LUFA/Drivers/USB/Class/Device/HID.h @@ -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); diff --git a/LUFA/Drivers/USB/Class/Device/MIDI.c b/LUFA/Drivers/USB/Class/Device/MIDI.c index 9b4cd4b0403cfc2f192e81c00a01d89f70be6089..42c06904bee705d4be4a6389c397f13db7006933 100644 --- a/LUFA/Drivers/USB/Class/Device/MIDI.c +++ b/LUFA/Drivers/USB/Class/Device/MIDI.c @@ -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) diff --git a/LUFA/Drivers/USB/HighLevel/Events.h b/LUFA/Drivers/USB/HighLevel/Events.h index ded027b12e901374faeaf2354d9a3576a0279b98..e6d2beaa77d5cc8b3cb0882a21970d4c0e2cf434 100644 --- a/LUFA/Drivers/USB/HighLevel/Events.h +++ b/LUFA/Drivers/USB/HighLevel/Events.h @@ -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 diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c index 0ccbe61557eabc6f39914ec69f28f62d50d16b73..0b9d082236b197deed9111bfbf32352291aa55e7 100644 --- a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c +++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c @@ -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) diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.c b/LUFA/Drivers/USB/LowLevel/LowLevel.c index 255a6ef2997cd3d6831705dfa825ba4ff635252c..82705db9667dff1772a40c3010eb947d5e8eff7b 100644 --- a/LUFA/Drivers/USB/LowLevel/LowLevel.c +++ b/LUFA/Drivers/USB/LowLevel/LowLevel.c @@ -228,8 +228,6 @@ void USB_ResetInterface(void) #if defined(USB_DEVICE_ONLY) USB_INT_Enable(USB_INT_SUSPEND); USB_INT_Enable(USB_INT_EORSTI); - USB_INT_Enable(USB_INT_SOFI); - #if defined(CONTROL_ONLY_DEVICE) UENUM = ENDPOINT_CONTROLEP; #endif @@ -245,13 +243,11 @@ void USB_ResetInterface(void) USB_INT_Enable(USB_INT_SRPI); USB_INT_Enable(USB_INT_BCERRI); - USB_INT_Enable(USB_INT_HSOFI); #else if (USB_CurrentMode == USB_MODE_DEVICE) { USB_INT_Enable(USB_INT_SUSPEND); USB_INT_Enable(USB_INT_EORSTI); - USB_INT_Enable(USB_INT_SOFI); #if defined(CONTROL_ONLY_DEVICE) UENUM = ENDPOINT_CONTROLEP; @@ -269,7 +265,6 @@ void USB_ResetInterface(void) USB_INT_Enable(USB_INT_SRPI); USB_INT_Enable(USB_INT_BCERRI); - USB_INT_Enable(USB_INT_HSOFI); } #endif } diff --git a/Projects/Magstripe/Magstripe.c b/Projects/Magstripe/Magstripe.c index 5cd107e9a4bce512736d4d2ccfde9ae024015766..871db28c31e756f1a1dbf1863f107add0d01dd8b 100644 --- a/Projects/Magstripe/Magstripe.c +++ b/Projects/Magstripe/Magstripe.c @@ -39,6 +39,8 @@ USB_ClassInfo_HID_t Keyboard_HID_Interface = .ReportINEndpointNumber = KEYBOARD_EPNUM, .ReportINEndpointSize = KEYBOARD_EPSIZE, + + .ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t), }; int main(void) @@ -70,6 +72,12 @@ void SetupHardware(void) /* Hardware Initialization */ Magstripe_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 ReadMagstripeData(void) @@ -113,9 +121,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) diff --git a/Projects/Magstripe/Magstripe.h b/Projects/Magstripe/Magstripe.h index b0e47d596515b51954031a2ab743066cc06e9f80..2b8aa3770dc291802d28713d733fcb33dcf66f95 100644 --- a/Projects/Magstripe/Magstripe.h +++ b/Projects/Magstripe/Magstripe.h @@ -78,7 +78,6 @@ 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, diff --git a/Projects/Magstripe/makefile b/Projects/Magstripe/makefile index 138456fe8f5a883643e97f0a3ff6cab416f03262..80b17448f5acb6220c44790435bf9cd11294c7c4 100644 --- a/Projects/Magstripe/makefile +++ b/Projects/Magstripe/makefile @@ -183,7 +183,7 @@ CSTANDARD = -std=gnu99 # Place -D or -U options here for C sources CDEFS = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD) -CDEFS += -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS -DUSB_DEVICE_ONLY +CDEFS += -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DUSB_DEVICE_ONLY CDEFS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 -DUSE_SINGLE_DEVICE_CONFIGURATION CDEFS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" CDEFS += -DMAG_T1_CLOCK="(1 << 0)"