ESPHome  2022.5.1
ssd1306_spi.cpp
Go to the documentation of this file.
1 #include "ssd1306_spi.h"
2 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace ssd1306_spi {
7 
8 static const char *const TAG = "ssd1306_spi";
9 
11  ESP_LOGCONFIG(TAG, "Setting up SPI SSD1306...");
12  this->spi_setup();
13  this->dc_pin_->setup(); // OUTPUT
14 
15  this->init_reset_();
17 }
19  LOG_DISPLAY("", "SPI SSD1306", this);
20  ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_());
21  LOG_PIN(" CS Pin: ", this->cs_);
22  LOG_PIN(" DC Pin: ", this->dc_pin_);
23  LOG_PIN(" Reset Pin: ", this->reset_pin_);
24  ESP_LOGCONFIG(TAG, " External VCC: %s", YESNO(this->external_vcc_));
25  ESP_LOGCONFIG(TAG, " Flip X: %s", YESNO(this->flip_x_));
26  ESP_LOGCONFIG(TAG, " Flip Y: %s", YESNO(this->flip_y_));
27  ESP_LOGCONFIG(TAG, " Offset X: %d", this->offset_x_);
28  ESP_LOGCONFIG(TAG, " Offset Y: %d", this->offset_y_);
29  ESP_LOGCONFIG(TAG, " Inverted Color: %s", YESNO(this->invert_));
30  LOG_UPDATE_INTERVAL(this);
31 }
32 void SPISSD1306::command(uint8_t value) {
33  this->dc_pin_->digital_write(false);
34  this->enable();
35  this->write_byte(value);
36  this->disable();
37 }
39  if (this->is_sh1106_()) {
40  for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
41  this->command(0xB0 + y);
42  this->command(0x02);
43  this->command(0x10);
44  this->dc_pin_->digital_write(true);
45  for (uint8_t x = 0; x < (uint8_t) this->get_width_internal(); x++) {
46  this->enable();
47  this->write_byte(this->buffer_[x + y * this->get_width_internal()]);
48  this->disable();
49  App.feed_wdt();
50  }
51  }
52  } else {
53  this->dc_pin_->digital_write(true);
54  this->enable();
55  this->write_array(this->buffer_, this->get_buffer_length_());
56  this->disable();
57  }
58 }
59 
60 } // namespace ssd1306_spi
61 } // namespace esphome
void setup()
virtual void digital_write(bool value)=0
virtual void setup()=0
void command(uint8_t value) override
Definition: ssd1306_spi.cpp:32
Application App
Global storage of Application pointer - only one Application can exist.
Definition: a4988.cpp:4