Skip to content

Commit 35606bc

Browse files
committed
Batch display command arguments
1 parent 06c6935 commit 35606bc

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

src/drivers/St7789.cpp

+26-31
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ void St7789::Init() {
1616
HardwareReset();
1717
SoftwareReset();
1818
SleepOut();
19-
ColMod();
19+
PixelFormat();
2020
MemoryDataAccessControl();
21-
ColumnAddressSet();
22-
RowAddressSet();
21+
SetAddrWindow(0, 0, Width, Height);
2322
// P8B Mirrored version does not need display inversion.
2423
#ifndef DRIVER_DISPLAY_MIRROR
2524
DisplayInversionOn();
@@ -97,8 +96,9 @@ void St7789::SleepIn() {
9796
sleepIn = true;
9897
}
9998

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

@@ -118,22 +118,6 @@ void St7789::MemoryDataAccessControl() {
118118
#endif
119119
}
120120

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-
137121
void St7789::DisplayInversionOn() {
138122
WriteCommand(static_cast<uint8_t>(Commands::DisplayInversionOn));
139123
}
@@ -148,16 +132,23 @@ void St7789::DisplayOn() {
148132

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

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

163154
void St7789::WriteToRam(const uint8_t* data, size_t size) {
@@ -179,8 +170,12 @@ void St7789::DisplayOff() {
179170
void St7789::VerticalScrollStartAddress(uint16_t line) {
180171
verticalScrollingStartAddress = line;
181172
WriteCommand(static_cast<uint8_t>(Commands::VerticalScrollStartAddress));
182-
WriteData(line >> 8u);
183-
WriteData(line & 0x00ffu);
173+
uint8_t args[] = {
174+
static_cast<uint8_t>(line >> 8), // Frame memory line pointer MSB
175+
static_cast<uint8_t>(line) // Frame memory line pointer LSB
176+
};
177+
memcpy(verticalScrollArgs, args, sizeof(args));
178+
WriteData(verticalScrollArgs, sizeof(verticalScrollArgs));
184179
}
185180

186181
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)