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-
137122void St7789::DisplayInversionOn () {
138123 WriteCommand (static_cast <uint8_t >(Commands::DisplayInversionOn));
139124}
@@ -148,16 +133,23 @@ void St7789::DisplayOn() {
148133
149134void 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
163155void St7789::WriteToRam (const uint8_t * data, size_t size) {
@@ -179,8 +171,12 @@ void St7789::DisplayOff() {
179171void 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
186182void St7789::Uninit () {
0 commit comments