Author: John Crawford <coffeeboi47@protonmail.com>
aod: lower refresh rate when always on
src/drivers/St7789.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/drivers/St7789.h | 5 +++++
diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index 274e2b625ad13335dc25e9a4c18a46094a24e86a..035d61c9dde01f11a9f0757cf30ca60779614dc8 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -16,6 +16,7 @@ nrf_gpio_cfg_output(pinReset); nrf_gpio_pin_set(pinReset); HardwareReset(); SoftwareReset(); + Command2Enable(); SleepOut(); PixelFormat(); MemoryDataAccessControl(); @@ -61,6 +62,17 @@ // Unconditionally wait as software reset doesn't need to be performant sleepIn = true; lastSleepExit = xTaskGetTickCount(); vTaskDelay(pdMS_TO_TICKS(125)); +} + +void St7789::Command2Enable() { + WriteCommand(static_cast<uint8_t>(Commands::Command2Enable)); + constexpr uint8_t args[] = { + 0x5a, // Constant + 0x69, // Constant + 0x02, // Constant + 0x01, // Enable + }; + WriteData(args, sizeof(args)); } void St7789::SleepOut() { @@ -135,6 +147,31 @@ void St7789::IdleModeOff() { WriteCommand(static_cast<uint8_t>(Commands::IdleModeOff)); } +void St7789::FrameRateLow() { + WriteCommand(static_cast<uint8_t>(Commands::FrameRate)); + // Enable frame rate control for partial/idle mode, 8x frame divider + // According to the datasheet, these controls should apply only to partial/idle mode + // However they appear to apply to normal mode, so we have to enable/disable + // every time we enter/exit always on + // In testing this divider appears to actually be 16x? + constexpr uint8_t args[] = { + 0x13, // Enable frame rate control for partial/idle mode, 8x frame divider + 0x1f, // Idle mode frame rate (lowest possible) + 0x1f, // Partial mode frame rate (lowest possible, unused) + }; + WriteData(args, sizeof(args)); +} + +void St7789::FrameRateNormal() { + WriteCommand(static_cast<uint8_t>(Commands::FrameRate)); + constexpr uint8_t args[] = { + 0x00, // Disable frame rate control and divider + 0x0f, // Idle mode frame rate (normal) + 0x0f, // Partial mode frame rate (normal, unused) + }; + WriteData(args, sizeof(args)); +} + void St7789::DisplayOn() { WriteCommand(static_cast<uint8_t>(Commands::DisplayOn)); } @@ -208,11 +245,13 @@ } void St7789::LowPowerOn() { IdleModeOn(); + FrameRateLow(); NRF_LOG_INFO("[LCD] Low power mode"); } void St7789::LowPowerOff() { IdleModeOff(); + FrameRateNormal(); NRF_LOG_INFO("[LCD] Normal power mode"); } diff --git a/src/drivers/St7789.h b/src/drivers/St7789.h index ccc951ff7bbc55f57ca2c0add48a337304d29510..e249e0b00403979d9267a50cd20d9b3a23368446 100644 --- a/src/drivers/St7789.h +++ b/src/drivers/St7789.h @@ -39,6 +39,7 @@ TickType_t lastSleepExit; void HardwareReset(); void SoftwareReset(); + void Command2Enable(); void SleepOut(); void EnsureSleepOutPostDelay(); void SleepIn(); @@ -49,6 +50,8 @@ void NormalModeOn(); void WriteToRam(const uint8_t* data, size_t size); void IdleModeOn(); void IdleModeOff(); + void FrameRateNormal(); + void FrameRateLow(); void DisplayOn(); void DisplayOff(); @@ -75,7 +78,9 @@ VerticalScrollStartAddress = 0x37, IdleModeOff = 0x38, IdleModeOn = 0x39, PixelFormat = 0x3a, + FrameRate = 0xb3, VdvSet = 0xc4, + Command2Enable = 0xdf, }; void WriteData(uint8_t data); void WriteData(const uint8_t* data, size_t size);