Fixed EVENT_USB_CDC_ControLineStateChanged() event not taking the CDC interface struc...
[pub/USBasp.git] / Bootloaders / CDC / BootloaderCDC.c
index cb2672c..265e90f 100644 (file)
  *  current encoding options, including baud rate, character format, parity mode and total number of \r
  *  bits in each data chunk.\r
  */\r
  *  current encoding options, including baud rate, character format, parity mode and total number of \r
  *  bits in each data chunk.\r
  */\r
-CDC_Line_Coding_t LineCoding = { BaudRateBPS: 9600,\r
-                                 CharFormat:  OneStopBit,\r
-                                 ParityType:  Parity_None,\r
-                                 DataBits:    8            };\r
+CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,\r
+                                 .CharFormat  = OneStopBit,\r
+                                 .ParityType  = Parity_None,\r
+                                 .DataBits    = 8            };\r
 \r
 /** Current address counter. This stores the current address of the FLASH or EEPROM as set by the host,\r
  *  and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued\r
 \r
 /** Current address counter. This stores the current address of the FLASH or EEPROM as set by the host,\r
  *  and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued\r
@@ -119,7 +119,7 @@ int main(void)
 /** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user\r
  *  application started.\r
  */\r
 /** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user\r
  *  application started.\r
  */\r
-EVENT_HANDLER(USB_Disconnect)\r
+void EVENT_USB_Disconnect(void)\r
 {\r
        /* Upon disconnection, run user application */\r
        RunBootloader = false;\r
 {\r
        /* Upon disconnection, run user application */\r
        RunBootloader = false;\r
@@ -128,7 +128,7 @@ EVENT_HANDLER(USB_Disconnect)
 /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready\r
  *  to relay data to and from the attached USB host.\r
  */\r
 /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready\r
  *  to relay data to and from the attached USB host.\r
  */\r
-EVENT_HANDLER(USB_ConfigurationChanged)\r
+void EVENT_USB_ConfigurationChanged(void)\r
 {\r
        /* Setup CDC Notification, Rx and Tx Endpoints */\r
        Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
 {\r
        /* Setup CDC Notification, Rx and Tx Endpoints */\r
        Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
@@ -148,57 +148,55 @@ EVENT_HANDLER(USB_ConfigurationChanged)
  *  control requests that are not handled internally by the USB library, so that they can be handled appropriately\r
  *  for the application.\r
  */\r
  *  control requests that are not handled internally by the USB library, so that they can be handled appropriately\r
  *  for the application.\r
  */\r
-EVENT_HANDLER(USB_UnhandledControlPacket)\r
+void EVENT_USB_UnhandledControlPacket(void)\r
 {\r
        uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
 \r
 {\r
        uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
 \r
-       Endpoint_Discard_Word();\r
-\r
        /* Process CDC specific control requests */\r
        /* Process CDC specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetLineEncoding:\r
        {\r
                case REQ_GetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                        {\r
-                               Endpoint_ClearControlSETUP();\r
+                               Endpoint_ClearSETUP();\r
 \r
                                for (uint8_t i = 0; i < sizeof(LineCoding); i++)\r
                                  Endpoint_Write_Byte(*(LineCodingData++));     \r
                                \r
 \r
                                for (uint8_t i = 0; i < sizeof(LineCoding); i++)\r
                                  Endpoint_Write_Byte(*(LineCodingData++));     \r
                                \r
-                               Endpoint_ClearControlIN();\r
+                               Endpoint_ClearIN();\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsOUTReceived()));\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsOUTReceived()));\r
-                               Endpoint_ClearControlOUT();\r
+                               Endpoint_ClearOUT();\r
                        }\r
                        \r
                        break;\r
                case REQ_SetLineEncoding:\r
                        }\r
                        \r
                        break;\r
                case REQ_SetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                        {\r
-                               Endpoint_ClearControlSETUP();\r
+                               Endpoint_ClearSETUP();\r
 \r
                                while (!(Endpoint_IsOUTReceived()));\r
 \r
                                for (uint8_t i = 0; i < sizeof(LineCoding); i++)\r
                                  *(LineCodingData++) = Endpoint_Read_Byte();\r
 \r
 \r
                                while (!(Endpoint_IsOUTReceived()));\r
 \r
                                for (uint8_t i = 0; i < sizeof(LineCoding); i++)\r
                                  *(LineCodingData++) = Endpoint_Read_Byte();\r
 \r
-                               Endpoint_ClearControlOUT();\r
+                               Endpoint_ClearOUT();\r
 \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
 \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
-                               Endpoint_ClearControlIN();\r
+                               Endpoint_ClearIN();\r
                        }\r
        \r
                        break;\r
                case REQ_SetControlLineState:\r
                        }\r
        \r
                        break;\r
                case REQ_SetControlLineState:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                        {\r
-                               Endpoint_ClearControlSETUP();\r
+                               Endpoint_ClearSETUP();\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
-                               Endpoint_ClearControlIN();\r
+                               Endpoint_ClearIN();\r
                        }\r
        \r
                        break;\r
                        }\r
        \r
                        break;\r
@@ -352,7 +350,7 @@ static void WriteNextResponseByte(const uint8_t Response)
        /* Select the IN endpoint so that the next data byte can be written */\r
        Endpoint_SelectEndpoint(CDC_TX_EPNUM);\r
        \r
        /* Select the IN endpoint so that the next data byte can be written */\r
        Endpoint_SelectEndpoint(CDC_TX_EPNUM);\r
        \r
-       /* If OUT endpoint empty, clear it and wait for the next packet from the host */\r
+       /* If IN endpoint full, clear it and wait util ready for the next packet to the host */\r
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
                Endpoint_ClearIN();\r
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
                Endpoint_ClearIN();\r
@@ -426,9 +424,9 @@ TASK(CDC_Task)
                }\r
                else if (Command == 's')\r
                {\r
                }\r
                else if (Command == 's')\r
                {\r
-                       WriteNextResponseByte(SIGNATURE_0);\r
-                       WriteNextResponseByte(SIGNATURE_1);\r
                        WriteNextResponseByte(SIGNATURE_2);             \r
                        WriteNextResponseByte(SIGNATURE_2);             \r
+                       WriteNextResponseByte(SIGNATURE_1);\r
+                       WriteNextResponseByte(SIGNATURE_0);\r
                }\r
                else if (Command == 'b')\r
                {\r
                }\r
                else if (Command == 'b')\r
                {\r