ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
st7701s.h
Go to the documentation of this file.
1//
2// Created by Clyde Stubbs on 29/10/2023.
3//
4#pragma once
5
6// only applicable on ESP32-S3
7#ifdef USE_ESP32_VARIANT_ESP32S3
11#include "esp_lcd_panel_ops.h"
12
13#include "esp_lcd_panel_rgb.h"
14
15namespace esphome::st7701s {
16
17constexpr static const char *const TAG = "display.st7701s";
18const uint8_t SW_RESET_CMD = 0x01;
19const uint8_t SLEEP_OUT = 0x11;
20const uint8_t SDIR_CMD = 0xC7;
21const uint8_t MADCTL_CMD = 0x36;
22const uint8_t INVERT_OFF = 0x20;
23const uint8_t INVERT_ON = 0x21;
24const uint8_t DISPLAY_ON = 0x29;
25const uint8_t CMD2_BKSEL = 0xFF;
26const uint8_t CMD2_BK0[5] = {0x77, 0x01, 0x00, 0x00, 0x10};
27const uint8_t ST7701S_DELAY_FLAG = 0xFF;
28
30 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
31 spi::DATA_RATE_1MHZ> {
32 public:
33 void update() override { this->do_update_(); }
34 void setup() override;
35 void loop() override;
36 void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
37 display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
38
40 void set_color_mode(display::ColorOrder color_mode) { this->color_mode_ = color_mode; }
41 void set_invert_colors(bool invert_colors) { this->invert_colors_ = invert_colors; }
42
43 void add_data_pin(InternalGPIOPin *data_pin, size_t index) { this->data_pins_[index] = data_pin; };
44 void set_de_pin(InternalGPIOPin *de_pin) { this->de_pin_ = de_pin; }
45 void set_pclk_pin(InternalGPIOPin *pclk_pin) { this->pclk_pin_ = pclk_pin; }
46 void set_vsync_pin(InternalGPIOPin *vsync_pin) { this->vsync_pin_ = vsync_pin; }
47 void set_hsync_pin(InternalGPIOPin *hsync_pin) { this->hsync_pin_ = hsync_pin; }
48 void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
49 void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
50 void set_width(uint16_t width) { this->width_ = width; }
51 void set_pclk_frequency(uint32_t pclk_frequency) { this->pclk_frequency_ = pclk_frequency; }
52 void set_pclk_inverted(bool inverted) { this->pclk_inverted_ = inverted; }
53 void set_dimensions(uint16_t width, uint16_t height) {
54 this->width_ = width;
55 this->height_ = height;
56 }
57 int get_width() override { return this->width_; }
58 int get_height() override { return this->height_; }
59 void set_hsync_back_porch(uint16_t hsync_back_porch) { this->hsync_back_porch_ = hsync_back_porch; }
60 void set_hsync_front_porch(uint16_t hsync_front_porch) { this->hsync_front_porch_ = hsync_front_porch; }
61 void set_hsync_pulse_width(uint16_t hsync_pulse_width) { this->hsync_pulse_width_ = hsync_pulse_width; }
62 void set_vsync_pulse_width(uint16_t vsync_pulse_width) { this->vsync_pulse_width_ = vsync_pulse_width; }
63 void set_vsync_back_porch(uint16_t vsync_back_porch) { this->vsync_back_porch_ = vsync_back_porch; }
64 void set_vsync_front_porch(uint16_t vsync_front_porch) { this->vsync_front_porch_ = vsync_front_porch; }
65 void set_init_sequence(const std::vector<uint8_t> &init_sequence) { this->init_sequence_ = init_sequence; }
66 void set_mirror_x(bool mirror_x) { this->mirror_x_ = mirror_x; }
67 void set_mirror_y(bool mirror_y) { this->mirror_y_ = mirror_y; }
68 void set_offsets(int16_t offset_x, int16_t offset_y) {
69 this->offset_x_ = offset_x;
70 this->offset_y_ = offset_y;
71 }
73 int get_width_internal() override { return this->width_; }
74 int get_height_internal() override { return this->height_; }
75 void dump_config() override;
76 void draw_pixel_at(int x, int y, Color color) override;
77
78 // this will be horribly slow.
79 protected:
80 void write_command_(uint8_t value);
81 void write_data_(uint8_t value);
82 void write_sequence_(uint8_t cmd, size_t len, const uint8_t *bytes);
84
90 GPIOPin *dc_pin_{nullptr};
92 uint16_t hsync_pulse_width_ = 10;
93 uint16_t hsync_back_porch_ = 10;
94 uint16_t hsync_front_porch_ = 20;
95 uint16_t vsync_pulse_width_ = 10;
96 uint16_t vsync_back_porch_ = 10;
97 uint16_t vsync_front_porch_ = 10;
98 std::vector<uint8_t> init_sequence_;
99 uint32_t pclk_frequency_ = 16 * 1000 * 1000;
100 bool pclk_inverted_{true};
101
104 size_t width_{};
105 size_t height_{};
106 int16_t offset_x_{0};
107 int16_t offset_y_{0};
108 bool mirror_x_{};
109 bool mirror_y_{};
110
111 esp_lcd_panel_handle_t handle_{};
112};
113
114} // namespace esphome::st7701s
115#endif
uint8_t h
Definition bl0906.h:2
The SPIDevice is what components using the SPI will create.
Definition spi.h:429
void set_pclk_inverted(bool inverted)
Definition st7701s.h:52
void setup() override
Definition st7701s.cpp:9
void set_hsync_pulse_width(uint16_t hsync_pulse_width)
Definition st7701s.h:61
void set_mirror_y(bool mirror_y)
Definition st7701s.h:67
void set_width(uint16_t width)
Definition st7701s.h:50
InternalGPIOPin * data_pins_[16]
Definition st7701s.h:91
int get_width_internal() override
Definition st7701s.h:73
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
Definition st7701s.cpp:53
void set_vsync_pin(InternalGPIOPin *vsync_pin)
Definition st7701s.h:46
void write_sequence_(uint8_t cmd, size_t len, const uint8_t *bytes)
this relies upon the init sequence being well-formed, which is guaranteed by the Python init code.
Definition st7701s.cpp:139
void set_hsync_pin(InternalGPIOPin *hsync_pin)
Definition st7701s.h:47
void set_offsets(int16_t offset_x, int16_t offset_y)
Definition st7701s.h:68
uint16_t vsync_front_porch_
Definition st7701s.h:97
esp_lcd_panel_handle_t handle_
Definition st7701s.h:111
void update() override
Definition st7701s.h:33
void set_dc_pin(GPIOPin *dc_pin)
Definition st7701s.h:48
void set_reset_pin(GPIOPin *reset_pin)
Definition st7701s.h:49
void set_hsync_front_porch(uint16_t hsync_front_porch)
Definition st7701s.h:60
void set_init_sequence(const std::vector< uint8_t > &init_sequence)
Definition st7701s.h:65
void set_pclk_frequency(uint32_t pclk_frequency)
Definition st7701s.h:51
InternalGPIOPin * vsync_pin_
Definition st7701s.h:88
void draw_pixel_at(int x, int y, Color color) override
Definition st7701s.cpp:85
void set_de_pin(InternalGPIOPin *de_pin)
Definition st7701s.h:44
InternalGPIOPin * de_pin_
Definition st7701s.h:85
uint16_t vsync_pulse_width_
Definition st7701s.h:95
void set_vsync_front_porch(uint16_t vsync_front_porch)
Definition st7701s.h:64
void add_data_pin(InternalGPIOPin *data_pin, size_t index)
Definition st7701s.h:43
int get_height_internal() override
Definition st7701s.h:74
void set_mirror_x(bool mirror_x)
Definition st7701s.h:66
void set_dimensions(uint16_t width, uint16_t height)
Definition st7701s.h:53
void set_vsync_back_porch(uint16_t vsync_back_porch)
Definition st7701s.h:63
void write_data_(uint8_t value)
Definition st7701s.cpp:124
display::DisplayType get_display_type() override
Definition st7701s.h:72
int get_height() override
Definition st7701s.h:58
display::ColorOrder color_mode_
Definition st7701s.h:103
uint16_t hsync_pulse_width_
Definition st7701s.h:92
std::vector< uint8_t > init_sequence_
Definition st7701s.h:98
void set_pclk_pin(InternalGPIOPin *pclk_pin)
Definition st7701s.h:45
int get_width() override
Definition st7701s.h:57
void set_hsync_back_porch(uint16_t hsync_back_porch)
Definition st7701s.h:59
void dump_config() override
Definition st7701s.cpp:179
void write_command_(uint8_t value)
Definition st7701s.cpp:112
display::ColorOrder get_color_mode()
Definition st7701s.h:39
InternalGPIOPin * hsync_pin_
Definition st7701s.h:87
void set_vsync_pulse_width(uint16_t vsync_pulse_width)
Definition st7701s.h:62
void set_color_mode(display::ColorOrder color_mode)
Definition st7701s.h:40
void set_invert_colors(bool invert_colors)
Definition st7701s.h:41
InternalGPIOPin * pclk_pin_
Definition st7701s.h:86
uint16_t hsync_front_porch_
Definition st7701s.h:94
void loop() override
Definition st7701s.cpp:48
const char *const TAG
Definition spi.cpp:7
const uint8_t SLEEP_OUT
Definition st7701s.h:19
const uint8_t SDIR_CMD
Definition st7701s.h:20
const uint8_t ST7701S_DELAY_FLAG
Definition st7701s.h:27
const uint8_t INVERT_ON
Definition st7701s.h:23
const uint8_t MADCTL_CMD
Definition st7701s.h:21
const uint8_t SW_RESET_CMD
Definition st7701s.h:18
const uint8_t CMD2_BK0[5]
Definition st7701s.h:26
const uint8_t DISPLAY_ON
Definition st7701s.h:24
const uint8_t CMD2_BKSEL
Definition st7701s.h:25
const uint8_t INVERT_OFF
Definition st7701s.h:22
const void size_t len
Definition hal.h:64
static void uint32_t
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6