Skip to content

Commit e2c6433

Browse files
sebromerofacchinm
authored andcommitted
Make low power the default for millis()
and high precision (microsecond) timer the default for micros()
1 parent 66f1f03 commit e2c6433

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

cores/arduino/wiring.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,26 @@
2626
#include "mbed/rtos/rtos.h"
2727
#include "mbed/platform/mbed_wait_api.h"
2828

29+
using namespace std::chrono_literals;
30+
using namespace std::chrono;
31+
32+
static mbed::Timer timer;
33+
2934
#if DEVICE_LPTICKER
30-
static mbed::LowPowerTimer t;
35+
static mbed::LowPowerTimer lowPowerTimer;
3136
#else
32-
static mbed::Timer t;
37+
// Fallback for devices which don't support
38+
// a low power ticker.
39+
static mbed::Timer lowPowerTimer;
3340
#endif
3441

35-
using namespace std::chrono_literals;
36-
using namespace std::chrono;
37-
3842
unsigned long millis()
3943
{
40-
return duration_cast<milliseconds>(t.elapsed_time()).count();
44+
return duration_cast<milliseconds>(lowPowerTimer.elapsed_time()).count();
4145
}
4246

4347
unsigned long micros() {
44-
return t.elapsed_time().count();
48+
return timer.elapsed_time().count();
4549
}
4650

4751
void delay(unsigned long ms)
@@ -60,7 +64,8 @@ void delayMicroseconds(unsigned int us)
6064

6165
void init()
6266
{
63-
t.start();
67+
timer.start();
68+
lowPowerTimer.start();
6469
}
6570

6671
void yield() {

0 commit comments

Comments
 (0)