mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 03:34:18 +01:00
66761ff340
* Add serveral options for SSD1306 integration * Add SSD1305 support (SSD1305 is similar to SSD1306, it seems SSD1305 has brightness and color register but does not have charge pump) * Add some description when manipulating registers * Add flip, offset and invert option to get more compatibility with various display modules * Fix typo `setup_ssd1036' -> `setup_ssd1306' * Add SSD1306 brightness validation tip * Add more description, limit offset range * Changes according to linter * Fix test * Raise error instead of using warning * Fix wrong logic * Remove logger Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Remove logging import Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
66 lines
2 KiB
C++
66 lines
2 KiB
C++
#include "ssd1306_i2c.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace ssd1306_i2c {
|
|
|
|
static const char *const TAG = "ssd1306_i2c";
|
|
|
|
void I2CSSD1306::setup() {
|
|
ESP_LOGCONFIG(TAG, "Setting up I2C SSD1306...");
|
|
this->init_reset_();
|
|
|
|
auto err = this->write(nullptr, 0);
|
|
if (err != i2c::ERROR_OK) {
|
|
this->error_code_ = COMMUNICATION_FAILED;
|
|
this->mark_failed();
|
|
return;
|
|
}
|
|
|
|
SSD1306::setup();
|
|
}
|
|
void I2CSSD1306::dump_config() {
|
|
LOG_DISPLAY("", "I2C SSD1306", this);
|
|
LOG_I2C_DEVICE(this);
|
|
ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_());
|
|
LOG_PIN(" Reset Pin: ", this->reset_pin_);
|
|
ESP_LOGCONFIG(TAG, " External VCC: %s", YESNO(this->external_vcc_));
|
|
ESP_LOGCONFIG(TAG, " Flip X: %s", YESNO(this->flip_x_));
|
|
ESP_LOGCONFIG(TAG, " Flip Y: %s", YESNO(this->flip_y_));
|
|
ESP_LOGCONFIG(TAG, " Offset X: %d", this->offset_x_);
|
|
ESP_LOGCONFIG(TAG, " Offset Y: %d", this->offset_y_);
|
|
ESP_LOGCONFIG(TAG, " Inverted Color: %s", YESNO(this->invert_));
|
|
LOG_UPDATE_INTERVAL(this);
|
|
|
|
if (this->error_code_ == COMMUNICATION_FAILED) {
|
|
ESP_LOGE(TAG, "Communication with SSD1306 failed!");
|
|
}
|
|
}
|
|
void I2CSSD1306::command(uint8_t value) { this->write_byte(0x00, value); }
|
|
void HOT I2CSSD1306::write_display_data() {
|
|
if (this->is_sh1106_()) {
|
|
uint32_t i = 0;
|
|
for (uint8_t page = 0; page < this->get_height_internal() / 8; page++) {
|
|
this->command(0xB0 + page); // row
|
|
this->command(0x02); // lower column
|
|
this->command(0x10); // higher column
|
|
|
|
for (uint8_t x = 0; x < this->get_width_internal() / 16; x++) {
|
|
uint8_t data[16];
|
|
for (uint8_t &j : data)
|
|
j = this->buffer_[i++];
|
|
this->write_bytes(0x40, data, sizeof(data));
|
|
}
|
|
}
|
|
} else {
|
|
for (uint32_t i = 0; i < this->get_buffer_length_();) {
|
|
uint8_t data[16];
|
|
for (uint8_t &j : data)
|
|
j = this->buffer_[i++];
|
|
this->write_bytes(0x40, data, sizeof(data));
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace ssd1306_i2c
|
|
} // namespace esphome
|