ESPHome 2025.9.0-dev
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, " Model: %s", this->model_str_());
22 LOG_PIN(" CS Pin: ", this->cs_);
23 LOG_PIN(" DC Pin: ", this->dc_pin_);
24 LOG_PIN(" Reset Pin: ", this->reset_pin_);
25 ESP_LOGCONFIG(TAG, " Mirror X: %s", YESNO(this->mirror_x_));
26 ESP_LOGCONFIG(TAG, " Mirror Y: %s", YESNO(this->mirror_y_));
27 ESP_LOGCONFIG(TAG, " Invert Colors: %s", YESNO(this->invert_colors_));
28 LOG_UPDATE_INTERVAL(this);
29}
30
31void SPIST7567::command(uint8_t value) {
32 if (this->cs_)
33 this->cs_->digital_write(true);
34 this->dc_pin_->digital_write(false);
35 delay(1);
36 this->enable();
37 if (this->cs_)
38 this->cs_->digital_write(false);
39 this->write_byte(value);
40 if (this->cs_)
41 this->cs_->digital_write(true);
42 this->disable();
43}
44
46 // ST7567A has built-in RAM with 132x65 bit capacity which stores the display data.
47 // but only first 128 pixels from each line are shown on screen
48 // if screen got flipped horizontally then it shows last 128 pixels,
49 // so we need to write x coordinate starting from column 4, not column 0
50 this->command(esphome::st7567_base::ST7567_SET_START_LINE + this->start_line_);
51 for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
52 this->dc_pin_->digital_write(false);
53 this->command(esphome::st7567_base::ST7567_PAGE_ADDR + y); // Set Page
54 this->command(esphome::st7567_base::ST7567_COL_ADDR_H); // Set MSB Column address
55 this->command(esphome::st7567_base::ST7567_COL_ADDR_L + this->get_offset_x_()); // Set LSB Column address
56 this->dc_pin_->digital_write(true);
57
58 this->enable();
59 this->write_array(&this->buffer_[y * this->get_width_internal()], this->get_width_internal());
60 this->disable();
61 }
62}
63
64} // namespace st7567_spi
65} // 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:29
uint16_t y
Definition tt21100.cpp:6