mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
[ili9xxx] Rework delay handling (#7115)
This commit is contained in:
parent
0a7d883633
commit
8fc42694f6
4 changed files with 21 additions and 34 deletions
|
@ -92,7 +92,9 @@ static const uint8_t ILI9XXX_GMCTRN1 = 0xE1;
|
||||||
|
|
||||||
static const uint8_t ILI9XXX_CSCON = 0xF0;
|
static const uint8_t ILI9XXX_CSCON = 0xF0;
|
||||||
static const uint8_t ILI9XXX_ADJCTL3 = 0xF7;
|
static const uint8_t ILI9XXX_ADJCTL3 = 0xF7;
|
||||||
static const uint8_t ILI9XXX_DELAY = 0xFF; // followed by one byte of delay time in ms
|
static const uint8_t ILI9XXX_DELAY_FLAG = 0xFF;
|
||||||
|
// special marker for delay - command byte reprents ms, length byte is an impossible value
|
||||||
|
#define ILI9XXX_DELAY(ms) ((uint8_t) ((ms) | 0x80)), ILI9XXX_DELAY_FLAG
|
||||||
|
|
||||||
} // namespace ili9xxx
|
} // namespace ili9xxx
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -34,8 +34,8 @@ void ILI9XXXDisplay::setup() {
|
||||||
ESP_LOGD(TAG, "Setting up ILI9xxx");
|
ESP_LOGD(TAG, "Setting up ILI9xxx");
|
||||||
|
|
||||||
this->setup_pins_();
|
this->setup_pins_();
|
||||||
this->init_lcd(this->init_sequence_);
|
this->init_lcd_(this->init_sequence_);
|
||||||
this->init_lcd(this->extra_init_sequence_.data());
|
this->init_lcd_(this->extra_init_sequence_.data());
|
||||||
switch (this->pixel_mode_) {
|
switch (this->pixel_mode_) {
|
||||||
case PIXEL_MODE_16:
|
case PIXEL_MODE_16:
|
||||||
if (this->is_18bitdisplay_) {
|
if (this->is_18bitdisplay_) {
|
||||||
|
@ -405,42 +405,29 @@ void ILI9XXXDisplay::reset_() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ILI9XXXDisplay::init_lcd(const uint8_t *addr) {
|
void ILI9XXXDisplay::init_lcd_(const uint8_t *addr) {
|
||||||
if (addr == nullptr)
|
if (addr == nullptr)
|
||||||
return;
|
return;
|
||||||
uint8_t cmd, x, num_args;
|
uint8_t cmd, x, num_args;
|
||||||
while ((cmd = *addr++) != 0) {
|
while ((cmd = *addr++) != 0) {
|
||||||
x = *addr++;
|
x = *addr++;
|
||||||
if (cmd == ILI9XXX_DELAY) {
|
if (x == ILI9XXX_DELAY_FLAG) {
|
||||||
ESP_LOGD(TAG, "Delay %dms", x);
|
cmd &= 0x7F;
|
||||||
delay(x);
|
ESP_LOGV(TAG, "Delay %dms", cmd);
|
||||||
|
delay(cmd);
|
||||||
} else {
|
} else {
|
||||||
num_args = x & 0x7F;
|
num_args = x & 0x7F;
|
||||||
ESP_LOGD(TAG, "Command %02X, length %d, bits %02X", cmd, num_args, *addr);
|
ESP_LOGV(TAG, "Command %02X, length %d, bits %02X", cmd, num_args, *addr);
|
||||||
this->send_command(cmd, addr, num_args);
|
this->send_command(cmd, addr, num_args);
|
||||||
addr += num_args;
|
addr += num_args;
|
||||||
if (x & 0x80) {
|
if (x & 0x80) {
|
||||||
ESP_LOGD(TAG, "Delay 150ms");
|
ESP_LOGV(TAG, "Delay 150ms");
|
||||||
delay(150); // NOLINT
|
delay(150); // NOLINT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ILI9XXXGC9A01A::init_lcd(const uint8_t *addr) {
|
|
||||||
if (addr == nullptr)
|
|
||||||
return;
|
|
||||||
uint8_t cmd, x, num_args;
|
|
||||||
while ((cmd = *addr++) != 0) {
|
|
||||||
x = *addr++;
|
|
||||||
num_args = x & 0x7F;
|
|
||||||
this->send_command(cmd, addr, num_args);
|
|
||||||
addr += num_args;
|
|
||||||
if (x & 0x80)
|
|
||||||
delay(150); // NOLINT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell the display controller where we want to draw pixels.
|
// Tell the display controller where we want to draw pixels.
|
||||||
void ILI9XXXDisplay::set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
void ILI9XXXDisplay::set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||||
x1 += this->offset_x_;
|
x1 += this->offset_x_;
|
||||||
|
|
|
@ -33,7 +33,9 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
uint8_t cmd, num_args, bits;
|
uint8_t cmd, num_args, bits;
|
||||||
const uint8_t *addr = init_sequence;
|
const uint8_t *addr = init_sequence;
|
||||||
while ((cmd = *addr++) != 0) {
|
while ((cmd = *addr++) != 0) {
|
||||||
num_args = *addr++ & 0x7F;
|
num_args = *addr++;
|
||||||
|
if (num_args == ILI9XXX_DELAY_FLAG)
|
||||||
|
continue;
|
||||||
bits = *addr;
|
bits = *addr;
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case ILI9XXX_MADCTL: {
|
case ILI9XXX_MADCTL: {
|
||||||
|
@ -50,13 +52,10 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ILI9XXX_DELAY:
|
|
||||||
continue; // no args to skip
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addr += num_args;
|
addr += (num_args & 0x7F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
|
|
||||||
virtual void set_madctl();
|
virtual void set_madctl();
|
||||||
void display_();
|
void display_();
|
||||||
virtual void init_lcd(const uint8_t *addr);
|
void init_lcd_(const uint8_t *addr);
|
||||||
void set_addr_window_(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2);
|
void set_addr_window_(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2);
|
||||||
void reset_();
|
void reset_();
|
||||||
|
|
||||||
|
@ -269,7 +268,6 @@ class ILI9XXXS3BoxLite : public ILI9XXXDisplay {
|
||||||
class ILI9XXXGC9A01A : public ILI9XXXDisplay {
|
class ILI9XXXGC9A01A : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXGC9A01A() : ILI9XXXDisplay(INITCMD_GC9A01A, 240, 240, true) {}
|
ILI9XXXGC9A01A() : ILI9XXXDisplay(INITCMD_GC9A01A, 240, 240, true) {}
|
||||||
void init_lcd(const uint8_t *addr) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9XXX_24_TFT display --------------
|
//----------- ILI9XXX_24_TFT display --------------
|
||||||
|
|
|
@ -372,9 +372,9 @@ static const uint8_t PROGMEM INITCMD_GC9A01A[] = {
|
||||||
|
|
||||||
static const uint8_t PROGMEM INITCMD_ST7735[] = {
|
static const uint8_t PROGMEM INITCMD_ST7735[] = {
|
||||||
ILI9XXX_SWRESET, 0, // Soft reset, then delay 10ms
|
ILI9XXX_SWRESET, 0, // Soft reset, then delay 10ms
|
||||||
ILI9XXX_DELAY, 10,
|
ILI9XXX_DELAY(10),
|
||||||
ILI9XXX_SLPOUT , 0, // Exit Sleep, delay
|
ILI9XXX_SLPOUT , 0, // Exit Sleep, delay
|
||||||
ILI9XXX_DELAY, 10,
|
ILI9XXX_DELAY(10),
|
||||||
ILI9XXX_PIXFMT , 1, 0x05,
|
ILI9XXX_PIXFMT , 1, 0x05,
|
||||||
ILI9XXX_FRMCTR1, 3, // 4: Frame rate control, 3 args + delay:
|
ILI9XXX_FRMCTR1, 3, // 4: Frame rate control, 3 args + delay:
|
||||||
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
||||||
|
@ -415,9 +415,9 @@ static const uint8_t PROGMEM INITCMD_ST7735[] = {
|
||||||
0x00, 0x00, 0x02, 0x10,
|
0x00, 0x00, 0x02, 0x10,
|
||||||
ILI9XXX_MADCTL , 1, 0x00, // Memory Access Control, BGR
|
ILI9XXX_MADCTL , 1, 0x00, // Memory Access Control, BGR
|
||||||
ILI9XXX_NORON , 0,
|
ILI9XXX_NORON , 0,
|
||||||
ILI9XXX_DELAY, 10,
|
ILI9XXX_DELAY(10),
|
||||||
ILI9XXX_DISPON , 0, // Display on
|
ILI9XXX_DISPON , 0, // Display on
|
||||||
ILI9XXX_DELAY, 10,
|
ILI9XXX_DELAY(10),
|
||||||
00, // endo of list
|
00, // endo of list
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue