-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from brentru/add-pico
Add support for Raspberry Pi Pico Arduino core
- Loading branch information
Showing
5 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=Adafruit SleepyDog Library | ||
version=1.6.1 | ||
version=1.6.2 | ||
author=Adafruit | ||
maintainer=Adafruit <[email protected]> | ||
sentence=Arduino library to use the watchdog timer for system reset and low power sleep. | ||
paragraph=Arduino library to use the watchdog timer for system reset and low power sleep. | ||
category=Other | ||
url=https://github.com/adafruit/Adafruit_SleepyDog | ||
architectures=avr,samd,nrf52,teensy,esp32,esp8266 | ||
architectures=avr,samd,nrf52,teensy,esp32,esp8266,rp2040 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#if defined(ARDUINO_ARCH_RP2040) | ||
|
||
#include "WatchdogRP2040.h" | ||
|
||
/**********************************************************************************************/ | ||
/*! | ||
@brief Initializes the RP2040's hardware watchdog timer. | ||
@param maxPeriodMS | ||
Timeout period of WDT in milliseconds | ||
@return The actual period (in milliseconds) before a watchdog timer | ||
reset is returned, 0 otherwise. | ||
*/ | ||
/**********************************************************************************************/ | ||
int WatchdogRP2040::enable(int maxPeriodMS) { | ||
if (maxPeriodMS < 0) | ||
return 0; | ||
|
||
// Enables the RP2040's hardware WDT with maxPeriodMS delay | ||
// (wdt should be updated every maxPeriodMS ms) and | ||
// enables pausing the WDT on debugging when stepping thru | ||
watchdog_enable(maxPeriodMS, 1); | ||
|
||
_wdto = maxPeriodMS; | ||
return maxPeriodMS; | ||
} | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Reload the watchdog counter with the amount of time set in | ||
enable(). | ||
*/ | ||
/**************************************************************************/ | ||
void WatchdogRP2040::reset() { watchdog_update(); } | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Once enabled, the RP2040's Watchdog Timer can NOT be disabled. | ||
*/ | ||
/**************************************************************************/ | ||
void WatchdogRP2040::disable() {} | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Configures the RP2040 to enter a lower power (WFE) sleep | ||
for a period of time. | ||
@param maxPeriodMS | ||
Time to sleep the RP2040, in millis. | ||
@return The actual period (in milliseconds) that the hardware was | ||
asleep will be returned. Otherwise, 0 will be returned if the | ||
hardware could not enter the low-power mode. | ||
*/ | ||
/**************************************************************************/ | ||
int WatchdogRP2040::sleep(int maxPeriodMS) { | ||
if (maxPeriodMS < 0) | ||
return 0; | ||
|
||
// perform a lower power (WFE) sleep (pico-core calls sleep_ms(sleepTime)) | ||
delay(maxPeriodMS); | ||
|
||
return maxPeriodMS; | ||
} | ||
|
||
#endif // ARDUINO_ARCH_RP2040 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! | ||
* @file WatchdogRP2040.h | ||
* | ||
* Support for RP2040 Hardware Watchdog Timer API | ||
* | ||
* Adafruit invests time and resources providing this open source code, | ||
* please support Adafruit and open-source hardware by purchasing | ||
* products from Adafruit! | ||
* | ||
* Written by Brent Rubell for Adafruit Industries. | ||
* | ||
* MIT License, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
#ifndef WATCHDOGRP2040_H_ | ||
#define WATCHDOGRP2040_H_ | ||
|
||
#include <hardware/watchdog.h> | ||
#include <pico/time.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that contains functions for interacting with the | ||
RP2040's hardware watchdog timer | ||
*/ | ||
/**************************************************************************/ | ||
class WatchdogRP2040 { | ||
public: | ||
WatchdogRP2040() : _wdto(-1){}; | ||
int enable(int maxPeriodMS = 0); | ||
void disable() | ||
__attribute__((error("RP2040 WDT cannot be disabled once enabled"))); | ||
void reset(); | ||
int sleep(int maxPeriodMS = 0); | ||
|
||
private: | ||
int _wdto; | ||
}; | ||
|
||
#endif // WatchdogRP2040_H |