Skip to content

Commit

Permalink
ESP32: use of one board Id for both V2.0 and V2.1 versions of T-TWR P…
Browse files Browse the repository at this point in the history
…lus. Use of revision variable when necessary
  • Loading branch information
lyusupov committed Mar 4, 2024
1 parent a5165a1 commit d1e04c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
62 changes: 27 additions & 35 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */ ;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 ");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions software/firmware/source/SoftRF/src/platform/ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/libraries/LibAPRS_ESP32/AFSK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1e04c3

Please sign in to comment.