X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/9991321321d30ca9383d795ea7e796098c92045f..0214e096a0274fd506b09812f47dc1183084851d:/Demos/KeyboardViaInt/KeyboardViaInt.c diff --git a/Demos/KeyboardViaInt/KeyboardViaInt.c b/Demos/KeyboardViaInt/KeyboardViaInt.c index 7f6fcd8cd..1e724e6fa 100644 --- a/Demos/KeyboardViaInt/KeyboardViaInt.c +++ b/Demos/KeyboardViaInt/KeyboardViaInt.c @@ -76,8 +76,8 @@ int main(void) MCUSR &= ~(1 << WDRF); wdt_disable(); - /* Disable Clock Division */ - SetSystemClockPrescaler(0); + /* Disable clock division */ + clock_prescale_set(clock_div_1); /* Hardware Initialization */ Joystick_Init(); @@ -211,10 +211,8 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Clear the endpoint data */ Endpoint_ClearSetupOUT(); - /* Wait until the host is ready to receive the request confirmation */ + /* Acknowledge status stage */ while (!(Endpoint_IsSetupINReady())); - - /* Handshake the request by sending an empty IN packet */ Endpoint_ClearSetupIN(); } @@ -229,6 +227,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Send the flag to the host */ Endpoint_ClearSetupIN(); + + /* Acknowledge status stage */ + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); } break; @@ -243,7 +245,8 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Set or clear the flag depending on what the host indicates that the current Protocol should be */ UsingReportProtocol = (wValue != 0x0000); - /* Send an empty packet to acknowedge the command */ + /* Acknowledge status stage */ + while (!(Endpoint_IsSetupINReady())); Endpoint_ClearSetupIN(); } @@ -259,7 +262,8 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Get idle period in MSB */ IdleCount = (wValue >> 8); - /* Send an empty packet to acknowedge the command */ + /* Acknowledge status stage */ + while (!(Endpoint_IsSetupINReady())); Endpoint_ClearSetupIN(); } @@ -274,6 +278,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Send the flag to the host */ Endpoint_ClearSetupIN(); + + /* Acknowledge status stage */ + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); } break; @@ -391,7 +399,16 @@ ISR(ENDPOINT_PIPE_vect, ISR_BLOCK) { USB_KeyboardReport_Data_t KeyboardReportData; bool SendReport; - + + /* Select the Keyboard Report Endpoint */ + Endpoint_SelectEndpoint(KEYBOARD_EPNUM); + + /* Clear the endpoint IN interrupt flag */ + USB_INT_Clear(ENDPOINT_INT_IN); + + /* Clear the Keyboard Report endpoint interrupt */ + Endpoint_ClearEndpointInterrupt(KEYBOARD_EPNUM); + /* Create the next keyboard report for transmission to the host */ SendReport = GetNextReport(&KeyboardReportData); @@ -408,15 +425,6 @@ ISR(ENDPOINT_PIPE_vect, ISR_BLOCK) /* Check to see if a report should be issued */ if (SendReport) { - /* Select the Keyboard Report Endpoint */ - Endpoint_SelectEndpoint(KEYBOARD_EPNUM); - - /* Clear the endpoint IN interrupt flag */ - USB_INT_Clear(ENDPOINT_INT_IN); - - /* Clear the Keyboard Report endpoint interrupt */ - Endpoint_ClearEndpointInterrupt(KEYBOARD_EPNUM); - /* Write Keyboard Report Data */ Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData)); }