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
+28
View File
@@ -0,0 +1,28 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import spi, ssd1327_base
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES
CODEOWNERS = ['@kbx81']
AUTO_LOAD = ['ssd1327_base']
DEPENDENCIES = ['spi']
ssd1327_spi = cg.esphome_ns.namespace('ssd1327_spi')
SPISSD1327 = ssd1327_spi.class_('SPISSD1327', ssd1327_base.SSD1327, spi.SPIDevice)
CONFIG_SCHEMA = cv.All(ssd1327_base.SSD1327_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(SPISSD1327),
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
}).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema(cs_pin_required=False)),
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 spi.register_spi_device(var, config)
dc = yield cg.gpio_pin_expression(config[CONF_DC_PIN])
cg.add(var.set_dc_pin(dc))
@@ -0,0 +1,59 @@
#include "ssd1327_spi.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
namespace esphome {
namespace ssd1327_spi {
static const char *TAG = "ssd1327_spi";
void SPISSD1327::setup() {
ESP_LOGCONFIG(TAG, "Setting up SPI SSD1327...");
this->spi_setup();
this->dc_pin_->setup(); // OUTPUT
if (this->cs_)
this->cs_->setup(); // OUTPUT
this->init_reset_();
delay(500); // NOLINT
SSD1327::setup();
}
void SPISSD1327::dump_config() {
LOG_DISPLAY("", "SPI SSD1327", this);
ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_());
if (this->cs_)
LOG_PIN(" CS Pin: ", this->cs_);
LOG_PIN(" DC Pin: ", this->dc_pin_);
LOG_PIN(" Reset Pin: ", this->reset_pin_);
ESP_LOGCONFIG(TAG, " Initial Brightness: %.2f", this->brightness_);
LOG_UPDATE_INTERVAL(this);
}
void SPISSD1327::command(uint8_t value) {
if (this->cs_)
this->cs_->digital_write(true);
this->dc_pin_->digital_write(false);
delay(1);
this->enable();
if (this->cs_)
this->cs_->digital_write(false);
this->write_byte(value);
if (this->cs_)
this->cs_->digital_write(true);
this->disable();
}
void HOT SPISSD1327::write_display_data() {
if (this->cs_)
this->cs_->digital_write(true);
this->dc_pin_->digital_write(true);
if (this->cs_)
this->cs_->digital_write(false);
delay(1);
this->enable();
this->write_array(this->buffer_, this->get_buffer_length_());
if (this->cs_)
this->cs_->digital_write(true);
this->disable();
}
} // namespace ssd1327_spi
} // namespace esphome
@@ -0,0 +1,29 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/ssd1327_base/ssd1327_base.h"
#include "esphome/components/spi/spi.h"
namespace esphome {
namespace ssd1327_spi {
class SPISSD1327 : public ssd1327_base::SSD1327,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING,
spi::DATA_RATE_8MHZ> {
public:
void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
void setup() override;
void dump_config() override;
protected:
void command(uint8_t value) override;
void write_display_data() override;
GPIOPin *dc_pin_;
};
} // namespace ssd1327_spi
} // namespace esphome