atmel-samd: Only output to USB after DTR and don't send anything larger than the room left in the USB TX buffer.

This commit is contained in:
Scott Shawcroft 2016-10-25 18:23:04 -07:00
parent b7768a74a7
commit 614c1fdba2
2 changed files with 17 additions and 4 deletions

View File

@ -54,8 +54,10 @@ extern void mp_cdc_disable(uint8_t port);
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
void usb_rx_notify(void);
#define UDI_CDC_SET_CODING_EXT(port,cfg)
#define UDI_CDC_SET_DTR_EXT(port,set)
#define UDI_CDC_SET_RTS_EXT(port,set)
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
void usb_dtr_notify(uint8_t port, bool set);
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)
void usb_rts_notify(uint8_t port, bool set);
/**
* USB CDC low level configuration

View File

@ -50,7 +50,7 @@ void mp_msc_disable()
bool mp_cdc_enable(uint8_t port)
{
mp_cdc_enabled = true;
mp_cdc_enabled = false;
return true;
}
@ -59,6 +59,14 @@ void mp_cdc_disable(uint8_t port)
mp_cdc_enabled = false;
}
void usb_dtr_notify(uint8_t port, bool set) {
mp_cdc_enabled = set;
}
void usb_rts_notify(uint8_t port, bool set) {
return;
}
void usb_rx_notify(void)
{
irqflags_t flags;
@ -177,7 +185,10 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
#endif
#ifdef USB_REPL
if (mp_cdc_enabled && udi_cdc_is_tx_ready()) {
// Always make sure there is enough room in the usb buffer for the outgoing
// string. If there isn't we risk getting caught in a loop within the usb
// code as it tries to send all the characters it can't buffer.
if (mp_cdc_enabled && udi_cdc_get_free_tx_buffer() >= len) {
udi_cdc_write_buf(str, len);
}
#endif