@@ -51,13 +51,13 @@ POSSIBILITY OF SUCH DAMAGE.
51
51
#include " sdkconfig.h"
52
52
53
53
/* Rotation Defines*/
54
- #define MADCTL_MY 0x80
55
- #define MADCTL_MX 0x40
56
- #define MADCTL_MV 0x20
54
+ #define MADCTL_MY 0x80 // Y-mirror
55
+ #define MADCTL_MX 0x40 // X-mirror
56
+ #define MADCTL_MV 0x20 // X-Y exchange
57
57
#define MADCTL_ML 0x10
58
58
#define MADCTL_RGB 0x00
59
59
#define MADCTL_BGR 0x08
60
- #define MADCTL_MH 0x04
60
+ #define MADCTL_MH 0x04 // Horizontal lcd refresh direction
61
61
62
62
63
63
#define SWAPBYTES (i ) ((i>>8 ) | (i<<8 ))
@@ -103,6 +103,22 @@ void CEspLcd::setSpiBus(lcd_conf_t *lcd_conf)
103
103
104
104
void CEspLcd::setAddrWindow (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
105
105
{
106
+ /*
107
+ * If screen is 240x240, an offset must be added when Y is mirrored because
108
+ * st7789 controller is for 320x240 and therefore the starting address is 80
109
+ * pixels below the screen.
110
+ * TODO: adding a start_x and start_y would be cleaner and safer
111
+ */
112
+ if (m_width == 240 && m_height == 240 ) {
113
+ if (rotation == 2 ) { // Y is mirrored
114
+ y0 += 80 ;
115
+ y1 += 80 ;
116
+ } else if (rotation == 3 ) { // X-Y are exchanged
117
+ x0 += 80 ;
118
+ x1 += 80 ;
119
+ }
120
+ }
121
+
106
122
xSemaphoreTakeRecursive (spi_mux, portMAX_DELAY);
107
123
transmitCmdData (LCD_CASET, MAKEWORD (x0 >> 8 , x0 & 0xFF , x1 >> 8 , x1 & 0xFF ));
108
124
transmitCmdData (LCD_PASET, MAKEWORD (y0 >> 8 , y0 & 0xFF , y1 >> 8 , y1 & 0xFF ));
@@ -409,22 +425,22 @@ void CEspLcd::setRotation(uint8_t m)
409
425
uint8_t data = 0 ;
410
426
rotation = m % 4 ; // Can't be more than 3
411
427
switch (rotation) {
412
- case 0 :
428
+ case 0 : // 0°
413
429
data = MADCTL_MX | MADCTL_BGR;
414
430
_width = m_width;
415
431
_height = m_height;
416
432
break ;
417
- case 1 :
433
+ case 1 : // 90° (counterclockwise)
418
434
data = MADCTL_MV | MADCTL_BGR;
419
435
_width = m_height;
420
436
_height = m_width;
421
437
break ;
422
- case 2 :
438
+ case 2 : // 180° (counterclockwise)
423
439
data = MADCTL_MY | MADCTL_BGR;
424
440
_width = m_width;
425
441
_height = m_height;
426
442
break ;
427
- case 3 :
443
+ case 3 : // 270° (counterclockwise)
428
444
data = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR;
429
445
_width = m_height;
430
446
_height = m_width;
0 commit comments