aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Device
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-08-04 08:06:26 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-08-04 08:06:26 +0000
commiteff07bb87758a12064d9de9c859b1e6e6502f2ea (patch)
tree1849b829b24d4c088fa97501d4cbfe63fd53ef13 /Demos/Device
parent5c069f909a844caa921e643d2b7d52ad61f544f6 (diff)
downloadlufa-eff07bb87758a12064d9de9c859b1e6e6502f2ea.tar.gz
lufa-eff07bb87758a12064d9de9c859b1e6e6502f2ea.tar.bz2
lufa-eff07bb87758a12064d9de9c859b1e6e6502f2ea.zip
Fix issue with CDC device demos causing broken communications when the device tries to send data before the host has set the line encoding.
Diffstat (limited to 'Demos/Device')
-rw-r--r--Demos/Device/LowLevel/CDC/CDC.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/Demos/Device/LowLevel/CDC/CDC.c b/Demos/Device/LowLevel/CDC/CDC.c
index 8a992c767..73b486ccd 100644
--- a/Demos/Device/LowLevel/CDC/CDC.c
+++ b/Demos/Device/LowLevel/CDC/CDC.c
@@ -49,6 +49,12 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,
.CharFormat = OneStopBit,
.ParityType = Parity_None,
.DataBits = 8 };
+
+/** Indicates if the host has set the device line encoding. Until the line encoding is set by the host, the device should
+ * not attempt to send any bytes.
+ */
+bool LineEncodingSet = false;
+
#if 0
/* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in
@@ -59,6 +65,9 @@ static int CDC_putchar(char c, FILE *stream)
{
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
+ if (!(LineEncodingSet))
+ return -1;
+
while (!(Endpoint_IsReadWriteAllowed()))
{
if (USB_DeviceState != DEVICE_STATE_Configured)
@@ -74,7 +83,10 @@ static int CDC_putchar(char c, FILE *stream)
static int CDC_getchar(FILE *stream)
{
int c;
-
+
+ if (!(LineEncodingSet))
+ return -1;
+
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
for (;;)
@@ -216,6 +228,9 @@ void EVENT_USB_UnhandledControlPacket(void)
/* Read the line coding data in from the host into the global struct */
Endpoint_Read_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t));
+
+ /* Indicate that the line encoding has been set, and the device may now send data */
+ LineEncodingSet = true;
/* Finalize the stream transfer to clear the last packet from the host */
Endpoint_ClearIN();
@@ -299,7 +314,7 @@ void CDC_Task(void)
{
ActionSent = false;
}
- else if (ActionSent == false)
+ else if ((ActionSent == false) && LineEncodingSet)
{
ActionSent = true;