File tree Expand file tree Collapse file tree 4 files changed +75
-0
lines changed Expand file tree Collapse file tree 4 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ extern analogin_config_t adcCurrentConfig;
100
100
#endif
101
101
102
102
#include " Serial.h"
103
+ #include " timer.h"
103
104
#if defined(SERIAL_CDC)
104
105
#define Serial _UART_USB_
105
106
#define SerialUSB _UART_USB_
Original file line number Diff line number Diff line change
1
+ #include " Arduino.h"
2
+ #include " timer.h"
3
+ #include " mbed.h"
4
+
5
+ using namespace arduino ;
6
+
7
+ struct _mbed_timer {
8
+ mbed::Timer* obj;
9
+ };
10
+
11
+ ArduinoTimer::ArduinoTimer (void * _timer) {
12
+
13
+ if (timer != NULL ) {
14
+ delete timer;
15
+ }
16
+
17
+ timer = new mbed_timer;
18
+ timer->obj = (mbed::Timer*)_timer;
19
+ }
20
+
21
+ ArduinoTimer::~ArduinoTimer () {
22
+ if (timer != NULL ) {
23
+ delete timer;
24
+ }
25
+ }
26
+
27
+ void ArduinoTimer::start () {
28
+ timer->obj ->start ();
29
+ }
30
+
31
+ void ArduinoTimer::stop () {
32
+ timer->obj ->stop ();
33
+ }
Original file line number Diff line number Diff line change
1
+ #include " Arduino.h"
2
+
3
+ #ifndef __ARDUINO_TIMER_H__
4
+ #define __ARDUINO_TIMER_H__
5
+
6
+ enum TimerType {
7
+ TIMER = 0x1 ,
8
+ LPTIMER = 0x2
9
+ };
10
+
11
+ typedef struct _mbed_timer mbed_timer;
12
+
13
+ namespace arduino {
14
+
15
+ class ArduinoTimer {
16
+ public:
17
+ ArduinoTimer (void * _timer);
18
+ ~ArduinoTimer ();
19
+ void start ();
20
+ void stop ();
21
+
22
+ private:
23
+ mbed_timer* timer = NULL ;
24
+ };
25
+
26
+ }
27
+
28
+ arduino::ArduinoTimer getTimer (TimerType t = TIMER);
29
+
30
+ #endif // __ARDUINO_TIMER_H__
31
+
32
+
Original file line number Diff line number Diff line change @@ -68,6 +68,15 @@ void init()
68
68
lowPowerTimer.start ();
69
69
}
70
70
71
+ ArduinoTimer getTimer (TimerType t)
72
+ {
73
+ if (t == LPTIMER) {
74
+ return ArduinoTimer ((mbed::Timer*)(&lowPowerTimer));
75
+ } else {
76
+ return ArduinoTimer (&timer);
77
+ }
78
+ }
79
+
71
80
void yield () {
72
81
#ifndef NO_RTOS
73
82
rtos::ThisThread::yield ();
You can’t perform that action at this time.
0 commit comments