Skip to content

Commit a55f128

Browse files
upgrade arduino-esp32
1 parent c516678 commit a55f128

38 files changed

+999
-349
lines changed

components/arduino-esp32/Esp.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ void EspClass::deepSleep(uint32_t time_us)
9292
esp_deep_sleep(time_us);
9393
}
9494

95-
uint32_t EspClass::getCycleCount()
96-
{
97-
uint32_t ccount;
98-
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
99-
return ccount;
100-
}
101-
10295
void EspClass::restart(void)
10396
{
10497
esp_restart();

components/arduino-esp32/HardwareSerial.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
5555
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
5656

5757
if(!baud) {
58+
uartStartDetectBaudrate(_uart);
5859
time_t startMillis = millis();
5960
unsigned long detectedBaudRate = 0;
6061
while(millis() - startMillis < timeout_ms && !(detectedBaudRate = uartDetectBaudrate(_uart))) {
@@ -130,11 +131,34 @@ int HardwareSerial::read(void)
130131
return -1;
131132
}
132133

133-
void HardwareSerial::flush()
134+
// read characters into buffer
135+
// terminates if size characters have been read, or no further are pending
136+
// returns the number of characters placed in the buffer
137+
// the buffer is NOT null terminated.
138+
size_t HardwareSerial::read(uint8_t *buffer, size_t size)
139+
{
140+
size_t avail = available();
141+
if (size < avail) {
142+
avail = size;
143+
}
144+
size_t count = 0;
145+
while(count < avail) {
146+
*buffer++ = uartRead(_uart);
147+
count++;
148+
}
149+
return count;
150+
}
151+
152+
void HardwareSerial::flush(void)
134153
{
135154
uartFlush(_uart);
136155
}
137156

157+
void HardwareSerial::flush(bool txOnly)
158+
{
159+
uartFlushTxOnly(_uart, txOnly);
160+
}
161+
138162
size_t HardwareSerial::write(uint8_t c)
139163
{
140164
uartWrite(_uart, c);

components/arduino-esp32/Print.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,24 @@ size_t Print::printf(const char *format, ...)
5252
va_list copy;
5353
va_start(arg, format);
5454
va_copy(copy, arg);
55-
size_t len = vsnprintf(NULL, 0, format, arg);
55+
int len = vsnprintf(temp, sizeof(loc_buf), format, copy);
5656
va_end(copy);
57+
if(len < 0) {
58+
va_end(arg);
59+
return 0;
60+
};
5761
if(len >= sizeof(loc_buf)){
58-
temp = new char[len+1];
62+
temp = (char*) malloc(len+1);
5963
if(temp == NULL) {
64+
va_end(arg);
6065
return 0;
6166
}
67+
len = vsnprintf(temp, len+1, format, arg);
6268
}
63-
len = vsnprintf(temp, len+1, format, arg);
64-
write((uint8_t*)temp, len);
6569
va_end(arg);
66-
if(len >= sizeof(loc_buf)){
67-
delete[] temp;
70+
len = write((uint8_t*)temp, len);
71+
if(temp != loc_buf){
72+
free(temp);
6873
}
6974
return len;
7075
}
@@ -154,8 +159,10 @@ size_t Print::print(struct tm * timeinfo, const char * format)
154159
}
155160
char buf[64];
156161
size_t written = strftime(buf, 64, f, timeinfo);
157-
print(buf);
158-
return written;
162+
if(written == 0){
163+
return written;
164+
}
165+
return print(buf);
159166
}
160167

161168
size_t Print::println(void)

components/arduino-esp32/WString.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
String::String(const char *cstr) {
3333
init();
34-
if(cstr)
34+
if (cstr)
3535
copy(cstr, strlen(cstr));
3636
}
3737

@@ -136,7 +136,7 @@ inline void String::init(void) {
136136
}
137137

138138
void String::invalidate(void) {
139-
if(!sso() && wbuffer())
139+
if(!isSSO() && wbuffer())
140140
free(wbuffer());
141141
init();
142142
}
@@ -154,17 +154,21 @@ unsigned char String::reserve(unsigned int size) {
154154

155155
unsigned char String::changeBuffer(unsigned int maxStrLen) {
156156
// Can we use SSO here to avoid allocation?
157-
if (maxStrLen < sizeof(sso_buf)) {
158-
if (sso() || !buffer()) {
157+
if (maxStrLen < sizeof(sso.buff) - 1) {
158+
if (isSSO() || !buffer()) {
159159
// Already using SSO, nothing to do
160+
uint16_t oldLen = len();
160161
setSSO(true);
162+
setLen(oldLen);
161163
return 1;
162-
} else { // if bufptr && !sso()
163-
// Using bufptr, need to shrink into sso_buff
164-
char temp[sizeof(sso_buf)];
164+
} else { // if bufptr && !isSSO()
165+
// Using bufptr, need to shrink into sso.buff
166+
char temp[sizeof(sso.buff)];
165167
memcpy(temp, buffer(), maxStrLen);
166168
free(wbuffer());
169+
uint16_t oldLen = len();
167170
setSSO(true);
171+
setLen(oldLen);
168172
memcpy(wbuffer(), temp, maxStrLen);
169173
return 1;
170174
}
@@ -176,12 +180,12 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
176180
return false;
177181
}
178182
uint16_t oldLen = len();
179-
char *newbuffer = (char *) realloc(sso() ? nullptr : wbuffer(), newSize);
180-
if(newbuffer) {
183+
char *newbuffer = (char *) realloc(isSSO() ? nullptr : wbuffer(), newSize);
184+
if (newbuffer) {
181185
size_t oldSize = capacity() + 1; // include NULL.
182-
if (sso()) {
186+
if (isSSO()) {
183187
// Copy the SSO buffer into allocated space
184-
memcpy(newbuffer, sso_buf, sizeof(sso_buf));
188+
memmove(newbuffer, sso.buff, sizeof(sso.buff));
185189
}
186190
if (newSize > oldSize)
187191
{
@@ -206,7 +210,7 @@ String & String::copy(const char *cstr, unsigned int length) {
206210
return *this;
207211
}
208212
setLen(length);
209-
strcpy(wbuffer(), cstr);
213+
memmove(wbuffer(), cstr, length + 1);
210214
return *this;
211215
}
212216

@@ -216,28 +220,28 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
216220
return *this;
217221
}
218222
setLen(length);
219-
strcpy_P(wbuffer(), (PGM_P)pstr);
223+
memcpy_P(wbuffer(), (PGM_P)pstr, length + 1); // We know wbuffer() cannot ever be in PROGMEM, so memcpy safe here
220224
return *this;
221225
}
222226

223227
#ifdef __GXX_EXPERIMENTAL_CXX0X__
224228
void String::move(String &rhs) {
225229
if(buffer()) {
226230
if(capacity() >= rhs.len()) {
227-
strcpy(wbuffer(), rhs.buffer());
231+
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
228232
setLen(rhs.len());
229233
rhs.invalidate();
230234
return;
231235
} else {
232-
if (!sso()) {
236+
if (!isSSO()) {
233237
free(wbuffer());
234238
setBuffer(nullptr);
235239
}
236240
}
237241
}
238-
if (rhs.sso()) {
242+
if (rhs.isSSO()) {
239243
setSSO(true);
240-
memmove(sso_buf, rhs.sso_buf, sizeof(sso_buf));
244+
memmove(sso.buff, rhs.sso.buff, sizeof(sso.buff));
241245
} else {
242246
setSSO(false);
243247
setBuffer(rhs.wbuffer());
@@ -309,7 +313,7 @@ unsigned char String::concat(const String &s) {
309313
return 1;
310314
if (!reserve(newlen))
311315
return 0;
312-
memcpy(wbuffer() + len(), buffer(), len());
316+
memmove(wbuffer() + len(), buffer(), len());
313317
setLen(newlen);
314318
wbuffer()[len()] = 0;
315319
return 1;
@@ -326,7 +330,12 @@ unsigned char String::concat(const char *cstr, unsigned int length) {
326330
return 1;
327331
if(!reserve(newlen))
328332
return 0;
329-
strcpy(wbuffer() + len(), cstr);
333+
if (cstr >= wbuffer() && cstr < wbuffer() + len())
334+
// compatible with SSO in ram #6155 (case "x += x.c_str()")
335+
memmove(wbuffer() + len(), cstr, length + 1);
336+
else
337+
// compatible with source in flash #6367
338+
memcpy_P(wbuffer() + len(), cstr, length + 1);
330339
setLen(newlen);
331340
return 1;
332341
}
@@ -392,7 +401,7 @@ unsigned char String::concat(const __FlashStringHelper * str) {
392401
if (length == 0) return 1;
393402
unsigned int newlen = len() + length;
394403
if (!reserve(newlen)) return 0;
395-
strcpy_P(wbuffer() + len(), (PGM_P)str);
404+
memcpy_P(wbuffer() + len(), (PGM_P)str, length + 1);
396405
setLen(newlen);
397406
return 1;
398407
}

components/arduino-esp32/base64.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ extern "C" {
3131

3232
/**
3333
* convert input data to base64
34-
* @param data uint8_t *
34+
* @param data const uint8_t *
3535
* @param length size_t
3636
* @return String
3737
*/
38-
String base64::encode(uint8_t * data, size_t length)
38+
String base64::encode(const uint8_t * data, size_t length)
3939
{
4040
size_t size = base64_encode_expected_len(length) + 1;
4141
char * buffer = (char *) malloc(size);
@@ -54,10 +54,10 @@ String base64::encode(uint8_t * data, size_t length)
5454

5555
/**
5656
* convert input data to base64
57-
* @param text String
57+
* @param text const String&
5858
* @return String
5959
*/
60-
String base64::encode(String text)
60+
String base64::encode(const String& text)
6161
{
6262
return base64::encode((uint8_t *) text.c_str(), text.length());
6363
}

0 commit comments

Comments
 (0)