From fcbf16f6a39a576de8af5ec22e6b6dd043062050 Mon Sep 17 00:00:00 2001 From: chiararuggeri Date: Wed, 19 Apr 2017 11:15:56 +0200 Subject: [PATCH 01/41] Proposed lowercase name for companion callback in sketch --- examples/TianStandby/TianStandby.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/TianStandby/TianStandby.ino b/examples/TianStandby/TianStandby.ino index e4f4d56..e74c53e 100644 --- a/examples/TianStandby/TianStandby.ino +++ b/examples/TianStandby/TianStandby.ino @@ -17,14 +17,14 @@ #define MIPS_PIN 32 -void MIPS_PM(bool sleep) { +void MipsPM(bool sleep) { pinMode(MIPS_PIN, OUTPUT); digitalWrite(MIPS_PIN, sleep ? LOW: HIGH); } void setup() { pinMode(LED_BUILTIN, OUTPUT); - LowPower.companionLowPowerCallback(MIPS_PM); + LowPower.companionLowPowerCallback(MipsPM); // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, onWakeup, CHANGE); } From 21d2f7527ff4d78f66a1bd7f81829807240d1d62 Mon Sep 17 00:00:00 2001 From: chiararuggeri Date: Wed, 19 Apr 2017 11:12:15 +0200 Subject: [PATCH 02/41] Added nRF52 compatibility Waking from deepSleep() is comparable to an hard reset; the sketch won't restart from the sleep invocation but the wakeuup source can be retrieved with wakeupReason() --- examples/PrimoDeepSleep/PrimoDeepSleep.ino | 92 +++++++++++ keywords.txt | 10 ++ library.properties | 4 +- src/ArduinoLowPower.h | 17 +- src/nrf52/ArduinoLowPower.cpp | 178 +++++++++++++++++++++ src/{ => samd}/ArduinoLowPower.cpp | 6 +- 6 files changed, 303 insertions(+), 4 deletions(-) create mode 100644 examples/PrimoDeepSleep/PrimoDeepSleep.ino create mode 100644 src/nrf52/ArduinoLowPower.cpp rename src/{ => samd}/ArduinoLowPower.cpp (96%) diff --git a/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/examples/PrimoDeepSleep/PrimoDeepSleep.ino new file mode 100644 index 0000000..9e7d9f8 --- /dev/null +++ b/examples/PrimoDeepSleep/PrimoDeepSleep.ino @@ -0,0 +1,92 @@ +/* + PrimoDeepSleep.ino + + Written by Chiara Ruggeri (chiara@arduino.org) + + This example for the Arduino Primo board shows how to use + low power library to enter in power off mode and save power. + This mode ensure the deepest power saving mode. If you need + a faster response from the board use standby function instead. + + Please note that once exited from the deepest sleep mode the + board will reset (so setup will be run again). + + The functions enableWakeupFrom set the peripheral that will wake up + the board. By calling it more than once you can choose more than + a wakeup source. + The board will be reset when it wakes up from power off. + You can use wakeUpCause() function to find out what signals woke up + the board if you use more than one wakeUpBy.. function. + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + + +// Pin used to wakeup the board +const int digitalPin = 10; + +// Pin used in Compatarot module to wake up the board +const int analogPin = A0; + + +void StmEspPM(bool sleep){ + // enable USER1_BUTTON to turn STM32 off and on when pressed. + // note that when STM32 is off you cannot load any new sketch. + pinMode(USER1_BUTTON, STM32_IT); + + // turn ESP8266 off or on + digitalWrite(GPIO_ESP_PW, sleep ? LOW: HIGH); +} + +void setup() { + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + + //look for what peripheral woke up the board + //reason is 0 at the first execution + wakeup_reason reason=LowPower.wakeupReason(); + if(reason==GPIO_WAKEUP) //GPIO caused the wake up + doMyStuff(); + else + if(reason==NFC_WAKEUP) //NFC caused the wake up + doMyStuffWithNFC(); + else + if(reason==ANALOG_COMPARATOR_WAKEUP) //Comparator caused the wake up + doOtherStuff(); + + Serial.println("Hi all, I return to sleep"); + + LowPower.companionLowPowerCallback(StmEspPM); + // Send sleep command to ESP and enable USER1_BUTTON to turn STM off + LowPower.companionSleep(); + + //set digital pin 10 to wake up the board when LOW level is detected + LowPower.enableWakeupFrom(GPIO_WAKEUP, digitalPin, LOW); + //let the board be woken up by any NFC field + LowPower.enableWakeupFrom(NFC_WAKEUP); + //wake up the board when the voltage on pin A0 goes below the voltage on pin AREF + LowPower.enableWakeupFrom(ANALOG_COMPARATOR_WAKEUP, analogPin, AREF, UP); + //go in low power mode. Note that the board will reset once it is woken up + LowPower.deepSleep(); +} + + +void loop() {} + +void doMyStuff(){ + //insert your code here +} + +void doMyStuffWithNFC(){ + //insert your code here +} + +void doOtherStuff(){ + //insert your code here +} diff --git a/keywords.txt b/keywords.txt index 3a02803..d0813b7 100644 --- a/keywords.txt +++ b/keywords.txt @@ -17,7 +17,17 @@ idle KEYWORD2 sleep KEYWORD2 deepSleep KEYWORD2 attachInterruptWakeup KEYWORD2 +enableWakeupFrom KEYWORD2 +companionLowPowerCallback KEYWORD2 +companionSleep KEYWORD2 +companionWakeup KEYWORD2 +wakeupReason KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### + +OTHER_WAKEUP LITERAL1 +GPIO_WAKEUP LITERAL1 +NFC_WAKEUP LITERAL1 +ANALOG_COMPARATOR_WAKEUP LITERAL1 \ No newline at end of file diff --git a/library.properties b/library.properties index aabaec8..2d3fb67 100644 --- a/library.properties +++ b/library.properties @@ -2,8 +2,8 @@ name=Arduino Low Power version=1.0.0 author=Arduino maintainer=Arduino LLC -sentence=Power save primitives features for SAMD 32bit boards +sentence=Power save primitives features for SAMD and nRF52 32bit boards paragraph=With this library you can manage the low power states of newer Arduino boards category=Device Control url=http://arduino.cc/libraries/ArduinoLowPower -architectures=samd +architectures=samd,nrf52 diff --git a/src/ArduinoLowPower.h b/src/ArduinoLowPower.h index 06f4a4e..474c879 100644 --- a/src/ArduinoLowPower.h +++ b/src/ArduinoLowPower.h @@ -11,7 +11,7 @@ #include "RTCZero.h" #endif -#if defined(ARDUINO_SAMD_TIAN) +#if defined(ARDUINO_SAMD_TIAN) || defined(ARDUINO_NRF52_PRIMO) // add here any board with companion chip which can be woken up #define BOARD_HAS_COMPANION_CHIP #endif @@ -21,6 +21,14 @@ //typedef void (*voidFuncPtr)( void ) ; typedef void (*onOffFuncPtr)( bool ) ; +typedef enum{ + OTHER_WAKEUP = 0, + GPIO_WAKEUP = 1, + NFC_WAKEUP = 2, + ANALOG_COMPARATOR_WAKEUP = 3 +} wakeup_reason; + + class ArduinoLowPowerClass { public: void idle(void); @@ -55,9 +63,16 @@ class ArduinoLowPowerClass { } #endif + #ifdef ARDUINO_ARCH_NRF52 + void enableWakeupFrom(wakeup_reason peripheral, uint32_t pin = 0xFF, uint32_t event = 0xFF, uint32_t option = 0xFF); + wakeup_reason wakeupReason(); + #endif + private: void setAlarmIn(uint32_t millis); + #ifdef ARDUINO_ARCH_SAMD RTCZero rtc; + #endif #ifdef BOARD_HAS_COMPANION_CHIP void (*companionSleepCB)(bool); #endif diff --git a/src/nrf52/ArduinoLowPower.cpp b/src/nrf52/ArduinoLowPower.cpp new file mode 100644 index 0000000..75889a1 --- /dev/null +++ b/src/nrf52/ArduinoLowPower.cpp @@ -0,0 +1,178 @@ +/* + ArduinoLowPower class for nRF52. + + Written by Chiara Ruggeri (chiara@arduino.org) + + Copyright (c) 2017 Arduino AG. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if defined(ARDUINO_ARCH_NRF52) + +#include "ArduinoLowPower.h" +#include "WInterrupts.h" +#include "nrf_rtc.h" + +volatile bool event = false; +void (*functionPointer)(void); +nrf_lpcomp_input_t aPin[]={NRF_LPCOMP_INPUT_1, NRF_LPCOMP_INPUT_2, NRF_LPCOMP_INPUT_4, NRF_LPCOMP_INPUT_5, NRF_LPCOMP_INPUT_6, NRF_LPCOMP_INPUT_7}; + +void wakeUpGpio(){ + event = true; + if(functionPointer) + functionPointer(); +} + +void ArduinoLowPowerClass::idle() { + // nRF52 has just two low power modes. Call sleep if idle is called. + sleep(); +} + +void ArduinoLowPowerClass::idle(uint32_t millis) { + setAlarmIn(millis); + idle(); +} + +void ArduinoLowPowerClass::sleep() { + sd_power_mode_set(NRF_POWER_MODE_LOWPWR); + event=false; + while(!event){ + sd_app_evt_wait(); + } +} + +void ArduinoLowPowerClass::sleep(uint32_t millis) { + setAlarmIn(millis); + sleep(); +} + +void ArduinoLowPowerClass::deepSleep() { + //Enter in systemOff mode only when no EasyDMA transfer is active + //this is achieved by disabling all peripheral that use it + NRF_UARTE0->ENABLE = UARTE_ENABLE_ENABLE_Disabled; //disable UART + NRF_SAADC ->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos); //disable ADC + NRF_PWM0 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); //disable all pwm instance + NRF_PWM1 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); + NRF_PWM2 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); + NRF_TWIM1 ->ENABLE = (TWIM_ENABLE_ENABLE_Disabled << TWIM_ENABLE_ENABLE_Pos); //disable TWI Master + NRF_TWIS1 ->ENABLE = (TWIS_ENABLE_ENABLE_Disabled << TWIS_ENABLE_ENABLE_Pos); //disable TWI Slave + + //Enter in System OFF mode + sd_power_system_off(); + + /*Only for debugging purpose, will not be reached without connected debugger*/ + while(1); +} + +void ArduinoLowPowerClass::setAlarmIn(uint32_t millis) { + nrf_rtc_prescaler_set(NRF_RTC1, 32); + //enable interrupt + NVIC_SetPriority(RTC1_IRQn, 2); //high priority + NVIC_ClearPendingIRQ(RTC1_IRQn); + NVIC_EnableIRQ(RTC1_IRQn); + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0); + nrf_rtc_int_enable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK); + //Tick every 1 ms + nrf_rtc_cc_set(NRF_RTC1, 0, millis); + + //start RTC + nrf_rtc_task_trigger(NRF_RTC1, NRF_RTC_TASK_START); +} + +void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callback, uint32_t mode) { + functionPointer = callback; + + if(pin == RTC_ALARM_WAKEUP) + return; + + pinMode(pin, INPUT_PULLUP); + attachInterrupt(pin, wakeUpGpio, mode); +} + +void ArduinoLowPowerClass::enableWakeupFrom(wakeup_reason peripheral, uint32_t pin, uint32_t event, uint32_t option){ + if(peripheral == NFC_WAKEUP){ + NRF_NFCT->TASKS_SENSE=1; + return; + } + if(peripheral == ANALOG_COMPARATOR_WAKEUP){ + detect_mode mode; + if(option == DOWN) + mode = DOWN; + else if(option == UP) + mode = UP; + else + mode = CROSS; + nrf_lpcomp_config_t config={(nrf_lpcomp_ref_t)event, (nrf_lpcomp_detect_t)mode}; + nrf_lpcomp_configure(&config); + if(pin<14 && pin>19) + return; //no analog pin is choosen + nrf_lpcomp_input_select(aPin[pin-14]); + nrf_lpcomp_enable(); + nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_START); + while(!nrf_lpcomp_event_check(NRF_LPCOMP_EVENT_READY)); + return; + } + if(peripheral == GPIO_WAKEUP){ + if(pin > 20)// allow wake up only from digital and analog pins + return; + if(event==LOW) + nrf_gpio_cfg_sense_input(g_APinDescription[pin].ulPin, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); + else + nrf_gpio_cfg_sense_input(g_APinDescription[pin].ulPin, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH); + } +} + +wakeup_reason ArduinoLowPowerClass::wakeupReason(){ + uint32_t guilty; + sd_power_reset_reason_get(&guilty); + if(guilty & 0x10000){ // GPIO + //RESETREAS is a cumulative register. We need to clear it by writing 1 in the relative field + sd_power_reset_reason_clr(1 << 16); + return GPIO_WAKEUP; + } + if(guilty & 0x80000){ //NFC + sd_power_reset_reason_clr(1 << 19); + return NFC_WAKEUP; + } + if(guilty & 0x20000){ //COMP + sd_power_reset_reason_clr(1 << 17); + return ANALOG_COMPARATOR_WAKEUP; + } + return OTHER_WAKEUP; +} + + +ArduinoLowPowerClass LowPower; + +#ifdef __cplusplus +extern "C"{ +#endif + +void RTC1_IRQHandler(void) +{ + event=true; + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0); + nrf_rtc_task_trigger(NRF_RTC1, NRF_RTC_TASK_CLEAR); + nrf_rtc_task_trigger(NRF_RTC1, NRF_RTC_TASK_STOP); + if(functionPointer) + functionPointer(); +} + +#ifdef __cplusplus +} +#endif + +#endif // ARDUINO_ARCH_NRF52 \ No newline at end of file diff --git a/src/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp similarity index 96% rename from src/ArduinoLowPower.cpp rename to src/samd/ArduinoLowPower.cpp index 466d763..e538426 100644 --- a/src/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -1,3 +1,5 @@ +#if defined(ARDUINO_ARCH_SAMD) + #include "ArduinoLowPower.h" #include "WInterrupts.h" @@ -87,4 +89,6 @@ void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callb NVMCTRL->CTRLB.bit.SLEEPPRM = NVMCTRL_CTRLB_SLEEPPRM_DISABLED_Val; } -ArduinoLowPowerClass LowPower; \ No newline at end of file +ArduinoLowPowerClass LowPower; + +#endif // ARDUINO_ARCH_SAMD \ No newline at end of file From 71ceedc1d7cf28fcce165777905a54326f494531 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 20 Apr 2017 14:43:33 +0200 Subject: [PATCH 03/41] publish 1.1.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 2d3fb67..914d5ec 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino Low Power -version=1.0.0 +version=1.1.0 author=Arduino maintainer=Arduino LLC sentence=Power save primitives features for SAMD and nRF52 32bit boards From 5456a1f69885ed9a670c156ab6326b2f0965b76e Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 13 Jul 2017 16:56:25 +0200 Subject: [PATCH 04/41] [Examples] Avoid spurious wakeup --- examples/ExternalWakeup/ExternalWakeup.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/ExternalWakeup/ExternalWakeup.ino b/examples/ExternalWakeup/ExternalWakeup.ino index 09a7610..6151258 100644 --- a/examples/ExternalWakeup/ExternalWakeup.ino +++ b/examples/ExternalWakeup/ExternalWakeup.ino @@ -21,6 +21,8 @@ const int pin = 8; void setup() { pinMode(LED_BUILTIN, OUTPUT); + // Set pin 8 as INPUT_PULLUP to avoid spurious wakeup + pinMode(pin, INPUT_PULLUP); // Attach a wakeup interrupt on pin 8, calling repetitionsIncrease when the device is woken up LowPower.attachInterruptWakeup(pin, repetitionsIncrease, CHANGE); } From 8cf4c737ddb755e76c20407df3d70cc507bd9651 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 13 Jul 2017 17:01:03 +0200 Subject: [PATCH 05/41] [SAMD] Disable USB on standby() --- src/samd/ArduinoLowPower.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index e538426..8867d6e 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -16,10 +16,19 @@ void ArduinoLowPowerClass::idle(uint32_t millis) { } void ArduinoLowPowerClass::sleep() { - USBDevice.standby(); + bool restoreUSBDevice = false; + if (SerialUSB) { + USBDevice.standby(); + } else { + USBDevice.detach(); + restoreUSBDevice = true; + } SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; __DSB(); __WFI(); + if (restoreUSBDevice) { + USBDevice.attach(); + } } void ArduinoLowPowerClass::sleep(uint32_t millis) { From 5399b362077f3630cbaa99d43c69e8a85c04ae95 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 13 Jul 2017 17:01:41 +0200 Subject: [PATCH 06/41] Update to version 1.2.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 914d5ec..e69c7fd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino Low Power -version=1.1.0 +version=1.2.0 author=Arduino maintainer=Arduino LLC sentence=Power save primitives features for SAMD and nRF52 32bit boards From b38a5bc50c06da903f6614f773d2a676203c7bf2 Mon Sep 17 00:00:00 2001 From: Stefan Lehmann Date: Mon, 20 Aug 2018 15:43:46 +0200 Subject: [PATCH 07/41] Add support for boards with different name of serial USB connection (#6) * Replace SerialUSB by SERIAL_PORT_USBVIRTUAL Support boards where USB serial is named differently. E.g. the Adafruit Feather M0 uses Serial1 as name for serial USB port. --- src/samd/ArduinoLowPower.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index 8867d6e..d756ed6 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -17,7 +17,7 @@ void ArduinoLowPowerClass::idle(uint32_t millis) { void ArduinoLowPowerClass::sleep() { bool restoreUSBDevice = false; - if (SerialUSB) { + if (SERIAL_PORT_USBVIRTUAL) { USBDevice.standby(); } else { USBDevice.detach(); @@ -100,4 +100,4 @@ void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callb ArduinoLowPowerClass LowPower; -#endif // ARDUINO_ARCH_SAMD \ No newline at end of file +#endif // ARDUINO_ARCH_SAMD From 4caff779d95cddea6200b653779940ed6d19dc5a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 14 Mar 2019 00:55:55 +0100 Subject: [PATCH 08/41] Added dependency --- library.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index e69c7fd..1359413 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino Low Power -version=1.2.0 +version=1.2.1 author=Arduino maintainer=Arduino LLC sentence=Power save primitives features for SAMD and nRF52 32bit boards @@ -7,3 +7,4 @@ paragraph=With this library you can manage the low power states of newer Arduino category=Device Control url=http://arduino.cc/libraries/ArduinoLowPower architectures=samd,nrf52 +depends=RTCZero From 892594adbccf45b198fc067ea994048c76523936 Mon Sep 17 00:00:00 2001 From: sslupsky Date: Tue, 14 May 2019 01:56:55 -0600 Subject: [PATCH 09/41] Fix SysTick timer lockup when waking from sleep (#17) * fix SysTick timer lockup when waking from sleep --- src/samd/ArduinoLowPower.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index d756ed6..faee7e8 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -23,9 +23,13 @@ void ArduinoLowPowerClass::sleep() { USBDevice.detach(); restoreUSBDevice = true; } + // Disable systick interrupt: See https://www.avrfreaks.net/forum/samd21-samd21e16b-sporadically-locks-and-does-not-wake-standby-sleep-mode + SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; __DSB(); __WFI(); + // Enable systick interrupt + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; if (restoreUSBDevice) { USBDevice.attach(); } From fa5c24937c177ec3928c53909e5e68bc0e090a7e Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 20 Feb 2020 00:57:37 -0800 Subject: [PATCH 10/41] Allow sleep durations of 1 day or longer Previously, sleep durations "overflowed" at one day, resulting in a maximum sleep duration of 1 millisecond less than a day. --- src/samd/ArduinoLowPower.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index faee7e8..a775137 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -56,7 +56,7 @@ void ArduinoLowPowerClass::setAlarmIn(uint32_t millis) { uint32_t now = rtc.getEpoch(); rtc.setAlarmEpoch(now + millis/1000); - rtc.enableAlarm(rtc.MATCH_HHMMSS); + rtc.enableAlarm(rtc.MATCH_YYMMDDHHMMSS); } void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callback, uint32_t mode) { From fa71703f5859bc26867e782a89821e3921fcf81d Mon Sep 17 00:00:00 2001 From: Simon Knopp Date: Tue, 18 Feb 2020 14:59:44 +1300 Subject: [PATCH 11/41] 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. --- examples/AdcWakeup/AdcWakeup.ino | 61 ++++++++++++++ src/ArduinoLowPower.h | 17 ++++ src/samd/ArduinoLowPower.cpp | 140 +++++++++++++++++++++++++++---- 3 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 examples/AdcWakeup/AdcWakeup.ino diff --git a/examples/AdcWakeup/AdcWakeup.ino b/examples/AdcWakeup/AdcWakeup.ino new file mode 100644 index 0000000..24cafe2 --- /dev/null +++ b/examples/AdcWakeup/AdcWakeup.ino @@ -0,0 +1,61 @@ +/* + AdcWakeup + + This sketch demonstrates the usage of the ADC to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, changing the voltage on pin A0 will wake up the board. You can test this by connecting a potentiometer between VCC, A0, and GND. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +// Blink sequence number +// Declare it volatile since it's incremented inside an interrupt +volatile int repetitions = 1; + +// Pin used to trigger a wakeup +const int pin = A0; +// How sensitive to be to changes in voltage +const int margin = 10; + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + pinMode(pin, INPUT); +} + +void loop() { + for (int i = 0; i < repetitions; i++) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } + + // Read the voltage at the ADC pin + int value = analogRead(pin); + + // Define a window around that value + uint16_t lo = max(value - margin, 0); + uint16_t hi = min(value + margin, UINT16_MAX); + + // Attach an ADC interrupt on pin A0, calling repetitionsIncrease when the voltage is outside the given range. + // This should be called immediately before LowPower.sleep() because it reconfigures the ADC internally. + LowPower.attachAdcInterrupt(pin, repetitionsIncrease, ADC_INT_OUTSIDE, lo, hi); + + // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources) + // The power consumption of the chip will drop consistently + LowPower.sleep(); + + // Detach the ADC interrupt. This should be called immediately after LowPower.sleep() because it restores the ADC configuration after waking up. + LowPower.detachAdcInterrupt(); +} + +void repetitionsIncrease() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + repetitions ++; +} \ No newline at end of file diff --git a/src/ArduinoLowPower.h b/src/ArduinoLowPower.h index 474c879..6863349 100644 --- a/src/ArduinoLowPower.h +++ b/src/ArduinoLowPower.h @@ -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); diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index a775137..fb8646f 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -3,6 +3,27 @@ #include "ArduinoLowPower.h" #include "WInterrupts.h" +static void configGCLK6() +{ + // enable EIC clock + GCLK->CLKCTRL.bit.CLKEN = 0; //disable GCLK module + while (GCLK->STATUS.bit.SYNCBUSY); + + GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK6 | GCLK_CLKCTRL_ID( GCM_EIC )) ; //EIC clock switched on GCLK6 + while (GCLK->STATUS.bit.SYNCBUSY); + + GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(6)); //source for GCLK6 is OSCULP32K + while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY); + + GCLK->GENCTRL.bit.RUNSTDBY = 1; //GCLK6 run standby + while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY); + + /* Errata: Make sure that the Flash does not power all the way down + * when in sleep mode. */ + + NVMCTRL->CTRLB.bit.SLEEPPRM = NVMCTRL_CTRLB_SLEEPPRM_DISABLED_Val; +} + void ArduinoLowPowerClass::idle() { SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; PM->SLEEP.reg = 2; @@ -80,26 +101,117 @@ void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callb //pinMode(pin, INPUT_PULLUP); attachInterrupt(pin, callback, mode); - // enable EIC clock - GCLK->CLKCTRL.bit.CLKEN = 0; //disable GCLK module - while (GCLK->STATUS.bit.SYNCBUSY); + configGCLK6(); - GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK6 | GCLK_CLKCTRL_ID( GCM_EIC )) ; //EIC clock switched on GCLK6 - while (GCLK->STATUS.bit.SYNCBUSY); + // Enable wakeup capability on pin in case being used during sleep + EIC->WAKEUP.reg |= (1 << in); +} - GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(6)); //source for GCLK6 is OSCULP32K - while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY); +void ArduinoLowPowerClass::attachAdcInterrupt(uint32_t pin, voidFuncPtr callback, adc_interrupt mode, uint16_t lo, uint16_t hi) +{ + uint8_t winmode = 0; - GCLK->GENCTRL.bit.RUNSTDBY = 1; //GCLK6 run standby - while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY); + switch (mode) { + case ADC_INT_BETWEEN: winmode = ADC_WINCTRL_WINMODE_MODE3; break; + case ADC_INT_OUTSIDE: winmode = ADC_WINCTRL_WINMODE_MODE4; break; + case ADC_INT_ABOVE_MIN: winmode = ADC_WINCTRL_WINMODE_MODE1; break; + case ADC_INT_BELOW_MAX: winmode = ADC_WINCTRL_WINMODE_MODE2; break; + default: return; + } - // Enable wakeup capability on pin in case being used during sleep - EIC->WAKEUP.reg |= (1 << in); + adc_cb = callback; - /* Errata: Make sure that the Flash does not power all the way down - * when in sleep mode. */ + configGCLK6(); - NVMCTRL->CTRLB.bit.SLEEPPRM = NVMCTRL_CTRLB_SLEEPPRM_DISABLED_Val; + // Configure ADC to use GCLK6 (OSCULP32K) + while (GCLK->STATUS.bit.SYNCBUSY) {} + GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID_ADC + | GCLK_CLKCTRL_GEN_GCLK6 + | GCLK_CLKCTRL_CLKEN; + while (GCLK->STATUS.bit.SYNCBUSY) {} + + // Set ADC prescaler as low as possible + ADC->CTRLB.bit.PRESCALER = ADC_CTRLB_PRESCALER_DIV4; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Configure window mode + ADC->WINLT.reg = lo; + ADC->WINUT.reg = hi; + ADC->WINCTRL.reg = winmode; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Enable window interrupt + ADC->INTENSET.bit.WINMON = 1; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Enable ADC in standby mode + ADC->CTRLA.bit.RUNSTDBY = 1; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Enable continuous conversions + ADC->CTRLB.bit.FREERUN = 1; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Configure input mux + ADC->INPUTCTRL.bit.MUXPOS = g_APinDescription[pin].ulADCChannelNumber; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Enable the ADC + ADC->CTRLA.bit.ENABLE = 1; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Start continuous conversions + ADC->SWTRIG.bit.START = 1; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Enable the ADC interrupt + NVIC_EnableIRQ(ADC_IRQn); +} + +void ArduinoLowPowerClass::detachAdcInterrupt() +{ + // Disable the ADC interrupt + NVIC_DisableIRQ(ADC_IRQn); + + // Disable the ADC + ADC->CTRLA.bit.ENABLE = 0; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Disable continuous conversions + ADC->CTRLB.bit.FREERUN = 0; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Disable ADC in standby mode + ADC->CTRLA.bit.RUNSTDBY = 1; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Disable window interrupt + ADC->INTENCLR.bit.WINMON = 1; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Disable window mode + ADC->WINCTRL.reg = ADC_WINCTRL_WINMODE_DISABLE; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Restore ADC prescaler + ADC->CTRLB.bit.PRESCALER = ADC_CTRLB_PRESCALER_DIV512_Val; + while (ADC->STATUS.bit.SYNCBUSY) {} + + // Restore ADC clock + while (GCLK->STATUS.bit.SYNCBUSY) {} + GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID_ADC + | GCLK_CLKCTRL_GEN_GCLK0 + | GCLK_CLKCTRL_CLKEN; + while (GCLK->STATUS.bit.SYNCBUSY) {} + + adc_cb = nullptr; +} + +void ADC_Handler() +{ + // Clear the interrupt flag + ADC->INTFLAG.bit.WINMON = 1; + LowPower.adc_cb(); } ArduinoLowPowerClass LowPower; From 39d72b123a19d313172ad6be2f509f3fbadcc0bc Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 17 Dec 2020 00:31:38 -0800 Subject: [PATCH 12/41] Use www subdomain in arduino.cc URLs (#34) www.arduino.cc is Arduino's preferred url. --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 1359413..aaeec59 100644 --- a/library.properties +++ b/library.properties @@ -5,6 +5,6 @@ maintainer=Arduino LLC sentence=Power save primitives features for SAMD and nRF52 32bit boards paragraph=With this library you can manage the low power states of newer Arduino boards category=Device Control -url=http://arduino.cc/libraries/ArduinoLowPower +url=https://www.arduino.cc/libraries/ArduinoLowPower architectures=samd,nrf52 depends=RTCZero From 043dedba3369ac6eb4d14ac2097532894637a1e7 Mon Sep 17 00:00:00 2001 From: Bhargav Patel <35295970+Engineer1999@users.noreply.github.com> Date: Thu, 17 Dec 2020 14:02:47 +0530 Subject: [PATCH 13/41] Added README.md in ArduinoLowPower (#26) * Added README.md in ArduinoLowPower * Update README.md Thank you for modification. Co-Authored-By: per1234 * Update README.md Co-Authored-By: per1234 Co-authored-by: per1234 --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0262128 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Arduino Low Power library + +This library allows the use of the low power features of the SAMD21 MCU. This means your battery powered projects will have a longer battery life on boards like [MKRZero](https://store.arduino.cc/usa/arduino-mkrzero), [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) and [MKRFox1200](https://www.arduino.cc/en/Main/ArduinoBoardMKRFox1200). + +For more information about this library please visit us at + + +# License +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA From b44168f2234082a90661c41f8691258856e17341 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 17 Dec 2020 10:54:44 +0100 Subject: [PATCH 14/41] Make the library compatible with both API and non API cores (#35) Fixes https://github.com/arduino/ArduinoCore-samd/issues/578 --- src/ArduinoLowPower.h | 8 +++++++- src/samd/ArduinoLowPower.cpp | 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ArduinoLowPower.h b/src/ArduinoLowPower.h index 6863349..8ac559a 100644 --- a/src/ArduinoLowPower.h +++ b/src/ArduinoLowPower.h @@ -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 ) ; @@ -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) { diff --git a/src/samd/ArduinoLowPower.cpp b/src/samd/ArduinoLowPower.cpp index fb8646f..1ba0f7c 100644 --- a/src/samd/ArduinoLowPower.cpp +++ b/src/samd/ArduinoLowPower.cpp @@ -1,7 +1,6 @@ #if defined(ARDUINO_ARCH_SAMD) #include "ArduinoLowPower.h" -#include "WInterrupts.h" static void configGCLK6() { @@ -72,7 +71,7 @@ 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(); @@ -80,7 +79,7 @@ void ArduinoLowPowerClass::setAlarmIn(uint32_t millis) { 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 From d70192271e15fd5d0d62b93b429b86b10bde9908 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 21 Dec 2020 10:39:43 +0100 Subject: [PATCH 15/41] Release 1.2.2 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index aaeec59..b8cce30 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino Low Power -version=1.2.1 +version=1.2.2 author=Arduino maintainer=Arduino LLC sentence=Power save primitives features for SAMD and nRF52 32bit boards From cd47d440249ec8efd0f58dce54b70fdfd582d9d7 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Apr 2021 02:25:08 -0700 Subject: [PATCH 16/41] Configure Dependabot to check for outdated actions used in workflows Dependabot will periodically check the versions of all actions used in the repository's workflows. If any are found to be outdated, it will submit a pull request to update them. NOTE: Dependabot's PRs will sometimes try to pin to the patch version of the action (e.g., updating `uses: foo/bar@v1` to `uses: foo/bar@v2.3.4`). When the action author has provided a major version ref, use that instead (e.g., `uses: foo/bar@v2`). Dependabot will automatically close its PR once the workflow has been updated. More information: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..03600dd --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +# See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file +version: 2 + +updates: + # Configure check for outdated GitHub Actions actions in workflows. + # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot + - package-ecosystem: github-actions + directory: / # Check the repository's workflows under /.github/workflows/ + schedule: + interval: daily From 7b1e211b7934539e5e7a95e4cf0eac63edbdb2b8 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Apr 2021 02:36:04 -0700 Subject: [PATCH 17/41] Add CI workflow to check for commonly misspelled words On every push, pull request, and periodically, use the codespell-project/actions-codespell action to check for commonly misspelled words. In the event of a false positive, the problematic word should be added, in all lowercase, to the ignore-words-list field of ./.codespellrc. Regardless of the case of the word in the false positive, it must be in all lowercase in the ignore list. The ignore list is comma-separated with no spaces. --- .codespellrc | 7 +++++++ .github/workflows/spell-check.yml | 22 ++++++++++++++++++++++ README.md | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 .codespellrc create mode 100644 .github/workflows/spell-check.yml diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..101edae --- /dev/null +++ b/.codespellrc @@ -0,0 +1,7 @@ +# See: https://github.com/codespell-project/codespell#using-a-config-file +[codespell] +# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: +ignore-words-list = , +check-filenames = +check-hidden = +skip = ./.git diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml new file mode 100644 index 0000000..01bee87 --- /dev/null +++ b/.github/workflows/spell-check.yml @@ -0,0 +1,22 @@ +name: Spell Check + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + spellcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Spell check + uses: codespell-project/actions-codespell@master diff --git a/README.md b/README.md index 0262128..f7a9e74 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Arduino Low Power library +[![Spell Check status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml) + This library allows the use of the low power features of the SAMD21 MCU. This means your battery powered projects will have a longer battery life on boards like [MKRZero](https://store.arduino.cc/usa/arduino-mkrzero), [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) and [MKRFox1200](https://www.arduino.cc/en/Main/ArduinoBoardMKRFox1200). For more information about this library please visit us at From fbee85bfbcb36dc7cdfd7466f27825e6e59c4b65 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Apr 2021 02:36:38 -0700 Subject: [PATCH 18/41] Correct typos in comments and documentation --- examples/PrimoDeepSleep/PrimoDeepSleep.ino | 10 +++++----- examples/TianStandby/TianStandby.ino | 6 +++--- keywords.txt | 4 ++-- src/nrf52/ArduinoLowPower.cpp | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/examples/PrimoDeepSleep/PrimoDeepSleep.ino index 9e7d9f8..702d8a9 100644 --- a/examples/PrimoDeepSleep/PrimoDeepSleep.ino +++ b/examples/PrimoDeepSleep/PrimoDeepSleep.ino @@ -4,16 +4,16 @@ Written by Chiara Ruggeri (chiara@arduino.org) This example for the Arduino Primo board shows how to use - low power library to enter in power off mode and save power. - This mode ensure the deepest power saving mode. If you need + Arduino Low Power library to enter in power off mode and save power. + This mode ensures the deepest power saving mode. If you need a faster response from the board use standby function instead. Please note that once exited from the deepest sleep mode the board will reset (so setup will be run again). The functions enableWakeupFrom set the peripheral that will wake up - the board. By calling it more than once you can choose more than - a wakeup source. + the board. By calling it more than once you can choose multiple + wakeup sources. The board will be reset when it wakes up from power off. You can use wakeUpCause() function to find out what signals woke up the board if you use more than one wakeUpBy.. function. @@ -27,7 +27,7 @@ // Pin used to wakeup the board const int digitalPin = 10; -// Pin used in Compatarot module to wake up the board +// Pin used in Comparator module to wake up the board const int analogPin = A0; diff --git a/examples/TianStandby/TianStandby.ino b/examples/TianStandby/TianStandby.ino index e74c53e..7fc18c4 100644 --- a/examples/TianStandby/TianStandby.ino +++ b/examples/TianStandby/TianStandby.ino @@ -1,12 +1,12 @@ /* TianStandby - This sketch demonstrates the usage of SAMD chip to furtherly reduce the power usage of Tian + This sketch demonstrates the usage of SAMD chip to further reduce the power usage of the Tian board. This method can be applied to any board with companion chips which expose a method (via direct pin interrupt or via a command) to enter and exit standby. - Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered applications can take advantage of these modes to enhance battery life significantly. - In this sketch, the internal RTC of SAMD chip will wake up the processor every 20 seconds. + In this sketch, the internal RTC of the SAMD chip will wake up the processor every 20 seconds. Before going to sleep, the SAMD chip tells the MIPS CPU to standby too. Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) diff --git a/keywords.txt b/keywords.txt index d0813b7..95fa6c9 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,5 +1,5 @@ ####################################### -# Syntax Coloring Map For Energy Saving +# Syntax Coloring Map For Arduino Low Power ####################################### ####################################### @@ -30,4 +30,4 @@ wakeupReason KEYWORD2 OTHER_WAKEUP LITERAL1 GPIO_WAKEUP LITERAL1 NFC_WAKEUP LITERAL1 -ANALOG_COMPARATOR_WAKEUP LITERAL1 \ No newline at end of file +ANALOG_COMPARATOR_WAKEUP LITERAL1 diff --git a/src/nrf52/ArduinoLowPower.cpp b/src/nrf52/ArduinoLowPower.cpp index 75889a1..898b774 100644 --- a/src/nrf52/ArduinoLowPower.cpp +++ b/src/nrf52/ArduinoLowPower.cpp @@ -64,7 +64,7 @@ void ArduinoLowPowerClass::deepSleep() { //this is achieved by disabling all peripheral that use it NRF_UARTE0->ENABLE = UARTE_ENABLE_ENABLE_Disabled; //disable UART NRF_SAADC ->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos); //disable ADC - NRF_PWM0 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); //disable all pwm instance + NRF_PWM0 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); //disable all PWM instances NRF_PWM1 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); NRF_PWM2 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); NRF_TWIM1 ->ENABLE = (TWIM_ENABLE_ENABLE_Disabled << TWIM_ENABLE_ENABLE_Pos); //disable TWI Master @@ -118,7 +118,7 @@ void ArduinoLowPowerClass::enableWakeupFrom(wakeup_reason peripheral, uint32_t p nrf_lpcomp_config_t config={(nrf_lpcomp_ref_t)event, (nrf_lpcomp_detect_t)mode}; nrf_lpcomp_configure(&config); if(pin<14 && pin>19) - return; //no analog pin is choosen + return; //no analog pin was chosen nrf_lpcomp_input_select(aPin[pin-14]); nrf_lpcomp_enable(); nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_START); From 8c055a48f0ed388244770b628b02e7d20c8ef284 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Apr 2021 02:36:54 -0700 Subject: [PATCH 19/41] Add CI workflow to do Arduino project-specific linting On every push, pull request, and periodically, run Arduino Lint to check for common problems not related to the project code. --- .github/workflows/check-arduino.yml | 28 ++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 29 insertions(+) create mode 100644 .github/workflows/check-arduino.yml diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml new file mode 100644 index 0000000..0d969f6 --- /dev/null +++ b/.github/workflows/check-arduino.yml @@ -0,0 +1,28 @@ +name: Check Arduino + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Arduino Lint + uses: arduino/arduino-lint-action@v1 + with: + compliance: specification + library-manager: update + # Always use this setting for official repositories. Remove for 3rd party projects. + official: true + project-type: library diff --git a/README.md b/README.md index f7a9e74..59979b4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Arduino Low Power library +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml) [![Spell Check status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml) This library allows the use of the low power features of the SAMD21 MCU. This means your battery powered projects will have a longer battery life on boards like [MKRZero](https://store.arduino.cc/usa/arduino-mkrzero), [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) and [MKRFox1200](https://www.arduino.cc/en/Main/ArduinoBoardMKRFox1200). From 0e89b28f57f7118b717c18c5aa915ae253d55a55 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Apr 2021 02:37:19 -0700 Subject: [PATCH 20/41] Add "smoke test" examples compilation CI workflow On every push or pull request that affects library source or example files, and periodically, compile all example sketches for the specified boards. --- .github/workflows/compile-examples.yml | 94 ++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 95 insertions(+) create mode 100644 .github/workflows/compile-examples.yml diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml new file mode 100644 index 0000000..6dcc9c2 --- /dev/null +++ b/.github/workflows/compile-examples.yml @@ -0,0 +1,94 @@ +name: Compile Examples + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/compile-examples.yml" + - "examples/**" + - "src/**" + pull_request: + paths: + - ".github/workflows/compile-examples.yml" + - "examples/**" + - "src/**" + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + build: + name: ${{ matrix.board.fqbn }} + runs-on: ubuntu-latest + + fail-fast: false + + matrix: + board: + - fqbn: arduino:samd:arduino_zero_edbg + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkr1000 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrzero + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrwifi1010 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrfox1200 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrwan1300 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrwan1310 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrgsm1400 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrnb1500 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrvidor4000 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:nano_33_iot + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:tian + platforms: | + - name: arduino:samd + sketch-paths: | + - examples/TianStandby + - fqbn: arduino:nrf52:primo + platforms: | + - name: arduino:nrf52 + sketch-paths: | + - examples/PrimoDeepSleep + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Compile examples + uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fqbn: ${{ matrix.board.fqbn }} + platforms: ${{ matrix.board.platforms }} + libraries: | + # Install the library from the local path. + - source-path: ./ + - name: RTCZero + sketch-paths: | + # Sketches to compile for all boards + - examples/AdcWakeup + - examples/ExternalWakeup + - examples/TimedWakeup + # Board-specific sketches + ${{ matrix.board.sketch-paths }} diff --git a/README.md b/README.md index 59979b4..55bf63e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Arduino Low Power library [![Check Arduino status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/compile-examples.yml) [![Spell Check status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml) This library allows the use of the low power features of the SAMD21 MCU. This means your battery powered projects will have a longer battery life on boards like [MKRZero](https://store.arduino.cc/usa/arduino-mkrzero), [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) and [MKRFox1200](https://www.arduino.cc/en/Main/ArduinoBoardMKRFox1200). From 609afddcc532a1b164299ca7cc7f16efbb9534ae Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 12 Apr 2021 02:37:38 -0700 Subject: [PATCH 21/41] Report changes in memory usage that would result from merging a PR On creation or commit to a pull request, a report of the resulting change in memory usage of the examples will be commented to the PR thread. --- .github/workflows/compile-examples.yml | 13 +++++++++++++ .github/workflows/report-size-deltas.yml | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .github/workflows/report-size-deltas.yml diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 6dcc9c2..3a2da64 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -23,6 +23,10 @@ jobs: name: ${{ matrix.board.fqbn }} runs-on: ubuntu-latest + env: + SKETCHES_REPORTS_PATH: sketches-reports + + strategy: fail-fast: false matrix: @@ -92,3 +96,12 @@ jobs: - examples/TimedWakeup # Board-specific sketches ${{ matrix.board.sketch-paths }} + enable-deltas-report: true + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} + + - name: Save sketches report as workflow artifact + uses: actions/upload-artifact@v2 + with: + if-no-files-found: error + path: ${{ env.SKETCHES_REPORTS_PATH }} + name: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml new file mode 100644 index 0000000..652be5d --- /dev/null +++ b/.github/workflows/report-size-deltas.yml @@ -0,0 +1,24 @@ +name: Report Size Deltas + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/report-size-deltas.yml" + schedule: + # Run at the minimum interval allowed by GitHub Actions. + # Note: GitHub Actions periodically has outages which result in workflow failures. + # In this event, the workflows will start passing again once the service recovers. + - cron: "*/5 * * * *" + workflow_dispatch: + repository_dispatch: + +jobs: + report: + runs-on: ubuntu-latest + steps: + - name: Comment size deltas reports to PRs + uses: arduino/report-size-deltas@v1 + with: + # The name of the workflow artifact created by the sketch compilation workflow + sketches-reports-source: sketches-reports From aeb714964d1f0c4edc29449cdd4eb10d0a3e805e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Tue, 21 Sep 2021 14:51:33 +0200 Subject: [PATCH 22/41] Added docs --- docs/api.md | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ docs/readme.md | 11 ++++ 2 files changed, 146 insertions(+) create mode 100644 docs/api.md create mode 100644 docs/readme.md diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..7adad27 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,135 @@ +# Ardunio Low Power + +## Methods + +### `LowPower.idle()` + +#### Description + +Puts the MCU in IDLE mode. This mode allows power optimization with the fastest wake-up time. The CPU is stopped. To further reduce power consumption, the user can manually disable the clocking of modules and clock sources. + + +#### Syntax + +``` +LowPower.idle(); +LowPower.idle(milliseconds); +``` + +#### Parameters + +milliseconds: the number of milliseconds to put the board in idle mode. If void the idle mode is used till a wakeup event. + +### `LowPower.sleep()` + +#### Description + +Puts the MCU in sleep mode. The sleep mode allows power optimization with a slower wakeup time. Only the chosen peripherals are on. + + +#### Syntax + +``` +LowPower.sleep(); +LowPower.sleep(milliseconds); +``` + +#### Parameters + +milliseconds: the number of milliseconds to put the board in sleep mode. If void the sleep mode is used till a wakeup event. + +### `LowPower.deepSleep()` + +#### Description + +Puts the MCU in deep sleep mode. The deep sleep mode allows power optimization with the slowest wake-up time. All but the RTC peripherals are stopped. The CPU can be wakeup only using RTC or wakeup on interrupt capable pins. + + +#### Syntax + +``` +LowPower.deepSleep(); +LowPower.deepSleep(milliseconds); +``` + +#### Parameters + +milliseconds: the number of milliseconds to put the board in deep sleep mode. If void the deep sleep mode is used till a wakeup event. + +### `LowPower.attachInterruptWakeup()` + +#### Description + +Indicates the function to call and the conditions for a wakeup event. + + +#### Syntax + +``` +LowPower.attachInterruptWakeup(pin, callback, mode); +``` + +#### Parameters + +pin: the pin used as external wakeup + +callback: the function to call on wakeup + +mode: the transitions to sense on the indicated pin. Can be one between: + +- FALLING +- RISING +- CHANGE + +### `LowPower.CompanionLowPowerCallback()` + +#### Description + +Indicates the function that the on-boad co-processor (Tian only) has to call just before going to sleep. + + +#### Syntax + +LowPower.CompanionLowPowerCallback(callback); + +#### Parameters + +callback: the function to call before going to sleep + +### `LowPower.companionSleep()` + +#### Description + +Puts the on-board co-processor (Tian only) in sleep mode + + +#### Syntax + +LowPower.companionSleep(); + +#### Parameters + +None + +### `LowPower.companionWakeup()` + +#### Description + +Forces the on board co-processor (Tian only) wakeup from sleep mode. + + +#### Syntax + +``` +LowPower.companionWakeup(); +``` + +#### Parameters + +None + +## Examples + +- [ExternalWakeup](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/ExternalWakeup/ExternalWakeup.ino) : Demonstrates how to wake your board from an external source like a button. +- [TianStandby](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/TianStandby/TianStandby.ino) : Demonstrates how to put a Tian in standby +- [TimedWakeup](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/TimedWakeup/TimedWakeup.ino) : Demonstrates how to put in sleep your board for a certain amount of time \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..a868ac8 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,11 @@ +# Arduino Low Power Library + +This library allows you to use the low power features of the SAMD21 MCU, which is used for all [MKR family boards](https://store.arduino.cc/collections/mkr-family) and the [Nano 33 IoT board](https://store.arduino.cc/products/arduino-nano-33-iot). + +In these pages, the term companion chip is used. This term refers to a board co-processor like the MIPS processor on the [Arduino Tian](https://docs.arduino.cc/retired/boards/arduino-tian). + +To use this library: + +``` +#include "" +``` \ No newline at end of file From fc955aeadaeb7ea766f501072d070fbf5fe21818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Tue, 21 Sep 2021 14:52:24 +0200 Subject: [PATCH 23/41] moved examples --- docs/api.md | 8 +------- docs/readme.md | 8 +++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/api.md b/docs/api.md index 7adad27..d920b2b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -126,10 +126,4 @@ LowPower.companionWakeup(); #### Parameters -None - -## Examples - -- [ExternalWakeup](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/ExternalWakeup/ExternalWakeup.ino) : Demonstrates how to wake your board from an external source like a button. -- [TianStandby](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/TianStandby/TianStandby.ino) : Demonstrates how to put a Tian in standby -- [TimedWakeup](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/TimedWakeup/TimedWakeup.ino) : Demonstrates how to put in sleep your board for a certain amount of time \ No newline at end of file +None \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md index a868ac8..237392c 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -8,4 +8,10 @@ To use this library: ``` #include "" -``` \ No newline at end of file +``` + +Examples: + +- [ExternalWakeup](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/ExternalWakeup/ExternalWakeup.ino) : Demonstrates how to wake your board from an external source like a button. +- [TianStandby](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/TianStandby/TianStandby.ino) : Demonstrates how to put a Tian in standby +- [TimedWakeup](https://github.com/arduino-libraries/ArduinoLowPower/blob/master/examples/TimedWakeup/TimedWakeup.ino) : Demonstrates how to put in sleep your board for a certain amount of time \ No newline at end of file From 1693ae4255977c41ac34a1076ec05773a480f5b9 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 10 Jan 2022 01:01:17 -0800 Subject: [PATCH 24/41] Add GitHub Actions workflow to synchronize with shared repository labels (#46) On every push that changes relevant files, and periodically, configure the repository's issue and pull request labels according to the universal, shared, and local label configuration files. --- .github/dependabot.yml | 2 + .github/workflows/sync-labels.yml | 138 ++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 .github/workflows/sync-labels.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 03600dd..fa738ec 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,3 +8,5 @@ updates: directory: / # Check the repository's workflows under /.github/workflows/ schedule: interval: daily + labels: + - "topic: infrastructure" diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 0000000..3ee6feb --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,138 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md +name: Sync Labels + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + pull_request: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + schedule: + # Run daily at 8 AM UTC to sync with changes to shared label configurations. + - cron: "0 8 * * *" + workflow_dispatch: + repository_dispatch: + +env: + CONFIGURATIONS_FOLDER: .github/label-configuration-files + CONFIGURATIONS_ARTIFACT: label-configuration-files + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v1 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: | + sudo npm install \ + --global \ + ajv-cli \ + ajv-formats + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "${{ steps.download-schema.outputs.file-path }}" \ + -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" + + download: + needs: check + runs-on: ubuntu-latest + + strategy: + matrix: + filename: + # Filenames of the shared configurations to apply to the repository in addition to the local configuration. + # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels + - universal.yml + + steps: + - name: Download + uses: carlosperate/download-file-action@v1 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v2 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + sync: + needs: download + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" + + - name: Determine whether to dry run + id: dry-run + if: > + github.event_name == 'pull_request' || + ( + ( + github.event_name == 'push' || + github.event_name == 'workflow_dispatch' + ) && + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + ) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "::set-output name=flag::--dry-run" + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download configuration files artifact + uses: actions/download-artifact@v2 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifact + uses: geekyeggo/delete-artifact@v1 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + - name: Merge label configuration files + run: | + # Merge all configuration files + shopt -s extglob + cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" + + - name: Install github-label-sync + run: sudo npm install --global github-label-sync + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} From 131dafec73779654c24108d94e35f524d1f53dad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:13:31 +0000 Subject: [PATCH 25/41] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 2 +- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index 0d969f6..3e0d26c 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Arduino Lint uses: arduino/arduino-lint-action@v1 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 3a2da64..025a152 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -77,7 +77,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Compile examples uses: arduino/compile-sketches@v1 diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 01bee87..3f6b03f 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 3ee6feb..4ea5755 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download configuration files artifact uses: actions/download-artifact@v2 From 1603da8c9b45e8e6ef4e72eaa93f31888d014602 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 14:32:58 +0000 Subject: [PATCH 26/41] Bump actions/download-artifact from 2 to 3 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 4ea5755..e84e803 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v3 - name: Download configuration files artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From f20f2e109f42d91940c7e24efb13e9f869158609 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 14:33:00 +0000 Subject: [PATCH 27/41] Bump actions/upload-artifact from 2 to 3 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/compile-examples.yml | 2 +- .github/workflows/sync-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 025a152..f897a58 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -100,7 +100,7 @@ jobs: sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - name: Save sketches report as workflow artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 4ea5755..1d969d5 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: path: | *.yaml From 4cc00d3af7a5bc834a0914db159cb761bb361d14 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 Oct 2022 14:10:38 +0000 Subject: [PATCH 28/41] Bump geekyeggo/delete-artifact from 1 to 2 Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 1 to 2. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v1...v2) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 986bda6..10abaea 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v1 + uses: geekyeggo/delete-artifact@v2 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 650712354d7193376e0340892b6b2eecea95a735 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:15:27 +0000 Subject: [PATCH 29/41] Bump carlosperate/download-file-action from 1 to 2 Bumps [carlosperate/download-file-action](https://github.com/carlosperate/download-file-action) from 1 to 2. - [Release notes](https://github.com/carlosperate/download-file-action/releases) - [Commits](https://github.com/carlosperate/download-file-action/compare/v1...v2) --- updated-dependencies: - dependency-name: carlosperate/download-file-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 10abaea..94938f3 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -31,7 +31,7 @@ jobs: - name: Download JSON schema for labels configuration file id: download-schema - uses: carlosperate/download-file-action@v1 + uses: carlosperate/download-file-action@v2 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json location: ${{ runner.temp }}/label-configuration-schema @@ -65,7 +65,7 @@ jobs: steps: - name: Download - uses: carlosperate/download-file-action@v1 + uses: carlosperate/download-file-action@v2 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} From b615a89714f0b2247ce28e09fb1ddbfe6e57cf11 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 2 Jan 2023 09:22:47 +0100 Subject: [PATCH 30/41] Remove support for ArduinoCore-Primo. (#55) The board is retired and the corresponding core (https://github.com/arduino/ArduinoCore-primo) has been archived. Considering that no one is going to maintain the low power code for nRF52/Primo its better to get rid of it alltogether (and no longer advertise compatibility to 'nrf52' which - imho rightfully - seems to confuse a lot of people. --- .github/workflows/compile-examples.yml | 5 - examples/PrimoDeepSleep/PrimoDeepSleep.ino | 92 ----------- library.properties | 2 +- src/nrf52/ArduinoLowPower.cpp | 178 --------------------- 4 files changed, 1 insertion(+), 276 deletions(-) delete mode 100644 examples/PrimoDeepSleep/PrimoDeepSleep.ino delete mode 100644 src/nrf52/ArduinoLowPower.cpp diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index f897a58..6537301 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -69,11 +69,6 @@ jobs: - name: arduino:samd sketch-paths: | - examples/TianStandby - - fqbn: arduino:nrf52:primo - platforms: | - - name: arduino:nrf52 - sketch-paths: | - - examples/PrimoDeepSleep steps: - name: Checkout repository diff --git a/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/examples/PrimoDeepSleep/PrimoDeepSleep.ino deleted file mode 100644 index 702d8a9..0000000 --- a/examples/PrimoDeepSleep/PrimoDeepSleep.ino +++ /dev/null @@ -1,92 +0,0 @@ -/* - PrimoDeepSleep.ino - - Written by Chiara Ruggeri (chiara@arduino.org) - - This example for the Arduino Primo board shows how to use - Arduino Low Power library to enter in power off mode and save power. - This mode ensures the deepest power saving mode. If you need - a faster response from the board use standby function instead. - - Please note that once exited from the deepest sleep mode the - board will reset (so setup will be run again). - - The functions enableWakeupFrom set the peripheral that will wake up - the board. By calling it more than once you can choose multiple - wakeup sources. - The board will be reset when it wakes up from power off. - You can use wakeUpCause() function to find out what signals woke up - the board if you use more than one wakeUpBy.. function. - - This example code is in the public domain. -*/ - -#include "ArduinoLowPower.h" - - -// Pin used to wakeup the board -const int digitalPin = 10; - -// Pin used in Comparator module to wake up the board -const int analogPin = A0; - - -void StmEspPM(bool sleep){ - // enable USER1_BUTTON to turn STM32 off and on when pressed. - // note that when STM32 is off you cannot load any new sketch. - pinMode(USER1_BUTTON, STM32_IT); - - // turn ESP8266 off or on - digitalWrite(GPIO_ESP_PW, sleep ? LOW: HIGH); -} - -void setup() { - Serial.begin(9600); - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); - delay(500); - digitalWrite(LED_BUILTIN, LOW); - delay(500); - - //look for what peripheral woke up the board - //reason is 0 at the first execution - wakeup_reason reason=LowPower.wakeupReason(); - if(reason==GPIO_WAKEUP) //GPIO caused the wake up - doMyStuff(); - else - if(reason==NFC_WAKEUP) //NFC caused the wake up - doMyStuffWithNFC(); - else - if(reason==ANALOG_COMPARATOR_WAKEUP) //Comparator caused the wake up - doOtherStuff(); - - Serial.println("Hi all, I return to sleep"); - - LowPower.companionLowPowerCallback(StmEspPM); - // Send sleep command to ESP and enable USER1_BUTTON to turn STM off - LowPower.companionSleep(); - - //set digital pin 10 to wake up the board when LOW level is detected - LowPower.enableWakeupFrom(GPIO_WAKEUP, digitalPin, LOW); - //let the board be woken up by any NFC field - LowPower.enableWakeupFrom(NFC_WAKEUP); - //wake up the board when the voltage on pin A0 goes below the voltage on pin AREF - LowPower.enableWakeupFrom(ANALOG_COMPARATOR_WAKEUP, analogPin, AREF, UP); - //go in low power mode. Note that the board will reset once it is woken up - LowPower.deepSleep(); -} - - -void loop() {} - -void doMyStuff(){ - //insert your code here -} - -void doMyStuffWithNFC(){ - //insert your code here -} - -void doOtherStuff(){ - //insert your code here -} diff --git a/library.properties b/library.properties index b8cce30..21c5375 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Power save primitives features for SAMD and nRF52 32bit boards paragraph=With this library you can manage the low power states of newer Arduino boards category=Device Control url=https://www.arduino.cc/libraries/ArduinoLowPower -architectures=samd,nrf52 +architectures=samd depends=RTCZero diff --git a/src/nrf52/ArduinoLowPower.cpp b/src/nrf52/ArduinoLowPower.cpp deleted file mode 100644 index 898b774..0000000 --- a/src/nrf52/ArduinoLowPower.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - ArduinoLowPower class for nRF52. - - Written by Chiara Ruggeri (chiara@arduino.org) - - Copyright (c) 2017 Arduino AG. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ARDUINO_ARCH_NRF52) - -#include "ArduinoLowPower.h" -#include "WInterrupts.h" -#include "nrf_rtc.h" - -volatile bool event = false; -void (*functionPointer)(void); -nrf_lpcomp_input_t aPin[]={NRF_LPCOMP_INPUT_1, NRF_LPCOMP_INPUT_2, NRF_LPCOMP_INPUT_4, NRF_LPCOMP_INPUT_5, NRF_LPCOMP_INPUT_6, NRF_LPCOMP_INPUT_7}; - -void wakeUpGpio(){ - event = true; - if(functionPointer) - functionPointer(); -} - -void ArduinoLowPowerClass::idle() { - // nRF52 has just two low power modes. Call sleep if idle is called. - sleep(); -} - -void ArduinoLowPowerClass::idle(uint32_t millis) { - setAlarmIn(millis); - idle(); -} - -void ArduinoLowPowerClass::sleep() { - sd_power_mode_set(NRF_POWER_MODE_LOWPWR); - event=false; - while(!event){ - sd_app_evt_wait(); - } -} - -void ArduinoLowPowerClass::sleep(uint32_t millis) { - setAlarmIn(millis); - sleep(); -} - -void ArduinoLowPowerClass::deepSleep() { - //Enter in systemOff mode only when no EasyDMA transfer is active - //this is achieved by disabling all peripheral that use it - NRF_UARTE0->ENABLE = UARTE_ENABLE_ENABLE_Disabled; //disable UART - NRF_SAADC ->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos); //disable ADC - NRF_PWM0 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); //disable all PWM instances - NRF_PWM1 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); - NRF_PWM2 ->ENABLE = (PWM_ENABLE_ENABLE_Disabled << PWM_ENABLE_ENABLE_Pos); - NRF_TWIM1 ->ENABLE = (TWIM_ENABLE_ENABLE_Disabled << TWIM_ENABLE_ENABLE_Pos); //disable TWI Master - NRF_TWIS1 ->ENABLE = (TWIS_ENABLE_ENABLE_Disabled << TWIS_ENABLE_ENABLE_Pos); //disable TWI Slave - - //Enter in System OFF mode - sd_power_system_off(); - - /*Only for debugging purpose, will not be reached without connected debugger*/ - while(1); -} - -void ArduinoLowPowerClass::setAlarmIn(uint32_t millis) { - nrf_rtc_prescaler_set(NRF_RTC1, 32); - //enable interrupt - NVIC_SetPriority(RTC1_IRQn, 2); //high priority - NVIC_ClearPendingIRQ(RTC1_IRQn); - NVIC_EnableIRQ(RTC1_IRQn); - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0); - nrf_rtc_int_enable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK); - //Tick every 1 ms - nrf_rtc_cc_set(NRF_RTC1, 0, millis); - - //start RTC - nrf_rtc_task_trigger(NRF_RTC1, NRF_RTC_TASK_START); -} - -void ArduinoLowPowerClass::attachInterruptWakeup(uint32_t pin, voidFuncPtr callback, uint32_t mode) { - functionPointer = callback; - - if(pin == RTC_ALARM_WAKEUP) - return; - - pinMode(pin, INPUT_PULLUP); - attachInterrupt(pin, wakeUpGpio, mode); -} - -void ArduinoLowPowerClass::enableWakeupFrom(wakeup_reason peripheral, uint32_t pin, uint32_t event, uint32_t option){ - if(peripheral == NFC_WAKEUP){ - NRF_NFCT->TASKS_SENSE=1; - return; - } - if(peripheral == ANALOG_COMPARATOR_WAKEUP){ - detect_mode mode; - if(option == DOWN) - mode = DOWN; - else if(option == UP) - mode = UP; - else - mode = CROSS; - nrf_lpcomp_config_t config={(nrf_lpcomp_ref_t)event, (nrf_lpcomp_detect_t)mode}; - nrf_lpcomp_configure(&config); - if(pin<14 && pin>19) - return; //no analog pin was chosen - nrf_lpcomp_input_select(aPin[pin-14]); - nrf_lpcomp_enable(); - nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_START); - while(!nrf_lpcomp_event_check(NRF_LPCOMP_EVENT_READY)); - return; - } - if(peripheral == GPIO_WAKEUP){ - if(pin > 20)// allow wake up only from digital and analog pins - return; - if(event==LOW) - nrf_gpio_cfg_sense_input(g_APinDescription[pin].ulPin, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); - else - nrf_gpio_cfg_sense_input(g_APinDescription[pin].ulPin, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH); - } -} - -wakeup_reason ArduinoLowPowerClass::wakeupReason(){ - uint32_t guilty; - sd_power_reset_reason_get(&guilty); - if(guilty & 0x10000){ // GPIO - //RESETREAS is a cumulative register. We need to clear it by writing 1 in the relative field - sd_power_reset_reason_clr(1 << 16); - return GPIO_WAKEUP; - } - if(guilty & 0x80000){ //NFC - sd_power_reset_reason_clr(1 << 19); - return NFC_WAKEUP; - } - if(guilty & 0x20000){ //COMP - sd_power_reset_reason_clr(1 << 17); - return ANALOG_COMPARATOR_WAKEUP; - } - return OTHER_WAKEUP; -} - - -ArduinoLowPowerClass LowPower; - -#ifdef __cplusplus -extern "C"{ -#endif - -void RTC1_IRQHandler(void) -{ - event=true; - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0); - nrf_rtc_task_trigger(NRF_RTC1, NRF_RTC_TASK_CLEAR); - nrf_rtc_task_trigger(NRF_RTC1, NRF_RTC_TASK_STOP); - if(functionPointer) - functionPointer(); -} - -#ifdef __cplusplus -} -#endif - -#endif // ARDUINO_ARCH_NRF52 \ No newline at end of file From 06a0d9f257dbe8b9999a53e84fc21768cb57382c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 14:18:23 +0000 Subject: [PATCH 31/41] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 2 +- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index 3e0d26c..adb330f 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Arduino Lint uses: arduino/arduino-lint-action@v1 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 6537301..76aa6dd 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -72,7 +72,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Compile examples uses: arduino/compile-sketches@v1 diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 3f6b03f..ef7d894 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 94938f3..9cde1ac 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download configuration files artifact uses: actions/download-artifact@v3 From af53400a115c2fba30abe1eef0fcacd87347b53d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:03:31 +0100 Subject: [PATCH 32/41] Bump actions/upload-artifact from 3 to 4 (#62) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/compile-examples.yml | 2 +- .github/workflows/sync-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 76aa6dd..9e3f7dc 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -95,7 +95,7 @@ jobs: sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - name: Save sketches report as workflow artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 9cde1ac..7680b37 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: path: | *.yaml From b859f1974864e9ed774ed75845943b566d06ab74 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:03:52 +0100 Subject: [PATCH 33/41] Bump actions/download-artifact from 3 to 4 (#63) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 7680b37..2e1d6e0 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v4 - name: Download configuration files artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From c8731ca5b821ce1012b8424a66744acc70c5e63c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:04:09 +0100 Subject: [PATCH 34/41] Bump geekyeggo/delete-artifact from 2 to 4 (#64) Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 2 to 4. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Changelog](https://github.com/GeekyEggo/delete-artifact/blob/main/CHANGELOG.md) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v2...v4) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 2e1d6e0..47ac50a 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v2 + uses: geekyeggo/delete-artifact@v4 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 6490e2545e01a2b68bebdf0d25a283c6a4ce7993 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Sat, 17 Feb 2024 06:07:43 +0100 Subject: [PATCH 35/41] Fix regression re report-size-deltas after updating actions/upload-artifact. (#65) For more information see https://github.com/arduino/report-size-deltas/blob/main/docs/FAQ.md#size-deltas-report-workflow-triggered-by-schedule-event . --- .github/workflows/compile-examples.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 9e3f7dc..eabf6be 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -34,39 +34,51 @@ jobs: - fqbn: arduino:samd:arduino_zero_edbg platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-arduino_zero_edbg - fqbn: arduino:samd:mkr1000 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkr1000 - fqbn: arduino:samd:mkrzero platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrzero - fqbn: arduino:samd:mkrwifi1010 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrwifi1010 - fqbn: arduino:samd:mkrfox1200 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrfox1200 - fqbn: arduino:samd:mkrwan1300 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrwan1300 - fqbn: arduino:samd:mkrwan1310 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrwan1310 - fqbn: arduino:samd:mkrgsm1400 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrgsm1400 - fqbn: arduino:samd:mkrnb1500 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrnb1500 - fqbn: arduino:samd:mkrvidor4000 platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrvidor4000 - fqbn: arduino:samd:nano_33_iot platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-nano_33_iot - fqbn: arduino:samd:tian platforms: | - name: arduino:samd + artifact-name-suffix: arduino-samd-tian sketch-paths: | - examples/TianStandby @@ -99,4 +111,4 @@ jobs: with: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} - name: ${{ env.SKETCHES_REPORTS_PATH }} + name: sketches-report-${{ matrix.board.artifact-name-suffix }} From 10e902f5539b1eec3c962169e19bd28e7f81df73 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 21 Feb 2024 07:06:25 +0100 Subject: [PATCH 36/41] Fix regression: report size delta size on PR. (#66) The necessary steps have in fact been documented here: https://github.com/arduino/report-size-deltas/blob/main/docs/FAQ.md#workflow-triggered-by-pull_request-event but I have overlooked them when I fixed the upload issue. With this PR the size deltas are - once again - reported within the PR. --- .github/workflows/compile-examples.yml | 23 +++++++++++++++++++---- .github/workflows/report-size-deltas.yml | 24 ------------------------ .gitignore | 1 + 3 files changed, 20 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/report-size-deltas.yml create mode 100644 .gitignore diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index eabf6be..b1f2f29 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -18,14 +18,14 @@ on: workflow_dispatch: repository_dispatch: +env: + SKETCHES_REPORTS_PATH: sketches-reports + jobs: - build: + compile: name: ${{ matrix.board.fqbn }} runs-on: ubuntu-latest - env: - SKETCHES_REPORTS_PATH: sketches-reports - strategy: fail-fast: false @@ -112,3 +112,18 @@ jobs: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} name: sketches-report-${{ matrix.board.artifact-name-suffix }} + + report: + needs: compile + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + + steps: + - name: Download sketches reports artifacts + uses: actions/download-artifact@v4 + with: + path: ${{ env.SKETCHES_REPORTS_PATH }} + + - uses: arduino/report-size-deltas@v1 + with: + sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml deleted file mode 100644 index 652be5d..0000000 --- a/.github/workflows/report-size-deltas.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Report Size Deltas - -# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows -on: - push: - paths: - - ".github/workflows/report-size-deltas.yml" - schedule: - # Run at the minimum interval allowed by GitHub Actions. - # Note: GitHub Actions periodically has outages which result in workflow failures. - # In this event, the workflows will start passing again once the service recovers. - - cron: "*/5 * * * *" - workflow_dispatch: - repository_dispatch: - -jobs: - report: - runs-on: ubuntu-latest - steps: - - name: Comment size deltas reports to PRs - uses: arduino/report-size-deltas@v1 - with: - # The name of the workflow artifact created by the sketch compilation workflow - sketches-reports-source: sketches-reports diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ From 99e892859b0cada3de3895196d52db53ee9c211a Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 21 Feb 2024 18:59:30 +0100 Subject: [PATCH 37/41] Revert "Fix regression: report size delta size on PR. (#66)" This reverts commit 10e902f5539b1eec3c962169e19bd28e7f81df73. --- .github/workflows/compile-examples.yml | 23 ++++------------------- .github/workflows/report-size-deltas.yml | 24 ++++++++++++++++++++++++ .gitignore | 1 - 3 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/report-size-deltas.yml delete mode 100644 .gitignore diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index b1f2f29..eabf6be 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -18,14 +18,14 @@ on: workflow_dispatch: repository_dispatch: -env: - SKETCHES_REPORTS_PATH: sketches-reports - jobs: - compile: + build: name: ${{ matrix.board.fqbn }} runs-on: ubuntu-latest + env: + SKETCHES_REPORTS_PATH: sketches-reports + strategy: fail-fast: false @@ -112,18 +112,3 @@ jobs: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} name: sketches-report-${{ matrix.board.artifact-name-suffix }} - - report: - needs: compile - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - - steps: - - name: Download sketches reports artifacts - uses: actions/download-artifact@v4 - with: - path: ${{ env.SKETCHES_REPORTS_PATH }} - - - uses: arduino/report-size-deltas@v1 - with: - sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml new file mode 100644 index 0000000..652be5d --- /dev/null +++ b/.github/workflows/report-size-deltas.yml @@ -0,0 +1,24 @@ +name: Report Size Deltas + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/report-size-deltas.yml" + schedule: + # Run at the minimum interval allowed by GitHub Actions. + # Note: GitHub Actions periodically has outages which result in workflow failures. + # In this event, the workflows will start passing again once the service recovers. + - cron: "*/5 * * * *" + workflow_dispatch: + repository_dispatch: + +jobs: + report: + runs-on: ubuntu-latest + steps: + - name: Comment size deltas reports to PRs + uses: arduino/report-size-deltas@v1 + with: + # The name of the workflow artifact created by the sketch compilation workflow + sketches-reports-source: sketches-reports diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 9f11b75..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.idea/ From 2137f7da76ec8f2e54d57d61b5ec965ffa445332 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 21 Feb 2024 19:00:05 +0100 Subject: [PATCH 38/41] Correct workflow artifact name pattern in size deltas report workflow The "sketches-reports-source" input of the "arduino/report-size-deltas" GitHub Actions action defines the regular expression that matches the names of the sketches report workflow artifacts produced by the "Compile Examples" workflow. The key string in the names of these artifacts was set to "sketches-report" when the "Compile Examples" workflow was adjusted for compatibility with the breaking changes introduced by updating to version 4.x of the workflow's "actions/upload-artifact" GitHub Actions action dependency. The pattern set in the size deltas report workflow was "sketches-reports". The "s" at the end of that pattern caused it to no longer match against the key string in the artifact names after that adjustment of the "Compile Examples" workflow, resulting in size deltas reports no longer being generated by the workflow. Although a minimal fix would be to simply remove the "s" from the end of the pattern, the decision was made to use a more strict regular expression. This will make it easier for maintainers and contributors to understand that this value is a regular expression and the exact nature of how that regular expression functions (which is less clear when relying on the "arduino/report-size-deltas" action's partial pattern matching behavior). --- .github/workflows/report-size-deltas.yml | 4 ++-- .gitignore | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml index 652be5d..39e2a0a 100644 --- a/.github/workflows/report-size-deltas.yml +++ b/.github/workflows/report-size-deltas.yml @@ -20,5 +20,5 @@ jobs: - name: Comment size deltas reports to PRs uses: arduino/report-size-deltas@v1 with: - # The name of the workflow artifact created by the sketch compilation workflow - sketches-reports-source: sketches-reports + # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow + sketches-reports-source: ^sketches-report-.+ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ From 0d3b7aa35137751ca9fa1ab9aa34dbe29e8e4a0a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 14:49:50 +0100 Subject: [PATCH 39/41] Bump geekyeggo/delete-artifact from 4 to 5 (#68) Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 4 to 5. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Changelog](https://github.com/GeekyEggo/delete-artifact/blob/main/CHANGELOG.md) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 47ac50a..53a9f54 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v4 + uses: geekyeggo/delete-artifact@v5 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 2a6585e132da0a4e406b3fe570f55921b96b3014 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:39:29 +0200 Subject: [PATCH 40/41] Change maintainer to `Arduino ` --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 21c5375..a585142 100644 --- a/library.properties +++ b/library.properties @@ -1,7 +1,7 @@ name=Arduino Low Power version=1.2.2 author=Arduino -maintainer=Arduino LLC +maintainer=Arduino sentence=Power save primitives features for SAMD and nRF52 32bit boards paragraph=With this library you can manage the low power states of newer Arduino boards category=Device Control From 06d7aca5ff3312e02505b0b039b106e1a8236678 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:38:07 +0000 Subject: [PATCH 41/41] Bump arduino/arduino-lint-action from 1 to 2 Bumps [arduino/arduino-lint-action](https://github.com/arduino/arduino-lint-action) from 1 to 2. - [Release notes](https://github.com/arduino/arduino-lint-action/releases) - [Commits](https://github.com/arduino/arduino-lint-action/compare/v1...v2) --- updated-dependencies: - dependency-name: arduino/arduino-lint-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index adb330f..e818685 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -19,7 +19,7 @@ jobs: uses: actions/checkout@v4 - name: Arduino Lint - uses: arduino/arduino-lint-action@v1 + uses: arduino/arduino-lint-action@v2 with: compliance: specification library-manager: update