From ea72abff22e416b4c813d7ba6810c38d0c2755a4 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 14 Dec 2024 20:21:19 -0600 Subject: [PATCH] Posthumous tronk --- src/mesh/NodeDB.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 201304395f..7fe5bd6568 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -72,22 +72,24 @@ static unsigned char userprefs_admin_key_2[] = USERPREFS_USE_ADMIN_KEY_2; #ifdef HELTEC_MESH_NODE_T114 -uint32_t read8(uint8_t bits, uint8_t dummy,uint8_t cs,uint8_t sck,uint8_t mosi,uint8_t dc,uint8_t rst) +uint32_t read8(uint8_t bits, uint8_t dummy, uint8_t cs, uint8_t sck, uint8_t mosi, uint8_t dc, uint8_t rst) { uint32_t ret = 0; uint8_t SDAPIN = mosi; pinMode(SDAPIN, INPUT_PULLUP); digitalWrite(dc, HIGH); - for (int i = 0; i < dummy; i++) { //any dummy clocks + for (int i = 0; i < dummy; i++) { // any dummy clocks digitalWrite(sck, HIGH); delay(1); digitalWrite(sck, LOW); delay(1); } - for (int i = 0; i < bits; i++) { // read results + for (int i = 0; i < bits; i++) { // read results ret <<= 1; delay(1); - if (digitalRead(SDAPIN)) ret |= 1;; + if (digitalRead(SDAPIN)) + ret |= 1; + ; digitalWrite(sck, HIGH); delay(1); digitalWrite(sck, LOW); @@ -95,11 +97,11 @@ uint32_t read8(uint8_t bits, uint8_t dummy,uint8_t cs,uint8_t sck,uint8_t mosi,u return ret; } -void write9(uint8_t val, uint8_t dc_val,uint8_t cs,uint8_t sck,uint8_t mosi,uint8_t dc,uint8_t rst) +void write9(uint8_t val, uint8_t dc_val, uint8_t cs, uint8_t sck, uint8_t mosi, uint8_t dc, uint8_t rst) { pinMode(mosi, OUTPUT); digitalWrite(dc, dc_val); - for (int i = 0; i < 8; i++) { //send command + for (int i = 0; i < 8; i++) { // send command digitalWrite(mosi, (val & 0x80) != 0); delay(1); digitalWrite(sck, HIGH); @@ -109,16 +111,16 @@ void write9(uint8_t val, uint8_t dc_val,uint8_t cs,uint8_t sck,uint8_t mosi,uint } } -uint32_t readwrite8(uint8_t cmd, uint8_t bits, uint8_t dummy,uint8_t cs,uint8_t sck,uint8_t mosi,uint8_t dc,uint8_t rst) +uint32_t readwrite8(uint8_t cmd, uint8_t bits, uint8_t dummy, uint8_t cs, uint8_t sck, uint8_t mosi, uint8_t dc, uint8_t rst) { digitalWrite(cs, LOW); - write9(cmd, 0,cs,sck,mosi,dc,rst); - uint32_t ret = read8(bits, dummy,cs,sck,mosi,dc,rst); + write9(cmd, 0, cs, sck, mosi, dc, rst); + uint32_t ret = read8(bits, dummy, cs, sck, mosi, dc, rst); digitalWrite(cs, HIGH); return ret; } -uint32_t get_st7789_id(uint8_t cs,uint8_t sck,uint8_t mosi,uint8_t dc,uint8_t rst) +uint32_t get_st7789_id(uint8_t cs, uint8_t sck, uint8_t mosi, uint8_t dc, uint8_t rst) { pinMode(cs, OUTPUT); digitalWrite(cs, HIGH); @@ -127,14 +129,14 @@ uint32_t get_st7789_id(uint8_t cs,uint8_t sck,uint8_t mosi,uint8_t dc,uint8_t rs pinMode(mosi, OUTPUT); pinMode(dc, OUTPUT); pinMode(rst, OUTPUT); - digitalWrite(rst, LOW); //Hardware Reset + digitalWrite(rst, LOW); // Hardware Reset delay(10); digitalWrite(rst, HIGH); delay(10); uint32_t ID = 0; - ID = readwrite8(0x04, 24, 1,cs,sck,mosi,dc,rst); - ID = readwrite8(0x04, 24, 1,cs,sck,mosi,dc,rst); //ST7789 needs twice + ID = readwrite8(0x04, 24, 1, cs, sck, mosi, dc, rst); + ID = readwrite8(0x04, 24, 1, cs, sck, mosi, dc, rst); // ST7789 needs twice return ID; } @@ -560,9 +562,8 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) defined(HX8357_CS) || defined(USE_ST7789) bool hasScreen = true; #ifdef HELTEC_MESH_NODE_T114 - uint32_t st7789_id=get_st7789_id(ST7789_NSS,ST7789_SCK,ST7789_SDA,ST7789_RS,ST7789_RESET); - if(st7789_id==0xFFFFFF) - { + uint32_t st7789_id = get_st7789_id(ST7789_NSS, ST7789_SCK, ST7789_SDA, ST7789_RS, ST7789_RESET); + if (st7789_id == 0xFFFFFF) { hasScreen = false; } #endif