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