Browse Source

Report Serial bool operator true only after 25 ms

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
PaulStoffregen 9 years ago
parent
commit
1225f43fd0
4 changed files with 10 additions and 1 deletions
  1. +1
    -0
      teensy3/usb_dev.c
  2. +2
    -0
      teensy3/usb_dev.h
  3. +1
    -0
      teensy3/usb_serial.c
  4. +6
    -1
      teensy3/usb_serial.h

+ 1
- 0
teensy3/usb_dev.c View File

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;

+ 2
- 0
teensy3/usb_dev.h View File



#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);

+ 1
- 0
teensy3/usb_serial.c View File

#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;



+ 6
- 1
teensy3/usb_serial.h View File

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();

Loading…
Cancel
Save