ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
display_buffer.cpp
Go to the documentation of this file.
1#include "display_buffer.h"
2
3#include <utility>
4
5#include "esphome/core/log.h"
6
7namespace esphome::display {
8
9ESPHOME_LOG_TAG(TAG, "display");
10
12 RAMAllocator<uint8_t> allocator;
13 this->buffer_ = allocator.allocate(buffer_length);
14 if (this->buffer_ == nullptr) {
15 ESP_LOGE(TAG, "Could not allocate buffer for display!");
16 return;
17 }
18 this->clear();
19}
20
22 switch (this->rotation_) {
25 return this->get_height_internal();
28 default:
29 return this->get_width_internal();
30 }
31}
32
34 switch (this->rotation_) {
37 return this->get_height_internal();
40 default:
41 return this->get_width_internal();
42 }
43}
44
45void HOT DisplayBuffer::draw_pixel_at(int x, int y, Color color) {
46 if (this->is_point_clipped(x, y))
47 return; // NOLINT
48
49 switch (this->rotation_) {
51 break;
53 std::swap(x, y);
54 x = this->get_width_internal() - x - 1;
55 break;
57 x = this->get_width_internal() - x - 1;
58 y = this->get_height_internal() - y - 1;
59 break;
61 std::swap(x, y);
62 y = this->get_height_internal() - y - 1;
63 break;
64 }
65 this->draw_absolute_pixel_internal(x, y, color);
66 this->feed_wdt_per_pixel_();
67}
68
69} // namespace esphome::display
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2298
T * allocate(size_t n)
Definition helpers.h:2325
int get_width() override
Get the width of the image in pixels with rotation applied.
void init_internal_(uint32_t buffer_length)
virtual void draw_absolute_pixel_internal(int x, int y, Color color)=0
int get_height() override
Get the height of the image in pixels with rotation applied.
void draw_pixel_at(int x, int y, Color color) override
Set a single pixel at the specified coordinates to the given color.
virtual void clear()
Clear the entire screen by filling it with OFF pixels.
Definition display.cpp:17
void ESPHOME_ALWAYS_INLINE feed_wdt_per_pixel_()
Watchdog feed for per pixel loops.
Definition display.h:845
bool ESPHOME_ALWAYS_INLINE is_point_clipped(int x, int y) const
Whether (x, y) falls outside the active clipping rectangle.
Definition display.h:810
virtual int get_width_internal()=0
virtual int get_height_internal()=0
DisplayRotation rotation_
Definition display.h:863
@ DISPLAY_ROTATION_0_DEGREES
Definition display.h:136
@ DISPLAY_ROTATION_270_DEGREES
Definition display.h:139
@ DISPLAY_ROTATION_180_DEGREES
Definition display.h:138
@ DISPLAY_ROTATION_90_DEGREES
Definition display.h:137
ESPHOME_LOG_TAG(TAG, "display")
static void uint32_t
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6