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