ESPHome 2025.6.3
Loading...
Searching...
No Matches
ssd1306_spi.cpp
Go to the documentation of this file.
1#include "ssd1306_spi.h"
2#include "esphome/core/log.h"
4
5namespace esphome {
6namespace ssd1306_spi {
7
8static const char *const TAG = "ssd1306_spi";
9
11 ESP_LOGCONFIG(TAG, "Running setup");
12 this->spi_setup();
13 this->dc_pin_->setup(); // OUTPUT
14
15 this->init_reset_();
16 SSD1306::setup();
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,
25 " External VCC: %s\n"
26 " Flip X: %s\n"
27 " Flip Y: %s\n"
28 " Offset X: %d\n"
29 " Offset Y: %d\n"
30 " Inverted Color: %s",
31 YESNO(this->external_vcc_), YESNO(this->flip_x_), YESNO(this->flip_y_), this->offset_x_,
32 this->offset_y_, YESNO(this->invert_));
33 LOG_UPDATE_INTERVAL(this);
34}
35void SPISSD1306::command(uint8_t value) {
36 this->dc_pin_->digital_write(false);
37 this->enable();
38 this->write_byte(value);
39 this->disable();
40}
42 if (this->is_sh1106_() || this->is_sh1107_()) {
43 for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
44 this->command(0xB0 + y);
45 if (this->is_sh1106_()) {
46 this->command(0x02);
47 } else {
48 this->command(0x00);
49 }
50 this->command(0x10);
51 this->dc_pin_->digital_write(true);
52 for (uint8_t x = 0; x < (uint8_t) this->get_width_internal(); x++) {
53 this->enable();
54 this->write_byte(this->buffer_[x + y * this->get_width_internal()]);
55 this->disable();
56 App.feed_wdt();
57 }
58 }
59 } else {
60 this->dc_pin_->digital_write(true);
61 this->enable();
62 this->write_array(this->buffer_, this->get_buffer_length_());
63 this->disable();
64 }
65}
66
67} // namespace ssd1306_spi
68} // namespace esphome
void feed_wdt(uint32_t time=0)
virtual void setup()=0
virtual void digital_write(bool value)=0
void command(uint8_t value) override
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Application App
Global storage of Application pointer - only one Application can exist.
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6