mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 10:14:13 +01:00
7789 controller fixes take 2 (#5320)
* Fix 7789 clock mode and increase clock rate. * Reverse change from dev. * Speed up 8 bit color. * Tweak buffer size
This commit is contained in:
parent
cdb67fc90e
commit
01f6791d1c
2 changed files with 15 additions and 6 deletions
|
@ -5,6 +5,7 @@ namespace esphome {
|
||||||
namespace st7789v {
|
namespace st7789v {
|
||||||
|
|
||||||
static const char *const TAG = "st7789v";
|
static const char *const TAG = "st7789v";
|
||||||
|
static const size_t TEMP_BUFFER_SIZE = 128;
|
||||||
|
|
||||||
void ST7789V::setup() {
|
void ST7789V::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Setting up SPI ST7789V...");
|
ESP_LOGCONFIG(TAG, "Setting up SPI ST7789V...");
|
||||||
|
@ -19,7 +20,6 @@ void ST7789V::setup() {
|
||||||
|
|
||||||
this->write_command_(ST7789_SLPOUT); // Sleep out
|
this->write_command_(ST7789_SLPOUT); // Sleep out
|
||||||
delay(120); // NOLINT
|
delay(120); // NOLINT
|
||||||
this->write_command_(ST7789_SLPOUT); //
|
|
||||||
|
|
||||||
this->write_command_(ST7789_NORON); // Normal display mode on
|
this->write_command_(ST7789_NORON); // Normal display mode on
|
||||||
|
|
||||||
|
@ -206,15 +206,23 @@ void ST7789V::write_display_data() {
|
||||||
this->dc_pin_->digital_write(true);
|
this->dc_pin_->digital_write(true);
|
||||||
|
|
||||||
if (this->eightbitcolor_) {
|
if (this->eightbitcolor_) {
|
||||||
|
uint8_t temp_buffer[TEMP_BUFFER_SIZE];
|
||||||
|
size_t temp_index = 0;
|
||||||
for (int line = 0; line < this->get_buffer_length_(); line = line + this->get_width_internal()) {
|
for (int line = 0; line < this->get_buffer_length_(); line = line + this->get_width_internal()) {
|
||||||
for (int index = 0; index < this->get_width_internal(); ++index) {
|
for (int index = 0; index < this->get_width_internal(); ++index) {
|
||||||
auto color = display::ColorUtil::color_to_565(
|
auto color = display::ColorUtil::color_to_565(
|
||||||
display::ColorUtil::to_color(this->buffer_[index + line], display::ColorOrder::COLOR_ORDER_RGB,
|
display::ColorUtil::to_color(this->buffer_[index + line], display::ColorOrder::COLOR_ORDER_RGB,
|
||||||
display::ColorBitness::COLOR_BITNESS_332, true));
|
display::ColorBitness::COLOR_BITNESS_332, true));
|
||||||
this->write_byte((color >> 8) & 0xff);
|
temp_buffer[temp_index++] = (uint8_t) (color >> 8);
|
||||||
this->write_byte(color & 0xff);
|
temp_buffer[temp_index++] = (uint8_t) color;
|
||||||
|
if (temp_index == TEMP_BUFFER_SIZE) {
|
||||||
|
this->write_array(temp_buffer, TEMP_BUFFER_SIZE);
|
||||||
|
temp_index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (temp_index != 0)
|
||||||
|
this->write_array(temp_buffer, temp_index);
|
||||||
} else {
|
} else {
|
||||||
this->write_array(this->buffer_, this->get_buffer_length_());
|
this->write_array(this->buffer_, this->get_buffer_length_());
|
||||||
}
|
}
|
||||||
|
@ -229,9 +237,10 @@ void ST7789V::init_reset_() {
|
||||||
delay(1);
|
delay(1);
|
||||||
// Trigger Reset
|
// Trigger Reset
|
||||||
this->reset_pin_->digital_write(false);
|
this->reset_pin_->digital_write(false);
|
||||||
delay(10);
|
delay(1);
|
||||||
// Wake up
|
// Wake up
|
||||||
this->reset_pin_->digital_write(true);
|
this->reset_pin_->digital_write(true);
|
||||||
|
delay(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,8 +117,8 @@ static const uint8_t ST7789_MADCTL_COLOR_ORDER = ST7789_MADCTL_BGR;
|
||||||
|
|
||||||
class ST7789V : public PollingComponent,
|
class ST7789V : public PollingComponent,
|
||||||
public display::DisplayBuffer,
|
public display::DisplayBuffer,
|
||||||
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING,
|
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
||||||
spi::DATA_RATE_10MHZ> {
|
spi::DATA_RATE_20MHZ> {
|
||||||
public:
|
public:
|
||||||
void set_model(ST7789VModel model);
|
void set_model(ST7789VModel model);
|
||||||
void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
|
void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
|
||||||
|
|
Loading…
Reference in a new issue