Skip to content

Commit 9264a38

Browse files
Merge branch 'master' into cleanup1
2 parents 4c5cc17 + a0634a7 commit 9264a38

Some content is hidden

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

41 files changed

+439
-683
lines changed

cores/esp8266/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
218218

219219
void attachInterrupt(uint8_t pin, void (*)(void), int mode);
220220
void detachInterrupt(uint8_t pin);
221+
void attachInterruptArg(uint8_t pin, void (*)(void*), void* arg, int mode);
221222

222223
void preinit(void);
223224
void setup(void);

cores/esp8266/FunctionalInterrupt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ typedef void (*voidFuncPtr)(void);
77
typedef void (*voidFuncPtrArg)(void*);
88

99
// Helper functions for Functional interrupt routines
10-
extern "C" void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, voidFuncPtr userFunc, void*fp , int mode);
10+
extern "C" void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtr userFunc, void*fp, int mode, bool functional);
1111

1212

1313
void ICACHE_RAM_ATTR interruptFunctional(void* arg)
@@ -47,7 +47,7 @@ void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode
4747
as->interruptInfo = ii;
4848
as->functionInfo = fi;
4949

50-
__attachInterruptArg (pin, (voidFuncPtr)interruptFunctional, as, mode);
50+
__attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
5151
}
5252

5353
void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode)
@@ -61,5 +61,5 @@ void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> sc
6161
as->interruptInfo = ii;
6262
as->functionInfo = fi;
6363

64-
__attachInterruptArg (pin, (voidFuncPtr)interruptFunctional, as, mode);
64+
__attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
6565
}

cores/esp8266/Updater.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class UpdaterHashClass {
3838
virtual void end() = 0;
3939
virtual int len() = 0;
4040
virtual const void *hash() = 0;
41+
virtual const unsigned char *oid() = 0;
4142
};
4243

4344
// Abstract class to implement a signature verifier

cores/esp8266/core_esp8266_wiring_digital.cpp

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ets_sys.h"
2727
#include "user_interface.h"
2828
#include "core_esp8266_waveform.h"
29+
#include "interrupts.h"
2930

3031
extern "C" {
3132

@@ -109,8 +110,9 @@ typedef void (*voidFuncPtrArg)(void*);
109110

110111
typedef struct {
111112
uint8_t mode;
112-
void (*fn)(void);
113+
voidFuncPtr fn;
113114
void * arg;
115+
bool functional;
114116
} interrupt_handler_t;
115117

116118
//duplicate from functionalInterrupt.h keep in sync
@@ -125,11 +127,11 @@ typedef struct {
125127
void* functionInfo;
126128
} ArgStructure;
127129

128-
static interrupt_handler_t interrupt_handlers[16];
130+
static interrupt_handler_t interrupt_handlers[16] = { {0, 0, 0, 0}, };
129131
static uint32_t interrupt_reg = 0;
130132

131-
void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
132-
(void) arg;
133+
void ICACHE_RAM_ATTR interrupt_handler(void*)
134+
{
133135
uint32_t status = GPIE;
134136
GPIEC = status;//clear them interrupts
135137
uint32_t levels = GPI;
@@ -144,34 +146,49 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
144146
if (handler->fn &&
145147
(handler->mode == CHANGE ||
146148
(handler->mode & 1) == !!(levels & (1 << i)))) {
147-
// to make ISR compatible to Arduino AVR model where interrupts are disabled
148-
// we disable them before we call the client ISR
149-
uint32_t savedPS = xt_rsil(15); // stop other interrupts
150-
ArgStructure* localArg = (ArgStructure*)handler->arg;
151-
if (localArg && localArg->interruptInfo)
152-
{
153-
localArg->interruptInfo->pin = i;
154-
localArg->interruptInfo->value = __digitalRead(i);
155-
localArg->interruptInfo->micro = micros();
156-
}
157-
if (handler->arg)
158-
{
159-
((voidFuncPtrArg)handler->fn)(handler->arg);
160-
}
161-
else
162-
{
163-
handler->fn();
149+
// to make ISR compatible to Arduino AVR model where interrupts are disabled
150+
// we disable them before we call the client ISR
151+
esp8266::InterruptLock irqLock; // stop other interrupts
152+
if (handler->functional)
153+
{
154+
ArgStructure* localArg = (ArgStructure*)handler->arg;
155+
if (localArg && localArg->interruptInfo)
156+
{
157+
localArg->interruptInfo->pin = i;
158+
localArg->interruptInfo->value = __digitalRead(i);
159+
localArg->interruptInfo->micro = micros();
160+
}
161+
}
162+
if (handler->arg)
163+
{
164+
((voidFuncPtrArg)handler->fn)(handler->arg);
165+
}
166+
else
167+
{
168+
handler->fn();
169+
}
164170
}
165-
xt_wsr_ps(savedPS);
166-
}
167171
}
168172
ETS_GPIO_INTR_ENABLE();
169173
}
170174

171175
extern void cleanupFunctional(void* arg);
172176

173-
extern void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, voidFuncPtr userFunc, void *arg, int mode) {
177+
static void set_interrupt_handlers(uint8_t pin, voidFuncPtr userFunc, void* arg, uint8_t mode, bool functional)
178+
{
179+
interrupt_handler_t* handler = &interrupt_handlers[pin];
180+
handler->mode = mode;
181+
handler->fn = userFunc;
182+
if (handler->functional && handler->arg) // Clean when new attach without detach
183+
{
184+
cleanupFunctional(handler->arg);
185+
}
186+
handler->arg = arg;
187+
handler->functional = functional;
188+
}
174189

190+
extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int mode, bool functional)
191+
{
175192
// #5780
176193
// https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
177194
if ((uint32_t)userFunc >= 0x40200000)
@@ -183,14 +200,7 @@ extern void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, voidFuncPtr userFu
183200

184201
if(pin < 16) {
185202
ETS_GPIO_INTR_DISABLE();
186-
interrupt_handler_t *handler = &interrupt_handlers[pin];
187-
handler->mode = mode;
188-
handler->fn = userFunc;
189-
if (handler->arg) // Clean when new attach without detach
190-
{
191-
cleanupFunctional(handler->arg);
192-
}
193-
handler->arg = arg;
203+
set_interrupt_handlers(pin, (voidFuncPtr)userFunc, arg, mode, functional);
194204
interrupt_reg |= (1 << pin);
195205
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
196206
GPIEC = (1 << pin); //Clear Interrupt for this pin
@@ -200,31 +210,32 @@ extern void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, voidFuncPtr userFu
200210
}
201211
}
202212

203-
extern void ICACHE_RAM_ATTR __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int mode )
213+
extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int mode)
204214
{
205-
__attachInterruptArg (pin, userFunc, 0, mode);
215+
__attachInterruptFunctionalArg(pin, userFunc, arg, mode, false);
206216
}
207217

208218
extern void ICACHE_RAM_ATTR __detachInterrupt(uint8_t pin) {
209-
if(pin < 16) {
210-
ETS_GPIO_INTR_DISABLE();
211-
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
212-
GPIEC = (1 << pin); //Clear Interrupt for this pin
213-
interrupt_reg &= ~(1 << pin);
214-
interrupt_handler_t *handler = &interrupt_handlers[pin];
215-
handler->mode = 0;
216-
handler->fn = 0;
217-
if (handler->arg)
218-
{
219-
cleanupFunctional(handler->arg);
220-
}
221-
handler->arg = 0;
222-
if (interrupt_reg)
223-
ETS_GPIO_INTR_ENABLE();
224-
}
219+
if (pin < 16)
220+
{
221+
ETS_GPIO_INTR_DISABLE();
222+
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
223+
GPIEC = (1 << pin); //Clear Interrupt for this pin
224+
interrupt_reg &= ~(1 << pin);
225+
set_interrupt_handlers(pin, nullptr, nullptr, 0, false);
226+
if (interrupt_reg)
227+
{
228+
ETS_GPIO_INTR_ENABLE();
229+
}
230+
}
231+
}
232+
233+
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int mode)
234+
{
235+
__attachInterruptFunctionalArg(pin, (voidFuncPtrArg)userFunc, 0, mode, false);
225236
}
226237

227-
void initPins() {
238+
extern void initPins() {
228239
//Disable UART interrupts
229240
system_set_os_print(0);
230241
U0IE = 0;
@@ -243,6 +254,7 @@ extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pi
243254
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite")));
244255
extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead")));
245256
extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias("__attachInterrupt")));
257+
extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void* arg, int mode) __attribute__((weak, alias("__attachInterruptArg")));
246258
extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias("__detachInterrupt")));
247259

248260
};

doc/esp8266wifi/station-class.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ Function returns one of the following connection statuses:
254254
- ``WL_CONNECT_FAILED`` if password is incorrect
255255
- ``WL_IDLE_STATUS`` when Wi-Fi is in process of changing between statuses
256256
- ``WL_DISCONNECTED`` if module is not configured in station mode
257+
- ``-1`` on timeout
257258

258259
Configuration
259260
~~~~~~~~~~~~~

doc/ota_updates/readme.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ Compile the sketch normally and, once a `.bin` file is available, sign it using
125125
126126
<ESP8266ArduioPath>/tools/signing.py --mode sign --privatekey <path-to-private.key> --bin <path-to-unsigned-bin> --out <path-to-signed-binary>
127127
128+
Old And New Signature Formats
129+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130+
131+
Up to version 2.5.2 of the core, the format of signatures was a little different. An additional signed binary with the extension legacy_sig is created. This file contains a signature in the old format and can be uploaded OTA to a device that checks for the old signature format.
132+
133+
To create a legacy signature, call the signing script with --legacy:
134+
135+
.. code:: bash
136+
137+
<ESP8266ArduioPath>/tools/signing.py --mode sign --privatekey <path-to-private.key> --bin <path-to-unsigned-bin> --out <path-to-signed-binary> --legacy <path-to-legacy-file>
138+
139+
128140
Safety
129141
~~~~~~
130142

libraries/ESP8266AVRISP/examples/Arduino_Wifi_AVRISP/Arduino_Wifi_AVRISP.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ void setup() {
2424

2525
WiFi.mode(WIFI_STA);
2626
WiFi.begin(ssid, pass);
27-
while (WiFi.waitForConnectResult() != WL_CONNECTED);
27+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
28+
WiFi.begin(ssid, pass);
29+
Serial.println("WiFi failed, retrying.");
30+
}
2831

2932
MDNS.begin(host);
3033
MDNS.addService("avrisp", "tcp", port);

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,7 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size)
656656
return returnError(HTTPC_ERROR_CONNECTION_REFUSED);
657657
}
658658

659-
if(payload && size > 0) {
660-
addHeader(F("Content-Length"), String(size));
661-
}
659+
addHeader(F("Content-Length"), String(payload && size > 0 ? size : 0));
662660

663661
// send Header
664662
if(!sendHeader(type)) {

libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const char* update_password = "admin";
3131
const char* ssid = STASSID;
3232
const char* password = STAPSK;
3333

34-
BearSSL::ESP8266WebServerSecure httpServer(443);
35-
ESP8266HTTPUpdateServer httpUpdater;
34+
ESP8266WebServerSecure httpServer(443);
35+
ESP8266HTTPUpdateServerSecure httpUpdater;
3636

3737
static const char serverCert[] PROGMEM = R"EOF(
3838
-----BEGIN CERTIFICATE-----
@@ -106,7 +106,7 @@ void setup()
106106

107107
MDNS.begin(host);
108108

109-
httpServer.setRSACert(new BearSSL::X509List(serverCert), new BearSSL::PrivateKey(serverKey));
109+
httpServer.getServer().setRSACert(new BearSSL::X509List(serverCert), new BearSSL::PrivateKey(serverKey));
110110
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
111111
httpServer.begin();
112112

libraries/ESP8266HTTPUpdateServer/examples/SecureHTTPSUpdater/SecureHTTPSUpdater.ino

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,21 @@
4242
This example is released into the public domain.
4343
*/
4444

45+
// AXTLS is deprecated, do not use in new code.
46+
#pragma GCC diagnostic push
47+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
48+
4549
#include <ESP8266WiFi.h>
4650
#include <WiFiClient.h>
4751
#include <ESP8266WebServerSecure.h>
4852
#include <ESP8266mDNS.h>
4953
#include <ESP8266HTTPUpdateServer.h>
54+
#include <WiFiServerSecure.h>
55+
#include <WiFiServerSecureAxTLS.h>
56+
#include <WiFiClientSecure.h>
57+
#include <WiFiClientSecureAxTLS.h>
58+
59+
#pragma GCC diagnostic pop
5060

5161
#ifndef STASSID
5262
#define STASSID "your-ssid"
@@ -60,8 +70,8 @@ const char* update_password = "admin";
6070
const char* ssid = STASSID;
6171
const char* password = STAPSK;
6272

63-
ESP8266WebServerSecure httpServer(443);
64-
ESP8266HTTPUpdateServer httpUpdater;
73+
axTLS::ESP8266WebServerSecure httpServer(443);
74+
axTLS::ESP8266HTTPUpdateServerSecure httpUpdater;
6575

6676
// The certificate is stored in PMEM
6777
static const uint8_t x509[] PROGMEM = {
@@ -176,7 +186,7 @@ void setup() {
176186

177187
MDNS.begin(host);
178188

179-
httpServer.setServerKeyAndCert_P(rsakey, sizeof(rsakey), x509, sizeof(x509));
189+
httpServer.getServer().setServerKeyAndCert_P(rsakey, sizeof(rsakey), x509, sizeof(x509));
180190
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
181191
httpServer.begin();
182192

libraries/ESP8266HTTPUpdateServer/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=The library accepts HTTP post requests to the /update url, and updates
77
category=Communication
88
url=
99
architectures=esp8266
10-
dot_a_linkage=true
10+
dot_a_linkage=false

libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp renamed to libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "StreamString.h"
77
#include "ESP8266HTTPUpdateServer.h"
88

9+
namespace esp8266httpupdateserver {
10+
using namespace esp8266webserver;
911

1012
static const char serverIndex[] PROGMEM =
1113
R"(<html><body><form method='POST' action='' enctype='multipart/form-data'>
@@ -16,7 +18,8 @@ static const char serverIndex[] PROGMEM =
1618
static const char successResponse[] PROGMEM =
1719
"<META http-equiv=\"refresh\" content=\"15;URL=/\">Update Success! Rebooting...\n";
1820

19-
ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug)
21+
template <typename ServerType>
22+
ESP8266HTTPUpdateServerTemplate<ServerType>::ESP8266HTTPUpdateServerTemplate(bool serial_debug)
2023
{
2124
_serial_output = serial_debug;
2225
_server = NULL;
@@ -25,7 +28,8 @@ ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug)
2528
_authenticated = false;
2629
}
2730

28-
void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& path, const String& username, const String& password)
31+
template <typename ServerType>
32+
void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate<ServerType> *server, const String& path, const String& username, const String& password)
2933
{
3034
_server = server;
3135
_username = username;
@@ -95,10 +99,13 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& path
9599
});
96100
}
97101

98-
void ESP8266HTTPUpdateServer::_setUpdaterError()
102+
template <typename ServerType>
103+
void ESP8266HTTPUpdateServerTemplate<ServerType>::_setUpdaterError()
99104
{
100105
if (_serial_output) Update.printError(Serial);
101106
StreamString str;
102107
Update.printError(str);
103108
_updaterError = str.c_str();
104109
}
110+
111+
};

0 commit comments

Comments
 (0)