Skip to content

Commit 5100bee

Browse files
Merge branch 'master' into optimistic_yield_recurrency
2 parents afe4021 + f066ed2 commit 5100bee

29 files changed

+260
-552
lines changed

cores/esp8266/Arduino.h

+7
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ void configTime(int timezone, int daylightOffset_sec, const char* server1,
282282
void configTime(const char* tz, const char* server1,
283283
const char* server2 = nullptr, const char* server3 = nullptr);
284284

285+
// esp32 api compatibility
286+
inline void configTzTime(const char* tz, const char* server1,
287+
const char* server2 = nullptr, const char* server3 = nullptr)
288+
{
289+
configTime(tz, server1, server2, server3);
290+
}
291+
285292
#endif // __cplusplus
286293

287294
#include "pins_arduino.h"

cores/esp8266/Print.cpp

+2-43
Original file line numberDiff line numberDiff line change
@@ -268,47 +268,6 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
268268
}
269269

270270
size_t Print::printFloat(double number, uint8_t digits) {
271-
size_t n = 0;
272-
273-
if(isnan(number))
274-
return print("nan");
275-
if(isinf(number))
276-
return print("inf");
277-
if(number > 4294967040.0)
278-
return print("ovf"); // constant determined empirically
279-
if(number < -4294967040.0)
280-
return print("ovf"); // constant determined empirically
281-
282-
// Handle negative numbers
283-
if(number < 0.0) {
284-
n += print('-');
285-
number = -number;
286-
}
287-
288-
// Round correctly so that print(1.999, 2) prints as "2.00"
289-
double rounding = 0.5;
290-
for(uint8_t i = 0; i < digits; ++i)
291-
rounding /= 10.0;
292-
293-
number += rounding;
294-
295-
// Extract the integer part of the number and print it
296-
unsigned long int_part = (unsigned long) number;
297-
double remainder = number - (double) int_part;
298-
n += print(int_part);
299-
300-
// Print the decimal point, but only if there are digits beyond
301-
if(digits > 0) {
302-
n += print(".");
303-
}
304-
305-
// Extract digits from the remainder one at a time
306-
while(digits-- > 0) {
307-
remainder *= 10.0;
308-
int toPrint = int(remainder);
309-
n += print(toPrint);
310-
remainder -= toPrint;
311-
}
312-
313-
return n;
271+
char buf[40];
272+
return write(dtostrf(number, 0, digits, buf));
314273
}

cores/esp8266/Print.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "WString.h"
2727
#include "Printable.h"
2828

29+
#include "stdlib_noniso.h"
30+
2931
#define DEC 10
3032
#define HEX 16
3133
#define OCT 8

cores/esp8266/StackThunk.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ uint32_t stack_thunk_get_max_usage()
111111
/* Print the stack from the first used 16-byte chunk to the top, decodable by the exception decoder */
112112
void stack_thunk_dump_stack()
113113
{
114-
uint32_t *pos = stack_thunk_top;
115-
while (pos < stack_thunk_ptr) {
114+
uint32_t *pos = stack_thunk_ptr;
115+
while (pos < stack_thunk_top) {
116116
if ((pos[0] != _stackPaint) || (pos[1] != _stackPaint) || (pos[2] != _stackPaint) || (pos[3] != _stackPaint))
117117
break;
118118
pos += 4;
119119
}
120120
ets_printf(">>>stack>>>\n");
121-
while (pos < stack_thunk_ptr) {
121+
while (pos < stack_thunk_top) {
122122
ets_printf("%08x: %08x %08x %08x %08x\n", (int32_t)pos, pos[0], pos[1], pos[2], pos[3]);
123123
pos += 4;
124124
}

cores/esp8266/WMath.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ long secureRandom(long howsmall, long howbig) {
7070
}
7171

7272
long map(long x, long in_min, long in_max, long out_min, long out_max) {
73-
long divisor = (in_max - in_min);
74-
if(divisor == 0){
75-
return -1; //AVR returns -1, SAM returns 0
76-
}
77-
return (x - in_min) * (out_max - out_min) / divisor + out_min;
73+
const long dividend = out_max - out_min;
74+
const long divisor = in_max - in_min;
75+
const long delta = x - in_min;
76+
77+
return (delta * dividend + (divisor / 2)) / divisor + out_min;
7878
}
7979

8080
unsigned int makeWord(unsigned int w) {

cores/esp8266/core_esp8266_noniso.cpp

+4-69
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
2323
*/
2424

25+
#include <stdio.h>
2526
#include <stdlib.h>
2627
#include <string.h>
2728
#include <stdbool.h>
@@ -40,75 +41,9 @@ char* ultoa(unsigned long value, char* result, int base) {
4041
}
4142

4243
char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
43-
bool negative = false;
44-
45-
if (isnan(number)) {
46-
strcpy(s, "nan");
47-
return s;
48-
}
49-
if (isinf(number)) {
50-
strcpy(s, "inf");
51-
return s;
52-
}
53-
54-
char* out = s;
55-
56-
int fillme = width; // how many cells to fill for the integer part
57-
if (prec > 0) {
58-
fillme -= (prec+1);
59-
}
60-
61-
// Handle negative numbers
62-
if (number < 0.0) {
63-
negative = true;
64-
fillme--;
65-
number = -number;
66-
}
67-
68-
// Round correctly so that print(1.999, 2) prints as "2.00"
69-
// I optimized out most of the divisions
70-
double rounding = 2.0;
71-
for (uint8_t i = 0; i < prec; ++i)
72-
rounding *= 10.0;
73-
rounding = 1.0 / rounding;
74-
75-
number += rounding;
76-
77-
// Figure out how big our number really is
78-
double tenpow = 1.0;
79-
int digitcount = 1;
80-
while (number >= 10.0 * tenpow) {
81-
tenpow *= 10.0;
82-
digitcount++;
83-
}
84-
85-
number /= tenpow;
86-
fillme -= digitcount;
87-
88-
// Pad unused cells with spaces
89-
while (fillme-- > 0) {
90-
*out++ = ' ';
91-
}
92-
93-
// Handle negative sign
94-
if (negative) *out++ = '-';
95-
96-
// Print the digits, and if necessary, the decimal point
97-
digitcount += prec;
98-
int8_t digit = 0;
99-
while (digitcount-- > 0) {
100-
digit = (int8_t)number;
101-
if (digit > 9) digit = 9; // insurance
102-
*out++ = (char)('0' | digit);
103-
if ((digitcount == prec) && (prec > 0)) {
104-
*out++ = '.';
105-
}
106-
number -= digit;
107-
number *= 10.0;
108-
}
109-
110-
// make sure the string is terminated
111-
*out = 0;
44+
char fmt[32];
45+
sprintf(fmt, "%%%d.%df", width, prec);
46+
sprintf(s, fmt, number);
11247
return s;
11348
}
11449

cores/esp8266/core_esp8266_postmortem.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void ets_printf_P(const char *str, ...) {
8989
vsnprintf(destStr, sizeof(destStr), str, argPtr);
9090
va_end(argPtr);
9191
while (*c) {
92-
ets_putc(*(c++));
92+
ets_uart_putc1(*(c++));
9393
}
9494
}
9595

@@ -147,10 +147,10 @@ void __wrap_system_restart_local() {
147147
// (determined empirically, might break)
148148
uint32_t offset = 0;
149149
if (rst_info.reason == REASON_SOFT_WDT_RST) {
150-
offset = 0x1b0;
150+
offset = 0x1a0;
151151
}
152152
else if (rst_info.reason == REASON_EXCEPTION_RST) {
153-
offset = 0x1a0;
153+
offset = 0x190;
154154
}
155155
else if (rst_info.reason == REASON_WDT_RST) {
156156
offset = 0x10;

cores/esp8266/coredecls.h

+2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ extern "C" {
1313
#include <cont.h> // g_pcont declaration
1414

1515
extern bool timeshift64_is_set;
16+
extern uint32_t sntp_real_timestamp;
1617

1718
bool can_yield();
1819
void esp_yield();
1920
void esp_schedule();
2021
void tune_timeshift64 (uint64_t now_us);
2122
void disable_extra4k_at_link_time (void) __attribute__((noinline));
23+
bool sntp_set_timezone_in_seconds(int32_t timezone);
2224

2325
uint32_t sqrt32 (uint32_t n);
2426
uint32_t crc32 (const void* data, size_t length, uint32_t crc = 0xffffffff);

0 commit comments

Comments
 (0)