From e002eb47a584956234581c62bd254557c6041fa8 Mon Sep 17 00:00:00 2001 From: dwightmulcahy Date: Fri, 15 Mar 2024 17:42:10 -0500 Subject: [PATCH 1/2] added consts for display rotation for clarification --- src/drivers/displays/amoledDisplayDriver.cpp | 11 +++-- src/drivers/displays/dongleDisplayDriver.cpp | 6 ++- src/drivers/displays/esp23_2432s028r.cpp | 6 ++- src/drivers/displays/m5stickCDriver.cpp | 7 ++-- src/drivers/displays/rotation.h | 42 ++++++++++++++++++++ src/drivers/displays/tDisplayDriver.cpp | 8 ++-- src/drivers/displays/tDisplayV1Driver.cpp | 6 ++- src/drivers/displays/t_qtDisplayDriver.cpp | 5 ++- 8 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 src/drivers/displays/rotation.h diff --git a/src/drivers/displays/amoledDisplayDriver.cpp b/src/drivers/displays/amoledDisplayDriver.cpp index 67fb27c..8c3c88d 100644 --- a/src/drivers/displays/amoledDisplayDriver.cpp +++ b/src/drivers/displays/amoledDisplayDriver.cpp @@ -1,5 +1,6 @@ #include "displayDriver.h" + #ifdef AMOLED_DISPLAY #include @@ -10,6 +11,7 @@ #include "version.h" #include "monitor.h" #include "OpenFontRender.h" +#include "rotation.h" #define WIDTH 536 #define HEIGHT 240 @@ -30,7 +32,8 @@ TFT_eSprite background = TFT_eSprite(&tft); void amoledDisplay_Init(void) { rm67162_init(); - lcd_setRotation(1); +// lcd_setRotation(1); + lcd_setRotation(LANDSCAPE); background.createSprite(WIDTH, HEIGHT); background.setSwapBytes(true); @@ -51,11 +54,11 @@ void amoledDisplay_AlternateScreenState(void) screen_state ^= 1; } -int screen_rotation = 1; +int screen_rotation = LANDSCAPE; void amoledDisplay_AlternateRotation(void) { - screen_rotation == 1 ? lcd_setRotation(3) : lcd_setRotation(1); - screen_rotation ^= 1; + screen_rotation = flipRotation(screen_rotation); + screen_rotation ^= 1; } void amoledDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/dongleDisplayDriver.cpp b/src/drivers/displays/dongleDisplayDriver.cpp index e790eb9..5e6bdd9 100644 --- a/src/drivers/displays/dongleDisplayDriver.cpp +++ b/src/drivers/displays/dongleDisplayDriver.cpp @@ -9,6 +9,7 @@ #include "version.h" #include "monitor.h" #include "OpenFontRender.h" +#include "rotation.h" #ifdef USE_LED #include @@ -85,7 +86,8 @@ void dongleDisplay_Init(void) #endif // USE_LED tft.init(); - tft.setRotation(3); +// tft.setRotation(ROTATION_270); + tft.setRotation(LANDSCAPE_INVERTED); tft.setSwapBytes(true); background.createSprite(BUFFER_WIDTH, BUFFER_HEIGHT); background.setSwapBytes(true); @@ -110,7 +112,7 @@ void dongleDisplay_AlternateScreenState(void) void dongleDisplay_AlternateRotation(void) { - tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1); + tft.setRotation(flipRotation(tft.getRotation())); } void dongleDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/esp23_2432s028r.cpp b/src/drivers/displays/esp23_2432s028r.cpp index ec9431f..884b6fc 100644 --- a/src/drivers/displays/esp23_2432s028r.cpp +++ b/src/drivers/displays/esp23_2432s028r.cpp @@ -12,6 +12,7 @@ #include "monitor.h" #include "OpenFontRender.h" #include +#include "rotation.h" #define WIDTH 130 //320 #define HEIGHT 170 @@ -31,7 +32,8 @@ bool hasChangedScreen = true; void esp32_2432S028R_Init(void) { tft.init(); - tft.setRotation(1); +// tft.setRotation(1); + tft.setRotation(ROTATION_90); #ifdef ESP32_2432S028_2USB /* In addition to TFT_INVERSION this adjusts the gamma curve to have better @@ -79,7 +81,7 @@ void esp32_2432S028R_AlternateScreenState(void) void esp32_2432S028R_AlternateRotation(void) { - tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1); + tft.setRotation(flipRotation(tft.getRotation())); hasChangedScreen = true; } diff --git a/src/drivers/displays/m5stickCDriver.cpp b/src/drivers/displays/m5stickCDriver.cpp index c18ace3..ddd0a11 100644 --- a/src/drivers/displays/m5stickCDriver.cpp +++ b/src/drivers/displays/m5stickCDriver.cpp @@ -9,6 +9,7 @@ #include "media/Free_Fonts.h" #include "version.h" #include "monitor.h" +#include "rotation.h" #define WIDTH 80 #define HEIGHT 160 @@ -21,7 +22,8 @@ int screen_state = 1; void m5stickCDriver_Init(void) { M5.begin(); - M5.Lcd.setRotation(1); +// M5.Lcd.setRotation(1); + M5.Lcd.setRotation(LANDSCAPE); M5.Lcd.setTextSize(1); M5.Lcd.fillScreen(BLACK); M5.Axp.ScreenBreath(10); //screen brightness 7-15 @@ -42,8 +44,7 @@ void m5stickCDriver_AlternateScreenState(void) void m5stickCDriver_AlternateRotation(void) { - if (M5.Lcd.getRotation() == 3) M5.Lcd.setRotation(1); - else M5.Lcd.setRotation(3); + M5.Lcd.setRotation(flipRotation(M5.Lcd.getRotation())); } void m5stickCDriver_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/rotation.h b/src/drivers/displays/rotation.h new file mode 100644 index 0000000..f931df6 --- /dev/null +++ b/src/drivers/displays/rotation.h @@ -0,0 +1,42 @@ +// +// Rotation can be 0, 90, 180 or 270 degrees, but TFT_eSPI cryptically +// identifies these as 0, 1, 2, and 3. ?!?!?!?!?!? +// +// Created by dwight on 3/14/24. +// + +#ifndef NERDMINER_V2_ROTATION_H + +// Rotation value 0 sets the display to a portrait (tall) mode, with the USB jack at the top right. +#define ROTATION_0 0 +#define PORTRAIT ROTATION_0 + +// Rotation 1 is landscape (wide) mode, with the USB jack at the bottom right. +#define ROTATION_90 1 +#define LANDSCAPE ROTATION_90 + +// Rotation value 2 is also a portrait mode, with the USB jack at the bottom left. +#define ROTATION_180 2 +#define PORTRAIT_INVERTED ROTATION_180 + +// Rotation 3 is also landscape, but with the USB jack at the top left. +#define ROTATION_270 3 +#define LANDSCAPE_INVERTED ROTATION_270 + +// Helper function to rotate display left (-90 deg) +int rotationLeft(int d) { + return (d-ROTATION_90) % 4; +} + +// Helper function to rotate display right (90 deg) +int rotationRight(int d) { + return (d+ROTATION_90) % 4; +} + +// Helper function to rotate display 180 deg +int flipRotation(int d) { + return (d+ROTATION_180) % 4; +} + +#define NERDMINER_V2_ROTATION_H +#endif //NERDMINER_V2_ROTATION_H diff --git a/src/drivers/displays/tDisplayDriver.cpp b/src/drivers/displays/tDisplayDriver.cpp index e78d00d..08216f4 100644 --- a/src/drivers/displays/tDisplayDriver.cpp +++ b/src/drivers/displays/tDisplayDriver.cpp @@ -9,6 +9,7 @@ #include "version.h" #include "monitor.h" #include "OpenFontRender.h" +#include "rotation.h" #define WIDTH 340 #define HEIGHT 170 @@ -21,9 +22,10 @@ void tDisplay_Init(void) { tft.init(); #ifdef LILYGO_S3_T_EMBED - tft.setRotation(3); +// tft.setRotation(3); + tft.setRotation(ROTATION_270); #else - tft.setRotation(1); + tft.setRotation(ROTATION_90); #endif tft.setSwapBytes(true); // Swap the colour byte order when rendering background.createSprite(WIDTH, HEIGHT); // Background Sprite @@ -49,7 +51,7 @@ void tDisplay_AlternateScreenState(void) void tDisplay_AlternateRotation(void) { - tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1); + tft.setRotation(flipRotation(tft.getRotation())); } void tDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/tDisplayV1Driver.cpp b/src/drivers/displays/tDisplayV1Driver.cpp index 8c8fee2..2a89f57 100644 --- a/src/drivers/displays/tDisplayV1Driver.cpp +++ b/src/drivers/displays/tDisplayV1Driver.cpp @@ -9,6 +9,7 @@ #include "version.h" #include "monitor.h" #include "OpenFontRender.h" +#include "rotation.h" #define WIDTH 240 #define HEIGHT 135 @@ -20,7 +21,8 @@ TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite void tDisplay_Init(void) { tft.init(); - tft.setRotation(1); +// tft.setRotation(1); + tft.setRotation(ROTATION_90); tft.setSwapBytes(true); // Swap the colour byte order when rendering background.createSprite(WIDTH, HEIGHT); // Background Sprite background.setSwapBytes(true); @@ -45,7 +47,7 @@ void tDisplay_AlternateScreenState(void) void tDisplay_AlternateRotation(void) { - tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1); + tft.setRotation(flipRotation(tft.getRotation())); } void tDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/t_qtDisplayDriver.cpp b/src/drivers/displays/t_qtDisplayDriver.cpp index 453bbf2..ef9d642 100644 --- a/src/drivers/displays/t_qtDisplayDriver.cpp +++ b/src/drivers/displays/t_qtDisplayDriver.cpp @@ -9,6 +9,7 @@ #include "version.h" #include "monitor.h" #include "OpenFontRender.h" +#include "rotation.h" #define WIDTH 128 #define HEIGHT 128 @@ -20,7 +21,7 @@ TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite void t_qtDisplay_Init(void) { tft.init(); - tft.setRotation(1); + tft.setRotation(LANDSCAPE); tft.setSwapBytes(true); // Swap the colour byte order when rendering background.createSprite(WIDTH, HEIGHT); // Background Sprite background.setSwapBytes(true); @@ -45,7 +46,7 @@ void t_qtDisplay_AlternateScreenState(void) void t_qtDisplay_AlternateRotation(void) { - tft.setRotation((tft.getRotation()+1) % 4); + tft.setRotation(rotationRight(tft.getRotation())); } void t_qtDisplay_MinerScreen(unsigned long mElapsed) From 1e2e7c838add5b1dbd0ab0075532cd9ea1e8e19f Mon Sep 17 00:00:00 2001 From: dwightmulcahy Date: Fri, 15 Mar 2024 17:47:55 -0500 Subject: [PATCH 2/2] removed commented out stuff and clean up --- src/drivers/displays/amoledDisplayDriver.cpp | 1 - src/drivers/displays/dongleDisplayDriver.cpp | 3 +-- src/drivers/displays/esp23_2432s028r.cpp | 3 +-- src/drivers/displays/m5stickCDriver.cpp | 3 +-- src/drivers/displays/tDisplayDriver.cpp | 3 +-- src/drivers/displays/tDisplayV1Driver.cpp | 3 +-- src/drivers/displays/t_qtDisplayDriver.cpp | 2 +- 7 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/drivers/displays/amoledDisplayDriver.cpp b/src/drivers/displays/amoledDisplayDriver.cpp index 8c3c88d..5c8a344 100644 --- a/src/drivers/displays/amoledDisplayDriver.cpp +++ b/src/drivers/displays/amoledDisplayDriver.cpp @@ -32,7 +32,6 @@ TFT_eSprite background = TFT_eSprite(&tft); void amoledDisplay_Init(void) { rm67162_init(); -// lcd_setRotation(1); lcd_setRotation(LANDSCAPE); background.createSprite(WIDTH, HEIGHT); diff --git a/src/drivers/displays/dongleDisplayDriver.cpp b/src/drivers/displays/dongleDisplayDriver.cpp index 5e6bdd9..7a71df5 100644 --- a/src/drivers/displays/dongleDisplayDriver.cpp +++ b/src/drivers/displays/dongleDisplayDriver.cpp @@ -86,7 +86,6 @@ void dongleDisplay_Init(void) #endif // USE_LED tft.init(); -// tft.setRotation(ROTATION_270); tft.setRotation(LANDSCAPE_INVERTED); tft.setSwapBytes(true); background.createSprite(BUFFER_WIDTH, BUFFER_HEIGHT); @@ -112,7 +111,7 @@ void dongleDisplay_AlternateScreenState(void) void dongleDisplay_AlternateRotation(void) { - tft.setRotation(flipRotation(tft.getRotation())); + tft.setRotation( flipRotation(tft.getRotation()) ); } void dongleDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/esp23_2432s028r.cpp b/src/drivers/displays/esp23_2432s028r.cpp index 884b6fc..8c55c08 100644 --- a/src/drivers/displays/esp23_2432s028r.cpp +++ b/src/drivers/displays/esp23_2432s028r.cpp @@ -32,7 +32,6 @@ bool hasChangedScreen = true; void esp32_2432S028R_Init(void) { tft.init(); -// tft.setRotation(1); tft.setRotation(ROTATION_90); #ifdef ESP32_2432S028_2USB /* @@ -81,7 +80,7 @@ void esp32_2432S028R_AlternateScreenState(void) void esp32_2432S028R_AlternateRotation(void) { - tft.setRotation(flipRotation(tft.getRotation())); + tft.setRotation( flipRotation(tft.getRotation()) ); hasChangedScreen = true; } diff --git a/src/drivers/displays/m5stickCDriver.cpp b/src/drivers/displays/m5stickCDriver.cpp index ddd0a11..3cf98d5 100644 --- a/src/drivers/displays/m5stickCDriver.cpp +++ b/src/drivers/displays/m5stickCDriver.cpp @@ -22,7 +22,6 @@ int screen_state = 1; void m5stickCDriver_Init(void) { M5.begin(); -// M5.Lcd.setRotation(1); M5.Lcd.setRotation(LANDSCAPE); M5.Lcd.setTextSize(1); M5.Lcd.fillScreen(BLACK); @@ -44,7 +43,7 @@ void m5stickCDriver_AlternateScreenState(void) void m5stickCDriver_AlternateRotation(void) { - M5.Lcd.setRotation(flipRotation(M5.Lcd.getRotation())); + M5.Lcd.setRotation( flipRotation(M5.Lcd.getRotation()) ); } void m5stickCDriver_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/tDisplayDriver.cpp b/src/drivers/displays/tDisplayDriver.cpp index 08216f4..88c0344 100644 --- a/src/drivers/displays/tDisplayDriver.cpp +++ b/src/drivers/displays/tDisplayDriver.cpp @@ -22,7 +22,6 @@ void tDisplay_Init(void) { tft.init(); #ifdef LILYGO_S3_T_EMBED -// tft.setRotation(3); tft.setRotation(ROTATION_270); #else tft.setRotation(ROTATION_90); @@ -51,7 +50,7 @@ void tDisplay_AlternateScreenState(void) void tDisplay_AlternateRotation(void) { - tft.setRotation(flipRotation(tft.getRotation())); + tft.setRotation( flipRotation(tft.getRotation()) ); } void tDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/tDisplayV1Driver.cpp b/src/drivers/displays/tDisplayV1Driver.cpp index 2a89f57..080a1a7 100644 --- a/src/drivers/displays/tDisplayV1Driver.cpp +++ b/src/drivers/displays/tDisplayV1Driver.cpp @@ -21,7 +21,6 @@ TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite void tDisplay_Init(void) { tft.init(); -// tft.setRotation(1); tft.setRotation(ROTATION_90); tft.setSwapBytes(true); // Swap the colour byte order when rendering background.createSprite(WIDTH, HEIGHT); // Background Sprite @@ -47,7 +46,7 @@ void tDisplay_AlternateScreenState(void) void tDisplay_AlternateRotation(void) { - tft.setRotation(flipRotation(tft.getRotation())); + tft.setRotation( flipRotation(tft.getRotation()) ); } void tDisplay_MinerScreen(unsigned long mElapsed) diff --git a/src/drivers/displays/t_qtDisplayDriver.cpp b/src/drivers/displays/t_qtDisplayDriver.cpp index ef9d642..9cd8338 100644 --- a/src/drivers/displays/t_qtDisplayDriver.cpp +++ b/src/drivers/displays/t_qtDisplayDriver.cpp @@ -46,7 +46,7 @@ void t_qtDisplay_AlternateScreenState(void) void t_qtDisplay_AlternateRotation(void) { - tft.setRotation(rotationRight(tft.getRotation())); + tft.setRotation( rotationRight(tft.getRotation()) ); } void t_qtDisplay_MinerScreen(unsigned long mElapsed)