Skip to content

Commit

Permalink
[ili9xxx] Make invert_colors required (esphome#7292)
Browse files Browse the repository at this point in the history
Co-authored-by: Gilles van den Hoven <[email protected]>
Co-authored-by: clydebarrow <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 7e18a5c commit 34cce0e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 39 deletions.
33 changes: 16 additions & 17 deletions esphome/components/ili9xxx/display.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import core, pins
from esphome.components import display, spi, font
import esphome.codegen as cg
from esphome.components import display, font, spi
from esphome.components.display import validate_rotation
from esphome.core import CORE, HexInt
import esphome.config_validation as cv
from esphome.const import (
CONF_COLOR_ORDER,
CONF_COLOR_PALETTE,
CONF_DC_PIN,
CONF_DIMENSIONS,
CONF_HEIGHT,
CONF_ID,
CONF_INVERT_COLORS,
CONF_LAMBDA,
CONF_MIRROR_X,
CONF_MIRROR_Y,
CONF_MODEL,
CONF_RAW_DATA_ID,
CONF_OFFSET_HEIGHT,
CONF_OFFSET_WIDTH,
CONF_PAGES,
CONF_RAW_DATA_ID,
CONF_RESET_PIN,
CONF_DIMENSIONS,
CONF_WIDTH,
CONF_HEIGHT,
CONF_ROTATION,
CONF_MIRROR_X,
CONF_MIRROR_Y,
CONF_SWAP_XY,
CONF_COLOR_ORDER,
CONF_OFFSET_HEIGHT,
CONF_OFFSET_WIDTH,
CONF_TRANSFORM,
CONF_INVERT_COLORS,
CONF_WIDTH,
)
from esphome.core import CORE, HexInt

DEPENDENCIES = ["spi"]

Expand Down Expand Up @@ -177,7 +177,7 @@ def _validate(config):
cv.Optional(CONF_INVERT_DISPLAY): cv.invalid(
"'invert_display' has been replaced by 'invert_colors'"
),
cv.Optional(CONF_INVERT_COLORS): cv.boolean,
cv.Required(CONF_INVERT_COLORS): cv.boolean,
cv.Optional(CONF_COLOR_ORDER): cv.one_of(*COLOR_ORDERS.keys(), upper=True),
cv.Exclusive(CONF_ROTATION, CONF_ROTATION): validate_rotation,
cv.Exclusive(CONF_TRANSFORM, CONF_ROTATION): cv.Schema(
Expand Down Expand Up @@ -287,5 +287,4 @@ def load_image(filename):
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
cg.add(var.set_palette(prog_arr))

if CONF_INVERT_COLORS in config:
cg.add(var.invert_colors(config[CONF_INVERT_COLORS]))
cg.add(var.invert_colors(config[CONF_INVERT_COLORS]))
2 changes: 1 addition & 1 deletion esphome/components/ili9xxx/ili9xxx_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void ILI9XXXDisplay::dump_config() {
ESP_LOGCONFIG(TAG, " Swap_xy: %s", YESNO(this->swap_xy_));
ESP_LOGCONFIG(TAG, " Mirror_x: %s", YESNO(this->mirror_x_));
ESP_LOGCONFIG(TAG, " Mirror_y: %s", YESNO(this->mirror_y_));
ESP_LOGCONFIG(TAG, " Invert colors: %s", YESNO(this->pre_invertcolors_));

if (this->is_failed()) {
ESP_LOGCONFIG(TAG, " => Failed to init Memory: YES!");
Expand Down Expand Up @@ -154,7 +155,6 @@ void ILI9XXXDisplay::fill(Color color) {
}
}
return;
break;
default:
new_color = display::ColorUtil::color_to_332(color, display::ColorOrder::COLOR_ORDER_RGB);
break;
Expand Down
36 changes: 18 additions & 18 deletions esphome/components/ili9xxx/ili9xxx_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
public:
ILI9XXXDisplay() = default;
ILI9XXXDisplay(uint8_t const *init_sequence, int16_t width, int16_t height, bool invert_colors)
: init_sequence_{init_sequence}, width_{width}, height_{height}, pre_invertcolors_{invert_colors} {
ILI9XXXDisplay(uint8_t const *init_sequence, int16_t width, int16_t height)
: init_sequence_{init_sequence}, width_{width}, height_{height} {
uint8_t cmd, num_args, bits;
const uint8_t *addr = init_sequence;
while ((cmd = *addr++) != 0) {
Expand Down Expand Up @@ -144,7 +144,7 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
bool need_update_ = false;
bool is_18bitdisplay_ = false;
PixelMode pixel_mode_{};
bool pre_invertcolors_ = false;
bool pre_invertcolors_{};
display::ColorOrder color_order_{display::COLOR_ORDER_BGR};
bool swap_xy_{};
bool mirror_x_{};
Expand All @@ -154,54 +154,54 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
//----------- M5Stack display --------------
class ILI9XXXM5Stack : public ILI9XXXDisplay {
public:
ILI9XXXM5Stack() : ILI9XXXDisplay(INITCMD_M5STACK, 320, 240, true) {}
ILI9XXXM5Stack() : ILI9XXXDisplay(INITCMD_M5STACK, 320, 240) {}
};

//----------- M5Stack display --------------
class ILI9XXXM5CORE : public ILI9XXXDisplay {
public:
ILI9XXXM5CORE() : ILI9XXXDisplay(INITCMD_M5CORE, 320, 240, true) {}
ILI9XXXM5CORE() : ILI9XXXDisplay(INITCMD_M5CORE, 320, 240) {}
};

//----------- ST7789V display --------------
class ILI9XXXST7789V : public ILI9XXXDisplay {
public:
ILI9XXXST7789V() : ILI9XXXDisplay(INITCMD_ST7789V, 240, 320, false) {}
ILI9XXXST7789V() : ILI9XXXDisplay(INITCMD_ST7789V, 240, 320) {}
};

//----------- ILI9XXX_24_TFT display --------------
class ILI9XXXILI9341 : public ILI9XXXDisplay {
public:
ILI9XXXILI9341() : ILI9XXXDisplay(INITCMD_ILI9341, 240, 320, false) {}
ILI9XXXILI9341() : ILI9XXXDisplay(INITCMD_ILI9341, 240, 320) {}
};

//----------- ILI9XXX_24_TFT rotated display --------------
class ILI9XXXILI9342 : public ILI9XXXDisplay {
public:
ILI9XXXILI9342() : ILI9XXXDisplay(INITCMD_ILI9341, 320, 240, false) {}
ILI9XXXILI9342() : ILI9XXXDisplay(INITCMD_ILI9341, 320, 240) {}
};

//----------- ILI9XXX_??_TFT rotated display --------------
class ILI9XXXILI9481 : public ILI9XXXDisplay {
public:
ILI9XXXILI9481() : ILI9XXXDisplay(INITCMD_ILI9481, 480, 320, false) {}
ILI9XXXILI9481() : ILI9XXXDisplay(INITCMD_ILI9481, 480, 320) {}
};

//----------- ILI9481 in 18 bit mode --------------
class ILI9XXXILI948118 : public ILI9XXXDisplay {
public:
ILI9XXXILI948118() : ILI9XXXDisplay(INITCMD_ILI9481_18, 320, 480, true) {}
ILI9XXXILI948118() : ILI9XXXDisplay(INITCMD_ILI9481_18, 320, 480) {}
};

//----------- ILI9XXX_35_TFT rotated display --------------
class ILI9XXXILI9486 : public ILI9XXXDisplay {
public:
ILI9XXXILI9486() : ILI9XXXDisplay(INITCMD_ILI9486, 480, 320, false) {}
ILI9XXXILI9486() : ILI9XXXDisplay(INITCMD_ILI9486, 480, 320) {}
};

class ILI9XXXILI9488 : public ILI9XXXDisplay {
public:
ILI9XXXILI9488(const uint8_t *seq = INITCMD_ILI9488) : ILI9XXXDisplay(seq, 480, 320, true) {}
ILI9XXXILI9488(const uint8_t *seq = INITCMD_ILI9488) : ILI9XXXDisplay(seq, 480, 320) {}

protected:
void set_madctl() override {
Expand Down Expand Up @@ -246,34 +246,34 @@ class WAVESHARERES35 : public ILI9XXXILI9488 {
//----------- ILI9XXX_35_TFT origin colors rotated display --------------
class ILI9XXXILI9488A : public ILI9XXXDisplay {
public:
ILI9XXXILI9488A() : ILI9XXXDisplay(INITCMD_ILI9488_A, 480, 320, true) {}
ILI9XXXILI9488A() : ILI9XXXDisplay(INITCMD_ILI9488_A, 480, 320) {}
};

//----------- ILI9XXX_35_TFT rotated display --------------
class ILI9XXXST7796 : public ILI9XXXDisplay {
public:
ILI9XXXST7796() : ILI9XXXDisplay(INITCMD_ST7796, 320, 480, false) {}
ILI9XXXST7796() : ILI9XXXDisplay(INITCMD_ST7796, 320, 480) {}
};

class ILI9XXXS3Box : public ILI9XXXDisplay {
public:
ILI9XXXS3Box() : ILI9XXXDisplay(INITCMD_S3BOX, 320, 240, false) {}
ILI9XXXS3Box() : ILI9XXXDisplay(INITCMD_S3BOX, 320, 240) {}
};

class ILI9XXXS3BoxLite : public ILI9XXXDisplay {
public:
ILI9XXXS3BoxLite() : ILI9XXXDisplay(INITCMD_S3BOXLITE, 320, 240, true) {}
ILI9XXXS3BoxLite() : ILI9XXXDisplay(INITCMD_S3BOXLITE, 320, 240) {}
};

class ILI9XXXGC9A01A : public ILI9XXXDisplay {
public:
ILI9XXXGC9A01A() : ILI9XXXDisplay(INITCMD_GC9A01A, 240, 240, true) {}
ILI9XXXGC9A01A() : ILI9XXXDisplay(INITCMD_GC9A01A, 240, 240) {}
};

//----------- ILI9XXX_24_TFT display --------------
class ILI9XXXST7735 : public ILI9XXXDisplay {
public:
ILI9XXXST7735() : ILI9XXXDisplay(INITCMD_ST7735, 128, 160, false) {}
ILI9XXXST7735() : ILI9XXXDisplay(INITCMD_ST7735, 128, 160) {}
};

} // namespace ili9xxx
Expand Down
3 changes: 0 additions & 3 deletions esphome/components/ili9xxx/ili9xxx_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ static const uint8_t PROGMEM INITCMD_ILI9481[] = {
ILI9XXX_MADCTL , 1, MADCTL_MV | MADCTL_BGR, // Memory Access Control
ILI9XXX_CSCON , 1, 0x01,
ILI9XXX_PIXFMT, 1, 0x55, // 16 bit mode
ILI9XXX_INVON, 0,
ILI9XXX_DISPON, 0x80, // Set display on
0x00 // end
};
Expand All @@ -121,7 +120,6 @@ static const uint8_t PROGMEM INITCMD_ILI9481_18[] = {
ILI9XXX_MADCTL , 1, MADCTL_MX| MADCTL_BGR, // Memory Access Control
ILI9XXX_CSCON , 1, 0x01,
ILI9XXX_PIXFMT, 1, 0x66, // 18 bit mode
ILI9XXX_INVON, 0,
ILI9XXX_DISPON, 0x80, // Set display on
0x00 // end
};
Expand Down Expand Up @@ -204,7 +202,6 @@ static const uint8_t PROGMEM INITCMD_ILI9488_A[] = {


ILI9XXX_SLPOUT, 0x80, // Exit sleep mode
//ILI9XXX_INVON , 0,
ILI9XXX_DISPON, 0x80, // Set display on
0x00 // end
};
Expand Down
1 change: 1 addition & 0 deletions tests/components/ili9xxx/test.esp32-ard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ display:
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9xxx
invert_colors: false
dimensions:
width: 320
height: 240
Expand Down
1 change: 1 addition & 0 deletions tests/components/ili9xxx/test.esp32-c3-ard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ display:
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9xxx
invert_colors: false
dimensions:
width: 320
height: 240
Expand Down
1 change: 1 addition & 0 deletions tests/components/ili9xxx/test.esp32-c3-idf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ display:
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9xxx
invert_colors: false
dimensions:
width: 320
height: 240
Expand Down
1 change: 1 addition & 0 deletions tests/components/ili9xxx/test.esp8266-ard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ display:
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9xxx
invert_colors: false
dimensions:
width: 320
height: 240
Expand Down
1 change: 1 addition & 0 deletions tests/components/ili9xxx/test.rp2040-ard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ display:
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9xxx
invert_colors: false
dimensions:
width: 320
height: 240
Expand Down

0 comments on commit 34cce0e

Please sign in to comment.