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:
Clyde Stubbs 2023-09-01 09:43:24 +10:00 committed by GitHub
parent cdb67fc90e
commit 01f6791d1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -5,6 +5,7 @@ namespace esphome {
namespace st7789v {
static const char *const TAG = "st7789v";
static const size_t TEMP_BUFFER_SIZE = 128;
void ST7789V::setup() {
ESP_LOGCONFIG(TAG, "Setting up SPI ST7789V...");
@ -19,7 +20,6 @@ void ST7789V::setup() {
this->write_command_(ST7789_SLPOUT); // Sleep out
delay(120); // NOLINT
this->write_command_(ST7789_SLPOUT); //
this->write_command_(ST7789_NORON); // Normal display mode on
@ -206,15 +206,23 @@ void ST7789V::write_display_data() {
this->dc_pin_->digital_write(true);
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 index = 0; index < this->get_width_internal(); ++index) {
auto color = display::ColorUtil::color_to_565(
display::ColorUtil::to_color(this->buffer_[index + line], display::ColorOrder::COLOR_ORDER_RGB,
display::ColorBitness::COLOR_BITNESS_332, true));
this->write_byte((color >> 8) & 0xff);
this->write_byte(color & 0xff);
temp_buffer[temp_index++] = (uint8_t) (color >> 8);
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 {
this->write_array(this->buffer_, this->get_buffer_length_());
}
@ -229,9 +237,10 @@ void ST7789V::init_reset_() {
delay(1);
// Trigger Reset
this->reset_pin_->digital_write(false);
delay(10);
delay(1);
// Wake up
this->reset_pin_->digital_write(true);
delay(5);
}
}

View File

@ -117,8 +117,8 @@ static const uint8_t ST7789_MADCTL_COLOR_ORDER = ST7789_MADCTL_BGR;
class ST7789V : public PollingComponent,
public display::DisplayBuffer,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING,
spi::DATA_RATE_10MHZ> {
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
spi::DATA_RATE_20MHZ> {
public:
void set_model(ST7789VModel model);
void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }