@@ -199,13 +199,18 @@ where
199
199
self . properties
200
200
. change_mode ( AddrMode :: Horizontal )
201
201
. terminal_err ( ) ?;
202
+ let offset_x = match self . properties . get_rotation ( ) {
203
+ DisplayRotation :: Rotate0 | DisplayRotation :: Rotate270 => DSIZE :: OFFSETX ,
204
+ DisplayRotation :: Rotate180 | DisplayRotation :: Rotate90 => {
205
+ // If segment remapping is flipped, we need to calculate
206
+ // the offset from the other edge of the display.
207
+ DSIZE :: DRIVER_COLS - DSIZE :: WIDTH - DSIZE :: OFFSETX
208
+ }
209
+ } ;
202
210
self . properties
203
211
. set_draw_area (
204
- ( DSIZE :: OFFSETX , DSIZE :: OFFSETY ) ,
205
- (
206
- DSIZE :: WIDTH + DSIZE :: OFFSETX ,
207
- DSIZE :: HEIGHT + DSIZE :: OFFSETY ,
208
- ) ,
212
+ ( offset_x, DSIZE :: OFFSETY ) ,
213
+ ( DSIZE :: WIDTH + offset_x, DSIZE :: HEIGHT + DSIZE :: OFFSETY ) ,
209
214
)
210
215
. terminal_err ( ) ?;
211
216
@@ -308,18 +313,26 @@ where
308
313
if column >= width || row >= height {
309
314
Err ( OutOfBounds )
310
315
} else {
316
+ let offset_x = match self . properties . get_rotation ( ) {
317
+ DisplayRotation :: Rotate0 | DisplayRotation :: Rotate270 => DSIZE :: OFFSETX ,
318
+ DisplayRotation :: Rotate180 | DisplayRotation :: Rotate90 => {
319
+ // If segment remapping is flipped, we need to calculate
320
+ // the offset from the other edge of the display.
321
+ DSIZE :: DRIVER_COLS - DSIZE :: WIDTH - DSIZE :: OFFSETX
322
+ }
323
+ } ;
311
324
match self . properties . get_rotation ( ) {
312
325
DisplayRotation :: Rotate0 | DisplayRotation :: Rotate180 => {
313
326
self . properties
314
- . set_column ( DSIZE :: OFFSETX + column * 8 )
327
+ . set_column ( offset_x + column * 8 )
315
328
. terminal_err ( ) ?;
316
329
self . properties
317
330
. set_row ( DSIZE :: OFFSETY + row * 8 )
318
331
. terminal_err ( ) ?;
319
332
}
320
333
DisplayRotation :: Rotate90 | DisplayRotation :: Rotate270 => {
321
334
self . properties
322
- . set_column ( DSIZE :: OFFSETX + row * 8 )
335
+ . set_column ( offset_x + row * 8 )
323
336
. terminal_err ( ) ?;
324
337
self . properties
325
338
. set_row ( DSIZE :: OFFSETY + column * 8 )
@@ -334,7 +347,11 @@ where
334
347
/// Reset the draw area and move pointer to the top left corner
335
348
fn reset_pos ( & mut self ) -> Result < ( ) , TerminalModeError > {
336
349
// Initialise the counter when we know it's valid
337
- self . cursor = Some ( Cursor :: new ( DSIZE :: WIDTH , DSIZE :: HEIGHT ) ) ;
350
+ let ( w, h) = match self . properties . get_rotation ( ) {
351
+ DisplayRotation :: Rotate0 | DisplayRotation :: Rotate180 => ( DSIZE :: WIDTH , DSIZE :: HEIGHT ) ,
352
+ DisplayRotation :: Rotate90 | DisplayRotation :: Rotate270 => ( DSIZE :: HEIGHT , DSIZE :: WIDTH ) ,
353
+ } ;
354
+ self . cursor = Some ( Cursor :: new ( w, h) ) ;
338
355
339
356
// Reset cursor position
340
357
self . set_position ( 0 , 0 ) ?;
0 commit comments