Skip to content

Commit 5510c82

Browse files
committed
PicoDisplay: Fix rotation offset for #562.
Pico Display would have a pixel offset at 90 and 180 degree rotations. Add a special case offset tweak for these, and demystify the rotate_180 variable.
1 parent 3a10b29 commit 5510c82

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

drivers/st7789/st7789.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ namespace pimoroni {
133133

134134
void ST7789::configure_display(Rotation rotate) {
135135

136-
bool rotate180 = rotate == ROTATE_180 || rotate == ROTATE_90;
137-
138136
if(rotate == ROTATE_90 || rotate == ROTATE_270) {
139137
std::swap(width, height);
140138
}
@@ -185,20 +183,30 @@ namespace pimoroni {
185183
// Pico Display
186184
if(width == 240 && height == 135) {
187185
caset[0] = 40; // 240 cols
188-
caset[1] = 279;
189-
raset[0] = 53; // 135 rows
190-
raset[1] = 187;
191-
madctl = rotate180 ? MADCTL::ROW_ORDER : MADCTL::COL_ORDER;
186+
caset[1] = 40 + width - 1;
187+
raset[0] = 52; // 135 rows
188+
raset[1] = 52 + height - 1;
189+
if (rotate == ROTATE_0) {
190+
raset[0] += 1;
191+
raset[1] += 1;
192+
}
193+
madctl = rotate == ROTATE_180 ? MADCTL::ROW_ORDER : MADCTL::COL_ORDER;
192194
madctl |= MADCTL::SWAP_XY | MADCTL::SCAN_ORDER;
193195
}
194196

195197
// Pico Display at 90 degree rotation
196198
if(width == 135 && height == 240) {
197199
caset[0] = 52; // 135 cols
198-
caset[1] = 186;
200+
caset[1] = 52 + width - 1;
199201
raset[0] = 40; // 240 rows
200-
raset[1] = 279;
201-
madctl = rotate180 ? (MADCTL::COL_ORDER | MADCTL::ROW_ORDER) : 0;
202+
raset[1] = 40 + height - 1;
203+
madctl = 0;
204+
if (rotate == ROTATE_90) {
205+
caset[0] += 1;
206+
caset[1] += 1;
207+
madctl = MADCTL::COL_ORDER | MADCTL::ROW_ORDER;
208+
}
209+
madctl = rotate == ROTATE_90 ? (MADCTL::COL_ORDER | MADCTL::ROW_ORDER) : 0;
202210
}
203211

204212
// Pico Display 2.0
@@ -207,7 +215,7 @@ namespace pimoroni {
207215
caset[1] = 319;
208216
raset[0] = 0;
209217
raset[1] = 239;
210-
madctl = rotate180 ? MADCTL::ROW_ORDER : MADCTL::COL_ORDER;
218+
madctl = (rotate == ROTATE_180 || rotate == ROTATE_90) ? MADCTL::ROW_ORDER : MADCTL::COL_ORDER;
211219
madctl |= MADCTL::SWAP_XY | MADCTL::SCAN_ORDER;
212220
}
213221

@@ -217,7 +225,7 @@ namespace pimoroni {
217225
caset[1] = 239;
218226
raset[0] = 0;
219227
raset[1] = 319;
220-
madctl = rotate180 ? (MADCTL::COL_ORDER | MADCTL::ROW_ORDER) : 0;
228+
madctl = (rotate == ROTATE_180 || rotate == ROTATE_90) ? (MADCTL::COL_ORDER | MADCTL::ROW_ORDER) : 0;
221229
}
222230

223231
// Byte swap the 16bit rows/cols values

0 commit comments

Comments
 (0)