From c47eacd010e743792d9567d8ddc81ba7cb64b56f Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 13 May 2020 21:02:19 +0200 Subject: [PATCH] Add define to use native port on Arduino --- Config.h | 5 +++++ SerialArduino.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Config.h b/Config.h index 73e716b..2715f49 100644 --- a/Config.h +++ b/Config.h @@ -52,6 +52,11 @@ #define ARDUINO_DUE_ZUM_V10 #endif +// Use the native USB port instead of the programming port +// The native port is recommended when using FM network +// as the rpogramming port does not have the required throughput +// #define ARDUINO_DUE_USE_NATIVE_USB_PORT + // For the SP8NTH board // #define ARDUINO_DUE_NTH diff --git a/SerialArduino.cpp b/SerialArduino.cpp index db49759..fb79861 100644 --- a/SerialArduino.cpp +++ b/SerialArduino.cpp @@ -30,7 +30,11 @@ void CSerialPort::beginInt(uint8_t n, int speed) { switch (n) { case 1U: +#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT) + SerialUSB.begin(speed); +#else Serial.begin(speed); +#endif break; case 2U: Serial2.begin(speed); @@ -47,7 +51,11 @@ int CSerialPort::availableInt(uint8_t n) { switch (n) { case 1U: +#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT) + return SerialUSB.available(); +#else return Serial.available(); +#endif case 2U: return Serial2.available(); case 3U: @@ -61,7 +69,11 @@ int CSerialPort::availableForWriteInt(uint8_t n) { switch (n) { case 1U: +#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT) + return SerialUSB.availableForWrite(); +#else return Serial.availableForWrite(); +#endif case 2U: return Serial2.availableForWrite(); case 3U: @@ -75,7 +87,11 @@ uint8_t CSerialPort::readInt(uint8_t n) { switch (n) { case 1U: +#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT) + return SerialUSB.read(); +#else return Serial.read(); +#endif case 2U: return Serial2.read(); case 3U: @@ -89,10 +105,17 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool { switch (n) { case 1U: +#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT) + SerialUSB.write(data, length); + if (flush) + SerialUSB.flush(); + break; +#else Serial.write(data, length); if (flush) Serial.flush(); break; +#endif case 2U: Serial2.write(data, length); if (flush)