Add SSD1325 Display Component (#736)

* add ssd1325 component

* fix i2c

* remove ssd1325 i2c

* add test

* set max contrast

* No macros - see styleguide

* Remove invalid function

* Formatting


Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Evan Coleman
2019-10-19 14:44:43 -04:00
committed by Otto Winter
parent e553c0768e
commit 58b6311821
8 changed files with 395 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import spi, ssd1325_base
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES
AUTO_LOAD = ['ssd1325_base']
DEPENDENCIES = ['spi']
ssd1325_spi = cg.esphome_ns.namespace('ssd1325_spi')
SPISSD1325 = ssd1325_spi.class_('SPISSD1325', ssd1325_base.SSD1325, spi.SPIDevice)
CONFIG_SCHEMA = cv.All(ssd1325_base.SSD1325_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(SPISSD1325),
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
}).extend(cv.COMPONENT_SCHEMA).extend(spi.SPI_DEVICE_SCHEMA),
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield ssd1325_base.setup_ssd1036(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,64 @@
#include "ssd1325_spi.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
namespace esphome {
namespace ssd1325_spi {
static const char *TAG = "ssd1325_spi";
void SPISSD1325::setup() {
ESP_LOGCONFIG(TAG, "Setting up SPI SSD1325...");
this->spi_setup();
this->dc_pin_->setup(); // OUTPUT
this->cs_->setup(); // OUTPUT
this->init_reset_();
delay(500);
SSD1325::setup();
}
void SPISSD1325::dump_config() {
LOG_DISPLAY("", "SPI SSD1325", this);
ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_());
LOG_PIN(" CS Pin: ", this->cs_);
LOG_PIN(" DC Pin: ", this->dc_pin_);
LOG_PIN(" Reset Pin: ", this->reset_pin_);
ESP_LOGCONFIG(TAG, " External VCC: %s", YESNO(this->external_vcc_));
LOG_UPDATE_INTERVAL(this);
}
void SPISSD1325::command(uint8_t value) {
this->cs_->digital_write(true);
this->dc_pin_->digital_write(false);
delay(1);
this->enable();
this->cs_->digital_write(false);
this->write_byte(value);
this->cs_->digital_write(true);
this->disable();
}
void HOT SPISSD1325::write_display_data() {
this->cs_->digital_write(true);
this->dc_pin_->digital_write(true);
this->cs_->digital_write(false);
delay(1);
this->enable();
for (uint16_t x = 0; x < this->get_width_internal(); x += 2) {
for (uint16_t y = 0; y < this->get_height_internal(); y += 8) { // we write 8 pixels at once
uint8_t left8 = this->buffer_[y * 16 + x];
uint8_t right8 = this->buffer_[y * 16 + x + 1];
for (uint8_t p = 0; p < 8; p++) {
uint8_t d = 0;
if (left8 & (1 << p))
d |= 0xF0;
if (right8 & (1 << p))
d |= 0x0F;
this->write_byte(d);
}
}
}
this->cs_->digital_write(true);
this->disable();
}
} // namespace ssd1325_spi
} // namespace esphome
@@ -0,0 +1,29 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/ssd1325_base/ssd1325_base.h"
#include "esphome/components/spi/spi.h"
namespace esphome {
namespace ssd1325_spi {
class SPISSD1325 : public ssd1325_base::SSD1325,
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 ssd1325_spi
} // namespace esphome