From d10ff6262ecbfb8cf05ada3059f27b87552de414 Mon Sep 17 00:00:00 2001 From: Ian Geiser Date: Tue, 15 Sep 2020 08:18:27 -0400 Subject: [PATCH 1/2] add upstream for #998 --- components/st7735/display.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/st7735/display.py b/components/st7735/display.py index 9b7c1a3..05fe06f 100644 --- a/components/st7735/display.py +++ b/components/st7735/display.py @@ -19,7 +19,7 @@ CONFIG_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend({ cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema, cv.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, cv.Optional(CONF_BRIGHTNESS, default=1.0): cv.percentage, -}).extend(cv.polling_component_schema('1s')).extend(spi.SPI_DEVICE_SCHEMA) +}).extend(cv.polling_component_schema('1s')).extend(spi.spi_device_schema()) def to_code(config): From 5d2419b4ad94d2b405e67f34414bfe780af7434c Mon Sep 17 00:00:00 2001 From: Ian Geiser Date: Tue, 15 Sep 2020 11:38:33 -0400 Subject: [PATCH 2/2] use Color class from upstream --- components/st7735/st7735.cpp | 18 ++++++------------ components/st7735/st7735.h | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/components/st7735/st7735.cpp b/components/st7735/st7735.cpp index 3336bcd..dcdfdea 100644 --- a/components/st7735/st7735.cpp +++ b/components/st7735/st7735.cpp @@ -162,10 +162,7 @@ void ST7735::setup() { this->displayInit(Rcmd3); this->writecommand(ST7735_INVON); -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //this->disable(); delay(120); - //this->enable(); this->writecommand(ST7735_DISPON); //Display on delay(120); @@ -270,18 +267,15 @@ size_t ST7735::get_buffer_length_() { return size_t(this->get_width_internal()) * size_t(this->get_height_internal()) * 2; } -void HOT ST7735::draw_absolute_pixel_internal(int x, int y, int color) { + +void HOT ST7735::draw_absolute_pixel_internal(int x, int y, Color color) { if (x >= this->get_width_internal() || x < 0 || y >= this->get_height_internal() || y < 0) return; - if (color == display::COLOR_ON) { - color = ST7735_WHITE; - } else if (color == display::COLOR_OFF) { - color = ST7735_BLACK; - } - uint16_t pos = (x + y * this->get_width_internal())*2; - this->buffer_[pos++] = (color>>8) & 0xff; - this->buffer_[pos] = color & 0xff; + auto color565 = color.to_rgb_565(); + uint16_t pos = (x + y * this->get_width_internal()) * 2; + this->buffer_[pos++] = (color565 >> 8) & 0xff; + this->buffer_[pos] = color565 & 0xff; } void ST7735::displayInit(const uint8_t *addr) { diff --git a/components/st7735/st7735.h b/components/st7735/st7735.h index f610337..fe02b9a 100644 --- a/components/st7735/st7735.h +++ b/components/st7735/st7735.h @@ -136,8 +136,8 @@ class ST7735 : public PollingComponent, public display::DisplayBuffer, void spi_master_write_addr(uint16_t addr1, uint16_t addr2); void spi_master_write_color(uint16_t color, uint16_t size); - - void draw_absolute_pixel_internal(int x, int y, int color) override; + + void draw_absolute_pixel_internal(int x, int y, Color color) override; int get_height_internal() override; int get_width_internal() override;