]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added ability to configure display rotation
authorMark Qvist <mark@unsigned.io>
Tue, 31 Dec 2024 12:23:48 +0000 (13:23 +0100)
committerMark Qvist <mark@unsigned.io>
Tue, 31 Dec 2024 12:23:48 +0000 (13:23 +0100)
Display.h
Framing.h
RNode_Firmware.ino
ROM.h
Utilities.h

index f3ba8b2f5279a9cc38c80576d7acadb20dcce892..903d84e91952bcd1ccaf70dbd0e320675390b263 100644 (file)
--- a/Display.h
+++ b/Display.h
@@ -201,6 +201,13 @@ bool display_init() {
       Wire.begin(SDA_OLED, SCL_OLED);
     #endif
 
+    #if HAS_EEPROM
+      uint8_t display_rotation = EEPROM.read(eeprom_addr(ADDR_CONF_DROT));
+    #elif MCU_VARIANT == MCU_NRF52
+      uint8_t display_rotation = eeprom_read(eeprom_addr(ADDR_CONF_DROT));
+    #endif
+    if (display_rotation < 0 or display_rotation > 3) display_rotation = 0xFF;
+
     #if DISP_CUSTOM_ADDR == true
       #if HAS_EEPROM
       uint8_t display_address = EEPROM.read(eeprom_addr(ADDR_CONF_DADR));
@@ -236,43 +243,52 @@ bool display_init() {
       return false;
     } else {
       set_contrast(&display, display_contrast);
-      #if BOARD_MODEL == BOARD_RNODE_NG_20
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(3);
-      #elif BOARD_MODEL == BOARD_RNODE_NG_21
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(3);
-      #elif BOARD_MODEL == BOARD_LORA32_V1_0
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(3);
-      #elif BOARD_MODEL == BOARD_LORA32_V2_0
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(3);
-      #elif BOARD_MODEL == BOARD_LORA32_V2_1
-        disp_mode = DISP_MODE_LANDSCAPE;
-        display.setRotation(0);
-      #elif BOARD_MODEL == BOARD_TBEAM
-        disp_mode = DISP_MODE_LANDSCAPE;
-        display.setRotation(0);
-      #elif BOARD_MODEL == BOARD_TBEAM_S_V1
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(1);
-      #elif BOARD_MODEL == BOARD_HELTEC32_V2
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(1);
-      #elif BOARD_MODEL == BOARD_HELTEC32_V3
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(1);
-      #elif BOARD_MODEL == BOARD_RAK4631
-        disp_mode = DISP_MODE_LANDSCAPE;
-        display.setRotation(0);
-      #elif BOARD_MODEL == BOARD_TDECK
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(3);
-      #else
-        disp_mode = DISP_MODE_PORTRAIT;
-        display.setRotation(3);
-      #endif
+      if (display_rotation != 0xFF) {
+        if (display_rotation == 0 || display_rotation == 2) {
+          disp_mode = DISP_MODE_LANDSCAPE;
+        } else {
+          disp_mode = DISP_MODE_PORTRAIT;
+        }
+        display.setRotation(display_rotation);
+      } else {
+        #if BOARD_MODEL == BOARD_RNODE_NG_20
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(3);
+        #elif BOARD_MODEL == BOARD_RNODE_NG_21
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(3);
+        #elif BOARD_MODEL == BOARD_LORA32_V1_0
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(3);
+        #elif BOARD_MODEL == BOARD_LORA32_V2_0
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(3);
+        #elif BOARD_MODEL == BOARD_LORA32_V2_1
+          disp_mode = DISP_MODE_LANDSCAPE;
+          display.setRotation(0);
+        #elif BOARD_MODEL == BOARD_TBEAM
+          disp_mode = DISP_MODE_LANDSCAPE;
+          display.setRotation(0);
+        #elif BOARD_MODEL == BOARD_TBEAM_S_V1
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(1);
+        #elif BOARD_MODEL == BOARD_HELTEC32_V2
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(1);
+        #elif BOARD_MODEL == BOARD_HELTEC32_V3
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(1);
+        #elif BOARD_MODEL == BOARD_RAK4631
+          disp_mode = DISP_MODE_LANDSCAPE;
+          display.setRotation(0);
+        #elif BOARD_MODEL == BOARD_TDECK
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(3);
+        #else
+          disp_mode = DISP_MODE_PORTRAIT;
+          display.setRotation(3);
+        #endif
+      }
 
       update_area_positions();
       for (int i = 0; i < WATERFALL_SIZE; i++) {
index c124ffb7ef5fafa090368dcd8afd3277a5c623a3..37065b7ae524e3a57128e14c5af8c20448d62efe 100644 (file)
--- a/Framing.h
+++ b/Framing.h
@@ -56,6 +56,7 @@
   #define CMD_DISP_INT    0x45
   #define CMD_DISP_ADDR   0x63
   #define CMD_DISP_BLNK   0x64
+  #define CMD_DISP_ROT    0x67
   #define CMD_NP_INT      0x65
   #define CMD_BT_CTRL     0x46
   #define CMD_BT_PIN      0x62
index d1e923725e2c38a24c7e8fb113dc46e276b1d03d..924bf3459ec6e1cd2657d24c48cebe3fd572b56c 100644 (file)
@@ -1099,6 +1099,21 @@ void serialCallback(uint8_t sbyte) {
             display_unblank();
         }
 
+      #endif
+    } else if (command == CMD_DISP_ROT) {
+      #if HAS_DISPLAY
+        if (sbyte == FESC) {
+            ESCAPE = true;
+        } else {
+            if (ESCAPE) {
+                if (sbyte == TFEND) sbyte = FEND;
+                if (sbyte == TFESC) sbyte = FESC;
+                ESCAPE = false;
+            }
+            drot_conf_save(sbyte);
+            display_unblank();
+        }
+
       #endif
     } else if (command == CMD_NP_INT) {
       #if HAS_NP
diff --git a/ROM.h b/ROM.h
index 9ab3a705e53738c4169d017e6e2e80dcfa0b8a9b..6f2ac2f54e8a2794ad5c5cae7b8b9e597ef35458 100644 (file)
--- a/ROM.h
+++ b/ROM.h
@@ -39,6 +39,7 @@
   #define ADDR_CONF_DINT 0xB2
   #define ADDR_CONF_DADR 0xB3
   #define ADDR_CONF_DBLK 0xB4
+  #define ADDR_CONF_DROT 0xB8
   #define ADDR_CONF_PSET 0xB5
   #define ADDR_CONF_PINT 0xB6
   #define ADDR_CONF_BSET 0xB7
index aa567880807a50a642913c8c0560cd63cd1d23f7..4eb1f78f3c92855972c64eddeb9e322bfb3fb724 100644 (file)
@@ -1507,6 +1507,16 @@ void db_conf_save(uint8_t val) {
        #endif
 }
 
+void drot_conf_save(uint8_t val) {
+       #if HAS_DISPLAY
+               if (val >= 0x00 and val <= 0x03) {
+                       eeprom_update(eeprom_addr(ADDR_CONF_BSET), CONF_OK_BYTE);
+                       eeprom_update(eeprom_addr(ADDR_CONF_DROT), val);
+                       hard_reset();
+               }
+       #endif
+}
+
 void np_int_conf_save(uint8_t p_int) {
        eeprom_update(eeprom_addr(ADDR_CONF_PSET), CONF_OK_BYTE);
        eeprom_update(eeprom_addr(ADDR_CONF_PINT), p_int);