From d1e04c3e9907c30f0189192a72d3402d521b399a Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Mon, 4 Mar 2024 07:34:50 +0300 Subject: [PATCH] ESP32: use of one board Id for both V2.0 and V2.1 versions of T-TWR Plus. Use of revision variable when necessary --- .../source/SoftRF/src/platform/ESP32.cpp | 62 ++++++++----------- .../source/SoftRF/src/platform/ESP32.h | 3 +- .../source/libraries/LibAPRS_ESP32/AFSK.cpp | 2 +- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.cpp b/software/firmware/source/SoftRF/src/platform/ESP32.cpp index de5c90d27..da6654c85 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.cpp +++ b/software/firmware/source/SoftRF/src/platform/ESP32.cpp @@ -1137,8 +1137,8 @@ static void ESP32_setup() SOC_GPIO_PIN_TWR2_SDA, SOC_GPIO_PIN_TWR2_SCL); if (has_axp2101) { - esp32_board = ESP32_LILYGO_T_TWR_V2_0; - hw_info.revision = 20; + esp32_board = ESP32_LILYGO_T_TWR2; + hw_info.revision = 0; hw_info.pmu = PMU_AXP2101; // Set the minimum common working voltage of the PMU VBUS input, @@ -1220,7 +1220,7 @@ static void ESP32_setup() SOC_GPIO_PIN_TWR2_CONS_TX); #endif /* ARDUINO_USB_CDC_ON_BOOT */ - if (esp32_board == ESP32_LILYGO_T_TWR_V2_0) { + if (esp32_board == ESP32_LILYGO_T_TWR2) { int uSD_SS_pin = SOC_GPIO_PIN_TWR2_SD_SS; /* uSD-SPI init */ @@ -1386,7 +1386,7 @@ static void ESP32_setup() pid = (esp32_board == ESP32_TTGO_T_BEAM_SUPREME) ? SOFTRF_USB_PID_PRIME_MK3 : (esp32_board == ESP32_S2_T8_V1_1 ) ? SOFTRF_USB_PID_WEBTOP : (esp32_board == ESP32_S3_DEVKIT ) ? SOFTRF_USB_PID_STANDALONE : - (esp32_board == ESP32_LILYGO_T_TWR_V2_0 ) ? SOFTRF_USB_PID_HAM : + (esp32_board == ESP32_LILYGO_T_TWR2 ) ? SOFTRF_USB_PID_HAM : (esp32_board == ESP32_HELTEC_TRACKER ) ? SOFTRF_USB_PID_MIDI : USB_PID /* 0x1001 */ ; @@ -1398,7 +1398,7 @@ static void ESP32_setup() USB.VID(USB_VID); // USB_ESPRESSIF_VID = 0x303A USB.PID(pid); USB.productName(esp32_board == ESP32_TTGO_T_BEAM_SUPREME ? ESP32S3_Model_Prime3 : - esp32_board == ESP32_LILYGO_T_TWR_V2_0 ? ESP32S3_Model_Ham : + esp32_board == ESP32_LILYGO_T_TWR2 ? ESP32S3_Model_Ham : esp32_board == ESP32_HELTEC_TRACKER ? ESP32S3_Model_Midi : ESP32SX_Model_Stand); USB.firmwareVersion(ESP32SX_Device_Version); @@ -1472,7 +1472,7 @@ static void ESP32_setup() } } #endif /* EXCLUDE_IMU */ - } else if (esp32_board == ESP32_LILYGO_T_TWR_V2_0) { + } else if (esp32_board == ESP32_LILYGO_T_TWR2) { /* turn SA868 digital power off to make sure that SQL is inactive */ digitalWrite(SOC_GPIO_PIN_TWR2_RADIO_PD, LOW); @@ -1504,8 +1504,7 @@ static void ESP32_setup() if (probe_1 == LOW && probe_2 == HIGH) { #endif - esp32_board = ESP32_LILYGO_T_TWR_V2_1; - hw_info.revision = 21; + hw_info.revision = 1; axp_2xxx.setBLDO2Voltage(3300); // V2.1 - SA868 axp_2xxx.enableBLDO2(); @@ -1666,9 +1665,8 @@ static void ESP32_post_init() Serial.flush(); } - if (hw_info.model == SOFTRF_MODEL_PRIME_MK3 || - esp32_board == ESP32_LILYGO_T_TWR_V2_0 || - esp32_board == ESP32_LILYGO_T_TWR_V2_1) + if (esp32_board == ESP32_TTGO_T_BEAM_SUPREME || + esp32_board == ESP32_LILYGO_T_TWR2) { Serial.println(); @@ -1703,7 +1701,7 @@ static void ESP32_post_init() } #if !defined(EXCLUDE_VOICE_MESSAGE) - if (esp32_board == ESP32_LILYGO_T_TWR_V2_1 && uSD_is_attached) + if (esp32_board == ESP32_LILYGO_T_TWR2 && hw_info.revision == 1 && uSD_is_attached) { char filename[MAX_FILENAME_LEN]; strcpy(filename, WAV_FILE_PREFIX); @@ -2224,8 +2222,7 @@ static void ESP32_fini(int reason) ESP_EXT1_WAKEUP_ALL_LOW); #endif /* CONFIG_IDF_TARGET_ESP32C3 */ - } else if (esp32_board == ESP32_LILYGO_T_TWR_V2_0 || - esp32_board == ESP32_LILYGO_T_TWR_V2_1) { + } else if (esp32_board == ESP32_LILYGO_T_TWR2) { #if defined(CONFIG_IDF_TARGET_ESP32S3) #if defined(USE_NEOPIXELBUS_LIBRARY) @@ -2953,8 +2950,7 @@ static void ESP32_SPI_begin() SPI.begin(SOC_GPIO_PIN_C3_SCK, SOC_GPIO_PIN_C3_MISO, SOC_GPIO_PIN_C3_MOSI, SOC_GPIO_PIN_C3_SS); break; - case ESP32_LILYGO_T_TWR_V2_0: - case ESP32_LILYGO_T_TWR_V2_1: + case ESP32_LILYGO_T_TWR2: SPI.begin(SOC_GPIO_PIN_TWR2_SCK, SOC_GPIO_PIN_TWR2_MISO, SOC_GPIO_PIN_TWR2_MOSI, SOC_GPIO_PIN_TWR2_SS); break; @@ -3027,7 +3023,7 @@ static void ESP32_swSer_begin(unsigned long baud) Serial.println(F("INFO: ESP32-C3 DevKit is detected.")); Serial_GNSS_In.begin(baud, SERIAL_IN_BITS, SOC_GPIO_PIN_C3_GNSS_RX, SOC_GPIO_PIN_C3_GNSS_TX); - } else if (esp32_board == ESP32_LILYGO_T_TWR_V2_0) { + } else if (esp32_board == ESP32_LILYGO_T_TWR2 && hw_info.revision == 0) { Serial.println(F("INFO: LilyGO T-TWR rev. 2.0 is detected.")); #if defined(USE_SA8X8) if (ESP32_R22_workaround) { @@ -3036,7 +3032,7 @@ static void ESP32_swSer_begin(unsigned long baud) #endif /* USE_SA8X8 */ Serial_GNSS_In.begin(baud, SERIAL_IN_BITS, SOC_GPIO_PIN_TWR2_GNSS_RX, SOC_GPIO_PIN_TWR2_GNSS_TX); - } else if (esp32_board == ESP32_LILYGO_T_TWR_V2_1) { + } else if (esp32_board == ESP32_LILYGO_T_TWR2 && hw_info.revision == 1) { Serial.print(F("INFO: LilyGO T-TWR rev. 2.1 ")); #if defined(USE_SA8X8) Serial.print(controller.getBand() == Band::VHF ? "VHF " : "UHF "); @@ -3143,7 +3139,7 @@ static byte ESP32_Display_setup() u8x8 = &u8x8_1_3; rval = DISPLAY_OLED_1_3; } - } else if (hw_info.model == SOFTRF_MODEL_HAM) { + } else if (esp32_board == ESP32_LILYGO_T_TWR2) { Wire.begin(SOC_GPIO_PIN_TWR2_SDA, SOC_GPIO_PIN_TWR2_SCL); Wire.beginTransmission(SSD1306_OLED_I2C_ADDR); @@ -3788,7 +3784,7 @@ static void ESP32_Battery_setup() calibrate_voltage((adc1_channel_t) ADC1_GPIO9_CHANNEL); #elif defined(CONFIG_IDF_TARGET_ESP32S3) /* use this procedure on T-TWR Plus (has PMU) to calibrate audio ADC */ - if (esp32_board == ESP32_LILYGO_T_TWR_V2_0) { + if (esp32_board == ESP32_LILYGO_T_TWR2 && hw_info.revision == 0) { #if defined(USE_SA8X8) if (ESP32_R22_workaround) { calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL); @@ -3797,7 +3793,7 @@ static void ESP32_Battery_setup() { calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL, ADC_ATTEN_DB_0); } - } else if (esp32_board == ESP32_LILYGO_T_TWR_V2_1) { + } else if (esp32_board == ESP32_LILYGO_T_TWR2 && hw_info.revision == 1) { calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL, ADC_ATTEN_DB_0); } else if (esp32_board == ESP32_HELTEC_TRACKER) { calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL); @@ -3940,8 +3936,7 @@ static bool ESP32_Baro_setup() Wire.setPins(SOC_GPIO_PIN_C3_SDA, SOC_GPIO_PIN_C3_SCL); - } else if (esp32_board == ESP32_LILYGO_T_TWR_V2_0 || - esp32_board == ESP32_LILYGO_T_TWR_V2_1) { + } else if (esp32_board == ESP32_LILYGO_T_TWR2) { Wire.setPins(SOC_GPIO_PIN_TWR2_SDA, SOC_GPIO_PIN_TWR2_SCL); @@ -4011,8 +4006,7 @@ static bool ESP32_Baro_setup() static void ESP32_UATSerial_begin(unsigned long baud) { #if defined(USE_SA8X8) - if (esp32_board == ESP32_LILYGO_T_TWR_V2_0 || - esp32_board == ESP32_LILYGO_T_TWR_V2_1) { + if (esp32_board == ESP32_LILYGO_T_TWR2) { SA8X8_Serial.begin(baud, SERIAL_IN_BITS, SOC_GPIO_PIN_TWR2_RADIO_RX, SOC_GPIO_PIN_TWR2_RADIO_TX); @@ -4033,9 +4027,7 @@ static void ESP32_UATSerial_updateBaudRate(unsigned long baud) static void ESP32_UATModule_restart() { #if defined(USE_SA8X8) - if (esp32_board == ESP32_LILYGO_T_TWR_V2_0) { - /* TBD */ - } else if (esp32_board == ESP32_LILYGO_T_TWR_V2_1) { + if (esp32_board == ESP32_LILYGO_T_TWR2) { /* TBD */ } else @@ -4191,13 +4183,13 @@ static void ESP32_Button_setup() if (( hw_info.model == SOFTRF_MODEL_PRIME_MK2 && (hw_info.revision == 2 || hw_info.revision == 5)) || esp32_board == ESP32_S2_T8_V1_1 || - hw_info.model == SOFTRF_MODEL_HAM || + esp32_board == ESP32_LILYGO_T_TWR2 || esp32_board == ESP32_HELTEC_TRACKER || esp32_board == ESP32_S3_DEVKIT) { button_pin = esp32_board == ESP32_S2_T8_V1_1 ? SOC_GPIO_PIN_T8_S2_BUTTON : esp32_board == ESP32_S3_DEVKIT ? SOC_GPIO_PIN_S3_BUTTON : esp32_board == ESP32_HELTEC_TRACKER ? SOC_GPIO_PIN_S3_BUTTON : - hw_info.model == SOFTRF_MODEL_HAM ? + esp32_board == ESP32_LILYGO_T_TWR2 ? SOC_GPIO_PIN_TWR2_ENC_BUTTON : SOC_GPIO_PIN_TBEAM_V05_BUTTON; // Button(s) uses external pull up resistor. @@ -4217,7 +4209,7 @@ static void ESP32_Button_setup() PageButtonConfig->setLongPressDelay(2000); #if defined(USE_SA8X8) - if (hw_info.model == SOFTRF_MODEL_HAM) { + if (esp32_board == ESP32_LILYGO_T_TWR2) { int ptt_pin = SOC_GPIO_PIN_TWR2_BUTTON; pinMode(ptt_pin, INPUT_PULLUP); @@ -4254,12 +4246,12 @@ static void ESP32_Button_loop() if (esp32_board == ESP32_TTGO_T_BEAM || esp32_board == ESP32_TTGO_T_BEAM_SUPREME || esp32_board == ESP32_S2_T8_V1_1 || - hw_info.model == SOFTRF_MODEL_HAM || + esp32_board == ESP32_LILYGO_T_TWR2 || esp32_board == ESP32_HELTEC_TRACKER || esp32_board == ESP32_S3_DEVKIT) { button_1.check(); #if defined(USE_SA8X8) - if (hw_info.model == SOFTRF_MODEL_HAM) { + if (esp32_board == ESP32_LILYGO_T_TWR2) { button_ptt.check(); } #endif /* USE_SA8X8 */ @@ -4269,11 +4261,11 @@ static void ESP32_Button_loop() static void ESP32_Button_fini() { if (esp32_board == ESP32_S2_T8_V1_1 || - hw_info.model == SOFTRF_MODEL_HAM || + esp32_board == ESP32_LILYGO_T_TWR2 || esp32_board == ESP32_HELTEC_TRACKER || esp32_board == ESP32_S3_DEVKIT) { int button_pin = esp32_board == ESP32_S2_T8_V1_1 ? SOC_GPIO_PIN_T8_S2_BUTTON : - hw_info.model == SOFTRF_MODEL_HAM ? + esp32_board == ESP32_LILYGO_T_TWR2 ? SOC_GPIO_PIN_TWR2_ENC_BUTTON : SOC_GPIO_PIN_S3_BUTTON; while (digitalRead(button_pin) == LOW); } diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.h b/software/firmware/source/SoftRF/src/platform/ESP32.h index 8b94126ac..f36a07230 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.h +++ b/software/firmware/source/SoftRF/src/platform/ESP32.h @@ -261,8 +261,7 @@ enum esp32_board_id { ESP32_TTGO_T_BEAM_SUPREME, ESP32_TTGO_T_WATCH, ESP32_S2_T8_V1_1, - ESP32_LILYGO_T_TWR_V2_0, - ESP32_LILYGO_T_TWR_V2_1, + ESP32_LILYGO_T_TWR2, ESP32_HELTEC_TRACKER, ESP32_LILYGO_T3C6, }; diff --git a/software/firmware/source/libraries/LibAPRS_ESP32/AFSK.cpp b/software/firmware/source/libraries/LibAPRS_ESP32/AFSK.cpp index 706970541..e39fb01eb 100644 --- a/software/firmware/source/libraries/LibAPRS_ESP32/AFSK.cpp +++ b/software/firmware/source/libraries/LibAPRS_ESP32/AFSK.cpp @@ -379,7 +379,7 @@ void AFSK_hw_init(void) #if defined(SOFTRF_SKETCH) if (hw_info.model == SOFTRF_MODEL_HAM) { - if (hw_info.revision == 20) { + if (hw_info.revision == 0) { //uint64_t mac = ESP.getEfuseMac(); //if (mac == 0x58f8ab188534ULL /* || mac == 0x7475ac188534ULL */) { // adc1_config_channel_atten((adc1_channel_t) SPK_PIN, ADC_ATTEN_DB_0); // Input 1.24Vp-p,Use R 47K-(10K//10K) divider input power 1.2Vref