Skip to content

Commit

Permalink
Merge pull request #350 from dwightmulcahy/rotation
Browse files Browse the repository at this point in the history
added consts for display rotation for clarification
  • Loading branch information
BitMaker-hub authored Apr 9, 2024
2 parents 9f4954c + 1e2e7c8 commit ab5916a
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 18 deletions.
10 changes: 6 additions & 4 deletions src/drivers/displays/amoledDisplayDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "displayDriver.h"


#ifdef AMOLED_DISPLAY

#include <rm67162.h>
Expand All @@ -10,6 +11,7 @@
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#include "rotation.h"

#define WIDTH 536
#define HEIGHT 240
Expand All @@ -34,7 +36,7 @@ void amoledDisplay_Init(void)
digitalWrite(38, OUTPUT);
#endif
rm67162_init();
lcd_setRotation(1);
lcd_setRotation(LANDSCAPE);

background.createSprite(WIDTH, HEIGHT);
background.setSwapBytes(true);
Expand All @@ -55,11 +57,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)
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/displays/dongleDisplayDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#include "rotation.h"

#ifdef USE_LED
#include <FastLED.h>
Expand Down Expand Up @@ -85,7 +86,7 @@ void dongleDisplay_Init(void)
#endif // USE_LED

tft.init();
tft.setRotation(3);
tft.setRotation(LANDSCAPE_INVERTED);
tft.setSwapBytes(true);
background.createSprite(BUFFER_WIDTH, BUFFER_HEIGHT);
background.setSwapBytes(true);
Expand All @@ -110,7 +111,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)
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/displays/esp23_2432s028r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "monitor.h"
#include "OpenFontRender.h"
#include <SPI.h>
#include "rotation.h"

#define WIDTH 130 //320
#define HEIGHT 170
Expand All @@ -31,7 +32,7 @@ bool hasChangedScreen = true;
void esp32_2432S028R_Init(void)
{
tft.init();
tft.setRotation(1);
tft.setRotation(ROTATION_90);
#ifdef ESP32_2432S028_2USB
/*
In addition to TFT_INVERSION this adjusts the gamma curve to have better
Expand Down Expand Up @@ -79,7 +80,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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/drivers/displays/m5stickCDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "media/Free_Fonts.h"
#include "version.h"
#include "monitor.h"
#include "rotation.h"

#define WIDTH 80
#define HEIGHT 160
Expand All @@ -21,7 +22,7 @@ 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);
M5.Axp.ScreenBreath(10); //screen brightness 7-15
Expand All @@ -42,8 +43,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)
Expand Down
42 changes: 42 additions & 0 deletions src/drivers/displays/rotation.h
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions src/drivers/displays/tDisplayDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#include "rotation.h"

#define WIDTH 340
#define HEIGHT 170
Expand All @@ -21,9 +22,9 @@ void tDisplay_Init(void)
{
tft.init();
#ifdef LILYGO_S3_T_EMBED
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
Expand All @@ -49,7 +50,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)
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/displays/tDisplayV1Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#include "rotation.h"

#define WIDTH 240
#define HEIGHT 135
Expand All @@ -20,7 +21,7 @@ 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
background.setSwapBytes(true);
Expand All @@ -45,7 +46,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)
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/displays/t_qtDisplayDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#include "rotation.h"

#define WIDTH 128
#define HEIGHT 128
Expand All @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit ab5916a

Please sign in to comment.