ESPHome 2026.5.1
Loading...
Searching...
No Matches
st7567_spi.cpp
Go to the documentation of this file.
1#include "st7567_spi.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "st7567_spi";
7
9 this->spi_setup();
10 this->dc_pin_->setup();
11 if (this->cs_)
12 this->cs_->setup();
13
14 this->init_reset_();
15 ST7567::setup();
16}
17
19 LOG_DISPLAY("", "SPI ST7567", this);
20 ESP_LOGCONFIG(TAG,
21 " Model: %s\n"
22 " Mirror X: %s\n"
23 " Mirror Y: %s\n"
24 " Invert Colors: %s",
25 this->model_str_(), YESNO(this->mirror_x_), YESNO(this->mirror_y_), YESNO(this->invert_colors_));
26 LOG_PIN(" CS Pin: ", this->cs_);
27 LOG_PIN(" DC Pin: ", this->dc_pin_);
28 LOG_PIN(" Reset Pin: ", this->reset_pin_);
29 LOG_UPDATE_INTERVAL(this);
30}
31
32void SPIST7567::command(uint8_t value) {
33 if (this->cs_)
34 this->cs_->digital_write(true);
35 this->dc_pin_->digital_write(false);
36 delay(1);
37 this->enable();
38 if (this->cs_)
39 this->cs_->digital_write(false);
40 this->write_byte(value);
41 if (this->cs_)
42 this->cs_->digital_write(true);
43 this->disable();
44}
45
47 // ST7567A has built-in RAM with 132x65 bit capacity which stores the display data.
48 // but only first 128 pixels from each line are shown on screen
49 // if screen got flipped horizontally then it shows last 128 pixels,
50 // so we need to write x coordinate starting from column 4, not column 0
51 this->command(esphome::st7567_base::ST7567_SET_START_LINE + this->start_line_);
52 for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
53 this->dc_pin_->digital_write(false);
54 this->command(esphome::st7567_base::ST7567_PAGE_ADDR + y); // Set Page
55 this->command(esphome::st7567_base::ST7567_COL_ADDR_H); // Set MSB Column address
56 this->command(esphome::st7567_base::ST7567_COL_ADDR_L + this->get_offset_x_()); // Set LSB Column address
57 this->dc_pin_->digital_write(true);
58
59 this->enable();
60 this->write_array(&this->buffer_[y * this->get_width_internal()], this->get_width_internal());
61 this->disable();
62 }
63}
64
65} // namespace esphome::st7567_spi
virtual void setup()=0
virtual void digital_write(bool value)=0
void write_display_data() override
void command(uint8_t value) override
void HOT delay(uint32_t ms)
Definition hal.cpp:85
uint16_t y
Definition tt21100.cpp:6