projects
/
pub
/
USBasp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed inability to enumerate any devices while in host mode (broken in a previous...
[pub/USBasp.git]
/
Demos
/
Device
/
DualCDC
/
DualCDC.c
diff --git
a/Demos/Device/DualCDC/DualCDC.c
b/Demos/Device/DualCDC/DualCDC.c
index
3c598da
..
4185a76
100644
(file)
--- a/
Demos/Device/DualCDC/DualCDC.c
+++ b/
Demos/Device/DualCDC/DualCDC.c
@@
-36,18
+36,12
@@
\r
#include "DualCDC.h"
\r
\r
\r
#include "DualCDC.h"
\r
\r
-/* Project Tags, for reading out using the ButtLoad project */
\r
-BUTTLOADTAG(ProjName, "LUFA DualCDC App");
\r
-BUTTLOADTAG(BuildTime, __TIME__);
\r
-BUTTLOADTAG(BuildDate, __DATE__);
\r
-BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING);
\r
-
\r
/* Scheduler Task List */
\r
TASK_LIST
\r
{
\r
/* Scheduler Task List */
\r
TASK_LIST
\r
{
\r
- {
Task: USB_USBTask , TaskStatus:
TASK_STOP },
\r
- {
Task: CDC1_Task , TaskStatus:
TASK_STOP },
\r
- {
Task: CDC2_Task , TaskStatus:
TASK_STOP },
\r
+ {
.Task = USB_USBTask , .TaskStatus =
TASK_STOP },
\r
+ {
.Task = CDC1_Task , .TaskStatus =
TASK_STOP },
\r
+ {
.Task = CDC2_Task , .TaskStatus =
TASK_STOP },
\r
};
\r
\r
/* Globals: */
\r
};
\r
\r
/* Globals: */
\r
@@
-57,12
+51,12
@@
TASK_LIST
*
\r
* These values are set by the host via a class-specific request, however they are not required to be used accurately.
\r
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
\r
*
\r
* These values are set by the host via a class-specific request, however they are not required to be used accurately.
\r
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
\r
- * serial link characteristics and instead sends and rec
ie
ves data in endpoint streams.
\r
+ * serial link characteristics and instead sends and rec
ei
ves data in endpoint streams.
\r
*/
\r
*/
\r
-CDC_Line_Coding_t LineCoding1 = {
BaudRateBPS:
9600,
\r
-
CharFormat:
OneStopBit,
\r
-
ParityType:
Parity_None,
\r
-
DataBits:
8 };
\r
+CDC_Line_Coding_t LineCoding1 = {
.BaudRateBPS =
9600,
\r
+
.CharFormat =
OneStopBit,
\r
+
.ParityType =
Parity_None,
\r
+
.DataBits =
8 };
\r
\r
/** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use
\r
* the physical USART and thus does not use these settings, they must still be retained and returned to the host
\r
\r
/** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use
\r
* the physical USART and thus does not use these settings, they must still be retained and returned to the host
\r
@@
-70,17
+64,17
@@
CDC_Line_Coding_t LineCoding1 = { BaudRateBPS: 9600,
*
\r
* These values are set by the host via a class-specific request, however they are not required to be used accurately.
\r
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
\r
*
\r
* These values are set by the host via a class-specific request, however they are not required to be used accurately.
\r
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
\r
- * serial link characteristics and instead sends and rec
ie
ves data in endpoint streams.
\r
+ * serial link characteristics and instead sends and rec
ei
ves data in endpoint streams.
\r
*/
\r
*/
\r
-CDC_Line_Coding_t LineCoding2 = {
BaudRateBPS:
9600,
\r
-
CharFormat:
OneStopBit,
\r
-
ParityType:
Parity_None,
\r
-
DataBits:
8 };
\r
+CDC_Line_Coding_t LineCoding2 = {
.BaudRateBPS =
9600,
\r
+
.CharFormat =
OneStopBit,
\r
+
.ParityType =
Parity_None,
\r
+
.DataBits =
8 };
\r
\r
/** String to print through the first virtual serial port when the joystick is pressed upwards. */
\r
char JoystickUpString[] = "Joystick Up\r\n";
\r
\r
\r
/** String to print through the first virtual serial port when the joystick is pressed upwards. */
\r
char JoystickUpString[] = "Joystick Up\r\n";
\r
\r
-/** String to print through the first virtual serial port when the joystick is pressed downward
s
. */
\r
+/** String to print through the first virtual serial port when the joystick is pressed downward. */
\r
char JoystickDownString[] = "Joystick Down\r\n";
\r
\r
/** String to print through the first virtual serial port when the joystick is pressed left. */
\r
char JoystickDownString[] = "Joystick Down\r\n";
\r
\r
/** String to print through the first virtual serial port when the joystick is pressed left. */
\r
@@
-195,7
+189,7
@@
EVENT_HANDLER(USB_UnhandledControlPacket)
uint8_t* LineCodingData;
\r
\r
/* Discard the unused wValue parameter */
\r
uint8_t* LineCodingData;
\r
\r
/* Discard the unused wValue parameter */
\r
- Endpoint_
Ignore
_Word();
\r
+ Endpoint_
Discard
_Word();
\r
\r
/* wIndex indicates the interface being controlled */
\r
uint16_t wIndex = Endpoint_Read_Word_LE();
\r
\r
/* wIndex indicates the interface being controlled */
\r
uint16_t wIndex = Endpoint_Read_Word_LE();
\r
@@
-204,45
+198,45
@@
EVENT_HANDLER(USB_UnhandledControlPacket)
LineCodingData = (wIndex == 0) ? (uint8_t*)&LineCoding1 : (uint8_t*)&LineCoding2;
\r
\r
/* Process CDC specific control requests */
\r
LineCodingData = (wIndex == 0) ? (uint8_t*)&LineCoding1 : (uint8_t*)&LineCoding2;
\r
\r
/* Process CDC specific control requests */
\r
- switch (bRequest)
\r
+ switch (
USB_ControlRequest.
bRequest)
\r
{
\r
case REQ_GetLineEncoding:
\r
{
\r
case REQ_GetLineEncoding:
\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
\r
+ if (
USB_ControlRequest.
bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
\r
{
\r
/* Acknowledge the SETUP packet, ready for data transfer */
\r
{
\r
/* Acknowledge the SETUP packet, ready for data transfer */
\r
- Endpoint_ClearS
etupReceived
();
\r
+ Endpoint_ClearS
ETUP
();
\r
\r
/* Write the line coding data to the control endpoint */
\r
Endpoint_Write_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t));
\r
\r
/* Finalize the stream transfer to send the last packet or clear the host abort */
\r
\r
/* Write the line coding data to the control endpoint */
\r
Endpoint_Write_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t));
\r
\r
/* Finalize the stream transfer to send the last packet or clear the host abort */
\r
- Endpoint_Clear
Setup
OUT();
\r
+ Endpoint_ClearOUT();
\r
}
\r
\r
break;
\r
case REQ_SetLineEncoding:
\r
}
\r
\r
break;
\r
case REQ_SetLineEncoding:
\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
\r
+ if (
USB_ControlRequest.
bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
\r
{
\r
/* Acknowledge the SETUP packet, ready for data transfer */
\r
{
\r
/* Acknowledge the SETUP packet, ready for data transfer */
\r
- Endpoint_ClearS
etupReceived
();
\r
+ Endpoint_ClearS
ETUP
();
\r
\r
/* Read the line coding data in from the host into the global struct */
\r
Endpoint_Read_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t));
\r
\r
/* Finalize the stream transfer to clear the last packet from the host */
\r
\r
/* Read the line coding data in from the host into the global struct */
\r
Endpoint_Read_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t));
\r
\r
/* Finalize the stream transfer to clear the last packet from the host */
\r
- Endpoint_Clear
Setup
IN();
\r
+ Endpoint_ClearIN();
\r
}
\r
\r
break;
\r
case REQ_SetControlLineState:
\r
}
\r
\r
break;
\r
case REQ_SetControlLineState:
\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
\r
+ if (
USB_ControlRequest.
bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
\r
{
\r
/* Acknowledge the SETUP packet, ready for data transfer */
\r
{
\r
/* Acknowledge the SETUP packet, ready for data transfer */
\r
- Endpoint_ClearS
etupReceived
();
\r
+ Endpoint_ClearS
ETUP
();
\r
\r
/* Acknowledge status stage */
\r
\r
/* Acknowledge status stage */
\r
- while (!(Endpoint_Is
Setup
INReady()));
\r
- Endpoint_Clear
Setup
IN();
\r
+ while (!(Endpoint_IsINReady()));
\r
+ Endpoint_ClearIN();
\r
}
\r
\r
break;
\r
}
\r
\r
break;
\r
@@
-313,18
+307,24
@@
TASK(CDC1_Task)
Endpoint_Write_Stream_LE(ReportString, strlen(ReportString));
\r
\r
/* Finalize the stream transfer to send the last packet */
\r
Endpoint_Write_Stream_LE(ReportString, strlen(ReportString));
\r
\r
/* Finalize the stream transfer to send the last packet */
\r
- Endpoint_ClearCurrentBank();
\r
+ Endpoint_ClearIN();
\r
+
\r
+ /* Wait until the endpoint is ready for another packet */
\r
+ while (!(Endpoint_IsINReady()));
\r
+
\r
+ /* Send an empty packet to ensure that the host does not buffer data sent to it */
\r
+ Endpoint_ClearIN();
\r
}
\r
\r
/* Select the Serial Rx Endpoint */
\r
Endpoint_SelectEndpoint(CDC1_RX_EPNUM);
\r
\r
/* Throw away any received data from the host */
\r
}
\r
\r
/* Select the Serial Rx Endpoint */
\r
Endpoint_SelectEndpoint(CDC1_RX_EPNUM);
\r
\r
/* Throw away any received data from the host */
\r
- if (Endpoint_
ReadWriteAllow
ed())
\r
- Endpoint_Clear
CurrentBank
();
\r
+ if (Endpoint_
IsOUTReceiv
ed())
\r
+ Endpoint_Clear
OUT
();
\r
}
\r
\r
}
\r
\r
-/** Function to manage CDC data transmission and reception to and from the host for the second CDC interface, which echos back
\r
+/** Function to manage CDC data transmission and reception to and from the host for the second CDC interface, which echo
e
s back
\r
* all data sent to it from the host.
\r
*/
\r
TASK(CDC2_Task)
\r
* all data sent to it from the host.
\r
*/
\r
TASK(CDC2_Task)
\r
@@
-333,19
+333,19
@@
TASK(CDC2_Task)
Endpoint_SelectEndpoint(CDC2_RX_EPNUM);
\r
\r
/* Check to see if any data has been received */
\r
Endpoint_SelectEndpoint(CDC2_RX_EPNUM);
\r
\r
/* Check to see if any data has been received */
\r
- if (Endpoint_
ReadWriteAllow
ed())
\r
+ if (Endpoint_
IsOUTReceiv
ed())
\r
{
\r
{
\r
- /* Create a temp buffer big enough to hold the incom
m
ing endpoint packet */
\r
+ /* Create a temp buffer big enough to hold the incoming endpoint packet */
\r
uint8_t Buffer[Endpoint_BytesInEndpoint()];
\r
\r
uint8_t Buffer[Endpoint_BytesInEndpoint()];
\r
\r
- /* Remember how large the incom
m
ing packet is */
\r
+ /* Remember how large the incoming packet is */
\r
uint16_t DataLength = Endpoint_BytesInEndpoint();
\r
\r
uint16_t DataLength = Endpoint_BytesInEndpoint();
\r
\r
- /* Read in the incom
m
ing packet into the buffer */
\r
+ /* Read in the incoming packet into the buffer */
\r
Endpoint_Read_Stream_LE(&Buffer, DataLength);
\r
\r
/* Finalize the stream transfer to send the last packet */
\r
Endpoint_Read_Stream_LE(&Buffer, DataLength);
\r
\r
/* Finalize the stream transfer to send the last packet */
\r
- Endpoint_Clear
CurrentBank
();
\r
+ Endpoint_Clear
OUT
();
\r
\r
/* Select the Serial Tx Endpoint */
\r
Endpoint_SelectEndpoint(CDC2_TX_EPNUM);
\r
\r
/* Select the Serial Tx Endpoint */
\r
Endpoint_SelectEndpoint(CDC2_TX_EPNUM);
\r
@@
-354,6
+354,12
@@
TASK(CDC2_Task)
Endpoint_Write_Stream_LE(&Buffer, DataLength);
\r
\r
/* Finalize the stream transfer to send the last packet */
\r
Endpoint_Write_Stream_LE(&Buffer, DataLength);
\r
\r
/* Finalize the stream transfer to send the last packet */
\r
- Endpoint_ClearCurrentBank();
\r
+ Endpoint_ClearIN();
\r
+
\r
+ /* Wait until the endpoint is ready for the next packet */
\r
+ while (!(Endpoint_IsINReady()));
\r
+
\r
+ /* Send an empty packet to prevent host buffering */
\r
+ Endpoint_ClearIN();
\r
}
\r
}
\r
}
\r
}
\r