Sometimes the PC or Mac drivers are not actually ready to begin receiving data immediately after they cause DTR or RTS to assert. This delay allows the PC to become ready before we tell sketches the Serial device is true (ready).main
return; | return; | ||||
#if defined(CDC_STATUS_INTERFACE) | #if defined(CDC_STATUS_INTERFACE) | ||||
case 0x2221: // CDC_SET_CONTROL_LINE_STATE | case 0x2221: // CDC_SET_CONTROL_LINE_STATE | ||||
usb_cdc_line_rtsdtr_millis = systick_millis_count; | |||||
usb_cdc_line_rtsdtr = setup.wValue; | usb_cdc_line_rtsdtr = setup.wValue; | ||||
//serial_print("set control line state\n"); | //serial_print("set control line state\n"); | ||||
break; | break; |
#ifdef CDC_DATA_INTERFACE | #ifdef CDC_DATA_INTERFACE | ||||
extern uint32_t usb_cdc_line_coding[2]; | extern uint32_t usb_cdc_line_coding[2]; | ||||
extern volatile uint32_t usb_cdc_line_rtsdtr_millis; | |||||
extern volatile uint32_t systick_millis_count; | |||||
extern volatile uint8_t usb_cdc_line_rtsdtr; | extern volatile uint8_t usb_cdc_line_rtsdtr; | ||||
extern volatile uint8_t usb_cdc_transmit_flush_timer; | extern volatile uint8_t usb_cdc_transmit_flush_timer; | ||||
extern void usb_serial_flush_callback(void); | extern void usb_serial_flush_callback(void); |
#if F_CPU >= 20000000 | #if F_CPU >= 20000000 | ||||
uint32_t usb_cdc_line_coding[2]; | uint32_t usb_cdc_line_coding[2]; | ||||
volatile uint32_t usb_cdc_line_rtsdtr_millis; | |||||
volatile uint8_t usb_cdc_line_rtsdtr=0; | volatile uint8_t usb_cdc_line_rtsdtr=0; | ||||
volatile uint8_t usb_cdc_transmit_flush_timer=0; | volatile uint8_t usb_cdc_transmit_flush_timer=0; | ||||
int usb_serial_write_buffer_free(void); | int usb_serial_write_buffer_free(void); | ||||
void usb_serial_flush_output(void); | void usb_serial_flush_output(void); | ||||
extern uint32_t usb_cdc_line_coding[2]; | extern uint32_t usb_cdc_line_coding[2]; | ||||
extern volatile uint32_t usb_cdc_line_rtsdtr_millis; | |||||
extern volatile uint32_t systick_millis_count; | |||||
extern volatile uint8_t usb_cdc_line_rtsdtr; | extern volatile uint8_t usb_cdc_line_rtsdtr; | ||||
extern volatile uint8_t usb_cdc_transmit_flush_timer; | extern volatile uint8_t usb_cdc_transmit_flush_timer; | ||||
extern volatile uint8_t usb_configuration; | extern volatile uint8_t usb_configuration; | ||||
uint8_t numbits(void) { return usb_cdc_line_coding[1] >> 16; } | uint8_t numbits(void) { return usb_cdc_line_coding[1] >> 16; } | ||||
uint8_t dtr(void) { return (usb_cdc_line_rtsdtr & USB_SERIAL_DTR) ? 1 : 0; } | uint8_t dtr(void) { return (usb_cdc_line_rtsdtr & USB_SERIAL_DTR) ? 1 : 0; } | ||||
uint8_t rts(void) { return (usb_cdc_line_rtsdtr & USB_SERIAL_RTS) ? 1 : 0; } | uint8_t rts(void) { return (usb_cdc_line_rtsdtr & USB_SERIAL_RTS) ? 1 : 0; } | ||||
operator bool() { return usb_configuration && (usb_cdc_line_rtsdtr & (USB_SERIAL_DTR | USB_SERIAL_RTS)); } | |||||
operator bool() { return usb_configuration && | |||||
(usb_cdc_line_rtsdtr & (USB_SERIAL_DTR | USB_SERIAL_RTS)) && | |||||
((uint32_t)(systick_millis_count - usb_cdc_line_rtsdtr_millis) >= 25); | |||||
} | |||||
size_t readBytes(char *buffer, size_t length) { | size_t readBytes(char *buffer, size_t length) { | ||||
size_t count=0; | size_t count=0; | ||||
unsigned long startMillis = millis(); | unsigned long startMillis = millis(); |