Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ extern analogin_config_t adcCurrentConfig;
#endif

#include "Serial.h"
#include "timer.h"
#if defined(SERIAL_CDC)
#define Serial _UART_USB_
#define SerialUSB _UART_USB_
Expand Down
33 changes: 33 additions & 0 deletions cores/arduino/timer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "Arduino.h"
#include "timer.h"
#include "mbed.h"

using namespace arduino;

struct _mbed_timer {
mbed::Timer* obj;
};

ArduinoTimer::ArduinoTimer(void* _timer) {

if (timer != NULL) {
delete timer;
}

timer = new mbed_timer;
timer->obj = (mbed::Timer*)_timer;
}

ArduinoTimer::~ArduinoTimer() {
if (timer != NULL) {
delete timer;
}
}

void ArduinoTimer::start() {
timer->obj->start();
}

void ArduinoTimer::stop() {
timer->obj->stop();
}
32 changes: 32 additions & 0 deletions cores/arduino/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "Arduino.h"

#ifndef __ARDUINO_TIMER_H__
#define __ARDUINO_TIMER_H__

enum TimerType {
TIMER = 0x1,
LPTIMER = 0x2
};

typedef struct _mbed_timer mbed_timer;

namespace arduino {

class ArduinoTimer {
public:
ArduinoTimer(void* _timer);
~ArduinoTimer();
void start();
void stop();

private:
mbed_timer* timer = NULL;
};

}

arduino::ArduinoTimer getTimer(TimerType t = TIMER);

#endif //__ARDUINO_TIMER_H__


9 changes: 9 additions & 0 deletions cores/arduino/wiring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ void init()
lowPowerTimer.start();
}

ArduinoTimer getTimer(TimerType t)
{
if (t == LPTIMER) {
return ArduinoTimer((mbed::Timer*)(&lowPowerTimer));
} else {
return ArduinoTimer(&timer);
}
}

void yield() {
#ifndef NO_RTOS
rtos::ThisThread::yield();
Expand Down