FastLED 3.9.15
Loading...
Searching...
No Matches
fastled_delay.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef __INC_FASTLED_DELAY_H
4#define __INC_FASTLED_DELAY_H
5
6#include "platforms/cycle_type.h"
8#include "fl/system/delay.h"
9#include "platforms/cpu_frequency.h"
10
11// Note: micros() is used in inline templates below but not declared here.
12// It will be provided by platform headers (Arduino.h, etc.) included via led_sysdefs.h
13// when FastLED.h includes this file. The actual declaration varies by platform.
14
18
19
20
21
22#if (!defined(NO_MINIMUM_WAIT) || (NO_MINIMUM_WAIT==0))
23
26template<int WAIT> class CMinWait {
28 fl::u16 mLastMicros;
29
30public:
33
35 void wait() {
36 fl::u16 diff;
37 do {
38 diff = (fl::micros() & 0xFFFF) - mLastMicros;
39 } while(diff < WAIT);
40 }
41
43 void mark() { mLastMicros = fl::micros() & 0xFFFF; }
44};
45
46#else
47
48// if you keep your own FPS (and therefore don't call show() too quickly for pixels to latch), you may not want a minimum wait.
49template<int WAIT> class CMinWait {
50public:
51 CMinWait() { }
52 void wait() { }
53 void mark() {}
54};
55
56#endif
57
58
73
74// using fl::delaycycles;
75// using fl::delaycycles_min1;
76
78
79
82
83// Macro to convert from nano-seconds to clocks and clocks to nano-seconds
84// #define NS(_NS) (_NS / (1000 / (F_CPU / 1000000L)))
85
90#define F_CPU_MHZ (GET_CPU_FREQUENCY() / 1000000L)
91
92// #define NS(_NS) ( (_NS * (F_CPU / 1000000L))) / 1000
93
95#define NS(_NS) (((_NS * F_CPU_MHZ) + 999) / 1000)
97#define CLKS_TO_MICROS(_CLKS) ((long)(_CLKS)) / (GET_CPU_FREQUENCY() / 1000000L)
98
100#define NO_TIME(A, B, C) (NS(A) < 3 || NS(B) < 3 || NS(C) < 6)
101
103
104
105#endif
fl::u16 mLastMicros
Timestamp of the last time this was run, in microseconds.
CMinWait()
Constructor.
void mark()
Reset the timestamp that marks the start of the wait period.
void wait()
Blocking delay until WAIT time since mark() has passed.
Class to ensure that a minimum amount of time has kicked since the last time run - and delay if not e...
Delay utilities for FastLED Includes nanosecond-precision delays, cycle counting, and microsecond del...
fl::u32 micros()
Universal microsecond timer - returns microseconds since system startup.