aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/St7789.cpp
diff options
context:
space:
mode:
authormark9064 <30447455+mark9064@users.noreply.github.com>2024-01-30 23:29:16 +0000
committerJF <JF002@users.noreply.github.com>2024-05-01 16:17:59 +0200
commit7b1110187e92c739f85fbfdcf80f4547f1283a33 (patch)
tree4d5110dfe522ab9e25b64762b5475296778cff40 /src/drivers/St7789.cpp
parent7e460d3c8072cbddf98172be9e94ede8e6613de5 (diff)
Apply display driver datasheet delays
Diffstat (limited to 'src/drivers/St7789.cpp')
-rw-r--r--src/drivers/St7789.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp
index 82cefc43..f1917a77 100644
--- a/src/drivers/St7789.cpp
+++ b/src/drivers/St7789.cpp
@@ -1,7 +1,4 @@
#include "drivers/St7789.h"
-#include <hal/nrf_gpio.h>
-#include <nrfx_log.h>
-#include "drivers/Spi.h"
using namespace Pinetime::Drivers;
@@ -53,22 +50,52 @@ void St7789::WriteSpi(const uint8_t* data, size_t size, const std::function<void
}
void St7789::SoftwareReset() {
+ EnsureSleepOutPostDelay();
WriteCommand(static_cast<uint8_t>(Commands::SoftwareReset));
- vTaskDelay(pdMS_TO_TICKS(150));
+ // If sleep in: must wait 120ms before sleep out can sent (see driver datasheet)
+ // Unconditionally wait as software reset doesn't need to be performant
+ sleepIn = true;
+ lastSleepExit = xTaskGetTickCount();
+ vTaskDelay(pdMS_TO_TICKS(125));
}
void St7789::SleepOut() {
+ if (!sleepIn) {
+ return;
+ }
WriteCommand(static_cast<uint8_t>(Commands::SleepOut));
+ // Wait 5ms for clocks to stabilise
+ // pdMS rounds down => 6 used here
+ vTaskDelay(pdMS_TO_TICKS(6));
+ // Cannot send sleep in or software reset for 120ms
+ lastSleepExit = xTaskGetTickCount();
+ sleepIn = false;
+}
+
+void St7789::EnsureSleepOutPostDelay() {
+ TickType_t delta = xTaskGetTickCount() - lastSleepExit;
+ // Due to timer wraparound, there is a chance of delaying when not necessary
+ // It is very low (pdMS_TO_TICKS(125)/2^32) and waiting an extra 125ms isn't too bad
+ if (delta < pdMS_TO_TICKS(125)) {
+ vTaskDelay(pdMS_TO_TICKS(125) - delta);
+ }
}
void St7789::SleepIn() {
+ if (sleepIn) {
+ return;
+ }
+ EnsureSleepOutPostDelay();
WriteCommand(static_cast<uint8_t>(Commands::SleepIn));
+ // Wait 5ms for clocks to stabilise
+ // pdMS rounds down => 6 used here
+ vTaskDelay(pdMS_TO_TICKS(6));
+ sleepIn = true;
}
void St7789::ColMod() {
WriteCommand(static_cast<uint8_t>(Commands::ColMod));
WriteData(0x55);
- vTaskDelay(pdMS_TO_TICKS(10));
}
void St7789::MemoryDataAccessControl() {
@@ -105,12 +132,10 @@ void St7789::RowAddressSet() {
void St7789::DisplayInversionOn() {
WriteCommand(static_cast<uint8_t>(Commands::DisplayInversionOn));
- vTaskDelay(pdMS_TO_TICKS(10));
}
void St7789::NormalModeOn() {
WriteCommand(static_cast<uint8_t>(Commands::NormalModeOn));
- vTaskDelay(pdMS_TO_TICKS(10));
}
void St7789::DisplayOn() {
@@ -145,7 +170,6 @@ void St7789::SetVdv() {
void St7789::DisplayOff() {
WriteCommand(static_cast<uint8_t>(Commands::DisplayOff));
- vTaskDelay(pdMS_TO_TICKS(500));
}
void St7789::VerticalScrollStartAddress(uint16_t line) {
@@ -165,8 +189,13 @@ void St7789::DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
void St7789::HardwareReset() {
nrf_gpio_pin_clear(pinReset);
- vTaskDelay(pdMS_TO_TICKS(10));
+ vTaskDelay(pdMS_TO_TICKS(1));
nrf_gpio_pin_set(pinReset);
+ // If hardware reset started while sleep out, reset time may be up to 120ms
+ // Unconditionally wait as hardware reset doesn't need to be performant
+ sleepIn = true;
+ lastSleepExit = xTaskGetTickCount();
+ vTaskDelay(pdMS_TO_TICKS(125));
}
void St7789::Sleep() {