intermediate: try special handling for USBCDC

This commit is contained in:
andreas 2024-11-03 18:05:14 +01:00
parent 40c4089f86
commit 18b9946b62
1 changed files with 26 additions and 2 deletions

View File

@ -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<typename T>
class GwSerialImpl : public GwSerial{
private:
unsigned long lastWritable=0;
template<class C>
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<typename T>
#endif
template<class C>
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<class C>
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<typename T>
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){}