Skip to content

Commit 5aff343

Browse files
author
Jeroen88
committed
Merge branch 'master' into feature/HTTPClient_WiFiClient_parameter
2 parents 96636f2 + 9f67d83 commit 5aff343

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+251
-77
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ deploy:
5050
api_key:
5151
secure: A4FBmqyhlzy33oPeZVolg2Q/A3ZcJ3WnRQqQJ3NAPy+qGM5xcboOYtwcLL9vKaHZGfUB7lUP9QVZFGou1Wrmo9DnPvAoe3+XvCaDRGzVMxeIpu7UStbBD4Knbh98tlbMvZCXYRlT4VcusI9bMLK6UWw4sMdPislBh2FEfglTiag=
5252
file_glob: true
53+
tag_name: $TRAVIS_TAG
54+
target_commitish: $TRAVIS_COMMIT
5355
file:
5456
- package/versions/$TRAVIS_TAG/esp8266-$TRAVIS_TAG.zip
5557
- package/versions/$TRAVIS_TAG/package_esp8266com_index.json

cores/esp8266/Esp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
114114
esp_yield();
115115
}
116116

117+
void EspClass::deepSleepInstant(uint64_t time_us, WakeMode mode)
118+
{
119+
system_deep_sleep_set_option(static_cast<int>(mode));
120+
system_deep_sleep_instant(time_us);
121+
esp_yield();
122+
}
123+
117124
//this calculation was taken verbatim from the SDK api reference for SDK 2.1.0.
118125
//Note: system_rtc_clock_cali_proc() returns a uint32_t, even though system_deep_sleep() takes a uint64_t.
119126
uint64_t EspClass::deepSleepMax()

cores/esp8266/Esp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class EspClass {
9393
void wdtFeed();
9494

9595
void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT);
96+
void deepSleepInstant(uint64_t time_us, RFMode mode = RF_DEFAULT);
9697
uint64_t deepSleepMax();
9798

9899
bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);

cores/esp8266/Print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
size_t Print::write(const uint8_t *buffer, size_t size) {
3636

3737
#ifdef DEBUG_ESP_CORE
38-
static char not_the_best_way [] ICACHE_RODATA_ATTR STORE_ATTR = "Print::write(data,len) should be overridden for better efficiency\r\n";
38+
static char not_the_best_way [] PROGMEM STORE_ATTR = "Print::write(data,len) should be overridden for better efficiency\r\n";
3939
static bool once = false;
4040
if (!once) {
4141
once = true;

cores/esp8266/core_esp8266_phy.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ void user_rf_pre_init()
301301
// *((volatile uint32_t*) 0x60000710) = 0;
302302
spoof_init_data = false;
303303
volatile uint32_t* rtc_reg = (volatile uint32_t*) 0x60001000;
304-
if((rtc_reg[24] >> 16) > 4) {
305-
rtc_reg[24] &= 0xFFFF;
306-
rtc_reg[30] = 0;
307-
}
304+
rtc_reg[30] = 0;
308305

309306
system_set_os_print(0);
310307
int rf_mode = __get_rf_mode();

cores/esp8266/core_esp8266_postmortem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void __wrap_system_restart_local() {
166166

167167
// Use cap-X formatting to ensure the standard EspExceptionDecoder doesn't match the address
168168
if (umm_last_fail_alloc_addr) {
169-
ets_printf("\nlast failed alloc call: %08X(%d)\n", (uint32_t)umm_last_fail_alloc_addr, umm_last_fail_alloc_size);
169+
ets_printf_P("\nlast failed alloc call: %08X(%d)\n", (uint32_t)umm_last_fail_alloc_addr, umm_last_fail_alloc_size);
170170
}
171171

172172
custom_crash_callback( &rst_info, sp + offset, stack_end );

cores/esp8266/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C" {
2323
#endif
2424

2525
void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn));
26-
#define panic() __panic_func(__FILE__, __LINE__, __func__)
26+
#define panic() __panic_func(PSTR(__FILE__), __LINE__, __func__)
2727

2828
#ifdef __cplusplus
2929
}

cores/esp8266/heap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
8484
#undef calloc
8585
#undef realloc
8686

87-
static const char oom_fmt[] ICACHE_RODATA_ATTR STORE_ATTR = ":oom(%d)@?\n";
88-
static const char oom_fmt_1[] ICACHE_RODATA_ATTR STORE_ATTR = ":oom(%d)@";
89-
static const char oom_fmt_2[] ICACHE_RODATA_ATTR STORE_ATTR = ":%d\n";
87+
static const char oom_fmt[] PROGMEM STORE_ATTR = ":oom(%d)@?\n";
88+
static const char oom_fmt_1[] PROGMEM STORE_ATTR = ":oom(%d)@";
89+
static const char oom_fmt_2[] PROGMEM STORE_ATTR = ":%d\n";
9090

9191
void* malloc (size_t s)
9292
{

cores/esp8266/pgmspace.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@
1010
#include "ets_sys.h"
1111
#include "osapi.h"
1212

13-
#define PROGMEM ICACHE_RODATA_ATTR
13+
// Since __section__ is supposed to be only use for global variables,
14+
// there could be conflicts when a static/inlined function has them in the
15+
// same file as a non-static PROGMEM object.
16+
// Ref: https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html
17+
// Place each progmem object into its own named section, avoiding conflicts
18+
19+
// The following two macros cause a parameter to be enclosed in quotes
20+
// by the preopressor (i.e. for concatenating ints to strings)
21+
#define __STRINGIZE_NX(A) #A
22+
#define __STRINGIZE(A) __STRINGIZE_NX(A)
23+
24+
#define PROGMEM __attribute__((section( "\".irom.text." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\"")))
25+
1426
#define PGM_P const char *
1527
#define PGM_VOID_P const void *
1628
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))

cores/esp8266/uart.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
*
4242
*/
4343
#include "Arduino.h"
44+
#include <pgmspace.h>
4445
#include "uart.h"
4546
#include "esp8266_peri.h"
4647
#include "user_interface.h"
4748
#include "uart_register.h"
4849

49-
const char overrun_str [] ICACHE_RODATA_ATTR STORE_ATTR = "uart input full!\r\n";
50+
const char overrun_str [] PROGMEM STORE_ATTR = "uart input full!\r\n";
5051
static int s_uart_debug_nr = UART0;
5152

5253

cores/esp8266/umm_malloc/umm_malloc_cfg.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ extern char _heap_start;
178178
// this must be outside from "#ifndef _UMM_MALLOC_CFG_H"
179179
// because Arduino.h's <cstdlib> does #undef *alloc
180180
// Arduino.h recall us to redefine them
181-
#define malloc(s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; malloc_loc(s, mem_debug_file, __LINE__); })
182-
#define calloc(n,s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; calloc_loc(n, s, mem_debug_file, __LINE__); })
183-
#define realloc(p,s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; realloc_loc(p, s, mem_debug_file, __LINE__); })
181+
#include <pgmspace.h>
182+
#define malloc(s) ({ static const char mem_debug_file[] PROGMEM STORE_ATTR = __FILE__; malloc_loc(s, mem_debug_file, __LINE__); })
183+
#define calloc(n,s) ({ static const char mem_debug_file[] PROGMEM STORE_ATTR = __FILE__; calloc_loc(n, s, mem_debug_file, __LINE__); })
184+
#define realloc(p,s) ({ static const char mem_debug_file[] PROGMEM STORE_ATTR = __FILE__; realloc_loc(p, s, mem_debug_file, __LINE__); })
184185
#endif /* DEBUG_ESP_OOM */

doc/libraries.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Some ESP-specific APIs related to deep sleep, RTC and flash memories are availab
7373

7474
``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.) The chip can sleep for at most ``ESP.deepSleepMax()`` microseconds.
7575

76+
``ESP.deepSleepInstant(microseconds, mode)`` works similarly to ``ESP.deepSleep`` but sleeps instantly without waiting for WiFi to shutdown.
77+
7678
``ESP.rtcUserMemoryWrite(offset, &data, sizeof(data))`` and ``ESP.rtcUserMemoryRead(offset, &data, sizeof(data))`` allow data to be stored in and retrieved from the RTC user memory of the chip respectively. Total size of RTC user memory is 512 bytes, so ``offset + sizeof(data)`` shouldn't exceed 512. Data should be 4-byte aligned. The stored data can be retained between deep sleep cycles. However, the data might be lost after power cycling the chip.
7779

7880
``ESP.restart()`` restarts the CPU.

doc/reference.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ either to read voltage at ADC pin, or to read module supply voltage
4242
(VCC).
4343

4444
To read external voltage applied to ADC pin, use ``analogRead(A0)``.
45-
Input voltage range is 0 — 1.0V.
45+
Input voltage range of bare ESP8266 is 0 — 1.0V, however some many
46+
boards may implement voltage dividers. To be on the safe side, <1.0V
47+
can be tested. If e.g. 0.5V delivers values around ~512, then maximum
48+
voltage is very likely to be 1.0V and 3.3V may harm the ESP8266.
49+
However values around ~150 indicates that the maximum voltage is
50+
likely to be 3.3V.
4651

4752
To read VCC voltage, use ``ESP.getVcc()`` and ADC pin must be kept
4853
unconnected. Additionally, the following line has to be added to the

libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void setup() {
5353
delay(1000);
5454
Serial.begin(9600);
5555
Serial.println();
56-
Serial.print("Configuring access point...");
56+
Serial.println("Configuring access point...");
5757
/* You can remove the password parameter if you want the AP to be open. */
5858
WiFi.softAPConfig(apIP, apIP, netMsk);
5959
WiFi.softAP(softAP_ssid, softAP_password);

libraries/DNSServer/examples/CaptivePortalAdvanced/handleHttp.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void handleRoot() {
2727
/** Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
2828
boolean captivePortal() {
2929
if (!isIp(server.hostHeader()) && server.hostHeader() != (String(myHostname) + ".local")) {
30-
Serial.print("Request redirected to captive portal");
30+
Serial.println("Request redirected to captive portal");
3131
server.sendHeader("Location", String("http://") + toStringIp(server.client().localIP()), true);
3232
server.send(302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
3333
server.client().stop(); // Stop is needed because we sent no content length

libraries/ESP8266WebServer/src/detail/mimetable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace mime
55
{
66

77
// Table of extension->MIME strings stored in PROGMEM, needs to be global due to GCC section typing rules
8-
const Entry mimeTable[maxType] ICACHE_RODATA_ATTR =
8+
const Entry mimeTable[maxType] PROGMEM =
99
{
1010
{ ".html", "text/html" },
1111
{ ".htm", "text/html" },

libraries/ESP8266WiFi/examples/WiFiHTTPSServer/make-self-signed-cert.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# Replace your-name-here with somethine appropriate before running and use
55
# the generated .H files in your code as follows:
66
#
7-
# static const uint8_t rsakey[] ICACHE_RODATA_ATTR = {
7+
# static const uint8_t rsakey[] PROGMEM = {
88
# #include "key.h"
99
# };
1010
#
11-
# static const uint8_t x509[] ICACHE_RODATA_ATTR = {
11+
# static const uint8_t x509[] PROGMEM = {
1212
# #include "x509.h"
1313
# };
1414
#

libraries/Ticker/Ticker.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,23 @@ void Ticker::detach()
6565
os_timer_disarm(_timer);
6666
delete _timer;
6767
_timer = nullptr;
68+
_callback_function = nullptr;
6869
}
6970

7071
bool Ticker::active()
7172
{
7273
return (bool)_timer;
7374
}
75+
76+
void Ticker::_static_callback(void* arg)
77+
{
78+
Ticker* _this = (Ticker*)arg;
79+
if (_this == nullptr)
80+
{
81+
return;
82+
}
83+
if (_this->_callback_function)
84+
{
85+
_this->_callback_function();
86+
}
87+
}

libraries/Ticker/Ticker.h

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <stdint.h>
2626
#include <stdbool.h>
2727
#include <stddef.h>
28+
#include <functional>
29+
#include <Schedule.h>
2830

2931
extern "C" {
3032
typedef struct _ETSTIMER_ ETSTimer;
@@ -37,15 +39,28 @@ class Ticker
3739
~Ticker();
3840
typedef void (*callback_t)(void);
3941
typedef void (*callback_with_arg_t)(void*);
42+
typedef std::function<void(void)> callback_function_t;
4043

41-
void attach(float seconds, callback_t callback)
44+
void attach_scheduled(float seconds, callback_function_t callback)
4245
{
43-
_attach_ms(seconds * 1000, true, reinterpret_cast<callback_with_arg_t>(callback), 0);
46+
attach(seconds,std::bind(schedule_function, callback));
4447
}
4548

46-
void attach_ms(uint32_t milliseconds, callback_t callback)
49+
void attach(float seconds, callback_function_t callback)
4750
{
48-
_attach_ms(milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), 0);
51+
_callback_function = callback;
52+
attach(seconds, _static_callback, (void*)this);
53+
}
54+
55+
void attach_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
56+
{
57+
attach_ms(milliseconds, std::bind(schedule_function, callback));
58+
}
59+
60+
void attach_ms(uint32_t milliseconds, callback_function_t callback)
61+
{
62+
_callback_function = callback;
63+
attach_ms(milliseconds, _static_callback, (void*)this);
4964
}
5065

5166
template<typename TArg>
@@ -67,14 +82,26 @@ class Ticker
6782
_attach_ms(milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), arg32);
6883
}
6984

70-
void once(float seconds, callback_t callback)
85+
void once_scheduled(float seconds, callback_function_t callback)
7186
{
72-
_attach_ms(seconds * 1000, false, reinterpret_cast<callback_with_arg_t>(callback), 0);
87+
once(seconds, std::bind(schedule_function, callback));
7388
}
7489

75-
void once_ms(uint32_t milliseconds, callback_t callback)
90+
void once(float seconds, callback_function_t callback)
7691
{
77-
_attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), 0);
92+
_callback_function = callback;
93+
once(seconds, _static_callback, (void*)this);
94+
}
95+
96+
void once_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
97+
{
98+
once_ms(milliseconds, std::bind(schedule_function, callback));
99+
}
100+
101+
void once_ms(uint32_t milliseconds, callback_function_t callback)
102+
{
103+
_callback_function = callback;
104+
once_ms(milliseconds, _static_callback, (void*)this);
78105
}
79106

80107
template<typename TArg>
@@ -98,10 +125,11 @@ class Ticker
98125

99126
protected:
100127
void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, uint32_t arg);
101-
128+
static void _static_callback (void* arg);
102129

103130
protected:
104131
ETSTimer* _timer;
132+
callback_function_t _callback_function = nullptr;
105133
};
106134

107135

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "Arduino.h"
2+
#include "Ticker.h"
3+
4+
#define LED1 2
5+
#define LED2 4
6+
#define LED3 12
7+
#define LED4 14
8+
#define LED5 15
9+
10+
11+
class ExampleClass {
12+
public:
13+
ExampleClass(int pin, int duration) : _pin(pin), _duration(duration) {
14+
pinMode(_pin, OUTPUT);
15+
_myTicker.attach_ms(_duration, std::bind(&ExampleClass::classBlink, this));
16+
}
17+
~ExampleClass() {};
18+
19+
int _pin, _duration;
20+
Ticker _myTicker;
21+
22+
void classBlink() {
23+
digitalWrite(_pin, !digitalRead(_pin));
24+
}
25+
};
26+
27+
void staticBlink() {
28+
digitalWrite(LED2, !digitalRead(LED2));
29+
}
30+
31+
void scheduledBlink() {
32+
digitalWrite(LED3, !digitalRead(LED2));
33+
}
34+
35+
void parameterBlink(int p) {
36+
digitalWrite(p, !digitalRead(p));
37+
}
38+
39+
Ticker staticTicker;
40+
Ticker scheduledTicker;
41+
Ticker parameterTicker;
42+
Ticker lambdaTicker;
43+
44+
ExampleClass example(LED1, 100);
45+
46+
47+
void setup() {
48+
pinMode(LED2, OUTPUT);
49+
staticTicker.attach_ms(100, staticBlink);
50+
51+
pinMode(LED3, OUTPUT);
52+
scheduledTicker.attach_ms_scheduled(100, scheduledBlink);
53+
54+
pinMode(LED4, OUTPUT);
55+
parameterTicker.attach_ms(100, std::bind(parameterBlink, LED4));
56+
57+
pinMode(LED5, OUTPUT);
58+
lambdaTicker.attach_ms(100, []() {
59+
digitalWrite(LED5, !digitalRead(LED5));
60+
});
61+
}
62+
63+
void loop() {
64+
}

0 commit comments

Comments
 (0)