From d2940a8719f8674d9e6aa5d418c489938f352389 Mon Sep 17 00:00:00 2001 From: Serge Vakulenko Date: Thu, 19 Nov 2015 19:53:24 -0800 Subject: [PATCH] Fix screen orientation in the ILI9341 LCD driver. --- sys/pic32/gpanel-ili9341.c | 49 ++++++++++++++++++-------------------- sys/pic32/gpanel-nt35702.c | 18 ++++++++++---- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/sys/pic32/gpanel-ili9341.c b/sys/pic32/gpanel-ili9341.c index 34a2597..ebaf2fd 100644 --- a/sys/pic32/gpanel-ili9341.c +++ b/sys/pic32/gpanel-ili9341.c @@ -112,13 +112,12 @@ static int _width, _height; /* * Memory Access Control register */ -#define MADCTL_MY 0x80 -#define MADCTL_MX 0x40 -#define MADCTL_MV 0x20 -#define MADCTL_ML 0x10 -#define MADCTL_BGR 0x08 -#define MADCTL_MH 0x04 -#define MADCTL_RGB 0x00 +#define MADCTL_MY 0x80 /* Row address order */ +#define MADCTL_MX 0x40 /* Column address order */ +#define MADCTL_MV 0x20 /* Row/column exchange */ +#define MADCTL_ML 0x10 /* Vertical refresh order */ +#define MADCTL_BGR 0x08 /* Color filter selector: 0=RGB, 1=BGR */ +#define MADCTL_MH 0x04 /* Horisontal refresh direction: 1=left-to-right */ /* * Write a 8-bit value to the ILI9341 Command register. @@ -239,25 +238,25 @@ static void set_rotation(int rotation) write_command(ILI9341_Memory_Access_Control); switch (rotation & 3) { case 0: /* Portrait */ - write_data(MADCTL_MY | MADCTL_BGR); - _width = 240; - _height = 320; - break; - case 1: /* Landscape */ - write_data(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR); - _width = 320; - _height = 240; - break; - case 2: /* Upside down portrait */ write_data(MADCTL_MX | MADCTL_BGR); _width = 240; _height = 320; break; - case 3: /* Upside down landscape */ + case 1: /* Landscape */ write_data(MADCTL_MV | MADCTL_BGR); _width = 320; _height = 240; break; + case 2: /* Upside down portrait */ + write_data(MADCTL_MY | MADCTL_BGR); + _width = 240; + _height = 320; + break; + case 3: /* Upside down landscape */ + write_data(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR); + _width = 320; + _height = 240; + break; } } @@ -337,6 +336,9 @@ static void ili9341_draw_glyph(const struct gpanel_font_t *font, int h, w, c; unsigned bitmask = 0; + if (x + width > _width || y + font->height > _height) + return; + if (background >= 0) { /* * Clear background. @@ -393,9 +395,8 @@ void ili9341_init_display(struct gpanel_hw *h) write_command(ILI9341_No_Operation); write_command(ILI9341_No_Operation); - /* Need at least 200msec to restore after the soft Reset. */ - write_command(ILI9341_Software_Reset); - udelay(200000); + write_command(ILI9341_Sleep_OUT); + udelay(150000); write_command(ILI9341_Display_OFF); @@ -412,8 +413,6 @@ void ili9341_init_display(struct gpanel_hw *h) write_command(ILI9341_VCOM_Control_2); write_data(0xC0); - set_rotation(3); /* Landscape */ - write_command(ILI9341_Pixel_Format_Set); write_data(0x55); @@ -424,11 +423,9 @@ void ili9341_init_display(struct gpanel_hw *h) write_command(ILI9341_Entry_Mode_Set); write_data(0x07); - write_command(ILI9341_Sleep_OUT); - udelay(150000); - write_command(ILI9341_Display_ON); + set_rotation(1); /* Landscape */ set_window(0, 0, _width-1, _height-1); gpanel_cs_idle(); diff --git a/sys/pic32/gpanel-nt35702.c b/sys/pic32/gpanel-nt35702.c index 23568a7..2dc5744 100644 --- a/sys/pic32/gpanel-nt35702.c +++ b/sys/pic32/gpanel-nt35702.c @@ -110,6 +110,16 @@ static int _width, _height; #define NT35702_FRMCTR 0xFA /* Frame rate control */ #define NT35702_AVDDCLP 0xFD /* AVDD Clamp Voltage */ +/* + * Memory Access Control register + */ +#define MADCTL_MY 0x80 /* Row address order */ +#define MADCTL_MX 0x40 /* Column address order */ +#define MADCTL_MV 0x20 /* Row/column exchange */ +#define MADCTL_ML 0x10 /* Vertical refresh order */ +#define MADCTL_BGR 0x08 /* Color filter selector: 0=RGB, 1=BGR */ +#define MADCTL_MH 0x04 /* Horisontal refresh direction: 1=left-to-right */ + /* * Write a 8-bit value to the NT35702 Command register. */ @@ -229,22 +239,22 @@ static void set_rotation(int rotation) write_command(NT35702_MADCTL); switch (rotation & 3) { case 0: /* Portrait */ - write_data(0xC8); + write_data(MADCTL_MX | MADCTL_MY | MADCTL_BGR); _width = 240; _height = 320; break; case 1: /* Landscape */ - write_data(0xA8); + write_data(MADCTL_MY | MADCTL_MV | MADCTL_BGR); _width = 320; _height = 240; break; case 2: /* Upside down portrait */ - write_data(0x08); + write_data(MADCTL_BGR); _width = 240; _height = 320; break; case 3: /* Upside down landscape */ - write_data(0x68); + write_data(MADCTL_MX | MADCTL_MV | MADCTL_BGR); _width = 320; _height = 240; break;