Add demos/bootloaders/projects overview to the manual.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / CDC.c
index 8acaac7..fc6ea93 100644 (file)
   this software.\r
 */\r
 \r
-#define  INCLUDE_FROM_CDC_CLASS_C\r
+#include "../../HighLevel/USBMode.h"\r
+#if defined(USB_CAN_BE_DEVICE)\r
+\r
+#define  INCLUDE_FROM_CDC_CLASS_DEVICE_C\r
 #include "CDC.h"\r
 \r
-void USB_CDC_Event_Stub(void)\r
+void CDC_Device_Event_Stub(void)\r
 {\r
 \r
 }\r
 \r
-void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
+void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 {\r
        if (!(Endpoint_IsSETUPReceived()))\r
          return;\r
          \r
-       if (USB_ControlRequest.wIndex != CDCInterfaceInfo->ControlInterfaceNumber)\r
+       if (USB_ControlRequest.wIndex != CDCInterfaceInfo->Config.ControlInterfaceNumber)\r
          return;\r
 \r
        switch (USB_ControlRequest.bRequest)\r
@@ -50,7 +53,7 @@ void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
                        if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
-                               Endpoint_Write_Control_Stream_LE(&CDCInterfaceInfo->LineEncoding, sizeof(CDCInterfaceInfo->LineEncoding));\r
+                               Endpoint_Write_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));\r
                                Endpoint_ClearOUT();\r
                        }\r
                        \r
@@ -59,10 +62,10 @@ void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
-                               Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->LineEncoding, sizeof(CDCInterfaceInfo->LineEncoding));\r
+                               Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));\r
                                Endpoint_ClearIN();\r
 \r
-                               EVENT_USB_CDC_LineEncodingChanged(CDCInterfaceInfo);\r
+                               EVENT_CDC_Device_LineEncodingChanged(CDCInterfaceInfo);\r
                        }\r
        \r
                        break;\r
@@ -71,9 +74,9 @@ void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
                        {                               \r
                                Endpoint_ClearSETUP();\r
                                \r
-                               CDCInterfaceInfo->ControlLineState = USB_ControlRequest.wValue;\r
+                               CDCInterfaceInfo->State.ControlLineStates.HostToDevice = USB_ControlRequest.wValue;\r
                                \r
-                               EVENT_USB_CDC_ControLineStateChanged();\r
+                               EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo);\r
 \r
                                while (!(Endpoint_IsINReady()));\r
                                Endpoint_ClearIN();\r
@@ -83,24 +86,24 @@ void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
        }\r
 }\r
 \r
-bool USB_CDC_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
+bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 {\r
-       if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->DataINEndpointNumber, EP_TYPE_BULK,\r
-                                                                ENDPOINT_DIR_IN, CDCInterfaceInfo->DataINEndpointSize,\r
+       if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_BULK,\r
+                                                                ENDPOINT_DIR_IN, CDCInterfaceInfo->Config.DataINEndpointSize,\r
                                                                 ENDPOINT_BANK_SINGLE)))\r
        {\r
                return false;\r
        }\r
 \r
-       if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->DataOUTEndpointNumber, EP_TYPE_BULK,\r
-                                        ENDPOINT_DIR_OUT, CDCInterfaceInfo->DataOUTEndpointSize,\r
+       if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_BULK,\r
+                                        ENDPOINT_DIR_OUT, CDCInterfaceInfo->Config.DataOUTEndpointSize,\r
                                         ENDPOINT_BANK_SINGLE)))\r
        {\r
                return false;\r
        }\r
 \r
-       if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->NotificationEndpointNumber, EP_TYPE_INTERRUPT,\r
-                                        ENDPOINT_DIR_IN, CDCInterfaceInfo->NotificationEndpointSize,\r
+       if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->Config.NotificationEndpointNumber, EP_TYPE_INTERRUPT,\r
+                                        ENDPOINT_DIR_IN, CDCInterfaceInfo->Config.NotificationEndpointSize,\r
                                         ENDPOINT_BANK_SINGLE)))\r
        {\r
                return false;\r
@@ -109,12 +112,12 @@ bool USB_CDC_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
        return true;\r
 }\r
 \r
-void USB_CDC_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
+void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 {\r
        if (!(USB_IsConnected))\r
          return;\r
 \r
-       Endpoint_SelectEndpoint(CDCInterfaceInfo->DataINEndpointNumber);\r
+       Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);\r
 \r
        if (!(Endpoint_BytesInEndpoint()))\r
          return;\r
@@ -128,15 +131,21 @@ void USB_CDC_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
        Endpoint_ClearIN();\r
 }\r
 \r
-void USB_CDC_SendString(USB_ClassInfo_CDC_t* CDCInterfaceInfo, char* Data, uint16_t Length)\r
+void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, char* Data, uint16_t Length)\r
 {\r
-       Endpoint_SelectEndpoint(CDCInterfaceInfo->DataINEndpointNumber);\r
+       if (!(USB_IsConnected))\r
+         return;\r
+\r
+       Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);\r
        Endpoint_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK);\r
 }\r
 \r
-void USB_CDC_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data)\r
+void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, uint8_t Data)\r
 {\r
-       Endpoint_SelectEndpoint(CDCInterfaceInfo->DataINEndpointNumber);\r
+       if (!(USB_IsConnected))\r
+         return;\r
+\r
+       Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);\r
 \r
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
@@ -147,16 +156,19 @@ void USB_CDC_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data)
        Endpoint_Write_Byte(Data);      \r
 }\r
 \r
-uint16_t USB_CDC_BytesReceived(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
+uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 {\r
-       Endpoint_SelectEndpoint(CDCInterfaceInfo->DataOUTEndpointNumber);\r
+       Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);\r
 \r
        return Endpoint_BytesInEndpoint();\r
 }\r
 \r
-uint8_t USB_CDC_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
+uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 {\r
-       Endpoint_SelectEndpoint(CDCInterfaceInfo->DataOUTEndpointNumber);\r
+       if (!(USB_IsConnected))\r
+         return 0;\r
+\r
+       Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);\r
        \r
        uint8_t DataByte = Endpoint_Read_Byte();\r
        \r
@@ -166,9 +178,12 @@ uint8_t USB_CDC_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
        return DataByte;\r
 }\r
 \r
-void USB_CDC_SendSerialLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask)\r
+void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 {\r
-       Endpoint_SelectEndpoint(CDCInterfaceInfo->NotificationEndpointNumber);\r
+       if (!(USB_IsConnected))\r
+         return;\r
+\r
+       Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.NotificationEndpointNumber);\r
        \r
        USB_Request_Header_t Notification = (USB_Request_Header_t)\r
                {\r
@@ -180,6 +195,8 @@ void USB_CDC_SendSerialLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo, u
                };\r
 \r
        Endpoint_Write_Stream_LE(&Notification, sizeof(Notification), NO_STREAM_CALLBACK);\r
-       Endpoint_Write_Stream_LE(&LineStateMask, sizeof(LineStateMask), NO_STREAM_CALLBACK);\r
+       Endpoint_Write_Stream_LE(&CDCInterfaceInfo->State.ControlLineStates.DeviceToHost, sizeof(uint8_t), NO_STREAM_CALLBACK);\r
        Endpoint_ClearIN();\r
 }\r
+\r
+#endif\r