ESPHome  2024.4.0
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 
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 
64  void write_display_data_();
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 
85  GPIOPin *reset_pin_{nullptr};
86  GPIOPin *dc_pin_{nullptr};
87 };
88 
89 } // namespace st7735
90 } // 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:49
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
GPIOPin * reset_pin_
Definition: st7735.h:85
uint16_t y
Definition: tt21100.cpp:18
The SPIDevice is what components using the SPI will create.
Definition: spi.h:408
display::DisplayType get_display_type() override
Definition: st7735.h:55
void set_model(ST7735Model model)
Definition: st7735.h:48
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:20
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:51
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:52
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
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:78
GPIOPin * dc_pin_
Definition: st7735.h:86