Batch display command arguments

This commit is contained in:
mark9064 2024-04-04 19:29:46 +01:00 committed by JF
parent fdc3b8badb
commit f8f8993fac
2 changed files with 32 additions and 35 deletions

View file

@ -1,3 +1,4 @@
#include <cstring>
#include "drivers/St7789.h" #include "drivers/St7789.h"
#include <hal/nrf_gpio.h> #include <hal/nrf_gpio.h>
#include <nrfx_log.h> #include <nrfx_log.h>
@ -16,10 +17,9 @@ void St7789::Init() {
HardwareReset(); HardwareReset();
SoftwareReset(); SoftwareReset();
SleepOut(); SleepOut();
ColMod(); PixelFormat();
MemoryDataAccessControl(); MemoryDataAccessControl();
ColumnAddressSet(); SetAddrWindow(0, 0, Width, Height);
RowAddressSet();
// P8B Mirrored version does not need display inversion. // P8B Mirrored version does not need display inversion.
#ifndef DRIVER_DISPLAY_MIRROR #ifndef DRIVER_DISPLAY_MIRROR
DisplayInversionOn(); DisplayInversionOn();
@ -97,8 +97,9 @@ void St7789::SleepIn() {
sleepIn = true; sleepIn = true;
} }
void St7789::ColMod() { void St7789::PixelFormat() {
WriteCommand(static_cast<uint8_t>(Commands::ColMod)); WriteCommand(static_cast<uint8_t>(Commands::PixelFormat));
// 65K colours, 16-bit per pixel
WriteData(0x55); WriteData(0x55);
} }
@ -118,22 +119,6 @@ void St7789::MemoryDataAccessControl() {
#endif #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() { void St7789::DisplayInversionOn() {
WriteCommand(static_cast<uint8_t>(Commands::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) { void St7789::SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
WriteCommand(static_cast<uint8_t>(Commands::ColumnAddressSet)); WriteCommand(static_cast<uint8_t>(Commands::ColumnAddressSet));
WriteData(x0 >> 8); uint8_t colArgs[] = {
WriteData(x0 & 0xff); static_cast<uint8_t>(x0 >> 8), // x start MSB
WriteData(x1 >> 8); static_cast<uint8_t>(x0), // x start LSB
WriteData(x1 & 0xff); 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)); WriteCommand(static_cast<uint8_t>(Commands::RowAddressSet));
WriteData(y0 >> 8); uint8_t rowArgs[] = {
WriteData(y0 & 0xff); static_cast<uint8_t>(y0 >> 8), // y start MSB
WriteData(y1 >> 8); static_cast<uint8_t>(y0), // y start LSB
WriteData(y1 & 0xff); 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) { void St7789::WriteToRam(const uint8_t* data, size_t size) {
@ -179,8 +171,12 @@ void St7789::DisplayOff() {
void St7789::VerticalScrollStartAddress(uint16_t line) { void St7789::VerticalScrollStartAddress(uint16_t line) {
verticalScrollingStartAddress = line; verticalScrollingStartAddress = line;
WriteCommand(static_cast<uint8_t>(Commands::VerticalScrollStartAddress)); WriteCommand(static_cast<uint8_t>(Commands::VerticalScrollStartAddress));
WriteData(line >> 8u); uint8_t args[] = {
WriteData(line & 0x00ffu); 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() { void St7789::Uninit() {

View file

@ -40,7 +40,7 @@ namespace Pinetime {
void SleepOut(); void SleepOut();
void EnsureSleepOutPostDelay(); void EnsureSleepOutPostDelay();
void SleepIn(); void SleepIn();
void ColMod(); void PixelFormat();
void MemoryDataAccessControl(); void MemoryDataAccessControl();
void DisplayInversionOn(); void DisplayInversionOn();
void NormalModeOn(); void NormalModeOn();
@ -68,16 +68,17 @@ namespace Pinetime {
MemoryDataAccessControl = 0x36, MemoryDataAccessControl = 0x36,
VerticalScrollDefinition = 0x33, VerticalScrollDefinition = 0x33,
VerticalScrollStartAddress = 0x37, VerticalScrollStartAddress = 0x37,
ColMod = 0x3a, PixelFormat = 0x3a,
VdvSet = 0xc4, VdvSet = 0xc4,
}; };
void WriteData(uint8_t data); void WriteData(uint8_t data);
void WriteData(const uint8_t* data, size_t size); void WriteData(const uint8_t* data, size_t size);
void ColumnAddressSet();
static constexpr uint16_t Width = 240; static constexpr uint16_t Width = 240;
static constexpr uint16_t Height = 320; static constexpr uint16_t Height = 320;
void RowAddressSet();
uint8_t addrWindowArgs[4];
uint8_t verticalScrollArgs[2];
}; };
} }
} }