Skip to content

Commit 3f47089

Browse files
committed
rg_display+ili9341: RG_SCREEN_ROTATION now actually does something
It's simply impossible to intuitively map human-readable units (degrees or mirroring) to the actual reflected effect on all devices. There's too much hardware variability that we have to support. So what I did is make a small range of valid values and the user should try them one by one until it looks fine. Not ideal, but there's only 7 values to try...
1 parent a94c983 commit 3f47089

File tree

16 files changed

+49
-59
lines changed

16 files changed

+49
-59
lines changed

components/retro-go/drivers/display/ili9341.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
#include <driver/gpio.h>
55
#include <driver/ledc.h>
66

7-
#if defined(RG_SCREEN_ROTATE) && RG_SCREEN_ROTATE != 0
8-
#error "RG_SCREEN_ROTATE doesn't do anything on this driver, you have to use the 0x36 command during init!"
9-
#endif
10-
117
static spi_device_handle_t spi_dev;
128
static QueueHandle_t spi_transactions;
139
static QueueHandle_t spi_buffers;
@@ -236,17 +232,22 @@ static void lcd_init(void)
236232
rg_usleep(10 * 1000);
237233
#endif
238234

239-
ILI9341_CMD(0x01); // Reset
240-
rg_usleep(5 * 1000); // Wait 5ms after reset
241-
ILI9341_CMD(0x3A, 0X05); // Pixel Format Set RGB565
242-
#ifdef RG_SCREEN_INIT
243-
RG_SCREEN_INIT();
244-
#else
245-
#warning "LCD init sequence is not defined for this device!"
246-
#endif
247-
ILI9341_CMD(0x11); // Exit Sleep
248-
rg_usleep(10 * 1000);// Wait 10ms after sleep out
249-
ILI9341_CMD(0x29); // Display on
235+
ILI9341_CMD(0x01); // Reset
236+
rg_usleep(5 * 1000); // Wait 5ms after reset
237+
ILI9341_CMD(0x3A, 0X55); // COLMOD (Pixel Format Set RGB565 65k)
238+
#if defined(RG_SCREEN_ROTATION) && defined(RG_SCREEN_BGR)
239+
// The rotation is designed so that the user can simply try all values 0-7 to find what works.
240+
// It's simpler than trying to explain the MADCTL register bits, combined with hardware variations...
241+
ILI9341_CMD(0x36, (RG_SCREEN_BGR ? 0x08 : 0x00) | (RG_SCREEN_ROTATION << 5)); // MADCTL (0x08=BGR, 0x20=MV, 0x40=MX, 0x80=MY)
242+
#endif
243+
#ifdef RG_SCREEN_INIT
244+
RG_SCREEN_INIT();
245+
#else
246+
#warning "LCD init sequence is not defined for this device!"
247+
#endif
248+
ILI9341_CMD(0x11); // Exit Sleep
249+
rg_usleep(10 * 1000); // Wait 10ms after sleep out
250+
ILI9341_CMD(0x29); // Display on
250251
}
251252

252253
static void lcd_deinit(void)

components/retro-go/targets/byteboi-rev1/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#define RG_SCREEN_BACKLIGHT 0
2525
#define RG_SCREEN_WIDTH 320
2626
#define RG_SCREEN_HEIGHT 240
27-
#define RG_SCREEN_ROTATE 0
27+
#define RG_SCREEN_ROTATION 5 // Possible values are 0-7 (you'll have to experiment)
28+
#define RG_SCREEN_BGR 1 // Possible values are 0-1 (change if colors are bad)
2829
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0}
2930
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0}
3031
#define RG_SCREEN_INIT() \
@@ -39,7 +40,6 @@
3940
ILI9341_CMD(0xC1, 0x10); /* Power control //SAP[2:0];BT[3:0] */ \
4041
ILI9341_CMD(0xC5, 0x3e,0x28); /* VCM control */ \
4142
ILI9341_CMD(0xC7, 0x86); /* VCM control2 */ \
42-
ILI9341_CMD(0x36, 0xA8); /* Memory Access Control (MY|MV|BGR) */ \
4343
ILI9341_CMD(0xB1, 0x00, 0x10); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
4444
ILI9341_CMD(0xB6, 0x08, 0xC2, 0x27); /* Display Function Control */ \
4545
ILI9341_CMD(0xF6, 0x01, 0x30); \

components/retro-go/targets/crokpocket/config.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,11 @@
2020
#define RG_SCREEN_BACKLIGHT 1
2121
#define RG_SCREEN_WIDTH 320
2222
#define RG_SCREEN_HEIGHT 240
23-
#define RG_SCREEN_ROTATE 0
24-
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
23+
#define RG_SCREEN_ROTATION 0 // Possible values are 0-7 (you'll have to experiment)
24+
#define RG_SCREEN_BGR 1 // Possible values are 0-1 (change if colors are bad)
25+
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
2526
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
2627

27-
#define ST7789_MADCTL 0x36 // Memory Access Control
28-
#define ST7789_MADCTL_MV 0x20
29-
#define ST7789_MADCTL_RGB 0x00
30-
#define ST7789_MADCTL_BGR 0x08
31-
32-
3328
#define RG_SCREEN_INIT() \
3429
ILI9341_CMD(0xCF, 0x00, 0xc3, 0x30); \
3530
ILI9341_CMD(0xED, 0x64, 0x03, 0x12, 0x81); \
@@ -41,7 +36,6 @@
4136
ILI9341_CMD(0xC1, 0x12); /* Power control //SAP[2:0];BT[3:0] */ \
4237
ILI9341_CMD(0xC5, 0x32, 0x3C); /* VCM control */ \
4338
ILI9341_CMD(0xC7, 0x91); /* VCM control2 */ \
44-
ILI9341_CMD(ST7789_MADCTL, (ST7789_MADCTL_BGR)); \
4539
ILI9341_CMD(0xB1, 0x00, 0x10); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
4640
ILI9341_CMD(0xB6, 0x0A, 0xA2); /* Display Function Control */ \
4741
ILI9341_CMD(0xF6, 0x01, 0x30); \
@@ -75,7 +69,7 @@
7569
// Status LED
7670
#define RG_GPIO_LED GPIO_NUM_38
7771

78-
// SPI Display
72+
// SPI Display
7973
#define RG_GPIO_LCD_MISO GPIO_NUM_NC
8074
#define RG_GPIO_LCD_MOSI GPIO_NUM_12
8175
#define RG_GPIO_LCD_CLK GPIO_NUM_48

components/retro-go/targets/esp32-p4/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
#define RG_SCREEN_BACKLIGHT 0
6969
#define RG_SCREEN_WIDTH 320
7070
#define RG_SCREEN_HEIGHT 240
71-
#define RG_SCREEN_ROTATE 0
71+
#define RG_SCREEN_ROTATION 0 // Possible values are 0-7 (you'll have to experiment)
72+
#define RG_SCREEN_BGR 1 // Possible values are 0-1 (change if colors are bad)
7273
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
7374
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
7475
#define RG_SCREEN_PARTIAL_UPDATES 1
@@ -83,7 +84,6 @@ ILI9341_CMD(0xC0, 0x1B); /* Power control //VRH[5:0] */
8384
ILI9341_CMD(0xC1, 0x12); /* Power control //SAP[2:0];BT[3:0] */ \
8485
ILI9341_CMD(0xC5, 0x32, 0x3C); /* VCM control */ \
8586
ILI9341_CMD(0xC7, 0x91); /* VCM control2 */ \
86-
ILI9341_CMD(0x36, 0x08); /* Memory Access Control */ \
8787
ILI9341_CMD(0xB1, 0x00, 0x10); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
8888
ILI9341_CMD(0xB6, 0x0A, 0xA2); /* Display Function Control */ \
8989
ILI9341_CMD(0xF6, 0x01, 0x30); \

components/retro-go/targets/esplay-micro/config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#define RG_SCREEN_BACKLIGHT 1
2525
#define RG_SCREEN_WIDTH 320
2626
#define RG_SCREEN_HEIGHT 240
27-
#define RG_SCREEN_ROTATE 0
27+
#define RG_SCREEN_ROTATION 1 // Possible values are 0-7 (you'll have to experiment)
28+
#define RG_SCREEN_BGR 1 // Possible values are 0-1 (change if colors are bad)
2829
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0}
2930
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0}
3031
#define RG_SCREEN_INIT() \
@@ -37,8 +38,6 @@
3738
ILI9341_CMD(0xC0, 0x26); /* Power control */ \
3839
ILI9341_CMD(0xC1, 0x11); /* Power control */ \
3940
ILI9341_CMD(0xC5, 0x35, 0x3E); /* VCM control */ \
40-
ILI9341_CMD(0x36, 0x28); /* Memory Access Control (MV|BGR) */ \
41-
ILI9341_CMD(0x3A, 0x55); /* Pixel Format Set RGB565 */ \
4241
ILI9341_CMD(0xB1, 0x00, 0x1B); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
4342
ILI9341_CMD(0xB6, 0x0A, 0xA2); /* Display Function Control */ \
4443
ILI9341_CMD(0xF6, 0x01, 0x30); \

components/retro-go/targets/fri3d-2024/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#define RG_SCREEN_BACKLIGHT 0
2828
#define RG_SCREEN_WIDTH 296
2929
#define RG_SCREEN_HEIGHT 240
30-
#define RG_SCREEN_ROTATE 0
30+
#define RG_SCREEN_ROTATION 1 // Possible values are 0-7 (you'll have to experiment)
31+
#define RG_SCREEN_BGR 1 // Possible values are 0-1 (change if colors are bad)
3132
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
3233
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0} // Left, Top, Right, Bottom
3334
#define RG_SCREEN_INIT() \
@@ -41,7 +42,6 @@
4142
ILI9341_CMD(0xC1, 0x12); /* Power control //SAP[2:0];BT[3:0] */ \
4243
ILI9341_CMD(0xC5, 0x32, 0x3C); /* VCM control */ \
4344
ILI9341_CMD(0xC7, 0x91); /* VCM control2 */ \
44-
ILI9341_CMD(0x36, 0x28); /* Memory Access Control (MV|BGR) */ \
4545
ILI9341_CMD(0xB1, 0x00, 0x10); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
4646
ILI9341_CMD(0xB6, 0x0A, 0xA2); /* Display Function Control */ \
4747
ILI9341_CMD(0xF6, 0x01, 0x30); \

components/retro-go/targets/mrgc-g32/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@
6464
#define RG_SCREEN_BACKLIGHT 1
6565
#define RG_SCREEN_WIDTH 240
6666
#define RG_SCREEN_HEIGHT 320
67-
#define RG_SCREEN_ROTATE 0
67+
#define RG_SCREEN_ROTATION 0 // Possible values are 0-7 (you'll have to experiment)
68+
#define RG_SCREEN_BGR 0 // Possible values are 0-1 (change if colors are bad)
6869
#define RG_SCREEN_VISIBLE_AREA {0, 28, 0, 68} // left, top, right, bottom
6970
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0} // left, top, right, bottom
7071
#define RG_SCREEN_PARTIAL_UPDATES 1
7172
#define RG_SCREEN_INIT() \
72-
ILI9341_CMD(0x36, 0x00); \
7373
ILI9341_CMD(0xB1, 0x00, 0x10); \
7474
ILI9341_CMD(0xB2, 0x0c, 0x0c, 0x00, 0x33, 0x33); \
7575
ILI9341_CMD(0xB7, 0x35); \

components/retro-go/targets/mrgc-gbm/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#define RG_SCREEN_BACKLIGHT 1
2525
#define RG_SCREEN_WIDTH 240
2626
#define RG_SCREEN_HEIGHT 240
27-
#define RG_SCREEN_ROTATE 0
27+
#define RG_SCREEN_ROTATION 0 // Possible values are 0-7 (you'll have to experiment)
28+
#define RG_SCREEN_BGR 0 // Possible values are 0-1 (change if colors are bad)
2829
#define RG_SCREEN_VISIBLE_AREA {0, 38, 0, 10} /* Fullscreen for plastic case. Black bar on bottom for metal case. */
2930
// #define RG_SCREEN_VISIBLE_AREA {0, 38, 0, 0} /* Fullscreen for metal case. Cropped on bottom for plastic case. */
3031
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0}

components/retro-go/targets/nullnano/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#define RG_SCREEN_BACKLIGHT 1
2121
#define RG_SCREEN_WIDTH 300
2222
#define RG_SCREEN_HEIGHT 240
23-
#define RG_SCREEN_ROTATE 0
23+
#define RG_SCREEN_ROTATION 0 // Possible values are 0-7 (you'll have to experiment)
24+
#define RG_SCREEN_BGR 1 // Possible values are 0-1 (change if colors are bad)
2425
#define RG_SCREEN_VISIBLE_AREA {20, 0, 0, 0} // Left, Top, Right, Bottom
2526
#define RG_SCREEN_SAFE_AREA {20, 0, 20, 0} // Left, Top, Right, Bottom
2627
#define RG_SCREEN_INIT() \
@@ -34,7 +35,6 @@
3435
ILI9341_CMD(0xC1, 0x12); /* Power control //SAP[2:0];BT[3:0] */ \
3536
ILI9341_CMD(0xC5, 0x32, 0x3C); /* VCM control */ \
3637
ILI9341_CMD(0xC7, 0x91); /* VCM control2 */ \
37-
ILI9341_CMD(0x36, 0x08); /* Memory Access Control (BGR) */ \
3838
ILI9341_CMD(0xB1, 0x00, 0x10); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
3939
ILI9341_CMD(0xB6, 0x0A, 0xA2); /* Display Function Control */ \
4040
ILI9341_CMD(0xF6, 0x01, 0x30); \

components/retro-go/targets/odroid-go/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
#define RG_SCREEN_BACKLIGHT 1
6565
#define RG_SCREEN_WIDTH 320
6666
#define RG_SCREEN_HEIGHT 240
67-
#define RG_SCREEN_ROTATE 0
67+
#define RG_SCREEN_ROTATION 5 // Possible values are 0-7 (you'll have to experiment)
68+
#define RG_SCREEN_BGR 1 // Possible values are 0-1 (change if colors are bad)
6869
#define RG_SCREEN_VISIBLE_AREA {0, 0, 0, 0} // left, top, right, bottom
6970
#define RG_SCREEN_SAFE_AREA {0, 0, 0, 0} // left, top, right, bottom
7071
#define RG_SCREEN_PARTIAL_UPDATES 1
@@ -79,7 +80,6 @@
7980
ILI9341_CMD(0xC1, 0x12); /* Power control //SAP[2:0];BT[3:0] */ \
8081
ILI9341_CMD(0xC5, 0x32, 0x3C); /* VCM control */ \
8182
ILI9341_CMD(0xC7, 0x91); /* VCM control2 */ \
82-
ILI9341_CMD(0x36, 0xA8); /* Memory Access Control (MY|MV|BGR) */ \
8383
ILI9341_CMD(0xB1, 0x00, 0x10); /* Frame Rate Control (1B=70, 1F=61, 10=119) */ \
8484
ILI9341_CMD(0xB6, 0x0A, 0xA2); /* Display Function Control */ \
8585
ILI9341_CMD(0xF6, 0x01, 0x30); \

0 commit comments

Comments
 (0)