From ef4ec4185a3c8c3865a55bff81d08ffd5749627c Mon Sep 17 00:00:00 2001 From: git2212 Date: Thu, 11 May 2023 12:45:01 -0400 Subject: [PATCH] Add dummy Serial implementation when NO_USB defined (#1438) Fixes #1434 --- cores/rp2040/RP2040USB.cpp | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/cores/rp2040/RP2040USB.cpp b/cores/rp2040/RP2040USB.cpp index e700683a2..199fcaefe 100644 --- a/cores/rp2040/RP2040USB.cpp +++ b/cores/rp2040/RP2040USB.cpp @@ -550,6 +550,59 @@ usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { *driver_count = 1; return &_resetd_driver; } + +#elif defined NO_USB + +// will ensure backward compatibility with existing code when using pico-debug + +#warning "NO_USB selected. No output to Serial will occur!" + +#include + +void SerialUSB::begin(unsigned long baud) { +} + +void SerialUSB::end() { + +} + +int SerialUSB::peek() { + return 0; +} + +int SerialUSB::read() { + return -1; +} + +int SerialUSB::available() { + return 0; +} + +int SerialUSB::availableForWrite() { + return 0; +} + +void SerialUSB::flush() { + +} + +size_t SerialUSB::write(uint8_t c) { + (void) c; + return 0; +} + +size_t SerialUSB::write(const uint8_t *buf, size_t length) { + (void) buf; + (void) length; + return 0; +} + +SerialUSB::operator bool() { + return false; +} + +SerialUSB Serial; + #endif