9static const char *
const TAG =
"epaper_spi";
11static constexpr const char *
const EPAPER_STATE_STRINGS[] = {
12 "IDLE",
"UPDATE",
"RESET",
"RESET_END",
"SHOULD_WAIT",
"INITIALISE",
13 "TRANSFER_DATA",
"POWER_ON",
"REFRESH_SCREEN",
"POWER_OFF",
"DEEP_SLEEP",
17 if (
auto idx =
static_cast<unsigned>(this->
state_); idx < std::size(EPAPER_STATE_STRINGS))
18 return EPAPER_STATE_STRINGS[idx];
24 this->
mark_failed(LOG_STR(
"Failed to initialise buffer"));
71 ESP_LOGV(TAG,
"Command: 0x%02X, Length: %d, Data: %s",
command,
length,
109#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
115#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
135 this->delay_until_ = 0;
140#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
144#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
263 this->
mark_failed(LOG_STR(
"Malformed init sequence"));
266 const uint8_t cmd = sequence[index++];
267 if (
const uint8_t
x = sequence[index++];
x == DELAY_FLAG) {
268 ESP_LOGV(TAG,
"Delay %dms", cmd);
271 const uint8_t num_args =
x & 0x7F;
272 if (
length - index < num_args) {
273 ESP_LOGE(TAG,
"Malformed init sequence, cmd = %X, num_args = %u", cmd, num_args);
277 this->
cmd_data(cmd, sequence + index, num_args);
316 const size_t pixel_position =
y * this->
width_ +
x;
317 const size_t byte_position = pixel_position / 8;
318 const uint8_t bit_position = pixel_position % 8;
319 const uint8_t pixel_bit = 0x80 >> bit_position;
320 const auto original = this->
buffer_[byte_position];
322 this->
buffer_[byte_position] = original & ~pixel_bit;
324 this->
buffer_[byte_position] = original | pixel_bit;
329 LOG_DISPLAY(
"",
"E-Paper SPI",
this);
330 ESP_LOGCONFIG(TAG,
" Model: %s", this->
name_);
332 LOG_PIN(
" DC Pin: ", this->
dc_pin_);
334 LOG_PIN(
" CS Pin: ", this->
cs_);
335 LOG_UPDATE_INTERVAL(
this);
337 " SPI Data Rate: %uMHz\n"
338 " Full update every: %d\n"
virtual void mark_failed()
Mark this component as failed.
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
Rect get_clipping() const
Get the current the clipping rectangle.
uint32_t update_start_time_
virtual void power_off()=0
Power the display off.
void command(uint8_t value)
const uint8_t * init_sequence_
void process_state_()
Process the state machine.
virtual void deep_sleep()=0
Place the display into deep sleep.
void on_safe_shutdown() override
void draw_pixel_at(int x, int y, Color color) override
Default implementation for monochrome displays where 8 pixels are packed to a byte.
uint32_t waiting_for_idle_start_
bool rotate_coordinates_(int &x, int &y)
Check and rotate coordinates based on the transform flags.
void loop() override
Called during the loop task.
virtual void refresh_screen(bool partial)=0
Refresh the screen after data transfer.
uint8_t full_update_every_
void dump_config() override
virtual bool transfer_data()=0
Methods that must be implemented by concrete classes to control the display.
split_buffer::SplitBuffer buffer_
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 wait_for_idle_(bool should_wait)
uint32_t waiting_for_idle_last_print_
size_t init_sequence_length_
float get_setup_priority() const override
bool init_buffer_(size_t buffer_length)
static uint8_t color_to_bit(Color color)
void spi_setup() override
void write_byte(uint8_t data)
void write_array(const uint8_t *data, size_t length)
bool init(size_t total_length)
const float PROCESSOR
For components that use data from sensors like displays.
T clamp_at_most(T value, U max)
T clamp_at_least(T value, U min)
std::string format_hex_pretty(const uint8_t *data, size_t length, char separator, bool show_length)
Format a byte array in pretty-printed, human-readable hex format.
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()