1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

Add full SSD1327 display support (#1406)

This commit is contained in:
Keith Burzinski
2020-12-30 03:48:23 -06:00
committed by GitHub
parent ac15ce576b
commit 9aa14a2e83
13 changed files with 500 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import ssd1327_base, i2c
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES
CODEOWNERS = ['@kbx81']
AUTO_LOAD = ['ssd1327_base']
DEPENDENCIES = ['i2c']
ssd1327_i2c = cg.esphome_ns.namespace('ssd1327_i2c')
I2CSSD1327 = ssd1327_i2c.class_('I2CSSD1327', ssd1327_base.SSD1327, i2c.I2CDevice)
CONFIG_SCHEMA = cv.All(ssd1327_base.SSD1327_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(I2CSSD1327),
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x3D)),
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield ssd1327_base.setup_ssd1327(var, config)
yield i2c.register_i2c_device(var, config)

View File

@@ -0,0 +1,44 @@
#include "ssd1327_i2c.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ssd1327_i2c {
static const char *TAG = "ssd1327_i2c";
void I2CSSD1327::setup() {
ESP_LOGCONFIG(TAG, "Setting up I2C SSD1327...");
this->init_reset_();
this->parent_->raw_begin_transmission(this->address_);
if (!this->parent_->raw_end_transmission(this->address_)) {
this->error_code_ = COMMUNICATION_FAILED;
this->mark_failed();
return;
}
SSD1327::setup();
}
void I2CSSD1327::dump_config() {
LOG_DISPLAY("", "I2C SSD1327", this);
LOG_I2C_DEVICE(this);
ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_());
LOG_PIN(" Reset Pin: ", this->reset_pin_);
LOG_UPDATE_INTERVAL(this);
if (this->error_code_ == COMMUNICATION_FAILED) {
ESP_LOGE(TAG, "Communication with SSD1327 failed!");
}
}
void I2CSSD1327::command(uint8_t value) { this->write_byte(0x00, value); }
void HOT I2CSSD1327::write_display_data() {
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 ssd1327_i2c
} // namespace esphome

View File

@@ -0,0 +1,23 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/ssd1327_base/ssd1327_base.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace ssd1327_i2c {
class I2CSSD1327 : public ssd1327_base::SSD1327, public i2c::I2CDevice {
public:
void setup() override;
void dump_config() override;
protected:
void command(uint8_t value) override;
void write_display_data() override;
enum ErrorCode { NONE = 0, COMMUNICATION_FAILED } error_code_{NONE};
};
} // namespace ssd1327_i2c
} // namespace esphome