ESPHome  2022.6.3
ili9341_display.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "ili9341_defines.h"
7 #include "ili9341_init.h"
8 
9 namespace esphome {
10 namespace ili9341 {
11 
13  M5STACK = 0,
16 };
17 
21 };
22 
25  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
26  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
27  public:
28  void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
29  float get_setup_priority() const override;
30  void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
31  void set_led_pin(GPIOPin *led) { this->led_pin_ = led; }
32  void set_model(ILI9341Model model) { this->model_ = model; }
33  void set_palette(const uint8_t *palette) { this->palette_ = palette; }
34  void set_buffer_color_mode(ILI9341ColorMode color_mode) { this->buffer_color_mode_ = color_mode; }
35 
36  void command(uint8_t value);
37  void data(uint8_t value);
38  void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes);
39  uint8_t read_command(uint8_t command_byte, uint8_t index);
40  virtual void initialize() = 0;
41 
42  void update() override;
43 
44  void fill(Color color) override;
45 
46  void dump_config() override;
47  void setup() override {
48  this->setup_pins_();
49  this->initialize();
50  }
51 
53 
54  protected:
55  void draw_absolute_pixel_internal(int x, int y, Color color) override;
56  void setup_pins_();
57 
58  void init_lcd_(const uint8_t *init_cmd);
59  void set_addr_window_(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
60  void invert_display_(bool invert);
61  void reset_();
62  void fill_internal_(Color color);
63  void display_();
64 
66  int16_t width_{320};
67  int16_t height_{240};
68  uint16_t x_low_{0};
69  uint16_t y_low_{0};
70  uint16_t x_high_{0};
71  uint16_t y_high_{0};
72  const uint8_t *palette_;
73 
75 
76  uint32_t get_buffer_length_();
77  int get_width_internal() override;
78  int get_height_internal() override;
79 
80  void start_command_();
81  void end_command_();
82  void start_data_();
83  void end_data_();
84 
85  uint8_t transfer_buffer_[64];
86 
87  uint32_t buffer_to_transfer_(uint32_t pos, uint32_t sz);
88 
89  GPIOPin *reset_pin_{nullptr};
90  GPIOPin *led_pin_{nullptr};
92  GPIOPin *busy_pin_{nullptr};
93 };
94 
95 //----------- M5Stack display --------------
97  public:
98  void initialize() override;
99 };
100 
101 //----------- ILI9341_24_TFT display --------------
102 class ILI9341TFT24 : public ILI9341Display {
103  public:
104  void initialize() override;
105 };
106 
107 //----------- ILI9341_24_TFT rotated display --------------
109  public:
110  void initialize() override;
111 };
112 
113 } // namespace ili9341
114 } // namespace esphome
void set_reset_pin(GPIOPin *reset)
void init_lcd_(const uint8_t *init_cmd)
void set_buffer_color_mode(ILI9341ColorMode color_mode)
void set_model(ILI9341Model model)
void set_dc_pin(GPIOPin *dc_pin)
void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes)
This class simplifies creating components that periodically check a state.
Definition: component.h:266
void set_palette(const uint8_t *palette)
void fill(Color color) override
display::DisplayType get_display_type() override
void set_addr_window_(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
int16_t width_
Display width as modified by current rotation.
void draw_absolute_pixel_internal(int x, int y, Color color) override
uint32_t buffer_to_transfer_(uint32_t pos, uint32_t sz)
uint8_t h
Definition: bl0939.h:21
uint8_t read_command(uint8_t command_byte, uint8_t index)
float get_setup_priority() const override
Definition: a4988.cpp:4
int16_t height_
Display height as modified by current rotation.