diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2012-05-10 19:24:58 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2012-05-10 19:24:58 +0000 |
commit | 359fbfe14d00ab378f85a36664820ea9ba538c3f (patch) | |
tree | 0929d5663a3be4dc078dda0aba5ba798ebb627ab /LUFA/Drivers/USB/Class/Device/CDCClassDevice.c | |
parent | e8570c4a37e41117e3fd1e989e0b41f1e9608f3c (diff) | |
download | lufa-359fbfe14d00ab378f85a36664820ea9ba538c3f.tar.gz lufa-359fbfe14d00ab378f85a36664820ea9ba538c3f.tar.bz2 lufa-359fbfe14d00ab378f85a36664820ea9ba538c3f.zip |
Add branch for the conversion of demos to use standard C header files for configuration, rather than makefile defined macros.
Diffstat (limited to 'LUFA/Drivers/USB/Class/Device/CDCClassDevice.c')
-rw-r--r-- | LUFA/Drivers/USB/Class/Device/CDCClassDevice.c | 69 |
1 files changed, 23 insertions, 46 deletions
diff --git a/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c b/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c index 5b5343860..ff0f9bb55 100644 --- a/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c +++ b/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c @@ -69,8 +69,12 @@ void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInter { Endpoint_ClearSETUP(); - while (!(Endpoint_IsOUTReceived())); - + while (!(Endpoint_IsOUTReceived())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } + CDCInterfaceInfo->State.LineEncoding.BaudRateBPS = Endpoint_Read_32_LE(); CDCInterfaceInfo->State.LineEncoding.CharFormat = Endpoint_Read_8(); CDCInterfaceInfo->State.LineEncoding.ParityType = Endpoint_Read_8(); @@ -112,45 +116,18 @@ bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* const CDCInterfac { memset(&CDCInterfaceInfo->State, 0x00, sizeof(CDCInterfaceInfo->State)); - for (uint8_t EndpointNum = 1; EndpointNum < ENDPOINT_TOTAL_ENDPOINTS; EndpointNum++) - { - uint16_t Size; - uint8_t Type; - uint8_t Direction; - bool DoubleBanked; + CDCInterfaceInfo->Config.DataINEndpoint.Type = EP_TYPE_BULK; + CDCInterfaceInfo->Config.DataOUTEndpoint.Type = EP_TYPE_BULK; + CDCInterfaceInfo->Config.NotificationEndpoint.Type = EP_TYPE_INTERRUPT; - if (EndpointNum == CDCInterfaceInfo->Config.DataINEndpointNumber) - { - Size = CDCInterfaceInfo->Config.DataINEndpointSize; - Direction = ENDPOINT_DIR_IN; - Type = EP_TYPE_BULK; - DoubleBanked = CDCInterfaceInfo->Config.DataINEndpointDoubleBank; - } - else if (EndpointNum == CDCInterfaceInfo->Config.DataOUTEndpointNumber) - { - Size = CDCInterfaceInfo->Config.DataOUTEndpointSize; - Direction = ENDPOINT_DIR_OUT; - Type = EP_TYPE_BULK; - DoubleBanked = CDCInterfaceInfo->Config.DataOUTEndpointDoubleBank; - } - else if (EndpointNum == CDCInterfaceInfo->Config.NotificationEndpointNumber) - { - Size = CDCInterfaceInfo->Config.NotificationEndpointSize; - Direction = ENDPOINT_DIR_IN; - Type = EP_TYPE_INTERRUPT; - DoubleBanked = CDCInterfaceInfo->Config.NotificationEndpointDoubleBank; - } - else - { - continue; - } + if (!(Endpoint_ConfigureEndpointTable(&CDCInterfaceInfo->Config.DataINEndpoint, 1))) + return false; - if (!(Endpoint_ConfigureEndpoint(EndpointNum, Type, Direction, Size, - DoubleBanked ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE))) - { - return false; - } - } + if (!(Endpoint_ConfigureEndpointTable(&CDCInterfaceInfo->Config.DataOUTEndpoint, 1))) + return false; + + if (!(Endpoint_ConfigureEndpointTable(&CDCInterfaceInfo->Config.NotificationEndpoint, 1))) + return false; return true; } @@ -171,7 +148,7 @@ uint8_t CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)) return ENDPOINT_RWSTREAM_DeviceDisconnected; - Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address); return Endpoint_Write_Stream_LE(String, strlen(String), NULL); } @@ -182,7 +159,7 @@ uint8_t CDC_Device_SendData(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)) return ENDPOINT_RWSTREAM_DeviceDisconnected; - Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address); return Endpoint_Write_Stream_LE(Buffer, Length, NULL); } @@ -192,7 +169,7 @@ uint8_t CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)) return ENDPOINT_RWSTREAM_DeviceDisconnected; - Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address); if (!(Endpoint_IsReadWriteAllowed())) { @@ -215,7 +192,7 @@ uint8_t CDC_Device_Flush(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) uint8_t ErrorCode; - Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address); if (!(Endpoint_BytesInEndpoint())) return ENDPOINT_READYWAIT_NoError; @@ -240,7 +217,7 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterface if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)) return 0; - Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber); + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpoint.Address); if (Endpoint_IsOUTReceived()) { @@ -267,7 +244,7 @@ int16_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInf int16_t ReceivedByte = -1; - Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber); + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpoint.Address); if (Endpoint_IsOUTReceived()) { @@ -286,7 +263,7 @@ void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDC if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)) return; - Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.NotificationEndpointNumber); + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.NotificationEndpoint.Address); USB_Request_Header_t Notification = (USB_Request_Header_t) { |