From 2604b44d646ed0b1afdaf67d087f06e50dfdaa16 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 31 Dec 2024 13:23:48 +0100 Subject: [PATCH] Added ability to configure display rotation --- Display.h | 90 +++++++++++++++++++++++++++------------------- Framing.h | 1 + RNode_Firmware.ino | 15 ++++++++ ROM.h | 1 + Utilities.h | 10 ++++++ 5 files changed, 80 insertions(+), 37 deletions(-) diff --git a/Display.h b/Display.h index f3ba8b2..903d84e 100644 --- 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++) { diff --git a/Framing.h b/Framing.h index c124ffb7..37065b7 100644 --- 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 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index d1e9237..924bf34 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -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 9ab3a70..6f2ac2f 100644 --- 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 diff --git a/Utilities.h b/Utilities.h index aa56788..4eb1f78 100644 --- a/Utilities.h +++ b/Utilities.h @@ -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);