X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/c5038f1bf44aea75f1ae1ed035cb7d523ccfdacb..09bedd6555a72c70f6d6bfb965225d44dec171cd:/Demos/Device/LowLevel/CDC/CDC.c diff --git a/Demos/Device/LowLevel/CDC/CDC.c b/Demos/Device/LowLevel/CDC/CDC.c index 9ee744ea0..0c98c11af 100644 --- a/Demos/Device/LowLevel/CDC/CDC.c +++ b/Demos/Device/LowLevel/CDC/CDC.c @@ -62,11 +62,8 @@ static int CDC_putchar(char c, FILE *stream) if (!(LineEncoding.BaudRateBPS)) return -1; - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState != DEVICE_STATE_Configured) - return -1; - } + if (Endpoint_WaitUntilReady()) + return -1; Endpoint_Write_Byte(c); Endpoint_ClearIN(); @@ -85,11 +82,8 @@ static int CDC_getchar(FILE *stream) for (;;) { - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState != DEVICE_STATE_Configured) - return -1; - } + if (Endpoint_WaitUntilReady()) + return -1; if (!(Endpoint_BytesInEndpoint())) { @@ -253,14 +247,6 @@ void CDC_Task(void) char* ReportString = NULL; uint8_t JoyStatus_LCL = Joystick_GetStatus(); static bool ActionSent = false; - char* JoystickStrings[] = - { - "Joystick Up\r\n", - "Joystick Down\r\n", - "Joystick Left\r\n", - "Joystick Right\r\n", - "Joystick Pressed\r\n", - }; /* Device must be connected and configured for the task to run */ if (USB_DeviceState != DEVICE_STATE_Configured) @@ -291,22 +277,20 @@ void CDC_Task(void) /* Determine if a joystick action has occurred */ if (JoyStatus_LCL & JOY_UP) - ReportString = JoystickStrings[0]; + ReportString = "Joystick Up\r\n"; else if (JoyStatus_LCL & JOY_DOWN) - ReportString = JoystickStrings[1]; + ReportString = "Joystick Down\r\n"; else if (JoyStatus_LCL & JOY_LEFT) - ReportString = JoystickStrings[2]; + ReportString = "Joystick Left\r\n"; else if (JoyStatus_LCL & JOY_RIGHT) - ReportString = JoystickStrings[3]; + ReportString = "Joystick Right\r\n"; else if (JoyStatus_LCL & JOY_PRESS) - ReportString = JoystickStrings[4]; + ReportString = "Joystick Pressed\r\n"; + else + ActionSent = false; /* Flag management - Only allow one string to be sent per action */ - if (ReportString == NULL) - { - ActionSent = false; - } - else if ((ActionSent == false) && LineEncoding.BaudRateBPS) + if ((ReportString != NULL) && (ActionSent == false) && LineEncoding.BaudRateBPS) { ActionSent = true; @@ -327,11 +311,7 @@ void CDC_Task(void) if (IsFull) { /* Wait until the endpoint is ready for another packet */ - while (!(Endpoint_IsINReady())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } + Endpoint_WaitUntilReady(); /* Send an empty packet to ensure that the host does not buffer data sent to it */ Endpoint_ClearIN();