From 18b9946b62f8006d5cb482e7bf37cf1a42030920 Mon Sep 17 00:00:00 2001 From: andreas Date: Sun, 3 Nov 2024 18:05:14 +0100 Subject: [PATCH] intermediate: try special handling for USBCDC --- lib/serial/GwSerial.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/serial/GwSerial.h b/lib/serial/GwSerial.h index 8e37974..75f73a8 100644 --- a/lib/serial/GwSerial.h +++ b/lib/serial/GwSerial.h @@ -4,6 +4,7 @@ #include "GwLog.h" #include "GwBuffer.h" #include "GwChannelInterface.h" +#include "hal/usb_serial_jtag_ll.h" class GwSerialStream; class GwSerial : public GwChannelInterface{ protected: @@ -39,6 +40,7 @@ class GwSerial : public GwChannelInterface{ template class GwSerialImpl : public GwSerial{ private: + unsigned long lastWritable=0; template void beginImpl(C *s,unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1){} void beginImpl(HardwareSerial *s,unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1){ @@ -59,7 +61,29 @@ template #endif template long getFlushTimeoutImpl(const C*){return 2000;} - long getFlushTimeoutImpl(HWCDC *){return 200;} + #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 + long getFlushTimeoutImpl(HWCDC *){return 200;} + #endif + + template + int availableForWrite(C* c){ + return c->availableForWrite(); + } + + #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 + int availableForWrite(HWCDC* c){ + int rt=c->availableForWrite(); + if (rt > 0) { + lastWritable=millis(); + return rt; + } + if (usb_serial_jtag_ll_txfifo_writable() == 1){ + LOG_INFO("USBserial restart"); + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + } + return rt; + } + #endif T *serial; protected: @@ -67,7 +91,7 @@ template return getFlushTimeoutImpl(serial); } virtual int availableForWrite(){ - return serial->availableForWrite(); + return availableForWrite(serial); } public: GwSerialImpl(GwLog* logger,T* s,int i,int type,bool allowRead=true): GwSerial(logger,s,i,type,allowRead),serial(s){}