Skip to content

Commit

Permalink
Make the library compatible with both API and non API cores (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm authored Dec 17, 2020
1 parent 043dedb commit b44168f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/ArduinoLowPower.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

#define RTC_ALARM_WAKEUP 0xFF

#ifdef ARDUINO_API_VERSION
using irq_mode = PinStatus;
#else
using irq_mode = uint32_t;
#endif

//typedef void (*voidFuncPtr)( void ) ;
typedef void (*onOffFuncPtr)( bool ) ;

Expand Down Expand Up @@ -59,7 +65,7 @@ class ArduinoLowPowerClass {
deepSleep((uint32_t)millis);
}

void attachInterruptWakeup(uint32_t pin, voidFuncPtr callback, uint32_t mode);
void attachInterruptWakeup(uint32_t pin, voidFuncPtr callback, irq_mode mode);

#ifdef BOARD_HAS_COMPANION_CHIP
void companionLowPowerCallback(onOffFuncPtr callback) {
Expand Down
5 changes: 2 additions & 3 deletions src/samd/ArduinoLowPower.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if defined(ARDUINO_ARCH_SAMD)

#include "ArduinoLowPower.h"
#include "WInterrupts.h"

static void configGCLK6()
{
Expand Down Expand Up @@ -72,15 +71,15 @@ void ArduinoLowPowerClass::deepSleep(uint32_t millis) {
void ArduinoLowPowerClass::setAlarmIn(uint32_t millis) {

if (!rtc.isConfigured()) {
attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0);
attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, (irq_mode)0);
}

uint32_t now = rtc.getEpoch();
rtc.setAlarmEpoch(now + millis/1000);
rtc.enableAlarm(rtc.MATCH_YYMMDDHHMMSS);
}

void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callback, uint32_t mode) {
void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callback, irq_mode mode) {

if (pin > PINS_COUNT) {
// check for external wakeup sources
Expand Down

0 comments on commit b44168f

Please sign in to comment.