Skip to content

Commit f8895d1

Browse files
committed
Merge pull request #10 from esp8266/esp8266
Esp8266
2 parents 9bb29fc + 9dce0c4 commit f8895d1

File tree

8 files changed

+51
-42
lines changed

8 files changed

+51
-42
lines changed

Diff for: README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ APIs related to deep sleep and watchdog timer are available in the ```ESP``` obj
153153

154154
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_RF_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```. (GPIO16 needs to be tied to RST to wake from deepSleep.)
155155

156-
```ESP.wdtEnable()```, ```ESP.wdtDisable()```, and ```ESP.wdtFeed()``` provide some control over the watchdog timer.
157-
158-
```ESP.reset()``` resets the CPU.
156+
```ESP.restart()``` restarts the CPU.
159157

160158
```ESP.getFreeHeap()``` returns the free heap size.
161159

@@ -171,6 +169,16 @@ Several APIs may be used to get flash chip info:
171169

172170
```ESP.getCycleCount()``` returns the cpu instruction cycle count since start as an unsigned 32-bit. This is useful for accurate timing of very short actions like bit banging.
173171

172+
```ESP.getVcc()``` may be used to measure supply voltage. ESP needs to reconfigure the ADC
173+
at startup in order for this feature to be available. Add the following line to the top
174+
of your sketch to use ```getVcc```:
175+
```
176+
ADC_MODE(ADC_VCC);
177+
```
178+
TOUT pin has to be disconnected in this mode.
179+
180+
Note that by default ADC is configured to read from TOUT pin using ```analogRead(A0)```, and
181+
```ESP.getVCC()``` is not available.
174182

175183
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
176184

Diff for: cores/esp8266/Esp.cpp

+9-19
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ extern struct rst_info resetInfo;
3232

3333
// #define DEBUG_SERIAL Serial
3434

35-
//extern "C" void ets_wdt_init(uint32_t val);
36-
extern "C" void ets_wdt_enable(void);
37-
extern "C" void ets_wdt_disable(void);
38-
extern "C" void wdt_feed(void) {
39-
40-
}
4135

4236
/**
4337
* User-defined Literals
@@ -85,46 +79,42 @@ unsigned long long operator"" _GB(unsigned long long x) {
8579

8680
EspClass ESP;
8781

88-
EspClass::EspClass()
89-
{
90-
91-
}
92-
9382
void EspClass::wdtEnable(uint32_t timeout_ms)
9483
{
95-
//todo find doku for ets_wdt_init may set the timeout
96-
ets_wdt_enable();
9784
}
9885

9986
void EspClass::wdtEnable(WDTO_t timeout_ms)
10087
{
101-
wdtEnable((uint32_t) timeout_ms);
10288
}
10389

10490
void EspClass::wdtDisable(void)
10591
{
106-
ets_wdt_disable();
10792
}
10893

10994
void EspClass::wdtFeed(void)
11095
{
111-
wdt_feed();
11296
}
11397

11498
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
11599
{
116-
system_deep_sleep_set_option(static_cast<int>(mode));
117-
system_deep_sleep(time_us);
100+
system_deep_sleep_set_option(static_cast<int>(mode));
101+
system_deep_sleep(time_us);
118102
}
119103

104+
extern "C" void esp_yield();
105+
extern "C" void __real_system_restart_local();
120106
void EspClass::reset(void)
121107
{
122-
((void (*)(void))0x40000080)();
108+
__real_system_restart_local();
123109
}
124110

125111
void EspClass::restart(void)
126112
{
127113
system_restart();
114+
esp_yield();
115+
// todo: provide an alternative code path if this was called
116+
// from system context, not from continuation
117+
// (implement esp_is_cont_ctx()?)
128118
}
129119

130120
uint16_t EspClass::getVcc(void)

Diff for: cores/esp8266/Esp.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ enum RFMode {
6161
#define WAKE_NO_RFCAL RF_NO_CAL
6262
#define WAKE_RF_DISABLED RF_DISABLED
6363

64+
enum ADCMode {
65+
ADC_TOUT = 33,
66+
ADC_TOUT_3V3 = 33,
67+
ADC_VCC = 255,
68+
ADC_VDD = 255
69+
};
70+
71+
#define ADC_MODE(mode) extern "C" int __get_adc_mode() { return (int) (mode); }
72+
6473
typedef enum {
6574
FM_QIO = 0x00,
6675
FM_QOUT = 0x01,
@@ -71,8 +80,6 @@ typedef enum {
7180

7281
class EspClass {
7382
public:
74-
EspClass();
75-
7683
// TODO: figure out how to set WDT timeout
7784
void wdtEnable(uint32_t timeout_ms = 0);
7885
// note: setting the timeout value is not implemented at the moment

Diff for: cores/esp8266/core_esp8266_phy.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ static uint8_t phy_init_data[128] =
224224

225225
extern int __real_register_chipv6_phy(uint8_t* init_data);
226226
extern int __wrap_register_chipv6_phy(uint8_t* unused) {
227+
phy_init_data[107] = __get_adc_mode();
227228
return __real_register_chipv6_phy(phy_init_data);
228229
}
229230

@@ -243,6 +244,10 @@ extern int __get_rf_mode()
243244
return 0; // default mode
244245
}
245246

246-
247+
extern int __get_adc_mode() __attribute__((weak));
248+
extern int __get_adc_mode()
249+
{
250+
return 33; // default ADC mode
251+
}
247252

248253

Diff for: cores/esp8266/core_esp8266_wiring_analog.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
You should have received a copy of the GNU Lesser General Public
1818
License along with this library; if not, write to the Free Software
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
21+
22+
18/06/2015 analogRead bugfix by Testato
2023
*/
24+
2125
#include "wiring_private.h"
2226
#include "pins_arduino.h"
2327

24-
extern uint16_t readvdd33(void);
25-
26-
void analogReference(uint8_t mode) {}
2728

2829
extern int __analogRead(uint8_t pin) {
2930
if(pin == 17){
30-
return readvdd33() >> 2; // readvdd33 is 12 bit
31+
return system_adc_read();
3132
}
3233
return digitalRead(pin) * 1023;
3334
}

Diff for: libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void ESP8266WebServer::handleClient()
115115
_handleRequest();
116116
}
117117

118-
void ESP8266WebServer::sendHeader(String name, String value, bool first) {
118+
void ESP8266WebServer::sendHeader(const String& name, const String& value, bool first) {
119119
String headerLine = name;
120120
headerLine += ": ";
121121
headerLine += value;
@@ -129,7 +129,7 @@ void ESP8266WebServer::sendHeader(String name, String value, bool first) {
129129
}
130130
}
131131

132-
void ESP8266WebServer::send(int code, const char* content_type, String content) {
132+
void ESP8266WebServer::send(int code, const char* content_type, const String& content) {
133133
String response = "HTTP/1.1 ";
134134
response += String(code);
135135
response += " ";
@@ -155,15 +155,15 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
155155
sendContent(response);
156156
}
157157

158-
void ESP8266WebServer::send(int code, char* content_type, String content) {
158+
void ESP8266WebServer::send(int code, char* content_type, const String& content) {
159159
send(code, (const char*)content_type, content);
160160
}
161161

162-
void ESP8266WebServer::send(int code, String content_type, String content) {
162+
void ESP8266WebServer::send(int code, const String& content_type, const String& content) {
163163
send(code, (const char*)content_type.c_str(), content);
164164
}
165165

166-
void ESP8266WebServer::sendContent(String content) {
166+
void ESP8266WebServer::sendContent(const String& content) {
167167
size_t size_to_send = content.length();
168168
size_t size_sent = 0;
169169
while(size_to_send) {

Diff for: libraries/ESP8266WebServer/src/ESP8266WebServer.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ class ESP8266WebServer
7777
// code - HTTP response code, can be 200 or 404
7878
// content_type - HTTP content type, like "text/plain" or "image/png"
7979
// content - actual content body
80-
void send(int code, const char* content_type = NULL, String content = String(""));
81-
void send(int code, char* content_type, String content);
82-
void send(int code, String content_type, String content);
80+
void send(int code, const char* content_type = NULL, const String& content = String(""));
81+
void send(int code, char* content_type, const String& content);
82+
void send(int code, const String& content_type, const String& content);
8383

8484
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
85-
void sendHeader(String name, String value, bool first = false);
86-
void sendContent(String content);
85+
void sendHeader(const String& name, const String& value, bool first = false);
86+
void sendContent(const String& content);
8787

88-
template<typename T> size_t streamFile(T &file, String contentType){
88+
template<typename T> size_t streamFile(T &file, const String& contentType){
8989
setContentLength(file.size());
9090
if (String(file.name()).endsWith(".gz") &&
9191
contentType != "application/x-gzip" &&

Diff for: libraries/ESP8266WiFi/src/include/slist.h

-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ class SList {
99
protected:
1010

1111
static void _add(T* self) {
12-
DEBUGV("%s %08x %08x\n", __func__, (uint32_t) self, (uint32_t) _s_first);
1312
T* tmp = _s_first;
1413
_s_first = self;
1514
self->_next = tmp;
1615
}
1716

1817
static void _remove(T* self) {
19-
DEBUGV("%s %08x %08x\n", __func__, (uint32_t) self, (uint32_t) _s_first);
2018
if (_s_first == self) {
2119
_s_first = self->_next;
2220
self->_next = 0;

0 commit comments

Comments
 (0)