ESPHome  2024.10.2
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_dimensions(uint16_t width, uint16_t height) {
69  this->width_ = width;
70  this->height_ = height;
71  }
72  void set_invert_colors(bool invert_colors) {
73  this->invert_colors_ = invert_colors;
74  this->reset_params_();
75  }
76  void set_mirror_x(bool mirror_x) {
77  this->mirror_x_ = mirror_x;
78  this->reset_params_();
79  }
80  void set_mirror_y(bool mirror_y) {
81  this->mirror_y_ = mirror_y;
82  this->reset_params_();
83  }
84  void set_swap_xy(bool swap_xy) {
85  this->swap_xy_ = swap_xy;
86  this->reset_params_();
87  }
88  void set_brightness(uint8_t brightness) {
89  this->brightness_ = brightness;
90  this->reset_params_();
91  }
92  void set_offsets(int16_t offset_x, int16_t offset_y) {
93  this->offset_x_ = offset_x;
94  this->offset_y_ = offset_y;
95  }
97  void dump_config() override;
98 
99  int get_width_internal() override { return this->width_; }
100  int get_height_internal() override { return this->height_; }
101  bool can_proceed() override { return this->setup_complete_; }
102 
103  protected:
104  void draw_absolute_pixel_internal(int x, int y, Color color) override;
105  void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
106  display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
125  void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len) {
126  this->enable();
127  this->write_cmd_addr_data(8, 0x02, 24, cmd << 8, bytes, len);
128  this->disable();
129  }
130 
131  void write_command_(uint8_t cmd, uint8_t data) { this->write_command_(cmd, &data, 1); }
132  void write_command_(uint8_t cmd) { this->write_command_(cmd, &cmd, 0); }
133  void reset_params_(bool ready = false);
134  void write_init_sequence_();
135  void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
136 
137  GPIOPin *reset_pin_{nullptr};
138  GPIOPin *enable_pin_{nullptr};
139  uint16_t x_low_{0};
140  uint16_t y_low_{0};
141  uint16_t x_high_{0};
142  uint16_t y_high_{0};
144 
147  size_t width_{};
148  size_t height_{};
149  int16_t offset_x_{0};
150  int16_t offset_y_{0};
151  bool swap_xy_{};
152  bool mirror_x_{};
153  bool mirror_y_{};
154  uint8_t brightness_{0xD0};
156 
157  esp_lcd_panel_handle_t handle_{};
158 };
159 
160 } // namespace qspi_amoled
161 } // namespace esphome
162 #endif
void set_dimensions(uint16_t width, uint16_t height)
Definition: qspi_amoled.h:68
display::DisplayType get_display_type() override
Definition: qspi_amoled.h:96
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition: qspi_amoled.cpp:56
void reset_params_(bool ready=false)
Definition: qspi_amoled.cpp:93
void set_invert_colors(bool invert_colors)
Definition: qspi_amoled.h:72
uint16_t x
Definition: tt21100.cpp:17
display::ColorOrder color_mode_
Definition: qspi_amoled.h:146
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:76
void set_brightness(uint8_t brightness)
Definition: qspi_amoled.h:88
uint8_t h
Definition: bl0906.h:209
void set_mirror_y(bool mirror_y)
Definition: qspi_amoled.h:80
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:435
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:391
void set_offsets(int16_t offset_x, int16_t offset_y)
Definition: qspi_amoled.h:92
void set_reset_pin(GPIOPin *reset_pin)
Definition: qspi_amoled.h:66
std::string size_t len
Definition: helpers.h:292
Implementation of SPI Controller mode.
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:125
void set_enable_pin(GPIOPin *enable_pin)
Definition: qspi_amoled.h:67
void write_command_(uint8_t cmd)
Definition: qspi_amoled.h:132
esp_lcd_panel_handle_t handle_
Definition: qspi_amoled.h:157
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:131
void set_swap_xy(bool swap_xy)
Definition: qspi_amoled.h:84
stm32_cmd_t * cmd
Definition: stm32flash.h:96