Fixed USB_RemoteWakeupEnabled flag never being set (the REMOTE WAKEUP Set Feature...
[pub/USBasp.git] / Bootloaders / CDC / BootloaderCDC.c
index a1394bd..708ba35 100644 (file)
  *  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
@@ -90,7 +90,7 @@ int main(void)
        Endpoint_SelectEndpoint(CDC_TX_EPNUM);\r
 \r
        /* Wait until any pending transmissions have completed before shutting down */\r
-       while (!(Endpoint_ReadWriteAllowed()));\r
+       while (!(Endpoint_IsINReady()));\r
        \r
        /* Shut down the USB subsystem */\r
        USB_ShutDown();\r
@@ -152,53 +152,51 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
 {\r
        uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
 \r
-       Endpoint_Discard_Word();\r
-\r
        /* Process CDC specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\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
-                               Endpoint_ClearSetupReceived();\r
+                               Endpoint_ClearSETUP();\r
 \r
                                for (uint8_t i = 0; i < sizeof(LineCoding); i++)\r
                                  Endpoint_Write_Byte(*(LineCodingData++));     \r
                                \r
-                               Endpoint_ClearSetupIN();\r
+                               Endpoint_ClearIN();\r
                                \r
                                /* Acknowledge status stage */\r
-                               while (!(Endpoint_IsSetupOUTReceived()));\r
-                               Endpoint_ClearSetupOUT();\r
+                               while (!(Endpoint_IsOUTReceived()));\r
+                               Endpoint_ClearOUT();\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
-                               Endpoint_ClearSetupReceived();\r
+                               Endpoint_ClearSETUP();\r
 \r
-                               while (!(Endpoint_IsSetupOUTReceived()));\r
+                               while (!(Endpoint_IsOUTReceived()));\r
 \r
                                for (uint8_t i = 0; i < sizeof(LineCoding); i++)\r
                                  *(LineCodingData++) = Endpoint_Read_Byte();\r
 \r
-                               Endpoint_ClearSetupOUT();\r
+                               Endpoint_ClearOUT();\r
 \r
                                /* Acknowledge status stage */\r
-                               while (!(Endpoint_IsSetupINReady()));\r
-                               Endpoint_ClearSetupIN();\r
+                               while (!(Endpoint_IsINReady()));\r
+                               Endpoint_ClearIN();\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
-                               Endpoint_ClearSetupReceived();\r
+                               Endpoint_ClearSETUP();\r
                                \r
                                /* Acknowledge status stage */\r
-                               while (!(Endpoint_IsSetupINReady()));\r
-                               Endpoint_ClearSetupIN();\r
+                               while (!(Endpoint_IsINReady()));\r
+                               Endpoint_ClearIN();\r
                        }\r
        \r
                        break;\r
@@ -332,10 +330,10 @@ static uint8_t FetchNextCommandByte(void)
        Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r
        \r
        /* If OUT endpoint empty, clear it and wait for the next packet from the host */\r
-       if (!(Endpoint_ReadWriteAllowed()))\r
+       while (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
-               Endpoint_ClearCurrentBank();\r
-               while (!(Endpoint_ReadWriteAllowed()));\r
+               Endpoint_ClearOUT();\r
+               while (!(Endpoint_IsOUTReceived()));\r
        }\r
        \r
        /* Fetch the next byte from the OUT endpoint */\r
@@ -353,10 +351,10 @@ static void WriteNextResponseByte(const uint8_t Response)
        Endpoint_SelectEndpoint(CDC_TX_EPNUM);\r
        \r
        /* If OUT endpoint empty, clear it and wait for the next packet from the host */\r
-       if (!(Endpoint_ReadWriteAllowed()))\r
+       if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
-               Endpoint_ClearCurrentBank();\r
-               while (!(Endpoint_ReadWriteAllowed()));\r
+               Endpoint_ClearIN();\r
+               while (!(Endpoint_IsINReady()));\r
        }\r
        \r
        /* Write the next byte to the OUT endpoint */\r
@@ -372,7 +370,7 @@ TASK(CDC_Task)
        Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r
        \r
        /* Check if endpoint has a command in it sent from the host */\r
-       if (Endpoint_ReadWriteAllowed())\r
+       if (Endpoint_IsOUTReceived())\r
        {\r
                /* Read in the bootloader command (first byte sent from host) */\r
                uint8_t Command = FetchNextCommandByte();\r
@@ -510,7 +508,7 @@ TASK(CDC_Task)
                }\r
                else if ((Command == 'B') || (Command == 'g'))\r
                {\r
-                       /* Delegate the block write/read to a seperate function for clarity */\r
+                       /* Delegate the block write/read to a separate function for clarity */\r
                        ReadWriteMemoryBlock(Command);\r
                }\r
                else if (Command == 'R')\r
@@ -557,22 +555,22 @@ TASK(CDC_Task)
                Endpoint_SelectEndpoint(CDC_TX_EPNUM);\r
 \r
                /* Remember if the endpoint is completely full before clearing it */\r
-               bool IsEndpointFull = !(Endpoint_ReadWriteAllowed());\r
+               bool IsEndpointFull = !(Endpoint_IsReadWriteAllowed());\r
 \r
                /* Send the endpoint data to the host */\r
-               Endpoint_ClearCurrentBank();\r
+               Endpoint_ClearIN();\r
                \r
                /* If a full endpoint's worth of data was sent, we need to send an empty packet afterwards to signal end of transfer */\r
                if (IsEndpointFull)\r
                {\r
-                       while (!(Endpoint_ReadWriteAllowed()));\r
-                       Endpoint_ClearCurrentBank();\r
+                       while (!(Endpoint_IsINReady()));\r
+                       Endpoint_ClearIN();\r
                }\r
                \r
                /* Select the OUT endpoint */\r
                Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r
 \r
                /* Acknowledge the command from the host */\r
-               Endpoint_ClearCurrentBank();\r
+               Endpoint_ClearOUT();\r
        }\r
 }\r