ESPHome  2024.5.0
qspi_amoled.h
Go to the documentation of this file.
1 //
2 // Created by Clyde Stubbs on 29/10/2023.
3 //
4 #pragma once
5 
6 #ifdef USE_ESP_IDF
12 #include "esp_lcd_panel_ops.h"
13 
14 #include "esp_lcd_panel_rgb.h"
15 
16 namespace esphome {
17 namespace qspi_amoled {
18 
19 constexpr static const char *const TAG = "display.qspi_amoled";
20 static const uint8_t SW_RESET_CMD = 0x01;
21 static const uint8_t SLEEP_OUT = 0x11;
22 static const uint8_t INVERT_OFF = 0x20;
23 static const uint8_t INVERT_ON = 0x21;
24 static const uint8_t ALL_ON = 0x23;
25 static const uint8_t WRAM = 0x24;
26 static const uint8_t MIPI = 0x26;
27 static const uint8_t DISPLAY_ON = 0x29;
28 static const uint8_t RASET = 0x2B;
29 static const uint8_t CASET = 0x2A;
30 static const uint8_t WDATA = 0x2C;
31 static const uint8_t TEON = 0x35;
32 static const uint8_t MADCTL_CMD = 0x36;
33 static const uint8_t PIXFMT = 0x3A;
34 static const uint8_t BRIGHTNESS = 0x51;
35 static const uint8_t SWIRE1 = 0x5A;
36 static const uint8_t SWIRE2 = 0x5B;
37 static const uint8_t PAGESEL = 0xFE;
38 
39 static const uint8_t MADCTL_MY = 0x80;
40 static const uint8_t MADCTL_MX = 0x40;
41 static const uint8_t MADCTL_MV = 0x20;
42 static const uint8_t MADCTL_RGB = 0x00;
43 static const uint8_t MADCTL_BGR = 0x08;
44 
45 // store a 16 bit value in a buffer, big endian.
46 static inline void put16_be(uint8_t *buf, uint16_t value) {
47  buf[0] = value >> 8;
48  buf[1] = value;
49 }
50 
51 enum Model {
54 };
55 
57  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
58  spi::DATA_RATE_1MHZ> {
59  public:
60  void set_model(Model model) { this->model_ = model; }
61  void update() override;
62  void setup() override;
64  void set_color_mode(display::ColorOrder color_mode) { this->color_mode_ = color_mode; }
65 
66  void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
67  void set_enable_pin(GPIOPin *enable_pin) { this->enable_pin_ = enable_pin; }
68  void set_width(uint16_t width) { this->width_ = width; }
69  void set_dimensions(uint16_t width, uint16_t height) {
70  this->width_ = width;
71  this->height_ = height;
72  }
73  int get_width() override { return this->width_; }
74  int get_height() override { return this->height_; }
75  void set_invert_colors(bool invert_colors) {
76  this->invert_colors_ = invert_colors;
77  this->reset_params_();
78  }
79  void set_mirror_x(bool mirror_x) {
80  this->mirror_x_ = mirror_x;
81  this->reset_params_();
82  }
83  void set_mirror_y(bool mirror_y) {
84  this->mirror_y_ = mirror_y;
85  this->reset_params_();
86  }
87  void set_swap_xy(bool swap_xy) {
88  this->swap_xy_ = swap_xy;
89  this->reset_params_();
90  }
91  void set_brightness(uint8_t brightness) {
92  this->brightness_ = brightness;
93  this->reset_params_();
94  }
95  void set_offsets(int16_t offset_x, int16_t offset_y) {
96  this->offset_x_ = offset_x;
97  this->offset_y_ = offset_y;
98  }
100  void dump_config() override;
101 
102  int get_width_internal() override { return this->width_; }
103  int get_height_internal() override { return this->height_; }
104  bool can_proceed() override { return this->setup_complete_; }
105 
106  protected:
107  void draw_absolute_pixel_internal(int x, int y, Color color) override;
108  void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
109  display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
128  void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len) {
129  this->enable();
130  this->write_cmd_addr_data(8, 0x02, 24, cmd << 8, bytes, len);
131  this->disable();
132  }
133 
134  void write_command_(uint8_t cmd, uint8_t data) { this->write_command_(cmd, &data, 1); }
135  void write_command_(uint8_t cmd) { this->write_command_(cmd, &cmd, 0); }
136  void reset_params_(bool ready = false);
137  void write_init_sequence_();
138  void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
139 
140  GPIOPin *reset_pin_{nullptr};
141  GPIOPin *enable_pin_{nullptr};
142  uint16_t x_low_{0};
143  uint16_t y_low_{0};
144  uint16_t x_high_{0};
145  uint16_t y_high_{0};
147 
150  size_t width_{};
151  size_t height_{};
152  int16_t offset_x_{0};
153  int16_t offset_y_{0};
154  bool swap_xy_{};
155  bool mirror_x_{};
156  bool mirror_y_{};
157  uint8_t brightness_{0xD0};
159 
160  esp_lcd_panel_handle_t handle_{};
161 };
162 
163 } // namespace qspi_amoled
164 } // namespace esphome
165 #endif
void set_dimensions(uint16_t width, uint16_t height)
Definition: qspi_amoled.h:69
display::DisplayType get_display_type() override
Definition: qspi_amoled.h:99
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition: qspi_amoled.cpp:40
void reset_params_(bool ready=false)
Definition: qspi_amoled.cpp:77
void set_invert_colors(bool invert_colors)
Definition: qspi_amoled.h:75
uint16_t x
Definition: tt21100.cpp:17
display::ColorOrder color_mode_
Definition: qspi_amoled.h:149
void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
void set_mirror_x(bool mirror_x)
Definition: qspi_amoled.h:79
void set_brightness(uint8_t brightness)
Definition: qspi_amoled.h:91
void set_mirror_y(bool mirror_y)
Definition: qspi_amoled.h:83
uint16_t y
Definition: tt21100.cpp:18
void write_cmd_addr_data(size_t cmd_bits, uint32_t cmd, size_t addr_bits, uint32_t address, const uint8_t *data, size_t length, uint8_t bus_width=1)
Definition: spi.h:452
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order, display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override
The SPIDevice is what components using the SPI will create.
Definition: spi.h:408
void set_offsets(int16_t offset_x, int16_t offset_y)
Definition: qspi_amoled.h:95
void set_reset_pin(GPIOPin *reset_pin)
Definition: qspi_amoled.h:66
std::string size_t len
Definition: helpers.h:292
uint8_t h
Definition: bl0939.h:21
void set_width(uint16_t width)
Definition: qspi_amoled.h:68
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
display::ColorOrder get_color_mode()
Definition: qspi_amoled.h:63
std::vector< uint8_t > bytes
Definition: sml_parser.h:12
void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len)
the RM67162 in quad SPI mode seems to work like this (not in the datasheet, this is deduced from the ...
Definition: qspi_amoled.h:128
void set_enable_pin(GPIOPin *enable_pin)
Definition: qspi_amoled.h:67
void write_command_(uint8_t cmd)
Definition: qspi_amoled.h:135
esp_lcd_panel_handle_t handle_
Definition: qspi_amoled.h:160
void set_color_mode(display::ColorOrder color_mode)
Definition: qspi_amoled.h:64
void write_command_(uint8_t cmd, uint8_t data)
Definition: qspi_amoled.h:134
void set_swap_xy(bool swap_xy)
Definition: qspi_amoled.h:87
stm32_cmd_t * cmd
Definition: stm32flash.h:96