ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
st7567_i2c.cpp
Go to the documentation of this file.
1#include "st7567_i2c.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "st7567_i2c");
7
9 this->init_reset_();
10
11 auto err = this->write(nullptr, 0);
12 if (err != i2c::ERROR_OK) {
13 this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
14 return;
15 }
16 ST7567::setup();
17}
18
20 LOG_DISPLAY("", "I2CST7567", 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_I2C_DEVICE(this);
28 LOG_PIN(" Reset Pin: ", this->reset_pin_);
29 LOG_UPDATE_INTERVAL(this);
30}
31
32void I2CST7567::command(uint8_t value) { this->write_byte(0x00, value); }
33
35 // ST7567A has built-in RAM with 132x65 bit capacity which stores the display data.
36 // but only first 128 pixels from each line are shown on screen
37 // if screen got flipped horizontally then it shows last 128 pixels,
38 // so we need to write x coordinate starting from column 4, not column 0
39 this->command(esphome::st7567_base::ST7567_SET_START_LINE + this->start_line_);
40 for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
41 this->command(esphome::st7567_base::ST7567_PAGE_ADDR + y); // Set Page
42 this->command(esphome::st7567_base::ST7567_COL_ADDR_H); // Set MSB Column address
43 this->command(esphome::st7567_base::ST7567_COL_ADDR_L + this->get_offset_x_()); // Set LSB Column address
44
45 static const size_t BLOCK_SIZE = 64;
46 for (uint8_t x = 0; x < (uint8_t) this->get_width_internal(); x += BLOCK_SIZE) {
47 size_t remaining = static_cast<size_t>(this->get_width_internal()) - x;
48 size_t chunk = remaining > BLOCK_SIZE ? BLOCK_SIZE : remaining;
49 this->write_register(esphome::st7567_base::ST7567_SET_START_LINE, &buffer_[y * this->get_width_internal() + x],
50 chunk);
51 }
52 }
53}
54
55} // namespace esphome::st7567_i2c
void mark_failed()
Mark this component as failed.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
Definition i2c.cpp:37
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
Definition i2c.h:195
bool write_byte(uint8_t a_register, uint8_t data) const
Definition i2c.h:312
void command(uint8_t value) override
void write_display_data() override
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:15
ESPHOME_LOG_TAG(TAG, "st7567_i2c")
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6