From b33b88c648aa1012daaf0478011dc3f33a5fa014 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 1 Aug 2017 11:43:57 +0200 Subject: [PATCH] Fix ST7787 display rotation With this change, both the hardware-scrolling examples (TFT_Terminal and TFT_Matrix) work correctly. Rotations 0, 1, 2, and 3 are defined as successive clockwise 90 degree rotations. Vertical refresh is defined to be in direction from low to high coordinate ("top to bottom", or "left to right" in landscape orientations). --- TFT_Drivers/ST7787_Rotation.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/TFT_Drivers/ST7787_Rotation.h b/TFT_Drivers/ST7787_Rotation.h index 13a0ebe..3b9f8f6 100644 --- a/TFT_Drivers/ST7787_Rotation.h +++ b/TFT_Drivers/ST7787_Rotation.h @@ -1,17 +1,25 @@ -// This is the command sequence that rotates the ST7735 driver coordinate frame +// This is the command sequence that rotates the ST7787 driver coordinate frame +// +// Rotation 0 is portrait mode. Rotations 1, 2, and 3 are rotated clockwise +// by 90, 180, and 270 degrees. +// +// Vertical refresh direction is set to be the same as data write order. +// So coordinate 0 is refresh first, and coordinate 319 is refreshed last. +// For some reason, counter to datasheet information, MADCTL must be set +// with the ML bit as the inverse of the MY bit to achieve this. rotation = m % 4; // Limit the range of values to 0-3 writecommand(TFT_MADCTL); switch (rotation) { case 0: - writedata(TFT_MAD_RGB); + writedata(TFT_MAD_ML | TFT_MAD_RGB); _width = TFT_WIDTH; _height = TFT_HEIGHT; break; case 1: - writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB); + writedata(TFT_MAD_ML | TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_RGB); _width = TFT_HEIGHT; _height = TFT_WIDTH; break;