ESPHome 2025.5.0
Loading...
Searching...
No Matches
st7789v.h
Go to the documentation of this file.
1#pragma once
2
6#ifdef USE_POWER_SUPPLY
8#endif
9
10namespace esphome {
11namespace st7789v {
12
13static const uint8_t ST7789_NOP = 0x00; // No Operation
14static const uint8_t ST7789_SWRESET = 0x01; // Software Reset
15static const uint8_t ST7789_RDDID = 0x04; // Read Display ID
16static const uint8_t ST7789_RDDST = 0x09; // Read Display Status
17static const uint8_t ST7789_RDDPM = 0x0A; // Read Display Power Mode
18static const uint8_t ST7789_RDDMADCTL = 0x0B; // Read Display MADCTL
19static const uint8_t ST7789_RDDCOLMOD = 0x0C; // Read Display Pixel Format
20static const uint8_t ST7789_RDDIM = 0x0D; // Read Display Image Mode
21static const uint8_t ST7789_RDDSM = 0x0E; // Read Display Signal Mod
22static const uint8_t ST7789_RDDSDR = 0x0F; // Read Display Self-Diagnostic Result
23static const uint8_t ST7789_SLPIN = 0x10; // Sleep in
24static const uint8_t ST7789_SLPOUT = 0x11; // Sleep Out
25static const uint8_t ST7789_PTLON = 0x12; // Partial Display Mode On
26static const uint8_t ST7789_NORON = 0x13; // Normal Display Mode On
27static const uint8_t ST7789_INVOFF = 0x20; // Display Inversion Off
28static const uint8_t ST7789_INVON = 0x21; // Display Inversion On
29static const uint8_t ST7789_GAMSET = 0x26; // Gamma Set
30static const uint8_t ST7789_DISPOFF = 0x28; // Display Off
31static const uint8_t ST7789_DISPON = 0x29; // Display On
32static const uint8_t ST7789_CASET = 0x2A; // Column Address Set
33static const uint8_t ST7789_RASET = 0x2B; // Row Address Set
34static const uint8_t ST7789_RAMWR = 0x2C; // Memory Write
35static const uint8_t ST7789_RAMRD = 0x2E; // Memory Read
36static const uint8_t ST7789_PTLAR = 0x30; // Partial Area
37static const uint8_t ST7789_VSCRDEF = 0x33; // Vertical Scrolling Definition
38static const uint8_t ST7789_TEOFF = 0x34; // Tearing Effect Line Off
39static const uint8_t ST7789_TEON = 0x35; // Tearing Effect Line On
40static const uint8_t ST7789_MADCTL = 0x36; // Memory Data Access Control
41static const uint8_t ST7789_VSCSAD = 0x37; // Vertical Scroll Start Address of RAM
42static const uint8_t ST7789_IDMOFF = 0x38; // Idle Mode Off
43static const uint8_t ST7789_IDMON = 0x39; // Idle Mode On
44static const uint8_t ST7789_COLMOD = 0x3A; // Interface Pixel Format
45static const uint8_t ST7789_WRMEMC = 0x3C; // Write Memory Continue
46static const uint8_t ST7789_RDMEMC = 0x3E; // Read Memory Continue
47static const uint8_t ST7789_STE = 0x44; // Set Tear Scanline
48static const uint8_t ST7789_GSCAN = 0x45; // Get Scanline
49static const uint8_t ST7789_WRDISBV = 0x51; // Write Display Brightness
50static const uint8_t ST7789_RDDISBV = 0x52; // Read Display Brightness Value
51static const uint8_t ST7789_WRCTRLD = 0x53; // Write CTRL Display
52static const uint8_t ST7789_RDCTRLD = 0x54; // Read CTRL Value Display
53static const uint8_t ST7789_WRCACE = 0x55; // Write Content Adaptive Brightness Control and Color Enhancement
54static const uint8_t ST7789_RDCABC = 0x56; // Read Content Adaptive Brightness Control
55static const uint8_t ST7789_WRCABCMB = 0x5E; // Write CABC Minimum Brightnes
56static const uint8_t ST7789_RDCABCMB = 0x5F; // Read CABC Minimum Brightnes
57static const uint8_t ST7789_RDABCSDR = 0x68; // Read Automatic Brightness Control Self-Diagnostic Result
58static const uint8_t ST7789_RDID1 = 0xDA; // Read ID1
59static const uint8_t ST7789_RDID2 = 0xDB; // Read ID2
60static const uint8_t ST7789_RDID3 = 0xDC; // Read ID3
61static const uint8_t ST7789_RAMCTRL = 0xB0; // RAM Control
62static const uint8_t ST7789_RGBCTRL = 0xB1; // RGB Interface Control
63static const uint8_t ST7789_PORCTRL = 0xB2; // Porch Setting
64static const uint8_t ST7789_FRCTRL1 = 0xB3; // Frame Rate Control 1 (In partial mode/ idle colors)
65static const uint8_t ST7789_PARCTRL = 0xB5; // Partial mode Control
66static const uint8_t ST7789_GCTRL = 0xB7; // Gate Control
67static const uint8_t ST7789_GTADJ = 0xB8; // Gate On Timing Adjustment
68static const uint8_t ST7789_DGMEN = 0xBA; // Digital Gamma Enable
69static const uint8_t ST7789_VCOMS = 0xBB; // VCOMS Setting
70static const uint8_t ST7789_LCMCTRL = 0xC0; // LCM Control
71static const uint8_t ST7789_IDSET = 0xC1; // ID Code Setting
72static const uint8_t ST7789_VDVVRHEN = 0xC2; // VDV and VRH Command Enable
73static const uint8_t ST7789_VRHS = 0xC3; // VRH Set
74static const uint8_t ST7789_VDVS = 0xC4; // VDV Set
75static const uint8_t ST7789_VCMOFSET = 0xC5; // VCOMS Offset Set
76static const uint8_t ST7789_FRCTRL2 = 0xC6; // Frame Rate Control in Normal Mode
77static const uint8_t ST7789_CABCCTRL = 0xC7; // CABC Control
78static const uint8_t ST7789_REGSEL1 = 0xC8; // Register Value Selection 1
79static const uint8_t ST7789_REGSEL2 = 0xCA; // Register Value Selection
80static const uint8_t ST7789_PWMFRSEL = 0xCC; // PWM Frequency Selection
81static const uint8_t ST7789_PWCTRL1 = 0xD0; // Power Control 1
82static const uint8_t ST7789_VAPVANEN = 0xD2; // Enable VAP/VAN signal output
83static const uint8_t ST7789_CMD2EN = 0xDF; // Command 2 Enable
84static const uint8_t ST7789_PVGAMCTRL = 0xE0; // Positive Voltage Gamma Control
85static const uint8_t ST7789_NVGAMCTRL = 0xE1; // Negative Voltage Gamma Control
86static const uint8_t ST7789_DGMLUTR = 0xE2; // Digital Gamma Look-up Table for Red
87static const uint8_t ST7789_DGMLUTB = 0xE3; // Digital Gamma Look-up Table for Blue
88static const uint8_t ST7789_GATECTRL = 0xE4; // Gate Control
89static const uint8_t ST7789_SPI2EN = 0xE7; // SPI2 Enable
90static const uint8_t ST7789_PWCTRL2 = 0xE8; // Power Control 2
91static const uint8_t ST7789_EQCTRL = 0xE9; // Equalize time control
92static const uint8_t ST7789_PROMCTRL = 0xEC; // Program Mode Control
93static const uint8_t ST7789_PROMEN = 0xFA; // Program Mode Enable
94static const uint8_t ST7789_NVMSET = 0xFC; // NVM Setting
95static const uint8_t ST7789_PROMACT = 0xFE; // Program action
96
97// Flags for ST7789_MADCTL
98static const uint8_t ST7789_MADCTL_MY = 0x80;
99static const uint8_t ST7789_MADCTL_MX = 0x40;
100static const uint8_t ST7789_MADCTL_MV = 0x20;
101static const uint8_t ST7789_MADCTL_ML = 0x10;
102static const uint8_t ST7789_MADCTL_RGB = 0x00;
103static const uint8_t ST7789_MADCTL_BGR = 0x08;
104static const uint8_t ST7789_MADCTL_MH = 0x04;
105static const uint8_t ST7789_MADCTL_SS = 0x02;
106static const uint8_t ST7789_MADCTL_GS = 0x01;
107
108static const uint8_t ST7789_MADCTL_COLOR_ORDER = ST7789_MADCTL_BGR;
109
111 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
112 spi::DATA_RATE_20MHZ> {
113 public:
114 void set_model_str(const char *model_str);
115 void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
116 void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
117 void set_backlight_pin(GPIOPin *backlight_pin) { this->backlight_pin_ = backlight_pin; }
118#ifdef USE_POWER_SUPPLY
119 void set_power_supply(power_supply::PowerSupply *power_supply) { this->power_.set_parent(power_supply); }
120#endif
121
122 void set_eightbitcolor(bool eightbitcolor) { this->eightbitcolor_ = eightbitcolor; }
123 void set_height(uint32_t height) { this->height_ = height; }
124 void set_width(uint16_t width) { this->width_ = width; }
125 void set_offset_height(uint32_t offset_height) { this->offset_height_ = offset_height; }
126 void set_offset_width(uint16_t offset_width) { this->offset_width_ = offset_width; }
127
128 // ========== INTERNAL METHODS ==========
129 // (In most use cases you won't need these)
130 void setup() override;
131 void dump_config() override;
132 float get_setup_priority() const override;
133 void update() override;
134
135 void write_display_data();
136
138
139 protected:
140 GPIOPin *dc_pin_{nullptr};
143#ifdef USE_POWER_SUPPLY
145#endif
146
147 bool eightbitcolor_{false};
148 uint16_t height_{0};
149 uint16_t width_{0};
150 uint16_t offset_height_{0};
151 uint16_t offset_width_{0};
152
153 void init_reset_();
154 void backlight_(bool onoff);
155 void write_command_(uint8_t value);
156 void write_data_(uint8_t value);
157 void write_addr_(uint16_t addr1, uint16_t addr2);
158 void write_color_(uint16_t color, uint16_t size);
159
160 int get_height_internal() override { return this->height_; }
161 int get_width_internal() override { return this->width_; }
162 size_t get_buffer_length_();
163
164 void draw_filled_rect_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
165
166 void draw_absolute_pixel_internal(int x, int y, Color color) override;
167
168 const char *model_str_;
169};
170
171} // namespace st7789v
172} // namespace esphome
The SPIDevice is what components using the SPI will create.
Definition spi.h:421
void set_reset_pin(GPIOPin *reset_pin)
Definition st7789v.h:116
display::DisplayType get_display_type() override
Definition st7789v.h:137
void dump_config() override
Definition st7789v.cpp:123
void set_dc_pin(GPIOPin *dc_pin)
Definition st7789v.h:115
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition st7789v.cpp:292
void backlight_(bool onoff)
Definition st7789v.cpp:213
void write_addr_(uint16_t addr1, uint16_t addr2)
Definition st7789v.cpp:235
void draw_filled_rect_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition st7789v.cpp:271
void set_backlight_pin(GPIOPin *backlight_pin)
Definition st7789v.h:117
const char * model_str_
Definition st7789v.h:168
void set_model_str(const char *model_str)
Definition st7789v.cpp:149
void write_command_(uint8_t value)
Definition st7789v.cpp:220
void update() override
Definition st7789v.cpp:144
void set_offset_height(uint32_t offset_height)
Definition st7789v.h:125
float get_setup_priority() const override
Definition st7789v.cpp:142
void set_eightbitcolor(bool eightbitcolor)
Definition st7789v.h:122
void setup() override
Definition st7789v.cpp:10
void set_offset_width(uint16_t offset_width)
Definition st7789v.h:126
int get_height_internal() override
Definition st7789v.h:160
void write_data_(uint8_t value)
Definition st7789v.cpp:228
void set_power_supply(power_supply::PowerSupply *power_supply)
Definition st7789v.h:119
void write_color_(uint16_t color, uint16_t size)
Definition st7789v.cpp:246
int get_width_internal() override
Definition st7789v.h:161
void set_height(uint32_t height)
Definition st7789v.h:123
power_supply::PowerSupplyRequester power_
Definition st7789v.h:144
void set_width(uint16_t width)
Definition st7789v.h:124
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6