Unverified Commit 67c99142 authored by Rodrigo Garcia's avatar Rodrigo Garcia Committed by GitHub

Allows spiram malloc with wifi dynamic buffers - better free heap (#5791)

Summary

Modifies WiFi lib to allow dynamic buffer allocation along with SPIRAM MALLOC enabled
This gives more heap space to the users

Related PR in Arduino Lib Builder: espressif/esp32-arduino-lib-builder#47

Impact

WiFi will work the same as it was in version 1.0.6, restoring free heap.

close #5630
close #5474
close #5699
close #5697
parent 951c8bec
......@@ -542,6 +542,20 @@ bool tcpipInit(){
* */
static bool lowLevelInitDone = false;
bool WiFiGenericClass::_wifiUseStaticBuffers = false;
bool WiFiGenericClass::useStaticBuffers(){
return _wifiUseStaticBuffers;
}
void WiFiGenericClass::useStaticBuffers(bool bufferMode){
if (lowLevelInitDone) {
log_w("WiFi already started. Call WiFi.mode(WIFI_MODE_NULL) before setting Static Buffer Mode.");
}
_wifiUseStaticBuffers = bufferMode;
}
bool wifiLowLevelInit(bool persistent){
if(!lowLevelInitDone){
lowLevelInitDone = true;
......@@ -557,6 +571,16 @@ bool wifiLowLevelInit(bool persistent){
}
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
if(!WiFiGenericClass::useStaticBuffers()) {
cfg.static_tx_buf_num = 0;
cfg.dynamic_tx_buf_num = 32;
cfg.tx_buf_type = 1;
cfg.cache_tx_buf_num = 1; // can't be zero!
cfg.static_rx_buf_num = 4;
cfg.dynamic_rx_buf_num = 32;
}
esp_err_t err = esp_wifi_init(&cfg);
if(err){
log_e("esp_wifi_init %d", err);
......@@ -644,7 +668,6 @@ wifi_ps_type_t WiFiGenericClass::_sleepEnabled = WIFI_PS_MIN_MODEM;
WiFiGenericClass::WiFiGenericClass()
{
}
const char * WiFiGenericClass::getHostname()
......
......@@ -179,12 +179,16 @@ class WiFiGenericClass
static bool hostname(const String& aHostname) { return setHostname(aHostname.c_str()); }
static esp_err_t _eventCallback(arduino_event_t *event);
static void useStaticBuffers(bool bufferMode);
static bool useStaticBuffers();
protected:
static bool _persistent;
static bool _long_range;
static wifi_mode_t _forceSleepLastMode;
static wifi_ps_type_t _sleepEnabled;
static bool _wifiUseStaticBuffers;
static int setStatusBits(int bits);
static int clearStatusBits(int bits);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment