1
0
mirror of https://github.com/arduino-libraries/ArduinoLowPower.git synced 2025-10-16 02:46:40 +03:00

Add support for ADC wakeup interrupt on SAMD21

This can be used to configure the ADC window interrupt on the SAMD21. It
uses OSCULP32K via GCLK6 to clock the ADC while in sleep mode (the same
as used for the EIC).

Note that attachAdcInterrupt()/detachAdcInterrupt() should be called
immediately before/after LowPower.sleep() otherwise analogRead() will
not work as expected.

There is also an example (AdcWakeup.ino) which is much like the
ExternalWakeup example but uses the ADC interrupt instead.
This commit is contained in:
Simon Knopp
2020-02-18 14:59:44 +13:00
parent c1b24fb456
commit fa71703f58
3 changed files with 205 additions and 15 deletions

View File

@@ -28,6 +28,16 @@ typedef enum{
ANALOG_COMPARATOR_WAKEUP = 3
} wakeup_reason;
#ifdef ARDUINO_ARCH_SAMD
enum adc_interrupt
{
ADC_INT_BETWEEN,
ADC_INT_OUTSIDE,
ADC_INT_ABOVE_MIN,
ADC_INT_BELOW_MAX,
};
#endif
class ArduinoLowPowerClass {
public:
@@ -68,10 +78,17 @@ class ArduinoLowPowerClass {
wakeup_reason wakeupReason();
#endif
#ifdef ARDUINO_ARCH_SAMD
void attachAdcInterrupt(uint32_t pin, voidFuncPtr callback, adc_interrupt mode, uint16_t lo, uint16_t hi);
void detachAdcInterrupt();
#endif
private:
void setAlarmIn(uint32_t millis);
#ifdef ARDUINO_ARCH_SAMD
RTCZero rtc;
voidFuncPtr adc_cb;
friend void ADC_Handler();
#endif
#ifdef BOARD_HAS_COMPANION_CHIP
void (*companionSleepCB)(bool);