ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
st7735.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome::st7735 {
8
9static const uint8_t ST7735_TFTWIDTH_128 = 128; // for 1.44 and mini^M
10static const uint8_t ST7735_TFTWIDTH_80 = 80; // for mini^M
11static const uint8_t ST7735_TFTHEIGHT_128 = 128; // for 1.44" display^M
12static const uint8_t ST7735_TFTHEIGHT_160 = 160; // for 1.8" and mini display^M
13
14// some flags for initR() :(
15static const uint8_t INITR_GREENTAB = 0x00;
16static const uint8_t INITR_REDTAB = 0x01;
17static const uint8_t INITR_BLACKTAB = 0x02;
18static const uint8_t INITR_144GREENTAB = 0x01;
19static const uint8_t INITR_MINI_160X80 = 0x04;
20static const uint8_t INITR_HALLOWING = 0x05;
21static const uint8_t INITR_18GREENTAB = INITR_GREENTAB;
22static const uint8_t INITR_18REDTAB = INITR_REDTAB;
23static const uint8_t INITR_18BLACKTAB = INITR_BLACKTAB;
24
26 ST7735_INITR_GREENTAB = INITR_GREENTAB,
27 ST7735_INITR_REDTAB = INITR_REDTAB,
28 ST7735_INITR_BLACKTAB = INITR_BLACKTAB,
29 ST7735_INITR_MINI_160X80 = INITR_MINI_160X80,
30 ST7735_INITR_18BLACKTAB = INITR_18BLACKTAB,
31 ST7735_INITR_18REDTAB = INITR_18REDTAB
32};
33
35 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
36 spi::DATA_RATE_8MHZ> {
37 public:
38 ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr,
39 bool invert_colors);
40 void dump_config() override;
41 void setup() override;
42
43 void display();
44
45 void update() override;
46
47 void set_model(ST7735Model model) { this->model_ = model; }
48 float get_setup_priority() const override { return setup_priority::PROCESSOR; }
49
50 void set_reset_pin(GPIOPin *value) { this->reset_pin_ = value; }
51 void set_dc_pin(GPIOPin *value) { dc_pin_ = value; }
52 size_t get_buffer_length();
53
55
56 protected:
57 void sendcommand_(uint8_t cmd, const uint8_t *data_bytes, uint8_t num_data_bytes);
58 void senddata_(const uint8_t *data_bytes, uint8_t num_data_bytes);
59
60 void writecommand_(uint8_t value);
61 void writedata_(uint8_t value);
62
64
65 void init_reset_();
66 void display_init_(const uint8_t *addr);
67 void set_addr_window_(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
68 void draw_absolute_pixel_internal(int x, int y, Color color) override;
69 void spi_master_write_addr_(uint16_t addr1, uint16_t addr2);
70
71 int get_width_internal() override;
72 int get_height_internal() override;
73
74 const char *model_str_();
75
77 uint8_t colstart_ = 0, rowstart_ = 0;
78 bool eightbitcolor_ = false;
79 bool usebgr_ = false;
80 bool invert_colors_ = false;
81 int16_t width_ = 80, height_ = 80; // Watch heap size
82
84 GPIOPin *dc_pin_{nullptr};
85};
86
87} // namespace esphome::st7735
uint8_t h
Definition bl0906.h:2
The SPIDevice is what components using the SPI will create.
Definition spi.h:429
void set_reset_pin(GPIOPin *value)
Definition st7735.h:50
display::DisplayType get_display_type() override
Definition st7735.h:54
const char * model_str_()
Definition st7735.cpp:336
void set_dc_pin(GPIOPin *value)
Definition st7735.h:51
void senddata_(const uint8_t *data_bytes, uint8_t num_data_bytes)
Definition st7735.cpp:410
int get_height_internal() override
Definition st7735.cpp:297
GPIOPin * reset_pin_
Definition st7735.h:83
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition st7735.cpp:308
ST7735Model model_
Definition st7735.h:76
void display_init_(const uint8_t *addr)
Definition st7735.cpp:351
void writecommand_(uint8_t value)
Definition st7735.cpp:390
void set_addr_window_(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
float get_setup_priority() const override
Definition st7735.h:48
void writedata_(uint8_t value)
Definition st7735.cpp:398
int get_width_internal() override
Definition st7735.cpp:299
void update() override
Definition st7735.cpp:292
void dump_config() override
Definition st7735.cpp:373
ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr, bool invert_colors)
Definition st7735.cpp:223
void setup() override
Definition st7735.cpp:234
void spi_master_write_addr_(uint16_t addr1, uint16_t addr2)
Definition st7735.cpp:467
void set_model(ST7735Model model)
Definition st7735.h:47
void sendcommand_(uint8_t cmd, const uint8_t *data_bytes, uint8_t num_data_bytes)
Definition st7735.cpp:405
constexpr float PROCESSOR
For components that use data from sensors like displays.
Definition component.h:45
@ ST7735_INITR_18REDTAB
Definition st7735.h:31
@ ST7735_INITR_MINI_160X80
Definition st7735.h:29
@ ST7735_INITR_GREENTAB
Definition st7735.h:26
@ ST7735_INITR_18BLACKTAB
Definition st7735.h:30
@ ST7735_INITR_BLACKTAB
Definition st7735.h:28
@ ST7735_INITR_REDTAB
Definition st7735.h:27
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6