mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Clean up RAMAllocators in display related code (#9141)
This commit is contained in:
		| @@ -11,7 +11,7 @@ namespace display { | |||||||
| static const char *const TAG = "display"; | static const char *const TAG = "display"; | ||||||
|  |  | ||||||
| void DisplayBuffer::init_internal_(uint32_t buffer_length) { | void DisplayBuffer::init_internal_(uint32_t buffer_length) { | ||||||
|   ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE); |   RAMAllocator<uint8_t> allocator; | ||||||
|   this->buffer_ = allocator.allocate(buffer_length); |   this->buffer_ = allocator.allocate(buffer_length); | ||||||
|   if (this->buffer_ == nullptr) { |   if (this->buffer_ == nullptr) { | ||||||
|     ESP_LOGE(TAG, "Could not allocate buffer for display!"); |     ESP_LOGE(TAG, "Could not allocate buffer for display!"); | ||||||
|   | |||||||
| @@ -67,10 +67,10 @@ class Font | |||||||
|   inline int get_height() { return this->height_; } |   inline int get_height() { return this->height_; } | ||||||
|   inline int get_bpp() { return this->bpp_; } |   inline int get_bpp() { return this->bpp_; } | ||||||
|  |  | ||||||
|   const std::vector<Glyph, ExternalRAMAllocator<Glyph>> &get_glyphs() const { return glyphs_; } |   const std::vector<Glyph, RAMAllocator<Glyph>> &get_glyphs() const { return glyphs_; } | ||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|   std::vector<Glyph, ExternalRAMAllocator<Glyph>> glyphs_; |   std::vector<Glyph, RAMAllocator<Glyph>> glyphs_; | ||||||
|   int baseline_; |   int baseline_; | ||||||
|   int height_; |   int height_; | ||||||
|   uint8_t bpp_;  // bits per pixel |   uint8_t bpp_;  // bits per pixel | ||||||
|   | |||||||
| @@ -57,8 +57,8 @@ void Inkplate6::setup() { | |||||||
|  * Allocate buffers. May be called after setup to re-initialise if e.g. greyscale is changed. |  * Allocate buffers. May be called after setup to re-initialise if e.g. greyscale is changed. | ||||||
|  */ |  */ | ||||||
| void Inkplate6::initialize_() { | void Inkplate6::initialize_() { | ||||||
|   ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE); |   RAMAllocator<uint8_t> allocator; | ||||||
|   ExternalRAMAllocator<uint32_t> allocator32(ExternalRAMAllocator<uint32_t>::ALLOW_FAILURE); |   RAMAllocator<uint32_t> allocator32; | ||||||
|   uint32_t buffer_size = this->get_buffer_length_(); |   uint32_t buffer_size = this->get_buffer_length_(); | ||||||
|   if (buffer_size == 0) |   if (buffer_size == 0) | ||||||
|     return; |     return; | ||||||
|   | |||||||
| @@ -1,8 +1,8 @@ | |||||||
| #include "nextion.h" | #include "nextion.h" | ||||||
| #include "esphome/core/util.h" |  | ||||||
| #include "esphome/core/log.h" |  | ||||||
| #include "esphome/core/application.h" |  | ||||||
| #include <cinttypes> | #include <cinttypes> | ||||||
|  | #include "esphome/core/application.h" | ||||||
|  | #include "esphome/core/log.h" | ||||||
|  | #include "esphome/core/util.h" | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace nextion { | namespace nextion { | ||||||
| @@ -1003,7 +1003,7 @@ void Nextion::add_no_result_to_queue_(const std::string &variable_name) { | |||||||
|   } |   } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|   ExternalRAMAllocator<nextion::NextionQueue> allocator(ExternalRAMAllocator<nextion::NextionQueue>::ALLOW_FAILURE); |   RAMAllocator<nextion::NextionQueue> allocator; | ||||||
|   nextion::NextionQueue *nextion_queue = allocator.allocate(1); |   nextion::NextionQueue *nextion_queue = allocator.allocate(1); | ||||||
|   if (nextion_queue == nullptr) { |   if (nextion_queue == nullptr) { | ||||||
|     ESP_LOGW(TAG, "Queue alloc failed"); |     ESP_LOGW(TAG, "Queue alloc failed"); | ||||||
| @@ -1159,7 +1159,7 @@ void Nextion::add_to_get_queue(NextionComponentBase *component) { | |||||||
|   } |   } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|   ExternalRAMAllocator<nextion::NextionQueue> allocator(ExternalRAMAllocator<nextion::NextionQueue>::ALLOW_FAILURE); |   RAMAllocator<nextion::NextionQueue> allocator; | ||||||
|   nextion::NextionQueue *nextion_queue = allocator.allocate(1); |   nextion::NextionQueue *nextion_queue = allocator.allocate(1); | ||||||
|   if (nextion_queue == nullptr) { |   if (nextion_queue == nullptr) { | ||||||
|     ESP_LOGW(TAG, "Queue alloc failed"); |     ESP_LOGW(TAG, "Queue alloc failed"); | ||||||
| @@ -1191,7 +1191,7 @@ void Nextion::add_addt_command_to_queue(NextionComponentBase *component) { | |||||||
|   if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping()) |   if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping()) | ||||||
|     return; |     return; | ||||||
|  |  | ||||||
|   ExternalRAMAllocator<nextion::NextionQueue> allocator(ExternalRAMAllocator<nextion::NextionQueue>::ALLOW_FAILURE); |   RAMAllocator<nextion::NextionQueue> allocator; | ||||||
|   nextion::NextionQueue *nextion_queue = allocator.allocate(1); |   nextion::NextionQueue *nextion_queue = allocator.allocate(1); | ||||||
|   if (nextion_queue == nullptr) { |   if (nextion_queue == nullptr) { | ||||||
|     ESP_LOGW(TAG, "Queue alloc failed"); |     ESP_LOGW(TAG, "Queue alloc failed"); | ||||||
|   | |||||||
| @@ -3,12 +3,12 @@ | |||||||
| #ifdef USE_NEXTION_TFT_UPLOAD | #ifdef USE_NEXTION_TFT_UPLOAD | ||||||
| #ifdef USE_ARDUINO | #ifdef USE_ARDUINO | ||||||
|  |  | ||||||
|  | #include <cinttypes> | ||||||
|  | #include "esphome/components/network/util.h" | ||||||
| #include "esphome/core/application.h" | #include "esphome/core/application.h" | ||||||
| #include "esphome/core/defines.h" | #include "esphome/core/defines.h" | ||||||
| #include "esphome/core/util.h" |  | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
| #include "esphome/components/network/util.h" | #include "esphome/core/util.h" | ||||||
| #include <cinttypes> |  | ||||||
|  |  | ||||||
| #ifdef USE_ESP32 | #ifdef USE_ESP32 | ||||||
| #include <esp_heap_caps.h> | #include <esp_heap_caps.h> | ||||||
| @@ -52,7 +52,7 @@ int Nextion::upload_by_chunks_(HTTPClient &http_client, uint32_t &range_start) { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Allocate the buffer dynamically |   // Allocate the buffer dynamically | ||||||
|   ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE); |   RAMAllocator<uint8_t> allocator; | ||||||
|   uint8_t *buffer = allocator.allocate(4096); |   uint8_t *buffer = allocator.allocate(4096); | ||||||
|   if (!buffer) { |   if (!buffer) { | ||||||
|     ESP_LOGE(TAG, "Buffer alloc failed"); |     ESP_LOGE(TAG, "Buffer alloc failed"); | ||||||
|   | |||||||
| @@ -3,14 +3,14 @@ | |||||||
| #ifdef USE_NEXTION_TFT_UPLOAD | #ifdef USE_NEXTION_TFT_UPLOAD | ||||||
| #ifdef USE_ESP_IDF | #ifdef USE_ESP_IDF | ||||||
|  |  | ||||||
| #include "esphome/core/application.h" |  | ||||||
| #include "esphome/core/defines.h" |  | ||||||
| #include "esphome/core/util.h" |  | ||||||
| #include "esphome/core/log.h" |  | ||||||
| #include "esphome/components/network/util.h" |  | ||||||
| #include <cinttypes> |  | ||||||
| #include <esp_heap_caps.h> | #include <esp_heap_caps.h> | ||||||
| #include <esp_http_client.h> | #include <esp_http_client.h> | ||||||
|  | #include <cinttypes> | ||||||
|  | #include "esphome/components/network/util.h" | ||||||
|  | #include "esphome/core/application.h" | ||||||
|  | #include "esphome/core/defines.h" | ||||||
|  | #include "esphome/core/log.h" | ||||||
|  | #include "esphome/core/util.h" | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace nextion { | namespace nextion { | ||||||
| @@ -51,7 +51,7 @@ int Nextion::upload_by_chunks_(esp_http_client_handle_t http_client, uint32_t &r | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Allocate the buffer dynamically |   // Allocate the buffer dynamically | ||||||
|   ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE); |   RAMAllocator<uint8_t> allocator; | ||||||
|   uint8_t *buffer = allocator.allocate(4096); |   uint8_t *buffer = allocator.allocate(4096); | ||||||
|   if (!buffer) { |   if (!buffer) { | ||||||
|     ESP_LOGE(TAG, "Buffer alloc failed"); |     ESP_LOGE(TAG, "Buffer alloc failed"); | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| #include "waveshare_epaper.h" | #include "waveshare_epaper.h" | ||||||
|  | #include <bitset> | ||||||
|  | #include <cinttypes> | ||||||
| #include "esphome/core/application.h" | #include "esphome/core/application.h" | ||||||
| #include "esphome/core/helpers.h" | #include "esphome/core/helpers.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
| #include <cinttypes> |  | ||||||
| #include <bitset> |  | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace waveshare_epaper { | namespace waveshare_epaper { | ||||||
| @@ -185,7 +185,7 @@ void WaveshareEPaper7C::setup() { | |||||||
|   this->initialize(); |   this->initialize(); | ||||||
| } | } | ||||||
| void WaveshareEPaper7C::init_internal_7c_(uint32_t buffer_length) { | void WaveshareEPaper7C::init_internal_7c_(uint32_t buffer_length) { | ||||||
|   ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE); |   RAMAllocator<uint8_t> allocator; | ||||||
|   uint32_t small_buffer_length = buffer_length / NUM_BUFFERS; |   uint32_t small_buffer_length = buffer_length / NUM_BUFFERS; | ||||||
|  |  | ||||||
|   for (int i = 0; i < NUM_BUFFERS; i++) { |   for (int i = 0; i < NUM_BUFFERS; i++) { | ||||||
| @@ -2054,7 +2054,7 @@ void GDEW029T5::initialize() { | |||||||
|     this->deep_sleep_between_updates_ = true; |     this->deep_sleep_between_updates_ = true; | ||||||
|  |  | ||||||
|   // old buffer for partial update |   // old buffer for partial update | ||||||
|   ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE); |   RAMAllocator<uint8_t> allocator; | ||||||
|   this->old_buffer_ = allocator.allocate(this->get_buffer_length_()); |   this->old_buffer_ = allocator.allocate(this->get_buffer_length_()); | ||||||
|   if (this->old_buffer_ == nullptr) { |   if (this->old_buffer_ == nullptr) { | ||||||
|     ESP_LOGE(TAG, "Could not allocate old buffer for display!"); |     ESP_LOGE(TAG, "Could not allocate old buffer for display!"); | ||||||
| @@ -2199,7 +2199,7 @@ void GDEW029T5::dump_config() { | |||||||
|  |  | ||||||
| void GDEW0154M09::initialize() { | void GDEW0154M09::initialize() { | ||||||
|   this->init_internal_(); |   this->init_internal_(); | ||||||
|   ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE); |   RAMAllocator<uint8_t> allocator; | ||||||
|   this->lastbuff_ = allocator.allocate(this->get_buffer_length_()); |   this->lastbuff_ = allocator.allocate(this->get_buffer_length_()); | ||||||
|   if (this->lastbuff_ != nullptr) { |   if (this->lastbuff_ != nullptr) { | ||||||
|     memset(this->lastbuff_, 0xff, sizeof(uint8_t) * this->get_buffer_length_()); |     memset(this->lastbuff_, 0xff, sizeof(uint8_t) * this->get_buffer_length_()); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user