ESPHome  2024.4.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_() || this->is_sh1107_()) {
40  for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
41  this->command(0xB0 + y);
42  if (this->is_sh1106_()) {
43  this->command(0x02);
44  } else {
45  this->command(0x00);
46  }
47  this->command(0x10);
48  this->dc_pin_->digital_write(true);
49  for (uint8_t x = 0; x < (uint8_t) this->get_width_internal(); x++) {
50  this->enable();
51  this->write_byte(this->buffer_[x + y * this->get_width_internal()]);
52  this->disable();
53  App.feed_wdt();
54  }
55  }
56  } else {
57  this->dc_pin_->digital_write(true);
58  this->enable();
59  this->write_array(this->buffer_, this->get_buffer_length_());
60  this->disable();
61  }
62 }
63 
64 } // namespace ssd1306_spi
65 } // namespace esphome
void setup()
virtual void digital_write(bool value)=0
uint16_t x
Definition: tt21100.cpp:17
GPIOPin * cs_
Definition: spi.h:395
virtual void setup()=0
uint16_t y
Definition: tt21100.cpp:18
void command(uint8_t value) override
Definition: ssd1306_spi.cpp:32
Application App
Global storage of Application pointer - only one Application can exist.
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7