Skip to content

Commit f8f8993

Browse files
mark9064JF002
authored andcommitted
Batch display command arguments
1 parent fdc3b8b commit f8f8993

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

src/drivers/St7789.cpp

+27-31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <cstring>
12
#include "drivers/St7789.h"
23
#include <hal/nrf_gpio.h>
34
#include <nrfx_log.h>
@@ -16,10 +17,9 @@ void St7789::Init() {
1617
HardwareReset();
1718
SoftwareReset();
1819
SleepOut();
19-
ColMod();
20+
PixelFormat();
2021
MemoryDataAccessControl();
21-
ColumnAddressSet();
22-
RowAddressSet();
22+
SetAddrWindow(0, 0, Width, Height);
2323
// P8B Mirrored version does not need display inversion.
2424
#ifndef DRIVER_DISPLAY_MIRROR
2525
DisplayInversionOn();
@@ -97,8 +97,9 @@ void St7789::SleepIn() {
9797
sleepIn = true;
9898
}
9999

100-
void St7789::ColMod() {
101-
WriteCommand(static_cast<uint8_t>(Commands::ColMod));
100+
void St7789::PixelFormat() {
101+
WriteCommand(static_cast<uint8_t>(Commands::PixelFormat));
102+
// 65K colours, 16-bit per pixel
102103
WriteData(0x55);
103104
}
104105

@@ -118,22 +119,6 @@ void St7789::MemoryDataAccessControl() {
118119
#endif
119120
}
120121

121-
void St7789::ColumnAddressSet() {
122-
WriteCommand(static_cast<uint8_t>(Commands::ColumnAddressSet));
123-
WriteData(0x00);
124-
WriteData(0x00);
125-
WriteData(Width >> 8u);
126-
WriteData(Width & 0xffu);
127-
}
128-
129-
void St7789::RowAddressSet() {
130-
WriteCommand(static_cast<uint8_t>(Commands::RowAddressSet));
131-
WriteData(0x00);
132-
WriteData(0x00);
133-
WriteData(320u >> 8u);
134-
WriteData(320u & 0xffu);
135-
}
136-
137122
void St7789::DisplayInversionOn() {
138123
WriteCommand(static_cast<uint8_t>(Commands::DisplayInversionOn));
139124
}
@@ -148,16 +133,23 @@ void St7789::DisplayOn() {
148133

149134
void St7789::SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
150135
WriteCommand(static_cast<uint8_t>(Commands::ColumnAddressSet));
151-
WriteData(x0 >> 8);
152-
WriteData(x0 & 0xff);
153-
WriteData(x1 >> 8);
154-
WriteData(x1 & 0xff);
136+
uint8_t colArgs[] = {
137+
static_cast<uint8_t>(x0 >> 8), // x start MSB
138+
static_cast<uint8_t>(x0), // x start LSB
139+
static_cast<uint8_t>(x1 >> 8), // x end MSB
140+
static_cast<uint8_t>(x1) // x end LSB
141+
};
142+
WriteData(colArgs, sizeof(colArgs));
155143

156144
WriteCommand(static_cast<uint8_t>(Commands::RowAddressSet));
157-
WriteData(y0 >> 8);
158-
WriteData(y0 & 0xff);
159-
WriteData(y1 >> 8);
160-
WriteData(y1 & 0xff);
145+
uint8_t rowArgs[] = {
146+
static_cast<uint8_t>(y0 >> 8), // y start MSB
147+
static_cast<uint8_t>(y0), // y start LSB
148+
static_cast<uint8_t>(y1 >> 8), // y end MSB
149+
static_cast<uint8_t>(y1) // y end LSB
150+
};
151+
memcpy(addrWindowArgs, rowArgs, sizeof(rowArgs));
152+
WriteData(addrWindowArgs, sizeof(addrWindowArgs));
161153
}
162154

163155
void St7789::WriteToRam(const uint8_t* data, size_t size) {
@@ -179,8 +171,12 @@ void St7789::DisplayOff() {
179171
void St7789::VerticalScrollStartAddress(uint16_t line) {
180172
verticalScrollingStartAddress = line;
181173
WriteCommand(static_cast<uint8_t>(Commands::VerticalScrollStartAddress));
182-
WriteData(line >> 8u);
183-
WriteData(line & 0x00ffu);
174+
uint8_t args[] = {
175+
static_cast<uint8_t>(line >> 8), // Frame memory line pointer MSB
176+
static_cast<uint8_t>(line) // Frame memory line pointer LSB
177+
};
178+
memcpy(verticalScrollArgs, args, sizeof(args));
179+
WriteData(verticalScrollArgs, sizeof(verticalScrollArgs));
184180
}
185181

186182
void St7789::Uninit() {

src/drivers/St7789.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Pinetime {
4040
void SleepOut();
4141
void EnsureSleepOutPostDelay();
4242
void SleepIn();
43-
void ColMod();
43+
void PixelFormat();
4444
void MemoryDataAccessControl();
4545
void DisplayInversionOn();
4646
void NormalModeOn();
@@ -68,16 +68,17 @@ namespace Pinetime {
6868
MemoryDataAccessControl = 0x36,
6969
VerticalScrollDefinition = 0x33,
7070
VerticalScrollStartAddress = 0x37,
71-
ColMod = 0x3a,
71+
PixelFormat = 0x3a,
7272
VdvSet = 0xc4,
7373
};
7474
void WriteData(uint8_t data);
7575
void WriteData(const uint8_t* data, size_t size);
76-
void ColumnAddressSet();
7776

7877
static constexpr uint16_t Width = 240;
7978
static constexpr uint16_t Height = 320;
80-
void RowAddressSet();
79+
80+
uint8_t addrWindowArgs[4];
81+
uint8_t verticalScrollArgs[2];
8182
};
8283
}
8384
}

0 commit comments

Comments
 (0)