Skip to content

Commit 17b389e

Browse files
committed
Add getter function for Timer and LPTimer
With this API it is possible to retrieve the timer from sketch and start/stop it using mbed APIs.
1 parent bbc6284 commit 17b389e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

cores/arduino/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extern analogin_config_t adcCurrentConfig;
100100
#endif
101101

102102
#include "Serial.h"
103+
#include "timer.h"
103104
#if defined(SERIAL_CDC)
104105
#define Serial _UART_USB_
105106
#define SerialUSB _UART_USB_

cores/arduino/timer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "mbed.h"
2+
3+
enum TimerType {
4+
TIMER = 0x1,
5+
LPTIMER = 0x2
6+
};
7+
8+
mbed::Timer* getTimer(TimerType t = TIMER);

cores/arduino/wiring.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ void init()
6868
lowPowerTimer.start();
6969
}
7070

71+
mbed::Timer* getTimer(TimerType t)
72+
{
73+
if (t == LPTIMER) {
74+
return (mbed::Timer*)(&lowPowerTimer);
75+
} else {
76+
return &timer;
77+
}
78+
}
79+
7180
void yield() {
7281
#ifndef NO_RTOS
7382
rtos::ThisThread::yield();

0 commit comments

Comments
 (0)