mirror of
https://github.com/esphome/esphome.git
synced 2025-01-03 11:21:43 +01:00
ILI9XXX: Lazily allocate buffer (#6352)
This commit is contained in:
parent
d6bcc465a8
commit
c559ccbb83
2 changed files with 15 additions and 1 deletions
|
@ -42,7 +42,9 @@ void ILI9XXXDisplay::setup() {
|
||||||
this->y_low_ = this->height_;
|
this->y_low_ = this->height_;
|
||||||
this->x_high_ = 0;
|
this->x_high_ = 0;
|
||||||
this->y_high_ = 0;
|
this->y_high_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ILI9XXXDisplay::alloc_buffer_() {
|
||||||
if (this->buffer_color_mode_ == BITS_16) {
|
if (this->buffer_color_mode_ == BITS_16) {
|
||||||
this->init_internal_(this->get_buffer_length_() * 2);
|
this->init_internal_(this->get_buffer_length_() * 2);
|
||||||
if (this->buffer_ != nullptr) {
|
if (this->buffer_ != nullptr) {
|
||||||
|
@ -107,6 +109,8 @@ void ILI9XXXDisplay::dump_config() {
|
||||||
float ILI9XXXDisplay::get_setup_priority() const { return setup_priority::HARDWARE; }
|
float ILI9XXXDisplay::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||||
|
|
||||||
void ILI9XXXDisplay::fill(Color color) {
|
void ILI9XXXDisplay::fill(Color color) {
|
||||||
|
if (!this->check_buffer_())
|
||||||
|
return;
|
||||||
uint16_t new_color = 0;
|
uint16_t new_color = 0;
|
||||||
this->x_low_ = 0;
|
this->x_low_ = 0;
|
||||||
this->y_low_ = 0;
|
this->y_low_ = 0;
|
||||||
|
@ -124,7 +128,6 @@ void ILI9XXXDisplay::fill(Color color) {
|
||||||
// Upper and lower is equal can use quicker memset operation. Takes ~20ms.
|
// Upper and lower is equal can use quicker memset operation. Takes ~20ms.
|
||||||
memset(this->buffer_, (uint8_t) new_color, buffer_length_16_bits);
|
memset(this->buffer_, (uint8_t) new_color, buffer_length_16_bits);
|
||||||
} else {
|
} else {
|
||||||
// Slower set of both buffers. Takes ~30ms.
|
|
||||||
for (uint32_t i = 0; i < buffer_length_16_bits; i = i + 2) {
|
for (uint32_t i = 0; i < buffer_length_16_bits; i = i + 2) {
|
||||||
this->buffer_[i] = (uint8_t) (new_color >> 8);
|
this->buffer_[i] = (uint8_t) (new_color >> 8);
|
||||||
this->buffer_[i + 1] = (uint8_t) new_color;
|
this->buffer_[i + 1] = (uint8_t) new_color;
|
||||||
|
@ -144,6 +147,8 @@ void HOT ILI9XXXDisplay::draw_absolute_pixel_internal(int x, int y, Color color)
|
||||||
if (x >= this->get_width_internal() || x < 0 || y >= this->get_height_internal() || y < 0) {
|
if (x >= this->get_width_internal() || x < 0 || y >= this->get_height_internal() || y < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this->check_buffer_())
|
||||||
|
return;
|
||||||
uint32_t pos = (y * width_) + x;
|
uint32_t pos = (y * width_) + x;
|
||||||
uint16_t new_color;
|
uint16_t new_color;
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
|
|
|
@ -86,6 +86,14 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
|
display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
inline bool check_buffer_() {
|
||||||
|
if (this->buffer_ == nullptr) {
|
||||||
|
this->alloc_buffer_();
|
||||||
|
return !this->is_failed();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void draw_absolute_pixel_internal(int x, int y, Color color) override;
|
void draw_absolute_pixel_internal(int x, int y, Color color) override;
|
||||||
void setup_pins_();
|
void setup_pins_();
|
||||||
|
|
||||||
|
@ -116,6 +124,7 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
void end_command_();
|
void end_command_();
|
||||||
void start_data_();
|
void start_data_();
|
||||||
void end_data_();
|
void end_data_();
|
||||||
|
void alloc_buffer_();
|
||||||
|
|
||||||
GPIOPin *reset_pin_{nullptr};
|
GPIOPin *reset_pin_{nullptr};
|
||||||
GPIOPin *dc_pin_{nullptr};
|
GPIOPin *dc_pin_{nullptr};
|
||||||
|
|
Loading…
Reference in a new issue