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