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