aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/St7789.cpp
diff options
context:
space:
mode:
authormark9064 <30447455+mark9064@users.noreply.github.com>2024-04-04 19:29:46 +0100
committerJF <JF002@users.noreply.github.com>2024-06-19 17:25:15 +0200
commitf8f8993fac0bdd022dc9ef41a67c0b558f29ba89 (patch)
tree5d2aece191a7b7849559944ede55740116da1e01 /src/drivers/St7789.cpp
parentfdc3b8badbf5d11b50a378f0e572dfe3e443c08c (diff)
Batch display command arguments
Diffstat (limited to 'src/drivers/St7789.cpp')
-rw-r--r--src/drivers/St7789.cpp58
1 files changed, 27 insertions, 31 deletions
diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp
index 12e95a41..c22f2199 100644
--- a/src/drivers/St7789.cpp
+++ b/src/drivers/St7789.cpp
@@ -1,3 +1,4 @@
+#include <cstring>
#include "drivers/St7789.h"
#include <hal/nrf_gpio.h>
#include <nrfx_log.h>
@@ -16,10 +17,9 @@ void St7789::Init() {
HardwareReset();
SoftwareReset();
SleepOut();
- ColMod();
+ PixelFormat();
MemoryDataAccessControl();
- ColumnAddressSet();
- RowAddressSet();
+ SetAddrWindow(0, 0, Width, Height);
// P8B Mirrored version does not need display inversion.
#ifndef DRIVER_DISPLAY_MIRROR
DisplayInversionOn();
@@ -97,8 +97,9 @@ void St7789::SleepIn() {
sleepIn = true;
}
-void St7789::ColMod() {
- WriteCommand(static_cast<uint8_t>(Commands::ColMod));
+void St7789::PixelFormat() {
+ WriteCommand(static_cast<uint8_t>(Commands::PixelFormat));
+ // 65K colours, 16-bit per pixel
WriteData(0x55);
}
@@ -118,22 +119,6 @@ void St7789::MemoryDataAccessControl() {
#endif
}
-void St7789::ColumnAddressSet() {
- WriteCommand(static_cast<uint8_t>(Commands::ColumnAddressSet));
- WriteData(0x00);
- WriteData(0x00);
- WriteData(Width >> 8u);
- WriteData(Width & 0xffu);
-}
-
-void St7789::RowAddressSet() {
- WriteCommand(static_cast<uint8_t>(Commands::RowAddressSet));
- WriteData(0x00);
- WriteData(0x00);
- WriteData(320u >> 8u);
- WriteData(320u & 0xffu);
-}
-
void St7789::DisplayInversionOn() {
WriteCommand(static_cast<uint8_t>(Commands::DisplayInversionOn));
}
@@ -148,16 +133,23 @@ void St7789::DisplayOn() {
void St7789::SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
WriteCommand(static_cast<uint8_t>(Commands::ColumnAddressSet));
- WriteData(x0 >> 8);
- WriteData(x0 & 0xff);
- WriteData(x1 >> 8);
- WriteData(x1 & 0xff);
+ uint8_t colArgs[] = {
+ static_cast<uint8_t>(x0 >> 8), // x start MSB
+ static_cast<uint8_t>(x0), // x start LSB
+ static_cast<uint8_t>(x1 >> 8), // x end MSB
+ static_cast<uint8_t>(x1) // x end LSB
+ };
+ WriteData(colArgs, sizeof(colArgs));
WriteCommand(static_cast<uint8_t>(Commands::RowAddressSet));
- WriteData(y0 >> 8);
- WriteData(y0 & 0xff);
- WriteData(y1 >> 8);
- WriteData(y1 & 0xff);
+ uint8_t rowArgs[] = {
+ static_cast<uint8_t>(y0 >> 8), // y start MSB
+ static_cast<uint8_t>(y0), // y start LSB
+ static_cast<uint8_t>(y1 >> 8), // y end MSB
+ static_cast<uint8_t>(y1) // y end LSB
+ };
+ memcpy(addrWindowArgs, rowArgs, sizeof(rowArgs));
+ WriteData(addrWindowArgs, sizeof(addrWindowArgs));
}
void St7789::WriteToRam(const uint8_t* data, size_t size) {
@@ -179,8 +171,12 @@ void St7789::DisplayOff() {
void St7789::VerticalScrollStartAddress(uint16_t line) {
verticalScrollingStartAddress = line;
WriteCommand(static_cast<uint8_t>(Commands::VerticalScrollStartAddress));
- WriteData(line >> 8u);
- WriteData(line & 0x00ffu);
+ uint8_t args[] = {
+ static_cast<uint8_t>(line >> 8), // Frame memory line pointer MSB
+ static_cast<uint8_t>(line) // Frame memory line pointer LSB
+ };
+ memcpy(verticalScrollArgs, args, sizeof(args));
+ WriteData(verticalScrollArgs, sizeof(verticalScrollArgs));
}
void St7789::Uninit() {