atmel-samd: Stop hanging on usb write when a terminal isn't connected by checking DTR status.

This commit is contained in:
Scott Shawcroft 2017-10-25 17:38:17 -07:00 committed by Dan Halbert
parent db918da5f0
commit ab7da9353a

View File

@ -175,9 +175,11 @@ static bool write_complete(const uint8_t ep,
}
volatile bool reset_on_disconnect = false;
volatile bool cdc_connected = false;
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
{
cdc_connected = state.rs232.DTR;
if (state.rs232.DTR) {
} else if (!state.rs232.DTR && reset_on_disconnect) {
reset_to_bootloader();
@ -282,6 +284,10 @@ void usb_write(const char* buffer, uint32_t len) {
if (!cdc_enabled()) {
return;
}
if (!cdc_connected) {
// TODO(tannewt): Should we write to a file instead?
return;
}
uint8_t * output_buffer;
uint8_t output_len;
while (len > 0) {