mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[RAM] Move MQTT buffer and OLED frame buffer to 2nd heap
This commit is contained in:
@@ -27,6 +27,10 @@
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
|
||||
#ifdef USE_SECOND_HEAP
|
||||
#include <umm_malloc/umm_heap_select.h>
|
||||
#endif
|
||||
|
||||
OLEDDisplay::~OLEDDisplay() {
|
||||
end();
|
||||
}
|
||||
@@ -37,7 +41,12 @@ bool OLEDDisplay::init() {
|
||||
return false;
|
||||
}
|
||||
if(this->buffer==NULL) {
|
||||
this->buffer = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
|
||||
{
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
this->buffer = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
|
||||
}
|
||||
if(!this->buffer) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Not enough memory to create display\n");
|
||||
return false;
|
||||
@@ -46,7 +55,12 @@ bool OLEDDisplay::init() {
|
||||
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
if(this->buffer_back==NULL) {
|
||||
this->buffer_back = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
|
||||
{
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
this->buffer_back = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
|
||||
}
|
||||
if(!this->buffer_back) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Not enough memory to create back buffer\n");
|
||||
free(this->buffer);
|
||||
@@ -626,7 +640,12 @@ bool OLEDDisplay::setLogBuffer(uint16_t lines, uint16_t chars){
|
||||
this->logBufferFilled = 0; // Nothing stored yet
|
||||
this->logBufferMaxLines = lines; // Lines max printable
|
||||
this->logBufferSize = size; // Total number of characters the buffer can hold
|
||||
this->logBuffer = (char *) malloc(size * sizeof(uint8_t));
|
||||
{
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
this->logBuffer = (char *) malloc(size * sizeof(uint8_t));
|
||||
}
|
||||
if(!this->logBuffer) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][setLogBuffer] Not enough memory to create log buffer\n");
|
||||
return false;
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
#include <WiFiClient.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_SECOND_HEAP
|
||||
#include <umm_malloc/umm_heap_select.h>
|
||||
#endif
|
||||
|
||||
|
||||
PubSubClient::PubSubClient() {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
this->_client = NULL;
|
||||
@@ -105,6 +110,16 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGN
|
||||
setStream(stream);
|
||||
}
|
||||
|
||||
PubSubClient::~PubSubClient()
|
||||
{
|
||||
#ifdef USE_SECOND_HEAP
|
||||
if (buffer != nullptr) {
|
||||
free(buffer);
|
||||
buffer = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
boolean PubSubClient::connect(const char *id) {
|
||||
return connect(id,NULL,NULL,0,0,0,0,1);
|
||||
}
|
||||
@@ -326,6 +341,12 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
|
||||
}
|
||||
|
||||
bool PubSubClient::loop_read() {
|
||||
# ifdef USE_SECOND_HEAP
|
||||
if (!initBuffer()) {
|
||||
return false;
|
||||
}
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
if (_client == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -617,6 +638,15 @@ boolean PubSubClient::unsubscribe(const char* topic) {
|
||||
}
|
||||
|
||||
void PubSubClient::disconnect() {
|
||||
# ifdef USE_SECOND_HEAP
|
||||
if (!initBuffer()) {
|
||||
_state = MQTT_DISCONNECTED;
|
||||
lastInActivity = lastOutActivity = millis();
|
||||
|
||||
return;
|
||||
}
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
buffer[0] = MQTTDISCONNECT;
|
||||
buffer[1] = 0;
|
||||
if (_client != nullptr) {
|
||||
@@ -671,6 +701,20 @@ size_t PubSubClient::flushBuffer() {
|
||||
return rc;
|
||||
}
|
||||
|
||||
# ifdef USE_SECOND_HEAP
|
||||
bool PubSubClient::initBuffer()
|
||||
{
|
||||
if (buffer == nullptr) {
|
||||
{
|
||||
HeapSelectIram ephemeral;
|
||||
buffer = (uint8_t*) malloc(sizeof(uint8_t) * MQTT_MAX_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
return buffer != nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
boolean PubSubClient::connected() {
|
||||
if (_client == NULL ) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
|
||||
@@ -99,7 +99,11 @@
|
||||
class PubSubClient : public Print {
|
||||
private:
|
||||
Client* _client;
|
||||
#ifdef USE_SECOND_HEAP
|
||||
uint8_t *buffer = nullptr;
|
||||
#else
|
||||
uint8_t buffer[MQTT_MAX_PACKET_SIZE];
|
||||
#endif
|
||||
uint16_t nextMsgId;
|
||||
unsigned long lastOutActivity;
|
||||
unsigned long lastInActivity;
|
||||
@@ -123,6 +127,10 @@ private:
|
||||
size_t appendBuffer(const uint8_t *data, size_t size);
|
||||
size_t flushBuffer();
|
||||
|
||||
# ifdef USE_SECOND_HEAP
|
||||
bool initBuffer();
|
||||
#endif
|
||||
|
||||
IPAddress ip;
|
||||
String domain;
|
||||
uint16_t port;
|
||||
@@ -144,7 +152,7 @@ public:
|
||||
PubSubClient(const char*, uint16_t, Client& client, Stream&);
|
||||
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
|
||||
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
|
||||
virtual ~PubSubClient() {}
|
||||
virtual ~PubSubClient();
|
||||
|
||||
PubSubClient& setServer(IPAddress ip, uint16_t port);
|
||||
PubSubClient& setServer(uint8_t * ip, uint16_t port);
|
||||
|
||||
@@ -37,6 +37,7 @@ build_flags = -D NDEBUG
|
||||
-DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
||||
-DVTABLES_IN_FLASH
|
||||
-DPUYA_SUPPORT=1
|
||||
-DDISABLE_SC16IS752_SPI
|
||||
-fno-strict-aliasing
|
||||
-I$PROJECT_DIR/src/include
|
||||
-include "ESPEasy_config.h"
|
||||
@@ -116,6 +117,9 @@ extends = esp82xx_3_0_x
|
||||
platform = espressif8266@4.2.1
|
||||
platform_packages =
|
||||
build_flags = ${esp82xx_3_0_x.build_flags}
|
||||
-DPIO_FRAMEWORK_ARDUINO_MMU_CUSTOM
|
||||
-DMMU_IRAM_SIZE=0xC000
|
||||
-DMMU_ICACHE_SIZE=0x4000
|
||||
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
|
||||
-DUSES_LATEST_SOFTWARE_SERIAL_LIBRARY=1
|
||||
-DLIBRARIES_NO_LOG=1
|
||||
@@ -127,6 +131,9 @@ platform = espressif8266@4.2.1
|
||||
platform_packages =
|
||||
build_flags = ${esp82xx_3_0_x.build_flags}
|
||||
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
|
||||
-DPIO_FRAMEWORK_ARDUINO_MMU_CUSTOM
|
||||
-DMMU_IRAM_SIZE=0xC000
|
||||
-DMMU_ICACHE_SIZE=0x4000
|
||||
-DUSES_LATEST_SOFTWARE_SERIAL_LIBRARY=1
|
||||
-DLIBRARIES_NO_LOG=1
|
||||
-DPHASE_LOCKED_WAVEFORM
|
||||
@@ -139,7 +146,11 @@ lib_ignore = ${esp82xx_defaults.lib_ignore}
|
||||
extends = esp82xx_3_0_x
|
||||
platform = espressif8266@4.2.1
|
||||
platform_packages =
|
||||
build_flags = ${core_stage.build_flags}
|
||||
build_flags = ${esp82xx_3_0_x.build_flags}
|
||||
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
|
||||
-DUSES_LATEST_SOFTWARE_SERIAL_LIBRARY=1
|
||||
-DLIBRARIES_NO_LOG=1
|
||||
-DPHASE_LOCKED_WAVEFORM
|
||||
-DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
|
||||
-DUSE_SECOND_HEAP
|
||||
lib_ignore = ${core_stage.lib_ignore}
|
||||
|
||||
@@ -108,16 +108,6 @@ lib_ignore = ${regular_platform.lib_ignore}
|
||||
|
||||
|
||||
|
||||
[collection_beta]
|
||||
platform = ${beta_platform.platform}
|
||||
platform_packages = ${beta_platform.platform_packages}
|
||||
build_flags = ${beta_platform.build_flags}
|
||||
-DPLUGIN_BUILD_COLLECTION
|
||||
-DLIMIT_BUILD_SIZE
|
||||
-DDISABLE_SC16IS752_Serial
|
||||
lib_ignore = ${beta_platform.lib_ignore}
|
||||
|
||||
|
||||
;;; IR ***********************************************************
|
||||
; IR builds ;
|
||||
; *********************************************************************
|
||||
|
||||
@@ -50,7 +50,7 @@ extra_scripts = pre:tools/pio/pre_custom_esp82xx.py
|
||||
|
||||
|
||||
; Custom: 4M1M version --------------------------
|
||||
[env:custom_ESP8266_4M1M]
|
||||
[env:custom_274_ESP8266_4M1M]
|
||||
extends = esp8266_4M1M
|
||||
platform = ${esp8266_custom_common_274.platform}
|
||||
platform_packages = ${esp8266_custom_common_274.platform_packages}
|
||||
@@ -135,7 +135,7 @@ extra_scripts = ${esp8266_custom_common_312.extra_scripts}
|
||||
|
||||
|
||||
; Custom: 1M version --------------------------
|
||||
[env:custom_ESP8266_1M]
|
||||
[env:custom_274_ESP8266_1M]
|
||||
extends = esp8266_1M
|
||||
platform = ${esp8266_custom_common_274.platform}
|
||||
platform_packages = ${esp8266_custom_common_274.platform_packages}
|
||||
@@ -169,7 +169,7 @@ extra_scripts = ${esp8266_custom_common_312.extra_scripts}
|
||||
|
||||
|
||||
; Custom: 2M version --------------------------
|
||||
[env:custom_ESP8266_2M256]
|
||||
[env:custom_274_ESP8266_2M256]
|
||||
extends = espWroom2M256
|
||||
platform = ${esp8266_custom_common_274.platform}
|
||||
platform_packages = ${esp8266_custom_common_274.platform_packages}
|
||||
@@ -255,31 +255,6 @@ build_flags = ${regular_platform.build_flags}
|
||||
-D NO_LIMIT_BUILD_SIZE
|
||||
|
||||
|
||||
|
||||
[env:normal_312_ESP8266_4M1M]
|
||||
extends = esp8266_4M1M
|
||||
platform = ${core312_platform.platform}
|
||||
platform_packages = ${core312_platform.platform_packages}
|
||||
build_flags = ${core312_platform.build_flags}
|
||||
${esp8266_4M1M.build_flags}
|
||||
-DBUILD_NO_DEBUG
|
||||
lib_ignore = ${core312_platform.lib_ignore}
|
||||
SD
|
||||
SDFS
|
||||
LittleFS(esp8266)
|
||||
|
||||
[env:normal_beta_ESP8266_4M1M]
|
||||
extends = esp8266_4M1M
|
||||
platform = ${normal_beta.platform}
|
||||
platform_packages = ${normal_beta.platform_packages}
|
||||
build_flags = ${normal_beta.build_flags}
|
||||
${esp8266_4M1M.build_flags}
|
||||
-DBUILD_NO_DEBUG
|
||||
lib_ignore = ${normal_beta.lib_ignore}
|
||||
SD
|
||||
SDFS
|
||||
LittleFS(esp8266)
|
||||
|
||||
; NORMAL: 16M version --- LittleFS --------------
|
||||
; LittleFS is determined by using "LittleFS" in the pio env name
|
||||
[env:normal_beta_ESP8266_16M_LittleFS]
|
||||
@@ -438,12 +413,6 @@ build_flags = ${collection.build_flags}
|
||||
${limited_build_size.build_flags}
|
||||
|
||||
|
||||
[collection_beta_ESP8266_4M1M]
|
||||
extends = esp8266_4M1M, collection_beta
|
||||
build_flags = ${collection_beta.build_flags}
|
||||
${esp8266_4M1M.build_flags}
|
||||
|
||||
|
||||
[env:collection_A_ESP8266_4M1M]
|
||||
extends = collection_ESP8266_4M1M
|
||||
build_flags = ${collection_ESP8266_4M1M.build_flags}
|
||||
|
||||
@@ -131,6 +131,10 @@ Web_StreamingBuffer& Web_StreamingBuffer::addFlashString(PGM_P str, int length)
|
||||
}
|
||||
|
||||
Web_StreamingBuffer& Web_StreamingBuffer::addString(const String& a) {
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectDram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
if (lowMemorySkip) { return *this; }
|
||||
const unsigned int length = a.length();
|
||||
if (length == 0) { return *this; }
|
||||
|
||||
@@ -121,7 +121,7 @@ void sw_watchdog_callback(void *arg)
|
||||
void ESPEasy_setup()
|
||||
{
|
||||
#if defined(ESP8266_DISABLE_EXTRA4K) || defined(USE_SECOND_HEAP)
|
||||
disable_extra4k_at_link_time();
|
||||
// disable_extra4k_at_link_time();
|
||||
#endif
|
||||
#ifdef PHASE_LOCKED_WAVEFORM
|
||||
enablePhaseLockedWaveform();
|
||||
|
||||
@@ -29,16 +29,16 @@
|
||||
// -V::569
|
||||
|
||||
String concat(const __FlashStringHelper * str, const String &val) {
|
||||
/*
|
||||
String res;
|
||||
reserve_special(res, strlen_P((PGM_P)str) + val.length());
|
||||
res.concat(str);
|
||||
res.concat(val);
|
||||
*/
|
||||
|
||||
/*
|
||||
String res(str);
|
||||
reserve_special(res, res.length() + val.length());
|
||||
res.concat(val);
|
||||
*/
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,12 @@ bool P036_data_struct::init(taskIndex_t taskIndex,
|
||||
return false;
|
||||
}
|
||||
|
||||
LineContent = new (std::nothrow) P036_LineContent();
|
||||
{
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
LineContent = new (std::nothrow) P036_LineContent();
|
||||
}
|
||||
|
||||
if (isInitialized()) {
|
||||
display->init(); // call to local override of init function
|
||||
|
||||
@@ -958,6 +958,10 @@ bool P037_data_struct::parseJSONMessage(const String& message) {
|
||||
}
|
||||
|
||||
if (nullptr == root) {
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
root = new (std::nothrow) DynamicJsonDocument(lastJsonMessageLength); // Dynamic allocation
|
||||
}
|
||||
|
||||
@@ -965,6 +969,10 @@ bool P037_data_struct::parseJSONMessage(const String& message) {
|
||||
deserializeJson(*root, message);
|
||||
|
||||
if (!root->isNull()) {
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectIram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
result = true;
|
||||
doc = root->as<JsonObject>();
|
||||
iter = doc.begin();
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
// Web Interface handle other requests
|
||||
// ********************************************************************************
|
||||
void handleNotFound() {
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectDram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
#ifndef BUILD_NO_RAM_TRACKER
|
||||
checkRAM(F("handleNotFound"));
|
||||
#endif // ifndef BUILD_NO_RAM_TRACKER
|
||||
|
||||
@@ -59,6 +59,10 @@
|
||||
// Web Interface root page
|
||||
// ********************************************************************************
|
||||
void handle_root() {
|
||||
# ifdef USE_SECOND_HEAP
|
||||
HeapSelectDram ephemeral;
|
||||
# endif // ifdef USE_SECOND_HEAP
|
||||
|
||||
# ifndef BUILD_NO_RAM_TRACKER
|
||||
checkRAM(F("handle_root"));
|
||||
# endif // ifndef BUILD_NO_RAM_TRACKER
|
||||
|
||||
@@ -34,6 +34,7 @@ else:
|
||||
"-DUSES_P028", # BME280
|
||||
"-DUSES_P033", # Dummy
|
||||
"-DUSES_P036", # FrameOLED
|
||||
"-DUSES_P037", # MQTT Import
|
||||
"-DUSES_P045", # MPU6050
|
||||
"-DUSES_P049", # MHZ19
|
||||
"-DUSES_P052", # SenseAir
|
||||
@@ -54,7 +55,7 @@ else:
|
||||
"-DUSES_P146", # Cache Reader
|
||||
|
||||
"-DUSES_C016", # Cache Controller
|
||||
"-DUSES_C018", # TTN/RN2483
|
||||
# "-DUSES_C018", # TTN/RN2483
|
||||
# "-DUSES_C015", # Blynk
|
||||
|
||||
# "-DFEATURE_MDNS=1",
|
||||
|
||||
Reference in New Issue
Block a user