ESPHome 2025.6.3
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
4namespace esphome {
5namespace st7567_i2c {
6
7static const char *const TAG = "st7567_i2c";
8
10 ESP_LOGCONFIG(TAG, "Running setup");
11 this->init_reset_();
12
13 auto err = this->write(nullptr, 0);
14 if (err != i2c::ERROR_OK) {
15 this->error_code_ = COMMUNICATION_FAILED;
16 this->mark_failed();
17 return;
18 }
19 ST7567::setup();
20}
21
23 LOG_DISPLAY("", "I2CST7567", this);
24 LOG_I2C_DEVICE(this);
25 ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_());
26 LOG_PIN(" Reset Pin: ", this->reset_pin_);
27 ESP_LOGCONFIG(TAG,
28 " Mirror X: %s\n"
29 " Mirror Y: %s\n"
30 " Invert Colors: %s",
31 YESNO(this->mirror_x_), YESNO(this->mirror_y_), YESNO(this->invert_colors_));
32 LOG_UPDATE_INTERVAL(this);
33
34 if (this->error_code_ == COMMUNICATION_FAILED) {
35 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
36 }
37}
38
39void I2CST7567::command(uint8_t value) { this->write_byte(0x00, value); }
40
42 // ST7567A has built-in RAM with 132x65 bit capacity which stores the display data.
43 // but only first 128 pixels from each line are shown on screen
44 // if screen got flipped horizontally then it shows last 128 pixels,
45 // so we need to write x coordinate starting from column 4, not column 0
46 this->command(esphome::st7567_base::ST7567_SET_START_LINE + this->start_line_);
47 for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
48 this->command(esphome::st7567_base::ST7567_PAGE_ADDR + y); // Set Page
49 this->command(esphome::st7567_base::ST7567_COL_ADDR_H); // Set MSB Column address
50 this->command(esphome::st7567_base::ST7567_COL_ADDR_L + this->get_offset_x_()); // Set LSB Column address
51
52 static const size_t BLOCK_SIZE = 64;
53 for (uint8_t x = 0; x < (uint8_t) this->get_width_internal(); x += BLOCK_SIZE) {
54 this->write_register(esphome::st7567_base::ST7567_SET_START_LINE, &buffer_[y * this->get_width_internal() + x],
55 this->get_width_internal() - x > BLOCK_SIZE ? BLOCK_SIZE : this->get_width_internal() - x,
56 true);
57 }
58 }
59}
60
61} // namespace st7567_i2c
62} // namespace esphome
virtual void mark_failed()
Mark this component as failed.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
Definition i2c.cpp:25
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
Definition i2c.h:190
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Definition i2c.h:266
void command(uint8_t value) override
void write_display_data() override
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:13
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6