Skip to content

Commit dcfad8e

Browse files
authored
Merge branch 'master' into erase_flash
2 parents caacfe6 + 60c4eea commit dcfad8e

File tree

36 files changed

+633
-290
lines changed

36 files changed

+633
-290
lines changed

boards.txt

+446-282
Large diffs are not rendered by default.

libraries/WiFi/src/WiFiAP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class WiFiAPClass
3838
public:
3939

4040
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
41-
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = INADDR_NONE);
41+
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = (uint32_t) 0);
4242
bool softAPdisconnect(bool wifioff = false);
4343

4444
uint8_t softAPgetStationNum();

libraries/WiFi/src/WiFiGeneric.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ bool wifiLowLevelInit(bool persistent){
668668
cfg.static_tx_buf_num = 0;
669669
cfg.dynamic_tx_buf_num = 32;
670670
cfg.tx_buf_type = 1;
671-
cfg.cache_tx_buf_num = 1; // can't be zero!
671+
cfg.cache_tx_buf_num = 4; // can't be zero!
672672
cfg.static_rx_buf_num = 4;
673673
cfg.dynamic_rx_buf_num = 32;
674674
}

libraries/WiFiClientSecure/src/ssl_client.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "WiFi.h"
2222

2323
#if !defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
24-
# warning "Please configure IDF framework to include mbedTLS -> Enable pre-shared-key ciphersuites and activate at least one cipher"
24+
# warning "Please configure IDF framework to include mbedTLS -> Enable PSK based ciphersuite modes (MBEDTLS_KEY_EXCHANGE_PSK) and activate at least one cipher"
2525
#else
2626

2727
const char *pers = "esp32-tls";

libraries/Wire/src/Wire.cpp

+143-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ TwoWire::TwoWire(uint8_t bus_num)
3838
:num(bus_num & 1)
3939
,sda(-1)
4040
,scl(-1)
41+
,bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size
42+
,rxBuffer(NULL)
4143
,rxIndex(0)
4244
,rxLength(0)
45+
,txBuffer(NULL)
4346
,txLength(0)
4447
,txAddress(0)
4548
,_timeOutMillis(50)
@@ -74,8 +77,12 @@ bool TwoWire::initPins(int sdaPin, int sclPin)
7477
}
7578
} else {
7679
if(sda==-1) {
80+
#ifdef WIRE1_PIN_DEFINED
81+
sdaPin = SDA1;
82+
#else
7783
log_e("no Default SDA Pin for Second Peripheral");
7884
return false; //no Default pin for Second Peripheral
85+
#endif
7986
} else {
8087
sdaPin = sda; // reuse prior pin
8188
}
@@ -91,8 +98,12 @@ bool TwoWire::initPins(int sdaPin, int sclPin)
9198
}
9299
} else {
93100
if(scl == -1) {
101+
#ifdef WIRE1_PIN_DEFINED
102+
sclPin = SCL1;
103+
#else
94104
log_e("no Default SCL Pin for Second Peripheral");
95105
return false; //no Default pin for Second Peripheral
106+
#endif
96107
} else {
97108
sclPin = scl; // reuse prior pin
98109
}
@@ -132,6 +143,87 @@ bool TwoWire::setPins(int sdaPin, int sclPin)
132143
return !i2cIsInit(num);
133144
}
134145

146+
bool TwoWire::allocateWireBuffer(void)
147+
{
148+
// or both buffer can be allocated or none will be
149+
if (rxBuffer == NULL) {
150+
rxBuffer = (uint8_t *)malloc(bufferSize);
151+
if (rxBuffer == NULL) {
152+
log_e("Can't allocate memory for I2C_%d rxBuffer", num);
153+
return false;
154+
}
155+
}
156+
if (txBuffer == NULL) {
157+
txBuffer = (uint8_t *)malloc(bufferSize);
158+
if (txBuffer == NULL) {
159+
log_e("Can't allocate memory for I2C_%d txBuffer", num);
160+
freeWireBuffer(); // free rxBuffer for safety!
161+
return false;
162+
}
163+
}
164+
// in case both were allocated before, they must have the same size. All good.
165+
return true;
166+
}
167+
168+
void TwoWire::freeWireBuffer(void)
169+
{
170+
if (rxBuffer != NULL) {
171+
free(rxBuffer);
172+
rxBuffer = NULL;
173+
}
174+
if (txBuffer != NULL) {
175+
free(txBuffer);
176+
txBuffer = NULL;
177+
}
178+
}
179+
180+
size_t TwoWire::setBufferSize(size_t bSize)
181+
{
182+
// Maximum size .... HEAP limited ;-)
183+
if (bSize < 32) { // 32 bytes is the I2C FIFO Len for ESP32/S2/S3/C3
184+
log_e("Minimum Wire Buffer size is 32 bytes");
185+
return 0;
186+
}
187+
188+
#if !CONFIG_DISABLE_HAL_LOCKS
189+
if(lock == NULL){
190+
lock = xSemaphoreCreateMutex();
191+
if(lock == NULL){
192+
log_e("xSemaphoreCreateMutex failed");
193+
return 0;
194+
}
195+
}
196+
//acquire lock
197+
if(xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){
198+
log_e("could not acquire lock");
199+
return 0;
200+
}
201+
#endif
202+
// allocateWireBuffer allocates memory for both pointers or just free them
203+
if (rxBuffer != NULL || txBuffer != NULL) {
204+
// if begin() has been already executed, memory size changes... data may be lost. We don't care! :^)
205+
if (bSize != bufferSize) {
206+
// we want a new buffer size ... just reset buffer pointers and allocate new ones
207+
freeWireBuffer();
208+
bufferSize = bSize;
209+
if (!allocateWireBuffer()) {
210+
// failed! Error message already issued
211+
bSize = 0; // returns error
212+
log_e("Buffer allocation failed");
213+
}
214+
} // else nothing changes, all set!
215+
} else {
216+
// no memory allocated yet, just change the size value - allocation in begin()
217+
bufferSize = bSize;
218+
}
219+
#if !CONFIG_DISABLE_HAL_LOCKS
220+
//release lock
221+
xSemaphoreGive(lock);
222+
223+
#endif
224+
return bSize;
225+
}
226+
135227
// Slave Begin
136228
bool TwoWire::begin(uint8_t addr, int sdaPin, int sclPin, uint32_t frequency)
137229
{
@@ -159,17 +251,22 @@ bool TwoWire::begin(uint8_t addr, int sdaPin, int sclPin, uint32_t frequency)
159251
log_e("Bus already started in Master Mode.");
160252
goto end;
161253
}
254+
if (!allocateWireBuffer()) {
255+
// failed! Error Message already issued
256+
goto end;
257+
}
162258
if(!initPins(sdaPin, sclPin)){
163259
goto end;
164260
}
165261
i2cSlaveAttachCallbacks(num, onRequestService, onReceiveService, this);
166-
if(i2cSlaveInit(num, sda, scl, addr, frequency, I2C_BUFFER_LENGTH, I2C_BUFFER_LENGTH) != ESP_OK){
262+
if(i2cSlaveInit(num, sda, scl, addr, frequency, bufferSize, bufferSize) != ESP_OK){
167263
log_e("Slave Init ERROR");
168264
goto end;
169265
}
170266
is_slave = true;
171267
started = true;
172268
end:
269+
if (!started) freeWireBuffer();
173270
#if !CONFIG_DISABLE_HAL_LOCKS
174271
//release lock
175272
xSemaphoreGive(lock);
@@ -205,13 +302,18 @@ bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
205302
started = true;
206303
goto end;
207304
}
305+
if (!allocateWireBuffer()) {
306+
// failed! Error Message already issued
307+
goto end;
308+
}
208309
if(!initPins(sdaPin, sclPin)){
209310
goto end;
210311
}
211312
err = i2cInit(num, sda, scl, frequency);
212313
started = (err == ESP_OK);
213314

214315
end:
316+
if (!started) freeWireBuffer();
215317
#if !CONFIG_DISABLE_HAL_LOCKS
216318
//release lock
217319
xSemaphoreGive(lock);
@@ -239,6 +341,7 @@ bool TwoWire::end()
239341
} else if(i2cIsInit(num)){
240342
err = i2cDeinit(num);
241343
}
344+
freeWireBuffer();
242345
#if !CONFIG_DISABLE_HAL_LOCKS
243346
//release lock
244347
xSemaphoreGive(lock);
@@ -325,12 +428,26 @@ void TwoWire::beginTransmission(uint16_t address)
325428
txLength = 0;
326429
}
327430

431+
/*
432+
https://www.arduino.cc/reference/en/language/functions/communication/wire/endtransmission/
433+
endTransmission() returns:
434+
0: success.
435+
1: data too long to fit in transmit buffer.
436+
2: received NACK on transmit of address.
437+
3: received NACK on transmit of data.
438+
4: other error.
439+
5: timeout
440+
*/
328441
uint8_t TwoWire::endTransmission(bool sendStop)
329442
{
330443
if(is_slave){
331444
log_e("Bus is in Slave Mode");
332445
return 4;
333446
}
447+
if (txBuffer == NULL){
448+
log_e("NULL TX buffer pointer");
449+
return 4;
450+
}
334451
esp_err_t err = ESP_OK;
335452
if(sendStop){
336453
err = i2cWrite(num, txAddress, txBuffer, txLength, _timeOutMillis);
@@ -360,6 +477,10 @@ size_t TwoWire::requestFrom(uint16_t address, size_t size, bool sendStop)
360477
log_e("Bus is in Slave Mode");
361478
return 0;
362479
}
480+
if (rxBuffer == NULL || txBuffer == NULL){
481+
log_e("NULL buffer pointer");
482+
return 0;
483+
}
363484
esp_err_t err = ESP_OK;
364485
if(nonStop
365486
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -401,7 +522,11 @@ size_t TwoWire::requestFrom(uint16_t address, size_t size, bool sendStop)
401522

402523
size_t TwoWire::write(uint8_t data)
403524
{
404-
if(txLength >= I2C_BUFFER_LENGTH) {
525+
if (txBuffer == NULL){
526+
log_e("NULL TX buffer pointer");
527+
return 0;
528+
}
529+
if(txLength >= bufferSize) {
405530
return 0;
406531
}
407532
txBuffer[txLength++] = data;
@@ -428,6 +553,10 @@ int TwoWire::available(void)
428553
int TwoWire::read(void)
429554
{
430555
int value = -1;
556+
if (rxBuffer == NULL){
557+
log_e("NULL RX buffer pointer");
558+
return value;
559+
}
431560
if(rxIndex < rxLength) {
432561
value = rxBuffer[rxIndex++];
433562
}
@@ -437,6 +566,10 @@ int TwoWire::read(void)
437566
int TwoWire::peek(void)
438567
{
439568
int value = -1;
569+
if (rxBuffer == NULL){
570+
log_e("NULL RX buffer pointer");
571+
return value;
572+
}
440573
if(rxIndex < rxLength) {
441574
value = rxBuffer[rxIndex];
442575
}
@@ -520,6 +653,10 @@ void TwoWire::onReceiveService(uint8_t num, uint8_t* inBytes, size_t numBytes, b
520653
if(!wire->user_onReceive){
521654
return;
522655
}
656+
if (wire->rxBuffer == NULL){
657+
log_e("NULL RX buffer pointer");
658+
return;
659+
}
523660
for(uint8_t i = 0; i < numBytes; ++i){
524661
wire->rxBuffer[i] = inBytes[i];
525662
}
@@ -534,6 +671,10 @@ void TwoWire::onRequestService(uint8_t num, void * arg)
534671
if(!wire->user_onRequest){
535672
return;
536673
}
674+
if (wire->txBuffer == NULL){
675+
log_e("NULL TX buffer pointer");
676+
return;
677+
}
537678
wire->txLength = 0;
538679
wire->user_onRequest();
539680
if(wire->txLength){

libraries/Wire/src/Wire.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@
3434
#endif
3535
#include "Stream.h"
3636

37+
// WIRE_HAS_BUFFER_SIZE means Wire has setBufferSize()
38+
#define WIRE_HAS_BUFFER_SIZE 1
39+
// WIRE_HAS_END means Wire has end()
40+
#define WIRE_HAS_END 1
41+
3742
#ifndef I2C_BUFFER_LENGTH
38-
#define I2C_BUFFER_LENGTH 128
43+
#define I2C_BUFFER_LENGTH 128 // Default size, if none is set using Wire::setBuffersize(size_t)
3944
#endif
4045
typedef void(*user_onRequest)(void);
4146
typedef void(*user_onReceive)(uint8_t*, int);
@@ -47,11 +52,12 @@ class TwoWire: public Stream
4752
int8_t sda;
4853
int8_t scl;
4954

50-
uint8_t rxBuffer[I2C_BUFFER_LENGTH];
55+
size_t bufferSize;
56+
uint8_t *rxBuffer;
5157
size_t rxIndex;
5258
size_t rxLength;
5359

54-
uint8_t txBuffer[I2C_BUFFER_LENGTH];
60+
uint8_t *txBuffer;
5561
size_t txLength;
5662
uint16_t txAddress;
5763

@@ -68,6 +74,8 @@ class TwoWire: public Stream
6874
static void onRequestService(uint8_t, void *);
6975
static void onReceiveService(uint8_t, uint8_t*, size_t, bool, void *);
7076
bool initPins(int sdaPin, int sclPin);
77+
bool allocateWireBuffer(void);
78+
void freeWireBuffer(void);
7179

7280
public:
7381
TwoWire(uint8_t bus_num);
@@ -93,6 +101,8 @@ class TwoWire: public Stream
93101
}
94102
bool end();
95103

104+
size_t setBufferSize(size_t bSize);
105+
96106
void setTimeOut(uint16_t timeOutMillis); // default timeout of i2c transactions is 50ms
97107
uint16_t getTimeOut();
98108

variants/Microduino-esp32/pins_arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static const uint8_t RX = 3;
2626
static const uint8_t SDA = 22;//23;
2727
static const uint8_t SCL = 21;//19;
2828

29+
#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin)
2930
static const uint8_t SDA1 = 12;
3031
static const uint8_t SCL1 = 13;
3132

Binary file not shown.
-128 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-112 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ESP-IDF Partition Table
2+
# Name, Type, SubType, Offset, Size, Flags
3+
# bootloader.bin,, 0x1000, 32K
4+
# partition table, 0x8000, 4K
5+
6+
nvs, data, nvs, 0x9000, 20K,
7+
otadata, data, ota, 0xe000, 8K,
8+
ota_0, 0, ota_0, 0x10000, 1408K,
9+
ota_1, 0, ota_1, 0x170000, 1408K,
10+
uf2, app, factory,0x2d0000, 256K,
11+
ffat, data, fat, 0x310000, 960K,
16 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ESP-IDF Partition Table
2+
# Name, Type, SubType, Offset, Size, Flags
3+
# bootloader.bin,, 0x1000, 32K
4+
# partition table, 0x8000, 4K
5+
6+
nvs, data, nvs, 0x9000, 20K,
7+
otadata, data, ota, 0xe000, 8K,
8+
ota_0, 0, ota_0, 0x10000, 1408K,
9+
ota_1, 0, ota_1, 0x170000, 1408K,
10+
uf2, app, factory,0x2d0000, 256K,
11+
ffat, data, fat, 0x310000, 960K,
32 Bytes
Binary file not shown.
Binary file not shown.
-96 Bytes
Binary file not shown.
Binary file not shown.
-112 Bytes
Binary file not shown.
Binary file not shown.
-128 Bytes
Binary file not shown.

variants/adafruit_qtpy_esp32/pins_arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static const uint8_t RX = 7;
2323
static const uint8_t SDA = 4;
2424
static const uint8_t SCL = 33;
2525

26+
#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin)
2627
static const uint8_t SDA1 = 22;
2728
static const uint8_t SCL1 = 19;
2829

Binary file not shown.

variants/adafruit_qtpy_esp32s2/pins_arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
static const uint8_t SDA = 7;
3030
static const uint8_t SCL = 6;
3131

32+
#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin)
3233
static const uint8_t SDA1 = 41;
3334
static const uint8_t SCL1 = 40;
3435

-128 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)