-
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 #35 from brentru/add-esp8266
Add ESP8266 Support
- Loading branch information
Showing
12 changed files
with
138 additions
and
7 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
Empty file.
Empty file.
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
Empty file.
Empty file.
Empty file.
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.5.0 | ||
version=1.6.0 | ||
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 | ||
architectures=avr,samd,nrf52,teensy,esp32,esp8266 |
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,76 @@ | ||
#if defined(ARDUINO_ARCH_ESP8266) | ||
|
||
#include "WatchdogESP8266.h" | ||
|
||
/**********************************************************************************************/ | ||
/*! | ||
@brief Initializes the ESP8266's software WDT | ||
@param maxPeriodMS | ||
Timeout period of WDT in milliseconds | ||
@return The actual period (in milliseconds) before a watchdog timer | ||
reset is returned, 0 otherwise. | ||
NOTE: Configuring the software WDT timeout maxPeriodMS value is NOT | ||
IMPLEMENTED in the ESP8266 BSP [1]. Further, an investigation into the | ||
default software WDT time yielded a fixed timeout period of 3.2 seconds [2]. | ||
[1] https://github.com/esp8266/Arduino/blob/master/cores/esp8266/Esp.h#L91 | ||
[2]https://sigmdel.ca/michel/program/esp8266/arduino/watchdogs_en.html#ESP8266_WDT_TIMEOUT | ||
*/ | ||
/**********************************************************************************************/ | ||
int WatchdogESP8266::enable(int maxPeriodMS) { | ||
if (maxPeriodMS < 0) | ||
return 0; | ||
|
||
// Enable the WDT | ||
ESP.wdtEnable(0); | ||
|
||
_wdto = maxPeriodMS; | ||
return maxPeriodMS; | ||
} | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Feeds the Watchdog timer. | ||
NOTE: Calling yield() or delay() also feeds the hardware and software | ||
watchdog timers. | ||
*/ | ||
/**************************************************************************/ | ||
void WatchdogESP8266::reset() { ESP.wdtFeed(); } | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Disables the Watchdog Timer. | ||
NOTE: Please don't stop the software WDT too long | ||
(less than 6 seconds), otherwise it will trigger a hardware | ||
watchdog reset! | ||
*/ | ||
/**************************************************************************/ | ||
void WatchdogESP8266::disable() { ESP.wdtDisable(); } | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Configures the ESP8266 to enter a low-power sleep mode for a | ||
desired amount of time. | ||
@param maxPeriodMS | ||
Time to sleep the ESP8266, 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 WatchdogESP8266::sleep(int maxPeriodMS) { | ||
if (maxPeriodMS < 0) | ||
return 0; | ||
// Convert from MS to microseconds | ||
uint64_t sleepTime = maxPeriodMS * 1000; | ||
|
||
// Assert that we can not sleep longer than the max. time calculated by ESP | ||
if (sleepTime > ESP.deepSleepMax()) | ||
return 0; | ||
|
||
// Enters deep sleep with mode WAKE_RF_DEFAULT | ||
ESP.deepSleep(sleepTime); | ||
|
||
return maxPeriodMS; | ||
} | ||
|
||
#endif // ARDUINO_ARCH_ESP8266 |
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 WatchdogESP8266.h | ||
* | ||
* Support for ESP8266 WDT and low-power sleep modes. | ||
* | ||
* 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 WATCHDOGESP8266_H_ | ||
#define WATCHDOGESP8266_H_ | ||
|
||
// #include "esp_sleep.h" | ||
// #include "esp_task_wdt.h" | ||
#include "Esp.h" | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that contains functions for interacting with the | ||
ESP8266's WDT and low-power sleep functions. | ||
*/ | ||
/**************************************************************************/ | ||
class WatchdogESP8266 { | ||
public: | ||
WatchdogESP8266() : _wdto(-1){}; | ||
int enable(int maxPeriodMS = 0); | ||
void reset(); | ||
void disable(); | ||
int sleep(int maxPeriodMS = 0); | ||
|
||
private: | ||
int _wdto; | ||
}; | ||
|
||
#endif // WATCHDOGESP8266_H |