From 0960d670010852f294e8ba19a6d92eb93e537421 Mon Sep 17 00:00:00 2001 From: John Crawford Date: Sat, 14 Oct 2023 15:19:50 -0600 Subject: [PATCH] aod: lower refresh rate when always on --- src/drivers/St7789.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/drivers/St7789.h | 5 +++++ 2 files changed, 44 insertions(+) diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index 274e2b62..035d61c9 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -16,6 +16,7 @@ void St7789::Init() { nrf_gpio_pin_set(pinReset); HardwareReset(); SoftwareReset(); + Command2Enable(); SleepOut(); PixelFormat(); MemoryDataAccessControl(); @@ -63,6 +64,17 @@ void St7789::SoftwareReset() { vTaskDelay(pdMS_TO_TICKS(125)); } +void St7789::Command2Enable() { + WriteCommand(static_cast(Commands::Command2Enable)); + constexpr uint8_t args[] = { + 0x5a, // Constant + 0x69, // Constant + 0x02, // Constant + 0x01, // Enable + }; + WriteData(args, sizeof(args)); +} + void St7789::SleepOut() { if (!sleepIn) { return; @@ -135,6 +147,31 @@ void St7789::IdleModeOff() { WriteCommand(static_cast(Commands::IdleModeOff)); } +void St7789::FrameRateLow() { + WriteCommand(static_cast(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(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(Commands::DisplayOn)); } @@ -208,11 +245,13 @@ void St7789::HardwareReset() { 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 ccc951ff..e249e0b0 100644 --- a/src/drivers/St7789.h +++ b/src/drivers/St7789.h @@ -39,6 +39,7 @@ namespace Pinetime { void HardwareReset(); void SoftwareReset(); + void Command2Enable(); void SleepOut(); void EnsureSleepOutPostDelay(); void SleepIn(); @@ -49,6 +50,8 @@ namespace Pinetime { 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 @@ namespace Pinetime { 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);