X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/de70f0f1cf034d8f22141a2825f24ad60d14421b..c58c53dba90fdc19d38f5e5d6957f2ede2a740f3:/Projects/USBtoSerial/USBtoSerial.c diff --git a/Projects/USBtoSerial/USBtoSerial.c b/Projects/USBtoSerial/USBtoSerial.c index 31c80da1e..73be33e1f 100644 --- a/Projects/USBtoSerial/USBtoSerial.c +++ b/Projects/USBtoSerial/USBtoSerial.c @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -37,10 +37,10 @@ #include "USBtoSerial.h" /** Circular buffer to hold data from the host before it is sent to the device via the serial port. */ -RingBuff_t Rx_Buffer; +RingBuff_t USBtoUSART_Buffer; /** Circular buffer to hold data from the serial port before it is sent to the host. */ -RingBuff_t Tx_Buffer; +RingBuff_t USARTtoUSB_Buffer; /** LUFA CDC Class driver interface configuration and state information. This structure is * passed to all CDC Class driver functions, so that multiple instances of the same class @@ -50,16 +50,19 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = { .Config = { - .ControlInterfaceNumber = 0, + .ControlInterfaceNumber = 0, - .DataINEndpointNumber = CDC_TX_EPNUM, - .DataINEndpointSize = CDC_TXRX_EPSIZE, + .DataINEndpointNumber = CDC_TX_EPNUM, + .DataINEndpointSize = CDC_TXRX_EPSIZE, + .DataINEndpointDoubleBank = false, - .DataOUTEndpointNumber = CDC_RX_EPNUM, - .DataOUTEndpointSize = CDC_TXRX_EPSIZE, + .DataOUTEndpointNumber = CDC_RX_EPNUM, + .DataOUTEndpointSize = CDC_TXRX_EPSIZE, + .DataOUTEndpointDoubleBank = false, - .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, - .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, + .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, + .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, + .NotificationEndpointDoubleBank = false, }, }; @@ -70,8 +73,8 @@ int main(void) { SetupHardware(); - Buffer_Initialize(&Rx_Buffer); - Buffer_Initialize(&Tx_Buffer); + Buffer_Initialize(&USBtoUSART_Buffer); + Buffer_Initialize(&USARTtoUSB_Buffer); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); @@ -80,19 +83,19 @@ int main(void) /* Read bytes from the USB OUT endpoint into the USART transmit buffer */ for (uint8_t DataBytesRem = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); DataBytesRem != 0; DataBytesRem--) { - if (!(BUFF_STATICSIZE - Rx_Buffer.Elements)) + if (!(BUFF_STATICSIZE - USBtoUSART_Buffer.Elements)) break; - Buffer_StoreElement(&Rx_Buffer, CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface)); + Buffer_StoreElement(&USBtoUSART_Buffer, CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface)); } /* Read bytes from the USART receive buffer into the USB IN endpoint */ - if (Tx_Buffer.Elements) - CDC_Device_SendByte(&VirtualSerial_CDC_Interface, Buffer_GetElement(&Tx_Buffer)); + while (USARTtoUSB_Buffer.Elements) + CDC_Device_SendByte(&VirtualSerial_CDC_Interface, Buffer_GetElement(&USARTtoUSB_Buffer)); /* Load bytes from the USART transmit buffer into the USART */ - if (Rx_Buffer.Elements) - Serial_TxByte(Buffer_GetElement(&Rx_Buffer)); + while (USBtoUSART_Buffer.Elements) + Serial_TxByte(Buffer_GetElement(&USBtoUSART_Buffer)); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); @@ -150,7 +153,7 @@ ISR(USART1_RX_vect, ISR_BLOCK) uint8_t ReceivedByte = UDR1; if (USB_DeviceState == DEVICE_STATE_Configured) - Buffer_StoreElement(&Tx_Buffer, ReceivedByte); + Buffer_StoreElement(&USARTtoUSB_Buffer, ReceivedByte); } /** Event handler for the CDC Class driver Line Encoding Changed event.