ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
epaper_spi.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <queue>
9
10namespace esphome::epaper_spi {
11using namespace display;
12
13enum class EPaperState : uint8_t {
14 IDLE, // not doing anything
15 UPDATE, // update the buffer
16 RESET, // drive reset low (active)
17 RESET_END, // drive reset high (inactive)
18
19 SHOULD_WAIT, // states higher than this should wait for the display to be not busy
20 INITIALISE, // send the init sequence
21 TRANSFER_DATA, // transfer data to the display
22 POWER_ON, // power on the display
23 REFRESH_SCREEN, // send refresh command
24 POWER_OFF, // power off the display
25 DEEP_SLEEP, // deep sleep the display
26};
27
28static constexpr uint8_t MAX_TRANSFER_TIME = 10; // Transfer in 10ms blocks to allow the loop to run
29static constexpr uint8_t DELAY_FLAG = 0xFF;
30
32 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
33 spi::DATA_RATE_2MHZ> {
34 public:
35 EPaperBase(const char *name, uint16_t width, uint16_t height, const uint8_t *init_sequence,
36 size_t init_sequence_length, DisplayType display_type = DISPLAY_TYPE_BINARY)
37 : name_(name),
38 width_(width),
39 height_(height),
40 init_sequence_(init_sequence),
41 init_sequence_length_(init_sequence_length),
42 display_type_(display_type) {}
43 void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
44 float get_setup_priority() const override;
46 void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
47 void set_reset_duration(uint32_t reset_duration) { this->reset_duration_ = reset_duration; }
48 void dump_config() override;
49
50 void command(uint8_t value);
51 void data(uint8_t value);
52 void cmd_data(uint8_t command, const uint8_t *ptr, size_t length);
53
54 void update() override;
55 void loop() override;
56
57 void setup() override;
58
59 void on_safe_shutdown() override;
60
61 DisplayType get_display_type() override { return this->display_type_; };
62
63 protected:
64 int get_height_internal() override { return this->height_; };
65 int get_width_internal() override { return this->width_; };
66 void process_state_();
67
68 const char *epaper_state_to_string_();
69 bool is_idle_() const;
70 void setup_pins_() const;
71 bool reset_() const;
72 void initialise_();
73 void wait_for_idle_(bool should_wait);
74 bool init_buffer_(size_t buffer_length);
75
76 virtual int get_width_controller() { return this->get_width_internal(); };
77
85 virtual bool transfer_data() = 0;
89 virtual void refresh_screen() = 0;
90
94 virtual void power_on() = 0;
98 virtual void power_off() = 0;
99
103 virtual void deep_sleep() = 0;
104
105 void set_state_(EPaperState state, uint16_t delay = 0);
106
107 void start_command_();
108 void end_command_();
109 void start_data_();
110 void end_data_();
111
112 // properties initialised in the constructor
113 const char *name_;
114 uint16_t width_;
115 uint16_t height_;
116 const uint8_t *init_sequence_;
119
121 size_t current_data_index_{0}; // used by data transfer to track progress
122 uint32_t reset_duration_{200};
123#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
127#endif
128
132
133 bool waiting_for_idle_{false};
134 uint32_t delay_until_{0};
135
137
139};
140
141} // namespace esphome::epaper_spi
virtual void power_off()=0
Power the display off.
void command(uint8_t value)
void process_state_()
Process the state machine.
virtual void deep_sleep()=0
Place the display into deep sleep.
int get_height_internal() override
Definition epaper_spi.h:64
void loop() override
Called during the loop task.
void set_dc_pin(GPIOPin *dc_pin)
Definition epaper_spi.h:43
void set_reset_pin(GPIOPin *reset)
Definition epaper_spi.h:45
virtual bool transfer_data()=0
Methods that must be implemented by concrete classes to control the display.
split_buffer::SplitBuffer buffer_
Definition epaper_spi.h:136
void cmd_data(uint8_t command, const uint8_t *ptr, size_t length)
void set_state_(EPaperState state, uint16_t delay=0)
const char * epaper_state_to_string_()
virtual void power_on()=0
Power the display on.
void set_reset_duration(uint32_t reset_duration)
Definition epaper_spi.h:47
DisplayType get_display_type() override
Definition epaper_spi.h:61
void wait_for_idle_(bool should_wait)
float get_setup_priority() const override
bool init_buffer_(size_t buffer_length)
void set_busy_pin(GPIOPin *busy)
Definition epaper_spi.h:46
virtual void refresh_screen()=0
Refresh the screen after data transfer.
int get_width_internal() override
Definition epaper_spi.h:65
EPaperBase(const char *name, uint16_t width, uint16_t height, const uint8_t *init_sequence, size_t init_sequence_length, DisplayType display_type=DISPLAY_TYPE_BINARY)
Definition epaper_spi.h:35
The SPIDevice is what components using the SPI will create.
Definition spi.h:427
A SplitBuffer allocates a large memory buffer potentially as multiple smaller buffers to facilitate a...
bool state
Definition fan.h:0
uint16_t reset
Definition ina226.h:5
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:31
uint16_t length
Definition tt21100.cpp:0