From f4977eb57f8437faf585526071af5e200be547d1 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 30 Sep 2026 16:30:14 -0600 Subject: [PATCH 1/2] added function to support us delay - now on correct branch! --- src/sfTk/sfToolkit.h | 4 ++++ src/sfTkArduino.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/sfTk/sfToolkit.h b/src/sfTk/sfToolkit.h index c8b15ba..e0ffd2e 100644 --- a/src/sfTk/sfToolkit.h +++ b/src/sfTk/sfToolkit.h @@ -46,6 +46,10 @@ int32_t sftk_byte_swap(int32_t i); // delay in milliseconds void sftk_delay_ms(uint32_t ms); +// delay in microseconds +// see: https://docs.arduino.cc/language-reference/en/functions/time/delayMicroseconds/ +void sftk_delay_us(uint32_t us); + // ticks in milliseconds uint32_t sftk_ticks_ms(void); diff --git a/src/sfTkArduino.cpp b/src/sfTkArduino.cpp index 49b5aef..c49f380 100644 --- a/src/sfTkArduino.cpp +++ b/src/sfTkArduino.cpp @@ -17,9 +17,33 @@ void sftk_delay_ms(uint32_t ms) { + if (ms == 0) + return; delay(ms); } +// published max us delay for delayMicroseconds() on Arduino +static const uint32_t MAX_DELAY_US = 16383; + +void sftk_delay_us(uint32_t us) +{ + // no tick, not dice + if (us == 0) + return; + + // Can the built in just handle it? + if (us <= MAX_DELAY_US) + delayMicroseconds((unsigned int)us); + else + { + // break up microseconds into milliseconds and the remaining microseconds + delay(us / 1000); // whole ms + unsigned int rest = us % 1000; // always < 1000, safe cast + if (rest) + delayMicroseconds(rest); + } +} + uint32_t sftk_ticks_ms(void) { return millis(); From b65201164e14c67255de1a07965f035420181db4 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 30 Sep 2026 16:34:06 -0600 Subject: [PATCH 2/2] version bump --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index aeac01b..a3c24dd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun Toolkit -version=1.2.0 +version=1.2.1 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=A utility library that other SparkFun libraries can take advantage of.