From 3bca57a69d7bd9cd645735388dac3c85130536d0 Mon Sep 17 00:00:00 2001 From: Jan-Willem Gmelig Meyling Date: Thu, 2 May 2019 20:29:17 +0200 Subject: [PATCH] Support Arduino SAMD21 --- src/sps30.cpp | 13 ++++++++++++- src/sps30.h | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/sps30.cpp b/src/sps30.cpp index 57644eb..951145e 100644 --- a/src/sps30.cpp +++ b/src/sps30.cpp @@ -543,6 +543,8 @@ uint8_t SPS30::GetValues(struct sps_values *v) // I2C will only provide valid data bytes depending on I2C buffer // if I2C buffer is less than 64 it only providing MASS info (set in constructor) + +#if defined INCLUDE_I2C if (I2C_Max_bytes > 20) { v->NumPM0 = byte_to_float(offset + 16); v->NumPM1 = byte_to_float(offset + 20); @@ -551,6 +553,8 @@ uint8_t SPS30::GetValues(struct sps_values *v) v->NumPM10 = byte_to_float(offset + 32); v->PartSize = byte_to_float(offset + 36); } +#endif + return(ERR_OK); } @@ -615,12 +619,16 @@ bool SPS30::setSerialSpeed() _serial = &Serial; break; -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(_SAMD21_) case SERIALPORT1: Serial1.begin(_Serial_baud); _serial = &Serial1; break; +#endif + +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + case SERIALPORT2: Serial2.begin(_Serial_baud); _serial = &Serial2; @@ -655,12 +663,15 @@ bool SPS30::setSerialSpeed() if (_SPS30_Debug) printf("TX/RX line not defined\n"); return false; } + +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(_SAMD21_) // In case RX and TX are both pin 8, try Serial1 anyway. // A way to force-enable Serial1 on some boards. if (Serial_RX == 8 && Serial_TX == 8) { Serial1.begin(_Serial_baud); _serial = &Serial1; } +#endif else // try softserial { diff --git a/src/sps30.h b/src/sps30.h index 9ec0bce..14101d7 100755 --- a/src/sps30.h +++ b/src/sps30.h @@ -89,6 +89,13 @@ #endif // AVR definition check +/* + * Arduino SAMD does not include software serial +*/ +#if defined(_SAMD21_) + #undef INCLUDE_SOFTWARE_SERIAL +#endif + #if defined INCLUDE_I2C #if defined SOFTI2C_ESP32 // in case of SCD30