ESPHome  2022.5.1
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,
15 };
16 
19  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
20  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
21  public:
22  void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
23  float get_setup_priority() const override;
24  void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
25  void set_led_pin(GPIOPin *led) { this->led_pin_ = led; }
26  void set_model(ILI9341Model model) { this->model_ = model; }
27 
28  void command(uint8_t value);
29  void data(uint8_t value);
30  void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes);
31  uint8_t read_command(uint8_t command_byte, uint8_t index);
32  virtual void initialize() = 0;
33 
34  void update() override;
35 
36  void fill(Color color) override;
37 
38  void dump_config() override;
39  void setup() override {
40  this->setup_pins_();
41  this->initialize();
42  }
43 
44  protected:
45  void draw_absolute_pixel_internal(int x, int y, Color color) override;
46  void setup_pins_();
47 
48  void init_lcd_(const uint8_t *init_cmd);
49  void set_addr_window_(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
50  void invert_display_(bool invert);
51  void reset_();
52  void fill_internal_(Color color);
53  void display_();
54  uint16_t convert_to_16bit_color_(uint8_t color_8bit);
55  uint8_t convert_to_8bit_color_(uint16_t color_16bit);
56 
58  int16_t width_{320};
59  int16_t height_{240};
60  uint16_t x_low_{0};
61  uint16_t y_low_{0};
62  uint16_t x_high_{0};
63  uint16_t y_high_{0};
64 
65  uint32_t get_buffer_length_();
66  int get_width_internal() override;
67  int get_height_internal() override;
68 
69  void start_command_();
70  void end_command_();
71  void start_data_();
72  void end_data_();
73 
74  uint8_t transfer_buffer_[64];
75 
76  uint32_t buffer_to_transfer_(uint32_t pos, uint32_t sz);
77 
78  GPIOPin *reset_pin_{nullptr};
79  GPIOPin *led_pin_{nullptr};
81  GPIOPin *busy_pin_{nullptr};
82 };
83 
84 //----------- M5Stack display --------------
86  public:
87  void initialize() override;
88 };
89 
90 //----------- ILI9341_24_TFT display --------------
91 class ILI9341TFT24 : public ILI9341Display {
92  public:
93  void initialize() override;
94 };
95 } // namespace ili9341
96 } // namespace esphome
void set_reset_pin(GPIOPin *reset)
void init_lcd_(const uint8_t *init_cmd)
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 fill(Color color) 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.
uint8_t convert_to_8bit_color_(uint16_t color_16bit)
uint16_t convert_to_16bit_color_(uint8_t color_8bit)