ESPHome  2024.7.0
st7567_spi.cpp
Go to the documentation of this file.
1 #include "st7567_spi.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace st7567_spi {
6 
7 static const char *const TAG = "st7567_spi";
8 
10  ESP_LOGCONFIG(TAG, "Setting up SPI ST7567 display...");
11  this->spi_setup();
12  this->dc_pin_->setup();
13  if (this->cs_)
14  this->cs_->setup();
15 
16  this->init_reset_();
17  ST7567::setup();
18 }
19 
21  LOG_DISPLAY("", "SPI ST7567", this);
22  ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_());
23  LOG_PIN(" CS Pin: ", this->cs_);
24  LOG_PIN(" DC Pin: ", this->dc_pin_);
25  LOG_PIN(" Reset Pin: ", this->reset_pin_);
26  ESP_LOGCONFIG(TAG, " Mirror X: %s", YESNO(this->mirror_x_));
27  ESP_LOGCONFIG(TAG, " Mirror Y: %s", YESNO(this->mirror_y_));
28  ESP_LOGCONFIG(TAG, " Invert Colors: %s", YESNO(this->invert_colors_));
29  LOG_UPDATE_INTERVAL(this);
30 }
31 
32 void 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 st7567_spi
66 } // namespace esphome
void setup()
virtual void digital_write(bool value)=0
GPIOPin * cs_
Definition: spi.h:395
virtual void setup()=0
uint16_t y
Definition: tt21100.cpp:18
void write_display_data() override
Definition: st7567_spi.cpp:46
void command(uint8_t value) override
Definition: st7567_spi.cpp:32
int get_height_internal() override
int get_width_internal() override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26