-
Notifications
You must be signed in to change notification settings - Fork 2
/
ESPTimer0.cpp
75 lines (59 loc) · 1.34 KB
/
ESPTimer0.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "ESPTimer0.h"
ESPTimer0Class::ESPTimer0Class()
{
bind_member<ESPTimer0Class, &ESPTimer0Class::OnInterrupt> tCallBack(this);
timer0_isr_init();
timer0_attachInterrupt(tCallBack);
timer0_write(ESP.getCycleCount() + CYCLE_COUNT);
}
void ESPTimer0Class::OnInterrupt()
{
timer0_write(ESP.getCycleCount() + CYCLE_COUNT);
miliToSec++;
MiliSeconds++;
if (miliToSec >= 1000)
{
miliToSec = 0;
Time++;
}
}
void ESPTimer0Class::DelayMili(uint32_t pMili)
{
uint32_t tmpTicks = MiliSeconds + pMili;
while (MiliSeconds <= tmpTicks) { yield(); }
}
void ESPTimer0Class::DelayMili(uint32_t pMili, bool &pFlag)
{
uint32_t tmpTicks = MiliSeconds + pMili;
while ((!pFlag) && (MiliSeconds <= tmpTicks)) { yield(); }
}
void ESPTimer0Class::DelayMili(uint32_t pMili, void(*doWhile)(void))
{
uint32_t tmpTicks = MiliSeconds + pMili;
while (MiliSeconds <= tmpTicks)
{
doWhile();
}
}
bool ESPTimer0Class::DelayMili(uint32_t pMili, bool(*doWhile)(void))
{
uint32_t tmpTicks = MiliSeconds + pMili;
while (MiliSeconds <= tmpTicks)
{
if (doWhile())
return true;
}
return false;
}
void ESPTimer0Class::DelayMili(uint32_t pMili, bool &pFlag, void(*doWhile)(void))
{
uint32_t tmpTicks = MiliSeconds + pMili;
while ((!pFlag) && (MiliSeconds <= tmpTicks))
{
doWhile();
}
}
void ESPTimer0Class::SetTime(tTime pTime)
{
Time = pTime;
}