FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
Defines simple API to handle time and delays. More...
Classes | |
class | auto_delay |
Set a new time::delay function for the duration of the current scope; when the scope is left, the previous time::delay function is restored. More... | |
class | auto_millis |
Set a new time::millis function for the duration of the current scope; when the scope is left, the previous time::millis function is restored. More... | |
class | RTTTime |
Structure used to hold a time value with microsecond precision. More... | |
Typedefs | |
using | DELAY_PTR = void(*)(uint32_t ms) |
Function pointer type used for time::delay global variable. More... | |
using | MILLIS_PTR = uint32_t(*)() |
Function pointer type used for time::millis global variable. More... | |
Functions | |
RTTTime | operator- (const RTTTime &a, const RTTTime &b) |
Subtract 2 RTTTime instances. More... | |
bool | operator> (const RTTTime &a, const RTTTime &b) |
Compare 2 RTTTime instances. More... | |
bool | operator>= (const RTTTime &a, const RTTTime &b) |
Compare 2 RTTTime instances. More... | |
bool | operator< (const RTTTime &a, const RTTTime &b) |
Compare 2 RTTTime instances. More... | |
bool | operator<= (const RTTTime &a, const RTTTime &b) |
Compare 2 RTTTime instances. More... | |
bool | operator== (const RTTTime &a, const RTTTime &b) |
Compare 2 RTTTime instances. More... | |
bool | operator!= (const RTTTime &a, const RTTTime &b) |
Compare 2 RTTTime instances. More... | |
RTTTime | operator+ (const RTTTime &a, const RTTTime &b) |
Add 2 RTTTime instances. More... | |
void | yield () |
Utility method used by many FastArduino API in order to "yield" some processor time; concretely it just calls power::Power::sleep() which will put the MCU into a default sleep mode. More... | |
RTTTime | delta (const RTTTime &time1, const RTTTime &time2) |
Compute the time delta from time1 and time2 . More... | |
uint32_t | since (uint32_t start_ms) |
Compute the time elapsed, in milliseconds, since start_ms . More... | |
void | delay_us (uint16_t us) INLINE |
Delay program execution for the given amount of microseconds. More... | |
void | delay_ms (uint16_t ms) INLINE |
Delay program execution for the given amount of milliseconds. More... | |
void | default_delay (uint32_t ms) |
Delay program execution for the given amount of milliseconds. More... | |
template<typename CLOCK > | |
void | set_clock (const CLOCK &clock) |
Utility method to transform millis() and delay() methods of a clock instance of any CLOCK class into static method equivalents, and assign the resulting static methods to time::millis and time::delay global function pointers. More... | |
Variables | |
DELAY_PTR | delay = time::default_delay |
Delay program execution for the given amount of milliseconds. More... | |
MILLIS_PTR | millis = nullptr |
Count number of milliseconds elapsed since some time base reference (generally since MCU startup). More... | |
Defines simple API to handle time and delays.
using time::DELAY_PTR = typedef void (*)(uint32_t ms) |
Function pointer type used for time::delay
global variable.
using time::MILLIS_PTR = typedef uint32_t (*)() |
Function pointer type used for time::millis
global variable.
void time::yield | ( | ) |
Utility method used by many FastArduino API in order to "yield" some processor time; concretely it just calls power::Power::sleep()
which will put the MCU into a default sleep mode.
time::RTTTime time::delta | ( | const RTTTime & | time1, |
const RTTTime & | time2 | ||
) |
uint32_t time::since | ( | uint32_t | start_ms | ) |
Compute the time elapsed, in milliseconds, since start_ms
.
To calculate the elapsed time, this method uses the function pointed to by time::millis()
.
start_ms |
start_ms
and now (as returned by time::millis()
)
|
inline |
|
inline |
void time::default_delay | ( | uint32_t | ms | ) |
Delay program execution for the given amount of milliseconds.
This is the default implementation for delay
function pointer global variable.
ms | the number of milliseconds to hold program execution |
void time::set_clock | ( | const CLOCK & | clock | ) |
Utility method to transform millis()
and delay()
methods of a clock
instance of any CLOCK
class into static method equivalents, and assign the resulting static methods to time::millis
and time::delay
global function pointers.
This will work with any class as long as it defines the following methods:
clock | the instance which methods will be called |
|
extern |
Delay program execution for the given amount of milliseconds.
delay
is not actually a function but a function pointer; this allows FastArduino to set the best implementation based on currently used features. By default, delay
just performs a busy loop for the right amount of MCU cycles. Note that if you want to be sure reduce code size to the minimum and you are OK with always using busy loops for delays, then you should use time::delay_ms()
instead.
ms | number of milliseconds to wait for |
|
extern |
Count number of milliseconds elapsed since some time base reference (generally since MCU startup).
millis
is not actually a function but a function pointer; this allows FastArduino to set the best implementation based on currently used features. By default, millis
is not pointing to any concrete implementation, hence you should not call it if it has not been initialized yet. You can initialize it with timer::set_clock()
provided with the instance of a class implementing a minimal "clock" API. The following classes implement this minimal clock API: