Skip to content

Commit 13bd775

Browse files
authored
Merge branch 'master' into release/v3.2.x
2 parents f2e9a27 + 6208239 commit 13bd775

File tree

69 files changed

+1124
-352
lines changed

Some content is hidden

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

69 files changed

+1124
-352
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
294294
libraries/Zigbee/src/ep/ZigbeeContactSwitch.cpp
295295
libraries/Zigbee/src/ep/ZigbeeDoorWindowHandle.cpp
296296
libraries/Zigbee/src/ep/ZigbeeWindowCovering.cpp
297+
libraries/Zigbee/src/ep/ZigbeeVibrationSensor.cpp
297298
)
298299

299300
set(ARDUINO_LIBRARY_BLE_SRCS

boards.txt

-28
Original file line numberDiff line numberDiff line change
@@ -48923,20 +48923,6 @@ huidu_hd_wf2.menu.CPUFreq.80.build.f_cpu=80000000L
4892348923
huidu_hd_wf2.menu.CPUFreq.40=40MHz
4892448924
huidu_hd_wf2.menu.CPUFreq.40.build.f_cpu=40000000L
4892548925

48926-
huidu_hd_wf2.menu.PSRAM.enabled=QSPI Flash fix
48927-
huidu_hd_wf2.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM
48928-
huidu_hd_wf2.menu.PSRAM.enabled.build.psram_type=qspi
48929-
48930-
huidu_hd_wf2.menu.FlashMode.qio=QIO 80MHz
48931-
huidu_hd_wf2.menu.FlashMode.qio.build.flash_mode=dio
48932-
huidu_hd_wf2.menu.FlashMode.qio.build.boot=qio
48933-
huidu_hd_wf2.menu.FlashMode.qio.build.boot_freq=80m
48934-
huidu_hd_wf2.menu.FlashMode.qio.build.flash_freq=80m
48935-
huidu_hd_wf2.menu.FlashMode.qio120=QIO 120MHz
48936-
huidu_hd_wf2.menu.FlashMode.qio120.build.flash_mode=dio
48937-
huidu_hd_wf2.menu.FlashMode.qio120.build.boot=qio
48938-
huidu_hd_wf2.menu.FlashMode.qio120.build.boot_freq=120m
48939-
huidu_hd_wf2.menu.FlashMode.qio120.build.flash_freq=80m
4894048926
huidu_hd_wf2.menu.FlashMode.dio=DIO 80MHz
4894148927
huidu_hd_wf2.menu.FlashMode.dio.build.flash_mode=dio
4894248928
huidu_hd_wf2.menu.FlashMode.dio.build.boot=dio
@@ -49076,20 +49062,6 @@ huidu_hd_wf4.menu.CPUFreq.80.build.f_cpu=80000000L
4907649062
huidu_hd_wf4.menu.CPUFreq.40=40MHz
4907749063
huidu_hd_wf4.menu.CPUFreq.40.build.f_cpu=40000000L
4907849064

49079-
huidu_hd_wf4.menu.PSRAM.enabled=QSPI Flash fix
49080-
huidu_hd_wf4.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM
49081-
huidu_hd_wf4.menu.PSRAM.enabled.build.psram_type=qspi
49082-
49083-
huidu_hd_wf4.menu.FlashMode.qio=QIO 80MHz
49084-
huidu_hd_wf4.menu.FlashMode.qio.build.flash_mode=dio
49085-
huidu_hd_wf4.menu.FlashMode.qio.build.boot=qio
49086-
huidu_hd_wf4.menu.FlashMode.qio.build.boot_freq=80m
49087-
huidu_hd_wf4.menu.FlashMode.qio.build.flash_freq=80m
49088-
huidu_hd_wf4.menu.FlashMode.qio120=QIO 120MHz
49089-
huidu_hd_wf4.menu.FlashMode.qio120.build.flash_mode=dio
49090-
huidu_hd_wf4.menu.FlashMode.qio120.build.boot=qio
49091-
huidu_hd_wf4.menu.FlashMode.qio120.build.boot_freq=120m
49092-
huidu_hd_wf4.menu.FlashMode.qio120.build.flash_freq=80m
4909349065
huidu_hd_wf4.menu.FlashMode.dio=DIO 80MHz
4909449066
huidu_hd_wf4.menu.FlashMode.dio.build.flash_mode=dio
4909549067
huidu_hd_wf4.menu.FlashMode.dio.build.boot=dio

cores/esp32/USBCDC.cpp

+51-17
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ ESP_EVENT_DEFINE_BASE(ARDUINO_USB_CDC_EVENTS);
2525
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);
2626
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg);
2727

28-
#define MAX_USB_CDC_DEVICES 2
29-
USBCDC *devices[MAX_USB_CDC_DEVICES] = {NULL, NULL};
28+
USBCDC *devices[CFG_TUD_CDC];
3029

3130
static uint16_t load_cdc_descriptor(uint8_t *dst, uint8_t *itf) {
3231
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB CDC");
@@ -38,23 +37,43 @@ static uint16_t load_cdc_descriptor(uint8_t *dst, uint8_t *itf) {
3837
return TUD_CDC_DESC_LEN;
3938
}
4039

40+
static uint16_t load_cdc_descriptor2(uint8_t *dst, uint8_t *itf) {
41+
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB CDC2");
42+
uint8_t ep_ntfy = tinyusb_get_free_in_endpoint();
43+
TU_VERIFY(ep_ntfy != 0);
44+
uint8_t ep_in = tinyusb_get_free_in_endpoint();
45+
TU_VERIFY(ep_in != 0);
46+
uint8_t ep_out = tinyusb_get_free_out_endpoint();
47+
TU_VERIFY(ep_out != 0);
48+
uint8_t descriptor[TUD_CDC_DESC_LEN] = {
49+
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
50+
TUD_CDC_DESCRIPTOR(*itf, str_index, (uint8_t)(0x80 | ep_ntfy), CFG_TUD_ENDOINT_SIZE, ep_out, (uint8_t)(0x80 | ep_in), CFG_TUD_ENDOINT_SIZE)
51+
};
52+
*itf += 2;
53+
memcpy(dst, descriptor, TUD_CDC_DESC_LEN);
54+
return TUD_CDC_DESC_LEN;
55+
}
56+
4157
// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
4258
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
43-
if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) {
59+
//log_v("ITF: %u, DTR: %u, RTS: %u", itf, dtr, rts);
60+
if (itf < CFG_TUD_CDC && devices[itf] != NULL) {
4461
devices[itf]->_onLineState(dtr, rts);
4562
}
4663
}
4764

4865
// Invoked when line coding is change via SET_LINE_CODING
4966
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *p_line_coding) {
50-
if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) {
67+
//log_v("ITF: %u, BITRATE: %lu, STOP_BITS: %u, PARITY: %u, DATA_BITS: %u", itf, p_line_coding->bit_rate, p_line_coding->stop_bits, p_line_coding->parity, p_line_coding->data_bits);
68+
if (itf < CFG_TUD_CDC && devices[itf] != NULL) {
5169
devices[itf]->_onLineCoding(p_line_coding->bit_rate, p_line_coding->stop_bits, p_line_coding->parity, p_line_coding->data_bits);
5270
}
5371
}
5472

5573
// Invoked when received new data
5674
void tud_cdc_rx_cb(uint8_t itf) {
57-
if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) {
75+
//log_v("ITF: %u", itf);
76+
if (itf < CFG_TUD_CDC && devices[itf] != NULL) {
5877
devices[itf]->_onRX();
5978
}
6079
}
@@ -66,13 +85,13 @@ void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) {
6685

6786
// Invoked when space becomes available in TX buffer
6887
void tud_cdc_tx_complete_cb(uint8_t itf) {
69-
if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) {
88+
if (itf < CFG_TUD_CDC && devices[itf] != NULL) {
7089
devices[itf]->_onTX();
7190
}
7291
}
7392

7493
static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
75-
if (devices[0] != NULL) {
94+
if (CFG_TUD_CDC && devices[0] != NULL) {
7695
tud_cdc_n_write_char(0, c);
7796
}
7897
}
@@ -84,9 +103,15 @@ static void usb_unplugged_cb(void *arg, esp_event_base_t event_base, int32_t eve
84103
USBCDC::USBCDC(uint8_t itfn)
85104
: itf(itfn), bit_rate(0), stop_bits(0), parity(0), data_bits(0), dtr(false), rts(false), connected(false), reboot_enable(true), rx_queue(NULL), tx_lock(NULL),
86105
tx_timeout_ms(250) {
87-
tinyusb_enable_interface(USB_INTERFACE_CDC, TUD_CDC_DESC_LEN, load_cdc_descriptor);
88-
if (itf < MAX_USB_CDC_DEVICES) {
106+
if (itf < CFG_TUD_CDC) {
107+
if (itf == 0) {
108+
tinyusb_enable_interface(USB_INTERFACE_CDC, TUD_CDC_DESC_LEN, load_cdc_descriptor);
109+
} else {
110+
tinyusb_enable_interface(USB_INTERFACE_CDC2, TUD_CDC_DESC_LEN, load_cdc_descriptor2);
111+
}
89112
arduino_usb_event_handler_register_with(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, usb_unplugged_cb, this);
113+
} else {
114+
log_e("Maximum of %u CDC devices are supported", CFG_TUD_CDC);
90115
}
91116
}
92117

@@ -142,6 +167,9 @@ size_t USBCDC::setRxBufferSize(size_t rx_queue_len) {
142167
}
143168

144169
void USBCDC::begin(unsigned long baud) {
170+
if (itf >= CFG_TUD_CDC) {
171+
return;
172+
}
145173
if (tx_lock == NULL) {
146174
tx_lock = xSemaphoreCreateMutex();
147175
}
@@ -153,6 +181,9 @@ void USBCDC::begin(unsigned long baud) {
153181
}
154182

155183
void USBCDC::end() {
184+
if (itf >= CFG_TUD_CDC) {
185+
return;
186+
}
156187
connected = false;
157188
devices[itf] = NULL;
158189
setRxBufferSize(0);
@@ -298,14 +329,14 @@ bool USBCDC::rebootEnabled(void) {
298329
}
299330

300331
int USBCDC::available(void) {
301-
if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) {
332+
if (itf >= CFG_TUD_CDC || rx_queue == NULL) {
302333
return -1;
303334
}
304335
return uxQueueMessagesWaiting(rx_queue);
305336
}
306337

307338
int USBCDC::peek(void) {
308-
if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) {
339+
if (itf >= CFG_TUD_CDC || rx_queue == NULL) {
309340
return -1;
310341
}
311342
uint8_t c;
@@ -316,7 +347,7 @@ int USBCDC::peek(void) {
316347
}
317348

318349
int USBCDC::read(void) {
319-
if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) {
350+
if (itf >= CFG_TUD_CDC || rx_queue == NULL) {
320351
return -1;
321352
}
322353
uint8_t c = 0;
@@ -327,7 +358,7 @@ int USBCDC::read(void) {
327358
}
328359

329360
size_t USBCDC::read(uint8_t *buffer, size_t size) {
330-
if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) {
361+
if (itf >= CFG_TUD_CDC || rx_queue == NULL) {
331362
return -1;
332363
}
333364
uint8_t c = 0;
@@ -339,7 +370,7 @@ size_t USBCDC::read(uint8_t *buffer, size_t size) {
339370
}
340371

341372
void USBCDC::flush(void) {
342-
if (itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || !tud_cdc_n_connected(itf)) {
373+
if (itf >= CFG_TUD_CDC || tx_lock == NULL || !tud_cdc_n_connected(itf)) {
343374
return;
344375
}
345376
if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) {
@@ -350,7 +381,7 @@ void USBCDC::flush(void) {
350381
}
351382

352383
int USBCDC::availableForWrite(void) {
353-
if (itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || !tud_cdc_n_connected(itf)) {
384+
if (itf >= CFG_TUD_CDC || tx_lock == NULL || !tud_cdc_n_connected(itf)) {
354385
return 0;
355386
}
356387
if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) {
@@ -362,7 +393,7 @@ int USBCDC::availableForWrite(void) {
362393
}
363394

364395
size_t USBCDC::write(const uint8_t *buffer, size_t size) {
365-
if (itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || buffer == NULL || size == 0 || !tud_cdc_n_connected(itf)) {
396+
if (itf >= CFG_TUD_CDC || tx_lock == NULL || buffer == NULL || size == 0 || !tud_cdc_n_connected(itf)) {
366397
return 0;
367398
}
368399
if (xPortInIsrContext()) {
@@ -415,6 +446,9 @@ uint32_t USBCDC::baudRate() {
415446
}
416447

417448
void USBCDC::setDebugOutput(bool en) {
449+
if (itf) {
450+
return;
451+
}
418452
if (en) {
419453
uartSetDebug(NULL);
420454
ets_install_putc2((void (*)(char)) & cdc0_write_char);
@@ -424,7 +458,7 @@ void USBCDC::setDebugOutput(bool en) {
424458
}
425459

426460
USBCDC::operator bool() const {
427-
if (itf >= MAX_USB_CDC_DEVICES) {
461+
if (itf >= CFG_TUD_CDC) {
428462
return false;
429463
}
430464
return connected;

cores/esp32/WString.cpp

+21-33
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ bool String::changeBuffer(unsigned int maxStrLen) {
226226
/*********************************************/
227227

228228
String &String::copy(const char *cstr, unsigned int length) {
229-
if (!reserve(length)) {
229+
if (cstr == nullptr || !reserve(length)) {
230230
invalidate();
231231
return *this;
232232
}
233-
memmove(wbuffer(), cstr, length + 1);
233+
memmove(wbuffer(), cstr, length);
234234
setLen(length);
235235
return *this;
236236
}
@@ -239,15 +239,18 @@ String &String::copy(const char *cstr, unsigned int length) {
239239
void String::move(String &rhs) {
240240
if (buffer()) {
241241
if (capacity() >= rhs.len()) {
242-
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
242+
// Use case: When 'reserve()' was called and the first
243+
// assignment/append is the return value of a function.
244+
if (rhs.len() && rhs.buffer()) {
245+
memmove(wbuffer(), rhs.buffer(), rhs.length());
246+
}
243247
setLen(rhs.len());
244248
rhs.invalidate();
245249
return;
246-
} else {
247-
if (!isSSO()) {
248-
free(wbuffer());
249-
setBuffer(nullptr);
250-
}
250+
}
251+
if (!isSSO()) {
252+
free(wbuffer());
253+
setBuffer(nullptr);
251254
}
252255
}
253256
if (rhs.isSSO()) {
@@ -259,23 +262,15 @@ void String::move(String &rhs) {
259262
}
260263
setCapacity(rhs.capacity());
261264
setLen(rhs.len());
262-
rhs.setSSO(false);
263-
rhs.setCapacity(0);
264-
rhs.setBuffer(nullptr);
265-
rhs.setLen(0);
265+
rhs.init();
266266
}
267267
#endif
268268

269269
String &String::operator=(const String &rhs) {
270270
if (this == &rhs) {
271271
return *this;
272272
}
273-
if (rhs.buffer()) {
274-
copy(rhs.buffer(), rhs.len());
275-
} else {
276-
invalidate();
277-
}
278-
return *this;
273+
return copy(rhs.buffer(), rhs.len());
279274
}
280275

281276
#ifdef __GXX_EXPERIMENTAL_CXX0X__
@@ -295,12 +290,7 @@ String &String::operator=(StringSumHelper &&rval) {
295290
#endif
296291

297292
String &String::operator=(const char *cstr) {
298-
if (cstr) {
299-
copy(cstr, strlen(cstr));
300-
} else {
301-
invalidate();
302-
}
303-
return *this;
293+
return copy(cstr, strlen(cstr));
304294
}
305295

306296
/*********************************************/
@@ -311,23 +301,21 @@ bool String::concat(const String &s) {
311301
// Special case if we're concatting ourself (s += s;) since we may end up
312302
// realloc'ing the buffer and moving s.buffer in the method called
313303
if (&s == this) {
314-
unsigned int newlen = 2 * len();
315-
if (!s.buffer()) {
316-
return false;
317-
}
318304
if (s.len() == 0) {
319305
return true;
320306
}
307+
if (!s.buffer()) {
308+
return false;
309+
}
310+
unsigned int newlen = 2 * len();
321311
if (!reserve(newlen)) {
322312
return false;
323313
}
324314
memmove(wbuffer() + len(), buffer(), len());
325315
setLen(newlen);
326-
wbuffer()[len()] = 0;
327316
return true;
328-
} else {
329-
return concat(s.buffer(), s.len());
330317
}
318+
return concat(s.buffer(), s.len());
331319
}
332320

333321
bool String::concat(const char *cstr, unsigned int length) {
@@ -343,10 +331,10 @@ bool String::concat(const char *cstr, unsigned int length) {
343331
}
344332
if (cstr >= wbuffer() && cstr < wbuffer() + len()) {
345333
// compatible with SSO in ram #6155 (case "x += x.c_str()")
346-
memmove(wbuffer() + len(), cstr, length + 1);
334+
memmove(wbuffer() + len(), cstr, length);
347335
} else {
348336
// compatible with source in flash #6367
349-
memcpy_P(wbuffer() + len(), cstr, length + 1);
337+
memcpy_P(wbuffer() + len(), cstr, length);
350338
}
351339
setLen(newlen);
352340
return true;

0 commit comments

Comments
 (0)