1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-26 04:33:47 +00:00

SSD1322 display support (#1405)

This commit is contained in:
Keith Burzinski
2020-12-30 03:52:41 -06:00
committed by GitHub
parent 9aa14a2e83
commit 095d3181cd
9 changed files with 441 additions and 0 deletions

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, ssd1322_base
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES
CODEOWNERS = ['@kbx81']
AUTO_LOAD = ['ssd1322_base']
DEPENDENCIES = ['spi']
ssd1322_spi = cg.esphome_ns.namespace('ssd1322_spi')
SPISSD1322 = ssd1322_spi.class_('SPISSD1322', ssd1322_base.SSD1322, spi.SPIDevice)
CONFIG_SCHEMA = cv.All(ssd1322_base.SSD1322_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(SPISSD1322),
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 ssd1322_base.setup_ssd1322(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))

View File

@@ -0,0 +1,72 @@
#include "ssd1322_spi.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
namespace esphome {
namespace ssd1322_spi {
static const char *TAG = "ssd1322_spi";
void SPISSD1322::setup() {
ESP_LOGCONFIG(TAG, "Setting up SPI SSD1322...");
this->spi_setup();
this->dc_pin_->setup(); // OUTPUT
if (this->cs_)
this->cs_->setup(); // OUTPUT
this->init_reset_();
delay(500); // NOLINT
SSD1322::setup();
}
void SPISSD1322::dump_config() {
LOG_DISPLAY("", "SPI SSD1322", 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 SPISSD1322::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 SPISSD1322::data(uint8_t value) {
if (this->cs_)
this->cs_->digital_write(true);
this->dc_pin_->digital_write(true);
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 SPISSD1322::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 ssd1322_spi
} // namespace esphome

View File

@@ -0,0 +1,30 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/ssd1322_base/ssd1322_base.h"
#include "esphome/components/spi/spi.h"
namespace esphome {
namespace ssd1322_spi {
class SPISSD1322 : public ssd1322_base::SSD1322,
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 data(uint8_t value) override;
void write_display_data() override;
GPIOPin *dc_pin_;
};
} // namespace ssd1322_spi
} // namespace esphome