Merge pull request #7041 from dhalbert/serial-first-write-delay
delay first serial write to allow host setup time
This commit is contained in:
commit
e3688b4342
@ -28,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
|
#include "py/mphal.h"
|
||||||
|
|
||||||
#include "supervisor/shared/cpu.h"
|
#include "supervisor/shared/cpu.h"
|
||||||
#include "supervisor/shared/display.h"
|
#include "supervisor/shared/display.h"
|
||||||
@ -62,6 +63,13 @@ byte console_uart_rx_buf[64];
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART
|
||||||
|
// Flag to note whether this is the first write after connection.
|
||||||
|
// Delay slightly on the first write to allow time for the host to set up things,
|
||||||
|
// including turning off echo mode.
|
||||||
|
static bool _first_write_done = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_USB_VENDOR
|
#if CIRCUITPY_USB_VENDOR
|
||||||
bool tud_vendor_connected(void);
|
bool tud_vendor_connected(void);
|
||||||
#endif
|
#endif
|
||||||
@ -144,6 +152,10 @@ void serial_early_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void serial_init(void) {
|
void serial_init(void) {
|
||||||
|
#if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART
|
||||||
|
_first_write_done = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
port_serial_init();
|
port_serial_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,8 +313,11 @@ void serial_write_substring(const char *text, uint32_t length) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_CONSOLE_UART
|
#if CIRCUITPY_CONSOLE_UART
|
||||||
|
if (!_first_write_done) {
|
||||||
|
mp_hal_delay_ms(50);
|
||||||
|
_first_write_done = true;
|
||||||
|
}
|
||||||
int uart_errcode;
|
int uart_errcode;
|
||||||
|
|
||||||
common_hal_busio_uart_write(&console_uart, (const uint8_t *)text, length, &uart_errcode);
|
common_hal_busio_uart_write(&console_uart, (const uint8_t *)text, length, &uart_errcode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -321,6 +336,11 @@ void serial_write_substring(const char *text, uint32_t length) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_USB
|
#if CIRCUITPY_USB
|
||||||
|
// Delay the very first write
|
||||||
|
if (tud_cdc_connected() && !_first_write_done) {
|
||||||
|
mp_hal_delay_ms(50);
|
||||||
|
_first_write_done = true;
|
||||||
|
}
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
if (tud_cdc_connected()) {
|
if (tud_cdc_connected()) {
|
||||||
while (count < length) {
|
while (count < length) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user