Sfoglia il codice sorgente

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).
teensy4-core
PaulStoffregen 8 anni fa
parent
commit
1225f43fd0
4 ha cambiato i file con 10 aggiunte e 1 eliminazioni
  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 Vedi File

@@ -331,6 +331,7 @@ static void usb_setup(void)
return;
#if defined(CDC_STATUS_INTERFACE)
case 0x2221: // CDC_SET_CONTROL_LINE_STATE
usb_cdc_line_rtsdtr_millis = systick_millis_count;
usb_cdc_line_rtsdtr = setup.wValue;
//serial_print("set control line state\n");
break;

+ 2
- 0
teensy3/usb_dev.h Vedi File

@@ -69,6 +69,8 @@ static inline uint32_t usb_rx_byte_count(uint32_t endpoint)

#ifdef CDC_DATA_INTERFACE
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_transmit_flush_timer;
extern void usb_serial_flush_callback(void);

+ 1
- 0
teensy3/usb_serial.c Vedi File

@@ -39,6 +39,7 @@
#if F_CPU >= 20000000

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_transmit_flush_timer=0;


+ 6
- 1
teensy3/usb_serial.h Vedi File

@@ -53,6 +53,8 @@ int usb_serial_write(const void *buffer, uint32_t size);
int usb_serial_write_buffer_free(void);
void usb_serial_flush_output(void);
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_transmit_flush_timer;
extern volatile uint8_t usb_configuration;
@@ -90,7 +92,10 @@ public:
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 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 count=0;
unsigned long startMillis = millis();

Loading…
Annulla
Salva