FastLED 3.10.8
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#include "fl/stl/noexcept.h"
11
12// Note: micros() is used in inline templates below but not declared here.
13// It will be provided by platform headers (Arduino.h, etc.) included via led_sysdefs.h
14// when FastLED.h includes this file. The actual declaration varies by platform.
15
19
20
21
22
23#if (!defined(NO_MINIMUM_WAIT) || (NO_MINIMUM_WAIT==0))
24
27template<int WAIT> class CMinWait {
29 fl::u16 mLastMicros;
30
31public:
34
37 fl::u16 diff;
38 do {
39 diff = (fl::micros() & 0xFFFF) - mLastMicros;
40 } while(diff < WAIT);
41 }
42
44 void mark() FL_NO_EXCEPT { mLastMicros = fl::micros() & 0xFFFF; }
45};
46
47#else
48
49// 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.
50template<int WAIT> class CMinWait {
51public:
52 CMinWait() { }
53 void wait() { }
54 void mark() {}
55};
56
57#endif
58
59
74
75// using fl::delaycycles;
76// using fl::delaycycles_min1;
77
79
80
83
84// Macro to convert from nano-seconds to clocks and clocks to nano-seconds
85// #define NS(_NS) (_NS / (1000 / (F_CPU / 1000000L)))
86
91#define F_CPU_MHZ (FL_CPU_FREQUENCY() / 1000000L)
92
93// #define NS(_NS) ( (_NS * (F_CPU / 1000000L))) / 1000
94
96#define NS(_NS) (((_NS * F_CPU_MHZ) + 999) / 1000)
98#define CLKS_TO_MICROS(_CLKS) ((long)(_CLKS)) / (FL_CPU_FREQUENCY() / 1000000L)
99
101#define NO_TIME(A, B, C) (NS(A) < 3 || NS(B) < 3 || NS(C) < 6)
102
104
105
106#endif
fl::u16 mLastMicros
Timestamp of the last time this was run, in microseconds.
void mark() FL_NO_EXCEPT
Reset the timestamp that marks the start of the wait period.
void wait() FL_NO_EXCEPT
Blocking delay until WAIT time since mark() has passed.
CMinWait() FL_NO_EXCEPT
Constructor.
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() FL_NO_EXCEPT
Universal microsecond timer - returns microseconds since system startup.
#define FL_NO_EXCEPT