mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Add contrast option to PCD8544 (#1348)
* Add contrast option to PCD8544. Closes #1519 * Minor fixes as instructed by @jesserockz
This commit is contained in:
parent
a6c46eb8e5
commit
e536316e3d
4 changed files with 9 additions and 4 deletions
|
@ -3,7 +3,7 @@ import esphome.config_validation as cv
|
|||
from esphome import pins
|
||||
from esphome.components import display, spi
|
||||
from esphome.const import (
|
||||
CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES, CONF_RESET_PIN, CONF_CS_PIN,
|
||||
CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES, CONF_RESET_PIN, CONF_CS_PIN, CONF_CONTRAST
|
||||
)
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
|
@ -17,8 +17,9 @@ CONFIG_SCHEMA = cv.All(display.FULL_DISPLAY_SCHEMA.extend({
|
|||
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Required(CONF_RESET_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, # CE
|
||||
cv.Optional(CONF_CONTRAST, default=0x7f): cv.int_,
|
||||
}).extend(cv.polling_component_schema('1s')).extend(spi.spi_device_schema()),
|
||||
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
|
||||
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
|
@ -33,6 +34,8 @@ def to_code(config):
|
|||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
|
||||
cg.add(var.set_contrast(config[CONF_CONTRAST]))
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')],
|
||||
return_type=cg.void)
|
||||
|
|
|
@ -35,8 +35,7 @@ void PCD8544::initialize() {
|
|||
this->command(this->PCD8544_SETBIAS | 0x04);
|
||||
|
||||
// contrast
|
||||
// TODO: in future version we may add a user a control over contrast
|
||||
this->command(this->PCD8544_SETVOP | 0x7f); // Experimentally determined
|
||||
this->command(this->PCD8544_SETVOP | this->contrast_);
|
||||
|
||||
// normal mode
|
||||
this->command(this->PCD8544_FUNCTIONSET);
|
||||
|
|
|
@ -29,9 +29,11 @@ class PCD8544 : public PollingComponent,
|
|||
const uint8_t PCD8544_SETTEMP = 0x04;
|
||||
const uint8_t PCD8544_SETBIAS = 0x10;
|
||||
const uint8_t PCD8544_SETVOP = 0x80;
|
||||
uint8_t contrast_;
|
||||
|
||||
void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
|
||||
void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
|
||||
void set_contrast(uint8_t contrast) { this->contrast_ = contrast; }
|
||||
float get_setup_priority() const override { return setup_priority::PROCESSOR; }
|
||||
|
||||
void command(uint8_t value);
|
||||
|
|
|
@ -1585,6 +1585,7 @@ display:
|
|||
cs_pin: GPIO23
|
||||
dc_pin: GPIO23
|
||||
reset_pin: GPIO23
|
||||
contrast: 60
|
||||
lambda: |-
|
||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||
- platform: ssd1306_i2c
|
||||
|
|
Loading…
Reference in a new issue