Skip to content

Commit de988ef

Browse files
committed
Make low power the default for millis()
1 parent cebd497 commit de988ef

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

cores/arduino/Arduino.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,4 @@ extern analogin_config_t adcCurrentConfig;
143143

144144
#include "macros.h"
145145

146-
/**
147-
* Power Management
148-
**/
149-
150-
#if DEVICE_LPTICKER
151-
/**
152-
* Enables the low power timer being used by the timing functions
153-
* millis() and micros()
154-
* */
155-
void enableLowPowerTimer();
156-
157-
/**
158-
* Disables the low power timer
159-
* */
160-
void disableLowPowerTimer();
161-
#endif
162-
163146
#endif

cores/arduino/wiring.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,19 @@ static mbed::Timer timer;
3333

3434
#if DEVICE_LPTICKER
3535
static mbed::LowPowerTimer lowPowerTimer;
36-
static bool useLowPowerTimer = false;
37-
38-
void enableLowPowerTimer(){
39-
timer.stop();
40-
useLowPowerTimer = true;
41-
lowPowerTimer.start();
42-
}
43-
44-
void disableLowPowerTimer(){
45-
lowPowerTimer.stop();
46-
useLowPowerTimer = false;
47-
timer.start();
48-
}
36+
#else
37+
// Fallback for devices which don't support
38+
// a low power ticker.
39+
static mbed::Timer lowPowerTimer;
4940
#endif
5041

51-
52-
std::chrono::microseconds elapsedTime(){
53-
#if DEVICE_LPTICKER
54-
return useLowPowerTimer ? lowPowerTimer.elapsed_time() : timer.elapsed_time();
55-
#else
56-
return timer.elapsed_time();
57-
#endif
58-
}
59-
6042
unsigned long millis()
6143
{
62-
return duration_cast<milliseconds>(elapsedTime()).count();
44+
return duration_cast<milliseconds>(lowPowerTimer.elapsed_time()).count();
6345
}
6446

6547
unsigned long micros() {
66-
return elapsedTime().count();
48+
return timer.elapsed_time().count();
6749
}
6850

6951
void delay(unsigned long ms)
@@ -83,6 +65,7 @@ void delayMicroseconds(unsigned int us)
8365
void init()
8466
{
8567
timer.start();
68+
lowPowerTimer.start();
8669
}
8770

8871
void yield() {

0 commit comments

Comments
 (0)