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