Use bounded hardware CDC for the Full G2 repeater console
This commit is contained in:
1 parent
fed810ff50
commit
8bc3d2e476
3 files changed
+23
-1
No files matched your search
@@ -130,7 +130,14 @@ class SerialLogLine {
|
||||
inline void serialLogBegin() {
|
||||
#if defined(ESP32_PLATFORM) && defined(ARDUINO_USB_CDC_ON_BOOT) && \
|
||||
(ARDUINO_USB_CDC_ON_BOOT == 1)
|
||||
#if defined(ARDUINO_USB_MODE) && ARDUINO_USB_MODE == 1
|
||||
// Arduino 2.0.17 HWCDC decrements an unsigned retry counter when its
|
||||
// host stops reading. A zero timeout can underflow; retain the bounded
|
||||
// timeout established by prepareUsbLoggingPort().
|
||||
Serial.setTxTimeoutMs(5);
|
||||
#else
|
||||
Serial.setTxTimeoutMs(0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -483,9 +483,16 @@ public:
|
||||
|
||||
size_t write(const uint8_t* data, size_t size) override {
|
||||
if (data == nullptr || size == 0) return 0;
|
||||
// The shared producer guard excludes other application writers here.
|
||||
// The ISR can only free ring capacity, so one fresh capacity sample keeps
|
||||
// HWCDC::write out of its wait-for-space remainder loop.
|
||||
const int available = Serial.availableForWrite();
|
||||
if (available <= 0) return 0;
|
||||
const size_t attempt = size < static_cast<size_t>(available)
|
||||
? size : static_cast<size_t>(available);
|
||||
noteUsbLoggingTxAttempt();
|
||||
esp32_hwcdc_tx_kick_pending.store(true, std::memory_order_release);
|
||||
return Serial.write(data, size);
|
||||
return Serial.write(data, attempt);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in new issue
Block a user