From c98d41fd0a7e451ec1f9b275abcda6e15a5f52c6 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Wed, 4 Dec 2024 06:12:40 -0800 Subject: [PATCH] fixes for STM32 (#1011) resolves #1010 * compute `F_CPU` at runtime for STM32 in `startWrite()` * fix scanner examples `min()`/`max()` calls --- RF24.cpp | 5 +++++ examples/scanner/scanner.ino | 4 ++-- examples/scannerGraphic/scannerGraphic.ino | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index f0f7a0879..8c2bb77ac 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1368,6 +1368,11 @@ bool RF24::startWrite(const void* buf, uint8_t len, const bool multicast) ce(HIGH); #if !defined(F_CPU) || F_CPU > 20000000 delayMicroseconds(10); +#endif +#ifdef ARDUINO_ARCH_STM32 + if (F_CPU > 20000000) { + delayMicroseconds(10); + } #endif ce(LOW); return !(status & _BV(TX_FULL)); diff --git a/examples/scanner/scanner.ino b/examples/scanner/scanner.ino index c8b800931..d6c7d4413 100644 --- a/examples/scanner/scanner.ino +++ b/examples/scanner/scanner.ino @@ -141,7 +141,7 @@ void loop(void) { if (Serial.available()) { int8_t c = Serial.parseInt(); if (c >= 0) { - c = min(125, max(0, c)); // clamp channel to supported range + c = min((int8_t)125, c); // clamp channel to supported range constCarrierMode = 1; radio.stopListening(); delay(2); @@ -199,7 +199,7 @@ void loop(void) { // Print out channel measurements, clamped to a single hex digit for (int i = 0; i < num_channels; ++i) { if (values[i]) - Serial.print(min(0xf, values[i]), HEX); + Serial.print(min((uint8_t)0xf, values[i]), HEX); else Serial.print(F("-")); } diff --git a/examples/scannerGraphic/scannerGraphic.ino b/examples/scannerGraphic/scannerGraphic.ino index e11ef6ea3..ddbed5a1b 100644 --- a/examples/scannerGraphic/scannerGraphic.ino +++ b/examples/scannerGraphic/scannerGraphic.ino @@ -89,7 +89,7 @@ struct ChannelHistory { sum += history[i]; } history[cacheMax - 1] = value; - maxPeak = max(sum * 2, maxPeak); // sum * 2 to allow half-step decay + maxPeak = max((uint8_t)(sum * 2), maxPeak); // sum * 2 to allow half-step decay return sum; }