Add define to use native port on Arduino

This commit is contained in:
Geoffrey Merck 2020-05-13 21:02:19 +02:00
parent 6b01f12602
commit c47eacd010
2 changed files with 28 additions and 0 deletions

View File

@ -52,6 +52,11 @@
#define ARDUINO_DUE_ZUM_V10 #define ARDUINO_DUE_ZUM_V10
#endif #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 // For the SP8NTH board
// #define ARDUINO_DUE_NTH // #define ARDUINO_DUE_NTH

View File

@ -30,7 +30,11 @@ void CSerialPort::beginInt(uint8_t n, int speed)
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT)
SerialUSB.begin(speed);
#else
Serial.begin(speed); Serial.begin(speed);
#endif
break; break;
case 2U: case 2U:
Serial2.begin(speed); Serial2.begin(speed);
@ -47,7 +51,11 @@ int CSerialPort::availableInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT)
return SerialUSB.available();
#else
return Serial.available(); return Serial.available();
#endif
case 2U: case 2U:
return Serial2.available(); return Serial2.available();
case 3U: case 3U:
@ -61,7 +69,11 @@ int CSerialPort::availableForWriteInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT)
return SerialUSB.availableForWrite();
#else
return Serial.availableForWrite(); return Serial.availableForWrite();
#endif
case 2U: case 2U:
return Serial2.availableForWrite(); return Serial2.availableForWrite();
case 3U: case 3U:
@ -75,7 +87,11 @@ uint8_t CSerialPort::readInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT)
return SerialUSB.read();
#else
return Serial.read(); return Serial.read();
#endif
case 2U: case 2U:
return Serial2.read(); return Serial2.read();
case 3U: case 3U:
@ -89,10 +105,17 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool
{ {
switch (n) { switch (n) {
case 1U: case 1U:
#if defined(ARDUINO_DUE_USE_NATIVE_USB_PORT)
SerialUSB.write(data, length);
if (flush)
SerialUSB.flush();
break;
#else
Serial.write(data, length); Serial.write(data, length);
if (flush) if (flush)
Serial.flush(); Serial.flush();
break; break;
#endif
case 2U: case 2U:
Serial2.write(data, length); Serial2.write(data, length);
if (flush) if (flush)