@ -36,6 +36,7 @@
// Imports from Atmel USB Stack/CDC implementation
// Imports from Atmel USB Stack/CDC implementation
extern " C " {
extern " C " {
bool usb_task_cdc_isenabled ( void ) ;
bool usb_task_cdc_isenabled ( void ) ;
bool usb_task_cdc_dtr_active ( void ) ;
bool udi_cdc_is_rx_ready ( void ) ;
bool udi_cdc_is_rx_ready ( void ) ;
int udi_cdc_getc ( void ) ;
int udi_cdc_getc ( void ) ;
bool udi_cdc_is_tx_ready ( void ) ;
bool udi_cdc_is_tx_ready ( void ) ;
@ -56,9 +57,11 @@ int MarlinSerialUSB::peek(void) {
if ( pending_char > = 0 )
if ( pending_char > = 0 )
return pending_char ;
return pending_char ;
// If USB CDC not enumerated or not configured on the PC side
if ( ! usb_task_cdc_isenabled ( ) )
if ( ! usb_task_cdc_isenabled ( ) )
return - 1 ;
return - 1 ;
// If no bytes sent from the PC
if ( ! udi_cdc_is_rx_ready ( ) )
if ( ! udi_cdc_is_rx_ready ( ) )
return - 1 ;
return - 1 ;
@ -73,9 +76,11 @@ int MarlinSerialUSB::read(void) {
return ret ;
return ret ;
}
}
// If USB CDC not enumerated or not configured on the PC side
if ( ! usb_task_cdc_isenabled ( ) )
if ( ! usb_task_cdc_isenabled ( ) )
return - 1 ;
return - 1 ;
// If no bytes sent from the PC
if ( ! udi_cdc_is_rx_ready ( ) )
if ( ! udi_cdc_is_rx_ready ( ) )
return - 1 ;
return - 1 ;
@ -83,7 +88,10 @@ int MarlinSerialUSB::read(void) {
}
}
bool MarlinSerialUSB : : available ( void ) {
bool MarlinSerialUSB : : available ( void ) {
/* If Pending chars */
return pending_char > = 0 | |
return pending_char > = 0 | |
/* or USB CDC enumerated and configured on the PC side and some
bytes where sent to us */
( usb_task_cdc_isenabled ( ) & & udi_cdc_is_rx_ready ( ) ) ;
( usb_task_cdc_isenabled ( ) & & udi_cdc_is_rx_ready ( ) ) ;
}
}
@ -92,11 +100,22 @@ void MarlinSerialUSB::flush(void) {
void MarlinSerialUSB : : write ( const uint8_t c ) {
void MarlinSerialUSB : : write ( const uint8_t c ) {
/* Do not even bother sending anything if USB CDC is not enumerated
or not configured on the PC side or there is no program on the PC
listening to our messages */
if ( ! usb_task_cdc_isenabled ( ) | | ! usb_task_cdc_dtr_active ( ) )
return ;
/* Wait until the PC has read the pending to be sent data */
while ( usb_task_cdc_isenabled ( ) & &
while ( usb_task_cdc_isenabled ( ) & &
usb_task_cdc_dtr_active ( ) & &
! udi_cdc_is_tx_ready ( ) ) {
! udi_cdc_is_tx_ready ( ) ) {
} ;
} ;
if ( ! usb_task_cdc_isenabled ( ) )
/* Do not even bother sending anything if USB CDC is not enumerated
or not configured on the PC side or there is no program on the PC
listening to our messages at this point */
if ( ! usb_task_cdc_isenabled ( ) | | ! usb_task_cdc_dtr_active ( ) )
return ;
return ;
// Fifo full
// Fifo full