Skip to content

Commit 28a8788

Browse files
committed
Add watchdog and deep sleep APIs
requested in #34
1 parent 66daf7f commit 28a8788

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

hardware/esp8266com/esp8266/cores/esp8266/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ volatile uint32_t* portModeRegister(uint32_t port);
158158
#include "WString.h"
159159

160160
#include "HardwareSerial.h"
161+
#include "Esp.h"
161162

162163
uint16_t makeWord(uint16_t w);
163164
uint16_t makeWord(byte h, byte l);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Esp.cpp - ESP8266-specific APIs
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
This file is part of the esp8266 core for Arduino environment.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "Arduino.h"
22+
23+
extern "C" {
24+
#include "user_interface.h"
25+
}
26+
27+
extern "C" void ets_wdt_enable (void);
28+
extern "C" void ets_wdt_disable (void);
29+
extern "C" void wdt_feed (void);
30+
31+
EspClass ESP;
32+
33+
EspClass::EspClass()
34+
{
35+
36+
}
37+
38+
void EspClass::wdtEnable(int)
39+
{
40+
ets_wdt_enable();
41+
}
42+
43+
void EspClass::wdtDisable()
44+
{
45+
ets_wdt_disable();
46+
}
47+
48+
void EspClass::wdtFeed()
49+
{
50+
wdt_feed();
51+
}
52+
53+
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
54+
{
55+
system_deep_sleep_set_option(static_cast<int>(mode));
56+
system_deep_sleep(time_us);
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Esp.h - ESP8266-specific APIs
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
This file is part of the esp8266 core for Arduino environment.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#ifndef ESP_H
22+
#define ESP_H
23+
24+
25+
enum WakeMode {
26+
WAKE_RF_DEFAULT = 0, // RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
27+
WAKE_RFCAL = 1, // RF_CAL after deep-sleep wake up, there will be large current.
28+
WAKE_NO_RFCAL = 2, // no RF_CAL after deep-sleep wake up, there will only be small current.
29+
WAKE_RF_DISABLED = 4 // disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
30+
};
31+
32+
class EspClass {
33+
public:
34+
EspClass();
35+
36+
void wdtEnable(int timeout_ms = 0);
37+
// TODO: figure out how to set WDT timeout
38+
void wdtDisable();
39+
void wdtFeed();
40+
41+
void deepSleep(uint32_t time_us, WakeMode mode = WAKE_RF_DEFAULT);
42+
};
43+
44+
extern EspClass ESP;
45+
46+
#endif //ESP_H

0 commit comments

Comments
 (0)