Skip to content

Commit 33b959f

Browse files
authored
Merge branch 'master' into feat/p4_ble
2 parents f794498 + 54ed29c commit 33b959f

34 files changed

+488
-184
lines changed

.github/workflows/pre-commit-status.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,24 @@ jobs:
131131
gh pr edit ${{ steps.pr-info.outputs.pr_number }} --repo ${{ github.repository }} --remove-label 'Status: Pre-commit fixes required ⚠️'
132132
env:
133133
GH_TOKEN: ${{ github.token }}
134+
135+
- name: Comment on PR about pre-commit failures
136+
if: |
137+
steps.pr-info.outputs.artifacts_found == 'true' &&
138+
steps.pr-info.outputs.pre_commit_outcome == 'failure' &&
139+
steps.pr-info.outputs.pending_commit == '0'
140+
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
141+
with:
142+
pr-number: ${{ steps.pr-info.outputs.pr_number }}
143+
message: |
144+
## ⚠️ Pre-commit Hooks Failed
145+
146+
Some pre-commit hooks failed and require manual fixes. Please see the detailed error report below.
147+
148+
**What to do:**
149+
1. 📋 [**View the detailed error report**](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) to see which hooks failed
150+
2. 🔧 Fix the issues locally in your code
151+
3. 💾 Commit and push your changes
152+
4. 🔄 The hooks will run again automatically
153+
154+
**Need help?** Ask in the comments below.

cores/esp32/Arduino.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,36 @@ size_t getArduinoLoopTaskStackSize(void);
222222
return sz; \
223223
}
224224

225+
#define ESP32_USB_MIDI_DEFAULT_NAME "TinyUSB MIDI"
226+
/**
227+
* @brief Set the current device name
228+
* 1. Name set via constructor (if any)
229+
* 2. Name set via SET_USB_MIDI_DEVICE_NAME() macro (if defined)
230+
* 3. Default name "TinyUSB MIDI"
231+
* If device name is set as "", it will be ignored
232+
*/
233+
#define SET_USB_MIDI_DEVICE_NAME(name) \
234+
const char *getUSBMIDIDefaultDeviceName() { \
235+
if (!name || strlen(name) == 0) { \
236+
return ESP32_USB_MIDI_DEFAULT_NAME; \
237+
} \
238+
return name; \
239+
}
240+
225241
bool shouldPrintChipDebugReport(void);
226242
#define ENABLE_CHIP_DEBUG_REPORT \
227243
bool shouldPrintChipDebugReport(void) { \
228244
return true; \
229245
}
230246

247+
// macro SET_TIME_BEFORE_STARTING_SKETCH_MS(time_ms) can set a time in milliseconds
248+
// before the sketch would start its execution. It gives the user time to open the Serial Monitor
249+
uint64_t getArduinoSetupWaitTime_ms(void);
250+
#define SET_TIME_BEFORE_STARTING_SKETCH_MS(time_ms) \
251+
uint64_t getArduinoSetupWaitTime_ms() { \
252+
return (time_ms); \
253+
}
254+
231255
// allows user to bypass esp_spiram_test()
232256
bool esp_psram_extram_test(void);
233257
#define BYPASS_SPIRAM_TEST(bypass) \

cores/esp32/esp32-hal-rmt.c

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ bool rmtDeinit(int pin) {
285285
return false;
286286
}
287287

288-
static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool blocking, bool loop, uint32_t timeout_ms) {
288+
static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool blocking, uint32_t loop, uint32_t timeout_ms) {
289289
rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__);
290290
if (bus == NULL) {
291291
return false;
@@ -303,11 +303,21 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl
303303
}
304304
}
305305

306+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
306307
log_v("GPIO: %d - Request: %d RMT Symbols - %s - Timeout: %d", pin, num_rmt_symbols, blocking ? "Blocking" : "Non-Blocking", timeout_ms);
307-
log_v(
308-
"GPIO: %d - Currently in Loop Mode: [%s] | Asked to Loop: %s, LoopCancel: %s", pin, bus->rmt_ch_is_looping ? "YES" : "NO", loop ? "YES" : "NO",
309-
loopCancel ? "YES" : "NO"
310-
);
308+
// loop parameter semantics:
309+
// loop == 0: no looping (single transmission)
310+
// loop == 1: infinite looping
311+
// loop > 1: transmit the data 'loop' times
312+
{
313+
char buf[17]; // placeholder for up to maximum uint32_t value (4294967295) = 10 digits + " times" (6 chars) + null terminator (17 bytes)
314+
snprintf(buf, sizeof(buf), "%lu times", loop);
315+
log_v(
316+
"GPIO: %d - Currently in Loop Mode: [%s] | Loop Request: [%s], LoopCancel: [%s]", pin, bus->rmt_ch_is_looping ? "YES" : "NO",
317+
loop == 0 ? "NO" : (loop == 1 ? "FOREVER" : buf), loopCancel ? "YES" : "NO"
318+
);
319+
}
320+
#endif
311321

312322
if ((xEventGroupGetBits(bus->rmt_events) & RMT_FLAG_TX_DONE) == 0) {
313323
log_v("GPIO %d - RMT Write still pending to be completed.", pin);
@@ -336,8 +346,8 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl
336346
bus->rmt_ch_is_looping = false;
337347
} else { // new writing | looping request
338348
// looping | Writing over a previous looping state is valid
339-
if (loop) {
340-
transmit_cfg.loop_count = -1; // enable infinite loop mode
349+
if (loop > 0) {
350+
transmit_cfg.loop_count = (loop == 1) ? -1 : loop;
341351
// keeps RMT_FLAG_TX_DONE set - it never changes
342352
} else {
343353
// looping mode never sets this flag (IDF 5.1) in the callback
@@ -348,8 +358,10 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl
348358
retCode = false;
349359
log_w("GPIO %d - RMT Transmission failed.", pin);
350360
} else { // transmit OK
351-
if (loop) {
352-
bus->rmt_ch_is_looping = true; // for ever... until a channel canceling or new writing
361+
if (loop > 0) {
362+
// rmt_ch_is_looping is used as a flag to indicate that RMT is in looping execution in order to
363+
// be canceled whenever a new _rmtWrite() is executed while it is looping
364+
bus->rmt_ch_is_looping = true;
353365
} else {
354366
if (blocking) {
355367
// wait for transmission confirmation | timeout
@@ -402,15 +414,36 @@ static bool _rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, bool wa
402414
}
403415

404416
bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeout_ms) {
405-
return _rmtWrite(pin, data, num_rmt_symbols, true /*blocks*/, false /*looping*/, timeout_ms);
417+
return _rmtWrite(pin, data, num_rmt_symbols, true /*blocks*/, 0 /*looping*/, timeout_ms);
406418
}
407419

408420
bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols) {
409-
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, false /*looping*/, 0 /*N/A*/);
421+
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 0 /*looping*/, 0 /*N/A*/);
410422
}
411423

412424
bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) {
413-
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, true /*looping*/, 0 /*N/A*/);
425+
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 1 /*looping*/, 0 /*N/A*/);
426+
}
427+
428+
// Same as rmtWriteLooping(...) but it transmits the data a fixed number of times ("loop_count").
429+
// loop_count == 0 is invalid (no transmission); loop_count == 1 transmits once (no looping); loop_count > 1 transmits the data repeatedly (looping).
430+
bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count) {
431+
if (loop_count == 0) {
432+
log_e("RMT TX GPIO %d : Invalid loop_count (%u). Must be at least 1.", pin, loop_count);
433+
return false;
434+
}
435+
if (loop_count == 1) {
436+
// send the RMT symbols once using non-blocking write (single non-looping transmission)
437+
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, 0 /*looping*/, 0 /*N/A*/);
438+
} else {
439+
// write the RMT symbols for loop_count times
440+
#if SOC_RMT_SUPPORT_TX_LOOP_COUNT
441+
return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, loop_count /*looping*/, 0 /*N/A*/);
442+
#else
443+
log_e("RMT TX GPIO %d : Loop Count is not supported. Writing failed.", pin);
444+
return false;
445+
#endif
446+
}
414447
}
415448

416449
bool rmtTransmitCompleted(int pin) {

cores/esp32/esp32-hal-rmt.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeou
124124
bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols);
125125

126126
/**
127-
Writing data up to the reserved memsize, looping continuously
127+
Writing data up to the reserved memsize, looping continuously (rmtWriteLooping()) or fixed
128+
number of <loop_count> times (rmtWriteRepeated())
129+
128130
<rmt_symbol> is a 32 bits structure as defined by rmt_data_t type.
129131
It is possible to use the macro RMT_SYMBOLS_OF(data), if data is an array of rmt_data_t
130132
@@ -133,9 +135,11 @@ bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols);
133135
Non-Blocking mode - returns right after execution
134136
Returns <true> on execution success, <false> otherwise
135137
136-
<bool rmtTransmitCompleted(int pin)> will return always <true> while it is looping.
138+
<bool rmtTransmitCompleted(int pin)> will return always <true> while it is looping mode.
139+
looping mode is active for rmtWriteLooping() and for rmtWriteRepeated() when loop_count > 1.
137140
*/
138141
bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols);
142+
bool rmtWriteRepeated(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t loop_count);
139143

140144
/**
141145
Checks if transmission is completed and the rmtChannel ready for transmitting new data.

cores/esp32/esp32-hal-uart.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct uart_struct_t {
5959
uint16_t _rx_buffer_size, _tx_buffer_size; // UART RX and TX buffer sizes
6060
bool _inverted; // UART inverted signal
6161
uint8_t _rxfifo_full_thrhd; // UART RX FIFO full threshold
62-
int8_t _uart_clock_source; // UART Clock Source used when it is started using uartBegin()
62+
int8_t _uart_clock_source; // UART Clock Source that should be used if user defines an specific one with setClockSource()
6363
};
6464

6565
#if CONFIG_DISABLE_HAL_LOCKS
@@ -820,7 +820,7 @@ uart_t *uartBegin(
820820
uart_config.baud_rate = baudrate;
821821
#if SOC_UART_LP_NUM >= 1
822822
if (uart_nr >= SOC_UART_HP_NUM) { // it is a LP UART NUM
823-
if (uart->_uart_clock_source > 0) {
823+
if (uart->_uart_clock_source >= 0) {
824824
uart_config.lp_source_clk = (soc_periph_lp_uart_clk_src_t)uart->_uart_clock_source; // use user defined LP UART clock
825825
log_v("Setting UART%d to user defined LP clock source (%d) ", uart_nr, uart->_uart_clock_source);
826826
} else {
@@ -881,14 +881,7 @@ uart_t *uartBegin(
881881
uart->_tx_buffer_size = tx_buffer_size;
882882
uart->has_peek = false;
883883
uart->peek_byte = 0;
884-
#if SOC_UART_LP_NUM >= 1
885-
if (uart_nr >= SOC_UART_HP_NUM) {
886-
uart->_uart_clock_source = uart_config.lp_source_clk;
887-
} else
888-
#endif
889-
{
890-
uart->_uart_clock_source = uart_config.source_clk;
891-
}
884+
// uart->_uart_clock_source can only change by explicit user API request/call
892885
}
893886
UART_MUTEX_UNLOCK();
894887

@@ -1149,10 +1142,9 @@ bool uartSetBaudRate(uart_t *uart, uint32_t baud_rate) {
11491142
}
11501143
bool retCode = true;
11511144
soc_module_clk_t newClkSrc = UART_SCLK_DEFAULT;
1152-
int8_t previousClkSrc = uart->_uart_clock_source;
11531145
#if SOC_UART_LP_NUM >= 1
11541146
if (uart->num >= SOC_UART_HP_NUM) { // it is a LP UART NUM
1155-
if (uart->_uart_clock_source > 0) {
1147+
if (uart->_uart_clock_source >= 0) {
11561148
newClkSrc = (soc_periph_lp_uart_clk_src_t)uart->_uart_clock_source; // use user defined LP UART clock
11571149
log_v("Setting UART%d to user defined LP clock source (%d) ", uart->num, newClkSrc);
11581150
} else {
@@ -1187,13 +1179,10 @@ bool uartSetBaudRate(uart_t *uart, uint32_t baud_rate) {
11871179
}
11881180
}
11891181
UART_MUTEX_LOCK();
1190-
// if necessary, set the correct UART Clock Source before changing the baudrate
1191-
if (previousClkSrc < 0 || previousClkSrc != newClkSrc) {
1192-
HP_UART_SRC_CLK_ATOMIC() {
1193-
uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc);
1194-
}
1195-
uart->_uart_clock_source = newClkSrc;
1182+
HP_UART_SRC_CLK_ATOMIC() {
1183+
uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc);
11961184
}
1185+
// uart->_uart_clock_source can only change by explicit user API request/call
11971186
if (uart_set_baudrate(uart->num, baud_rate) == ESP_OK) {
11981187
log_v("Setting UART%d baud rate to %ld.", uart->num, baud_rate);
11991188
uart->_baudrate = baud_rate;
@@ -1312,7 +1301,7 @@ bool uartSetClockSource(uint8_t uartNum, uart_sclk_t clkSrc) {
13121301
{
13131302
uart->_uart_clock_source = clkSrc;
13141303
}
1315-
//log_i("UART%d set clock source to %d", uart->num, uart->_uart_clock_source);
1304+
log_v("UART%d set clock source to %d", uart->num, uart->_uart_clock_source);
13161305
return true;
13171306
}
13181307

cores/esp32/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,18 @@ __attribute__((weak)) bool shouldPrintChipDebugReport(void) {
4444
return false;
4545
}
4646

47+
// this function can be changed by the sketch using the macro SET_TIME_BEFORE_STARTING_SKETCH_MS(time_ms)
48+
__attribute__((weak)) uint64_t getArduinoSetupWaitTime_ms(void) {
49+
return 0;
50+
}
51+
4752
void loopTask(void *pvParameters) {
4853
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
4954
// sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h
5055
Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0));
56+
// time in ms that the sketch may wait before starting its execution - default is zero
57+
// usually done for opening the Serial Monitor and seeing all debug messages
58+
delay(getArduinoSetupWaitTime_ms());
5159
#endif
5260
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
5361
printBeforeSetupInfo();

libraries/BLE/src/BLE2902.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ This class will be removed in a future version.")]] BLE2902 : public BLEDescript
5555
bool getIndications();
5656
void setNotifications(bool flag);
5757
void setIndications(bool flag);
58-
59-
private:
60-
friend class BLECharacteristic;
6158
}; // BLE2902
6259

6360
#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */

libraries/BLE/src/BLE2904.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class BLE2904 : public BLEDescriptor {
9494
void setUnit(uint16_t unit);
9595

9696
private:
97-
friend class BLECharacteristic;
98-
9997
/***************************************************************************
10098
* Common private properties *
10199
***************************************************************************/

libraries/BLE/src/BLEAddress.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,8 @@ BLEAddress::BLEAddress() {
5858
* @param [in] otherAddress The other address to compare against.
5959
* @return True if the addresses are equal.
6060
*/
61-
bool BLEAddress::equals(BLEAddress otherAddress) {
62-
#if defined(CONFIG_NIMBLE_ENABLED)
63-
if (m_addrType != otherAddress.m_addrType) {
64-
return false;
65-
}
66-
#endif
67-
return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0;
61+
bool BLEAddress::equals(const BLEAddress &otherAddress) const {
62+
return *this == otherAddress;
6863
}
6964

7065
bool BLEAddress::operator==(const BLEAddress &otherAddress) const {
@@ -115,9 +110,9 @@ uint8_t *BLEAddress::getNative() {
115110
*
116111
* @return The string representation of the address.
117112
*/
118-
String BLEAddress::toString() {
119-
auto size = 18;
120-
char *res = (char *)malloc(size);
113+
String BLEAddress::toString() const {
114+
constexpr size_t size = 18;
115+
char res[size];
121116

122117
#if defined(CONFIG_BLUEDROID_ENABLED)
123118
snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
@@ -128,7 +123,6 @@ String BLEAddress::toString() {
128123
#endif
129124

130125
String ret(res);
131-
free(res);
132126
return ret;
133127
}
134128

@@ -157,7 +151,7 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
157151
*
158152
* @param [in] stringAddress The hex representation of the address.
159153
*/
160-
BLEAddress::BLEAddress(String stringAddress) {
154+
BLEAddress::BLEAddress(const String &stringAddress) {
161155
if (stringAddress.length() != 17) {
162156
return;
163157
}
@@ -192,7 +186,7 @@ BLEAddress::BLEAddress(ble_addr_t address) {
192186
m_addrType = address.type;
193187
}
194188

195-
uint8_t BLEAddress::getType() {
189+
uint8_t BLEAddress::getType() const {
196190
return m_addrType;
197191
}
198192

@@ -208,7 +202,7 @@ uint8_t BLEAddress::getType() {
208202
* @param [in] stringAddress The hex representation of the address.
209203
* @param [in] type The address type.
210204
*/
211-
BLEAddress::BLEAddress(String stringAddress, uint8_t type) {
205+
BLEAddress::BLEAddress(const String &stringAddress, uint8_t type) {
212206
if (stringAddress.length() != 17) {
213207
return;
214208
}

libraries/BLE/src/BLEAddress.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ class BLEAddress {
6464
***************************************************************************/
6565

6666
BLEAddress();
67-
bool equals(BLEAddress otherAddress);
67+
bool equals(const BLEAddress &otherAddress) const;
6868
bool operator==(const BLEAddress &otherAddress) const;
6969
bool operator!=(const BLEAddress &otherAddress) const;
7070
bool operator<(const BLEAddress &otherAddress) const;
7171
bool operator<=(const BLEAddress &otherAddress) const;
7272
bool operator>(const BLEAddress &otherAddress) const;
7373
bool operator>=(const BLEAddress &otherAddress) const;
7474
uint8_t *getNative();
75-
String toString();
75+
String toString() const;
7676

7777
/***************************************************************************
7878
* Bluedroid public declarations *
7979
***************************************************************************/
8080

8181
#if defined(CONFIG_BLUEDROID_ENABLED)
8282
BLEAddress(esp_bd_addr_t address);
83-
BLEAddress(String stringAddress);
83+
BLEAddress(const String &stringAddress);
8484
#endif
8585

8686
/***************************************************************************
@@ -89,9 +89,9 @@ class BLEAddress {
8989

9090
#if defined(CONFIG_NIMBLE_ENABLED)
9191
BLEAddress(ble_addr_t address);
92-
BLEAddress(String stringAddress, uint8_t type = BLE_ADDR_PUBLIC);
92+
BLEAddress(const String &stringAddress, uint8_t type = BLE_ADDR_PUBLIC);
9393
BLEAddress(uint8_t address[ESP_BD_ADDR_LEN], uint8_t type = BLE_ADDR_PUBLIC);
94-
uint8_t getType();
94+
uint8_t getType() const;
9595
#endif
9696

9797
private:

0 commit comments

Comments
 (0)