From 85c0b9f932d31be3c91f2ceb858bb20497f15c11 Mon Sep 17 00:00:00 2001
From: Silvano Seva <silseva@fastwebnet.it>
Date: Sun, 21 Nov 2021 19:10:07 +0100
Subject: [PATCH] Added configuration option for inversion of touch screen Y
 coordinate.

Signed-off-by: Federico Terraneo <fede.tft@miosix.org>
---
 config/mxgui_settings.h            | 7 +++++++
 drivers/event_stm32f4discovery.cpp | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/config/mxgui_settings.h b/config/mxgui_settings.h
index f72ef70..5c54fe6 100644
--- a/config/mxgui_settings.h
+++ b/config/mxgui_settings.h
@@ -84,6 +84,13 @@ static const unsigned int level2MaxNumApps=4;
 //#define MXGUI_ORIENTATION_VERTICAL_MIRRORED
 //#define MXGUI_ORIENTATION_HORIZONTAL_MIRRORED
 
+///
+/// Invert touch screen Y coordinate.
+/// Required on some boards as the touchscreen sensor is mounted with an
+/// inverted vertical coordinate with respect to the display's one.
+///
+//#define MXGUI_TOUCH_INVERT_Y
+
 ///
 /// Select which fonts are required. Choose one or more
 ///
diff --git a/drivers/event_stm32f4discovery.cpp b/drivers/event_stm32f4discovery.cpp
index a4889d6..1324229 100644
--- a/drivers/event_stm32f4discovery.cpp
+++ b/drivers/event_stm32f4discovery.cpp
@@ -188,6 +188,9 @@ static Point getTouchData()
         int x=static_cast<int>(tsData[0])<<4 | tsData[1]>>4;
         int y=((static_cast<int>(tsData[1]) & 0xf)<<8) | tsData[2];
         x=4095-x; //X is swapped
+        #ifdef MXGUI_TOUCH_INVERT_Y
+        y=4095-y; //On some boards Y is swapped too
+        #endif
         //Calibration values. May vary from unit to unit
         const int xMin=300;
         const int xMax=3770;
-- 
GitLab