ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
st7305.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
9#include "esphome/core/hal.h"
10
11namespace esphome::st7305 {
12
17
24 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
25 spi::DATA_RATE_10MHZ> {
26 public:
27 ST7305(const char *model, int width, int height, Orientation orientation, uint8_t column_start, uint8_t column_end,
28 uint8_t row_start, uint8_t row_end, const uint8_t *init_sequence, size_t init_sequence_length)
29 : model_(model),
30 width_(width),
31 height_(height),
33 column_start_(column_start),
34 column_end_(column_end),
35 row_start_(row_start),
36 row_end_(row_end),
37 buffer_length_(static_cast<size_t>(width) * static_cast<size_t>(height) / 8),
38 init_sequence_(init_sequence),
39 init_sequence_length_(init_sequence_length) {}
40
41 void setup() override;
42 void update() override;
43 void dump_config() override;
44
45 void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
46 void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
47
48 void fill(Color color) override;
50 float get_setup_priority() const override { return setup_priority::PROCESSOR; }
51
52 protected:
55 struct Window {
56 uint16_t outer_start;
57 uint16_t outer_end;
58 uint16_t block_start;
59 uint16_t block_end;
60 uint16_t stride;
61 uint8_t caset_start;
62 uint8_t caset_end;
63
64 size_t data_length() const {
65 return static_cast<size_t>(this->outer_end - this->outer_start + 1) *
66 static_cast<size_t>(this->block_end - this->block_start + 1);
67 }
68 };
69
70 void draw_absolute_pixel_internal(int x, int y, Color color) override;
71 int get_width_internal() override { return this->width_; }
72 int get_height_internal() override { return this->height_; }
73
74 bool init_buffer_();
75 void reset_();
77 void finish_init_();
78 void write_full_frame_();
79 void write_window_(const Window &window);
80 Window compute_window_() const;
81
84 static constexpr uint32_t STARTUP_TIMEOUT_ID = 0;
85
86 void send_command_(uint8_t command) {
87 this->dc_pin_->digital_write(false);
88 this->write_byte(command);
89 }
90 void send_data_(const uint8_t *data, size_t length) {
91 this->dc_pin_->digital_write(true);
92 this->write_array(data, length);
93 }
94
95 bool is_dirty_() const { return this->x_high_ >= this->x_low_ && this->y_high_ >= this->y_low_; }
96 void clear_dirty_() {
97 this->x_low_ = this->width_;
98 this->x_high_ = -1;
99 this->y_low_ = this->height_;
100 this->y_high_ = -1;
101 }
102 void extend_dirty_(int x0, int y0, int x1, int y1);
103
104 GPIOPin *dc_pin_{nullptr};
106
107 const char *model_;
112 uint8_t column_end_;
113 uint8_t row_start_;
114 uint8_t row_end_;
116 const uint8_t *init_sequence_;
118 size_t init_index_{0};
119 bool ready_{false};
120
121 int x_low_{0};
122 int x_high_{-1};
123 int y_low_{0};
124 int y_high_{-1};
125};
126
127} // namespace esphome::st7305
virtual void digital_write(bool value)=0
The SPIDevice is what components using the SPI will create.
Definition spi.h:456
Sitronix ST7305/ST7306 reflective monochrome LCD, 1 bit per pixel.
Definition st7305.h:25
void set_reset_pin(GPIOPin *reset_pin)
Definition st7305.h:46
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition st7305.cpp:177
void write_window_(const Window &window)
Definition st7305.cpp:138
float get_setup_priority() const override
Definition st7305.h:50
static constexpr uint32_t STARTUP_TIMEOUT_ID
Scheduler id for the non-blocking reset and init sequence.
Definition st7305.h:84
void setup() override
Definition st7305.cpp:12
void update() override
Definition st7305.cpp:160
void set_dc_pin(GPIOPin *dc_pin)
Definition st7305.h:45
void extend_dirty_(int x0, int y0, int x1, int y1)
Definition st7305.cpp:234
void send_data_(const uint8_t *data, size_t length)
Definition st7305.h:90
Orientation orientation_
Definition st7305.h:110
bool is_dirty_() const
Definition st7305.h:95
const uint8_t * init_sequence_
Definition st7305.h:116
void send_command_(uint8_t command)
Definition st7305.h:86
void dump_config() override
Definition st7305.cpp:245
ST7305(const char *model, int width, int height, Orientation orientation, uint8_t column_start, uint8_t column_end, uint8_t row_start, uint8_t row_end, const uint8_t *init_sequence, size_t init_sequence_length)
Definition st7305.h:27
int get_height_internal() override
Definition st7305.h:72
const char * model_
Definition st7305.h:107
display::DisplayType get_display_type() override
Definition st7305.h:49
Window compute_window_() const
Definition st7305.cpp:106
size_t init_sequence_length_
Definition st7305.h:117
int get_width_internal() override
Definition st7305.h:71
void fill(Color color) override
Definition st7305.cpp:199
constexpr float PROCESSOR
For components that use data from sensors like displays.
Definition component.h:47
@ ORIENTATION_PORTRAIT
Definition st7305.h:15
@ ORIENTATION_LANDSCAPE
Definition st7305.h:14
static void uint32_t
An addressable write window.
Definition st7305.h:55
size_t data_length() const
Definition st7305.h:64
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6
uint8_t orientation
Definition tt21100.cpp:9