Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/sfTk/sfToolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 24 additions & 0 deletions src/sfTkArduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading