ESPHome 2026.8.0-dev
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
6
7static const char *const TAG = "ssd1306_spi";
8
10 this->spi_setup();
11 this->dc_pin_->setup(); // OUTPUT
12
13 this->init_reset_();
14 SSD1306::setup();
15}
17 LOG_DISPLAY("", "SPI SSD1306", this);
18 ESP_LOGCONFIG(TAG,
19 " Model: %s\n"
20 " External VCC: %s\n"
21 " Flip X: %s\n"
22 " Flip Y: %s\n"
23 " Offset X: %d\n"
24 " Offset Y: %d\n"
25 " Inverted Color: %s",
26 LOG_STR_ARG(this->model_str_()), YESNO(this->external_vcc_), YESNO(this->flip_x_), YESNO(this->flip_y_),
27 this->offset_x_, this->offset_y_, YESNO(this->invert_));
28 LOG_PIN(" CS Pin: ", this->cs_);
29 LOG_PIN(" DC Pin: ", this->dc_pin_);
30 LOG_PIN(" Reset Pin: ", this->reset_pin_);
31 LOG_UPDATE_INTERVAL(this);
32}
33void SPISSD1306::command(uint8_t value) {
34 this->dc_pin_->digital_write(false);
35 this->enable();
36 this->write_byte(value);
37 this->disable();
38}
40 if (this->is_sh1106_() || this->is_sh1107_()) {
41 // Some panels wire their visible columns to a window of the controller RAM
42 // that does not start at column 0 (e.g. SH1107 M5Stack Unit OLED needs offset_x: 32).
43 // SH1106 keeps its historical 0x02 base column on top of any offset.
44 uint8_t start_column = this->offset_x_;
45 if (this->is_sh1106_()) {
46 start_column += 0x02;
47 }
48 for (uint8_t y = 0; y < (uint8_t) this->get_height_internal() / 8; y++) {
49 this->command(0xB0 + y);
50 this->command(start_column & 0x0F); // lower column
51 this->command(0x10 | (start_column >> 4)); // higher column
52 this->dc_pin_->digital_write(true);
53 for (uint8_t x = 0; x < (uint8_t) this->get_width_internal(); x++) {
54 this->enable();
55 this->write_byte(this->buffer_[x + y * this->get_width_internal()]);
56 this->disable();
57 App.feed_wdt();
58 }
59 }
60 } else {
61 this->dc_pin_->digital_write(true);
62 this->enable();
63 this->write_array(this->buffer_, this->get_buffer_length_());
64 this->disable();
65 }
66}
67
68} // namespace esphome::ssd1306_spi
void feed_wdt()
Feed the task watchdog.
virtual void setup()=0
virtual void digital_write(bool value)=0
void command(uint8_t value) override
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