Initial support for USB serial

Initial support for USB serial when define ARDUINO_USB_CDC_ON_BOOT=1
This commit is contained in:
Theo Arends 2022-04-24 17:36:10 +02:00
parent 0e9b3331e1
commit 522bccb3e2
2 changed files with 8 additions and 0 deletions

View File

@ -153,6 +153,9 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
#ifdef ESP32
if (TSerial == nullptr) { // Allow for dynamic change in baudrate or config
if (freeUart()) { // We prefer UART1 and UART2 and keep UART0 for debugging
#ifdef ARDUINO_USB_CDC_ON_BOOT
TSerial = new HardwareSerial(m_uart);
#else
if (0 == m_uart) {
Serial.flush();
Serial.end();
@ -161,6 +164,7 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
} else {
TSerial = new HardwareSerial(m_uart);
}
#endif // ARDUINO_USB_CDC_ON_BOOT
if (serial_buffer_size > 256) { // RX Buffer can't be resized when Serial is already running (HardwareSerial.cpp)
TSerial->setRxBufferSize(serial_buffer_size);
}

View File

@ -1901,7 +1901,11 @@ void SetSerialBegin(void) {
delay(10); // Allow time to cleanup queues - if not used hangs ESP32
Serial.end();
delay(10); // Allow time to cleanup queues - if not used hangs ESP32
#ifdef ARDUINO_USB_CDC_ON_BOOT
Serial.begin(TasmotaGlobal.baudrate);
#else
Serial.begin(TasmotaGlobal.baudrate, ConvertSerialConfig(Settings->serial_config));
#endif // ARDUINO_USB_CDC_ON_BOOT
#endif // ESP32
}