|
@@ -36,6 +36,7 @@
|
36
|
36
|
// Imports from Atmel USB Stack/CDC implementation
|
37
|
37
|
extern "C" {
|
38
|
38
|
bool usb_task_cdc_isenabled(void);
|
|
39
|
+ bool usb_task_cdc_dtr_active(void);
|
39
|
40
|
bool udi_cdc_is_rx_ready(void);
|
40
|
41
|
int udi_cdc_getc(void);
|
41
|
42
|
bool udi_cdc_is_tx_ready(void);
|
|
@@ -56,9 +57,11 @@ int MarlinSerialUSB::peek(void) {
|
56
|
57
|
if (pending_char >= 0)
|
57
|
58
|
return pending_char;
|
58
|
59
|
|
|
60
|
+ // If USB CDC not enumerated or not configured on the PC side
|
59
|
61
|
if (!usb_task_cdc_isenabled())
|
60
|
62
|
return -1;
|
61
|
63
|
|
|
64
|
+ // If no bytes sent from the PC
|
62
|
65
|
if (!udi_cdc_is_rx_ready())
|
63
|
66
|
return -1;
|
64
|
67
|
|
|
@@ -73,9 +76,11 @@ int MarlinSerialUSB::read(void) {
|
73
|
76
|
return ret;
|
74
|
77
|
}
|
75
|
78
|
|
|
79
|
+ // If USB CDC not enumerated or not configured on the PC side
|
76
|
80
|
if (!usb_task_cdc_isenabled())
|
77
|
81
|
return -1;
|
78
|
82
|
|
|
83
|
+ // If no bytes sent from the PC
|
79
|
84
|
if (!udi_cdc_is_rx_ready())
|
80
|
85
|
return -1;
|
81
|
86
|
|
|
@@ -83,7 +88,10 @@ int MarlinSerialUSB::read(void) {
|
83
|
88
|
}
|
84
|
89
|
|
85
|
90
|
bool MarlinSerialUSB::available(void) {
|
|
91
|
+ /* If Pending chars */
|
86
|
92
|
return pending_char >= 0 ||
|
|
93
|
+ /* or USB CDC enumerated and configured on the PC side and some
|
|
94
|
+ bytes where sent to us */
|
87
|
95
|
(usb_task_cdc_isenabled() && udi_cdc_is_rx_ready());
|
88
|
96
|
}
|
89
|
97
|
|
|
@@ -92,11 +100,22 @@ void MarlinSerialUSB::flush(void) {
|
92
|
100
|
|
93
|
101
|
void MarlinSerialUSB::write(const uint8_t c) {
|
94
|
102
|
|
|
103
|
+ /* Do not even bother sending anything if USB CDC is not enumerated
|
|
104
|
+ or not configured on the PC side or there is no program on the PC
|
|
105
|
+ listening to our messages */
|
|
106
|
+ if (!usb_task_cdc_isenabled() || !usb_task_cdc_dtr_active())
|
|
107
|
+ return;
|
|
108
|
+
|
|
109
|
+ /* Wait until the PC has read the pending to be sent data */
|
95
|
110
|
while (usb_task_cdc_isenabled() &&
|
|
111
|
+ usb_task_cdc_dtr_active() &&
|
96
|
112
|
!udi_cdc_is_tx_ready()) {
|
97
|
113
|
};
|
98
|
114
|
|
99
|
|
- if (!usb_task_cdc_isenabled())
|
|
115
|
+ /* Do not even bother sending anything if USB CDC is not enumerated
|
|
116
|
+ or not configured on the PC side or there is no program on the PC
|
|
117
|
+ listening to our messages at this point */
|
|
118
|
+ if (!usb_task_cdc_isenabled() || !usb_task_cdc_dtr_active())
|
100
|
119
|
return;
|
101
|
120
|
|
102
|
121
|
// Fifo full
|