Allow manual set "Invert_display" (#5494)

This commit is contained in:
NP v/d Spek 2023-10-12 03:26:07 +02:00 committed by GitHub
parent 41f29c46d0
commit e35de626a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View file

@ -54,6 +54,7 @@ COLOR_PALETTE = cv.one_of("NONE", "GRAYSCALE", "IMAGE_ADAPTIVE")
CONF_LED_PIN = "led_pin"
CONF_COLOR_PALETTE_IMAGES = "color_palette_images"
CONF_INVERT_DISPLAY = "invert_display"
def _validate(config):
@ -100,6 +101,7 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_COLOR_PALETTE_IMAGES, default=[]): cv.ensure_list(
cv.file_
),
cv.Optional(CONF_INVERT_DISPLAY): cv.boolean,
}
)
.extend(cv.polling_component_schema("1s"))
@ -176,3 +178,6 @@ async def to_code(config):
if rhs is not None:
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
cg.add(var.set_palette(prog_arr))
if CONF_INVERT_DISPLAY in config:
cg.add(var.invert_display(config[CONF_INVERT_DISPLAY]))

View file

@ -12,11 +12,13 @@ static const char *const TAG = "ili9xxx";
void ILI9XXXDisplay::setup() {
this->setup_pins_();
this->initialize();
this->command(this->pre_invertdisplay_ ? ILI9XXX_INVON : ILI9XXX_INVOFF);
this->x_low_ = this->width_;
this->y_low_ = this->height_;
this->x_high_ = 0;
this->y_high_ = 0;
if (this->buffer_color_mode_ == BITS_16) {
this->init_internal_(this->get_buffer_length_() * 2);
if (this->buffer_ != nullptr) {
@ -333,7 +335,12 @@ void ILI9XXXDisplay::set_addr_window_(uint16_t x1, uint16_t y1, uint16_t w, uint
this->command(ILI9XXX_RAMWR); // Write to RAM
}
void ILI9XXXDisplay::invert_display_(bool invert) { this->command(invert ? ILI9XXX_INVON : ILI9XXX_INVOFF); }
void ILI9XXXDisplay::invert_display(bool invert) {
this->pre_invertdisplay_ = invert;
if (is_ready()) {
this->command(invert ? ILI9XXX_INVON : ILI9XXX_INVOFF);
}
}
int ILI9XXXDisplay::get_width_internal() { return this->width_; }
int ILI9XXXDisplay::get_height_internal() { return this->height_; }
@ -345,7 +352,7 @@ void ILI9XXXM5Stack::initialize() {
this->width_ = 320;
if (this->height_ == 0)
this->height_ = 240;
this->invert_display_(true);
this->pre_invertdisplay_ = true;
}
// M5CORE display // Based on the configuration settings of M5stact's M5GFX code.
@ -355,7 +362,7 @@ void ILI9XXXM5CORE::initialize() {
this->width_ = 320;
if (this->height_ == 0)
this->height_ = 240;
this->invert_display_(true);
this->pre_invertdisplay_ = true;
}
// 24_TFT display
@ -462,7 +469,7 @@ void ILI9XXXS3BoxLite::initialize() {
if (this->height_ == 0) {
this->height_ = 240;
}
this->invert_display_(true);
this->pre_invertdisplay_ = true;
}
} // namespace ili9xxx

View file

@ -33,6 +33,7 @@ class ILI9XXXDisplay : public PollingComponent,
this->height_ = height;
this->width_ = width;
}
void invert_display(bool invert);
void command(uint8_t value);
void data(uint8_t value);
void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes);
@ -55,7 +56,7 @@ class ILI9XXXDisplay : public PollingComponent,
void display_();
void init_lcd_(const uint8_t *init_cmd);
void set_addr_window_(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
void invert_display_(bool invert);
void reset_();
int16_t width_{0}; ///< Display width as modified by current rotation
@ -88,6 +89,7 @@ class ILI9XXXDisplay : public PollingComponent,
bool prossing_update_ = false;
bool need_update_ = false;
bool is_18bitdisplay_ = false;
bool pre_invertdisplay_ = false;
};
//----------- M5Stack display --------------