Minor updates to the Benito programmer - remove redundant PORT register manipulations.
[pub/USBasp.git] / Demos / Device / ClassDriver / USBtoSerial / USBtoSerial.c
index dbe21c2..637071a 100644 (file)
@@ -46,18 +46,26 @@ RingBuff_t Tx_Buffer;
  *  passed to all CDC Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
  */\r
-USB_ClassInfo_CDC_t VirtualSerial_CDC_Interface =\r
+USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =\r
        {\r
-               .ControlInterfaceNumber     = 0,\r
+               .Config = \r
+                       {\r
+                               .ControlInterfaceNumber     = 0,\r
 \r
-               .DataINEndpointNumber       = CDC_TX_EPNUM,\r
-               .DataINEndpointSize         = CDC_TXRX_EPSIZE,\r
+                               .DataINEndpointNumber       = CDC_TX_EPNUM,\r
+                               .DataINEndpointSize         = CDC_TXRX_EPSIZE,\r
 \r
-               .DataOUTEndpointNumber      = CDC_RX_EPNUM,\r
-               .DataOUTEndpointSize        = CDC_TXRX_EPSIZE,\r
+                               .DataOUTEndpointNumber      = CDC_RX_EPNUM,\r
+                               .DataOUTEndpointSize        = CDC_TXRX_EPSIZE,\r
 \r
-               .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,\r
-               .NotificationEndpointSize   = CDC_NOTIFICATION_EPSIZE,\r
+                               .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,\r
+                               .NotificationEndpointSize   = CDC_NOTIFICATION_EPSIZE,\r
+                       },\r
+               \r
+               .State =\r
+                       {\r
+                               // Leave all state values to their defaults\r
+                       }\r
        };\r
 \r
 /** Main program entry point. This routine contains the overall program flow, including initial\r
@@ -87,7 +95,7 @@ int main(void)
                if (Tx_Buffer.Elements)\r
                  CDC_Device_SendByte(&VirtualSerial_CDC_Interface, Buffer_GetElement(&Tx_Buffer));\r
                \r
-               /* Read bytes from the USART transmit buffer into the USART */\r
+               /* Load bytes from the USART transmit buffer into the USART */\r
                if (Rx_Buffer.Elements)\r
                  Serial_TxByte(Buffer_GetElement(&Rx_Buffer));\r
                \r
@@ -144,35 +152,46 @@ void EVENT_USB_UnhandledControlPacket(void)
  */\r
 ISR(USART1_RX_vect, ISR_BLOCK)\r
 {\r
-       if (USB_IsConnected)\r
+       if (USB_DeviceState == DEVICE_STATE_Configured)\r
          Buffer_StoreElement(&Tx_Buffer, UDR1);\r
 }\r
 \r
 /** Event handler for the CDC Class driver Line Encoding Changed event.\r
  *\r
- *  \param CDCInterfaceInfo  Pointer to the CDC class interface configuration structure being referenced\r
+ *  \param[in] CDCInterfaceInfo  Pointer to the CDC class interface configuration structure being referenced\r
  */\r
-void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
+void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)\r
 {\r
        uint8_t ConfigMask = 0;\r
 \r
-       if (CDCInterfaceInfo->LineEncoding.ParityType == CDC_PARITY_Odd)\r
-         ConfigMask = ((1 << UPM11) | (1 << UPM10));\r
-       else if (CDCInterfaceInfo->LineEncoding.ParityType == CDC_PARITY_Even)\r
-         ConfigMask = (1 << UPM11);\r
+       switch (CDCInterfaceInfo->State.LineEncoding.ParityType)\r
+       {\r
+               case CDC_PARITY_Odd:\r
+                       ConfigMask = ((1 << UPM11) | (1 << UPM10));             \r
+                       break;\r
+               case CDC_PARITY_Even:\r
+                       ConfigMask = (1 << UPM11);              \r
+                       break;\r
+       }\r
 \r
-       if (CDCInterfaceInfo->LineEncoding.CharFormat == CDC_LINEENCODING_TwoStopBits)\r
+       if (CDCInterfaceInfo->State.LineEncoding.CharFormat == CDC_LINEENCODING_TwoStopBits)\r
          ConfigMask |= (1 << USBS1);\r
 \r
-       if (CDCInterfaceInfo->LineEncoding.DataBits == 6)\r
-         ConfigMask |= (1 << UCSZ10);\r
-       else if (CDCInterfaceInfo->LineEncoding.DataBits == 7)\r
-         ConfigMask |= (1 << UCSZ11);\r
-       else if (CDCInterfaceInfo->LineEncoding.DataBits == 8)\r
-         ConfigMask |= ((1 << UCSZ11) | (1 << UCSZ10));\r
+       switch (CDCInterfaceInfo->State.LineEncoding.DataBits)\r
+       {\r
+               case 6:\r
+                       ConfigMask |= (1 << UCSZ10);\r
+                       break;\r
+               case 7:\r
+                       ConfigMask |= (1 << UCSZ11);\r
+                       break;\r
+               case 8:\r
+                       ConfigMask |= ((1 << UCSZ11) | (1 << UCSZ10));\r
+                       break;\r
+       }\r
        \r
        UCSR1A = (1 << U2X1);   \r
        UCSR1B = ((1 << RXCIE1) | (1 << TXEN1) | (1 << RXEN1));\r
        UCSR1C = ConfigMask;    \r
-       UBRR1  = SERIAL_2X_UBBRVAL((uint16_t)CDCInterfaceInfo->LineEncoding.BaudRateBPS);\r
+       UBRR1  = SERIAL_2X_UBBRVAL((uint16_t)CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);\r
 }\r