X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/9991321321d30ca9383d795ea7e796098c92045f..a94b1911645b1f14f80eb0f1612d33f83866d4a3:/Demos/KeyboardFullInt/KeyboardFullInt.c?ds=inline diff --git a/Demos/KeyboardFullInt/KeyboardFullInt.c b/Demos/KeyboardFullInt/KeyboardFullInt.c index 7e90b5ff2..6a15a9233 100644 --- a/Demos/KeyboardFullInt/KeyboardFullInt.c +++ b/Demos/KeyboardFullInt/KeyboardFullInt.c @@ -70,8 +70,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(); @@ -212,10 +212,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(); } @@ -230,6 +228,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Send the flag to the host */ Endpoint_ClearSetupIN(); + + /* Acknowledge status stage */ + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); } break; @@ -244,7 +246,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(); } @@ -260,7 +263,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(); } @@ -275,6 +279,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket) /* Send the flag to the host */ Endpoint_ClearSetupIN(); + + /* Acknowledge status stage */ + while (!(Endpoint_IsSetupOUTReceived())); + Endpoint_ClearSetupOUT(); } break; @@ -404,6 +412,15 @@ 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); @@ -420,21 +437,12 @@ 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)); - - /* Finalize the stream transfer to send the last packet */ - Endpoint_ClearCurrentBank(); } + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearCurrentBank(); } /* Check if Keyboard LED status Endpoint has interrupted */