Skip to content

Commit

Permalink
Ham: a JSON setting to apply R22 ADC workaround to a certain T-TWR V2…
Browse files Browse the repository at this point in the history
….0 boards
  • Loading branch information
lyusupov committed Dec 14, 2023
1 parent d27d604 commit a8d7601
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
Binary file added documents/images/ham-24.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 25 additions & 7 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ extern uint32_t Data_Frequency;
extern uint32_t Voice_Frequency;
extern void sa868_Tx_LED_state(bool);

bool ESP32_R22_workaround = false;

#if !defined(EXCLUDE_VOICE_MESSAGE)
#include <driver/i2s.h>
#include <AudioFileSourceSdFat.h>
Expand Down Expand Up @@ -1192,6 +1194,13 @@ static void ESP32_setup()

uSD_is_attached = uSD.cardBegin(SD_CONFIG);

#if defined(USE_SA8X8)
uint64_t mac = ESP.getEfuseMac();
if (mac == 0x7475ac188534ULL /* || mac == 0x58f8ab188534ULL */) {
ESP32_R22_workaround = true;
}
#endif /* USE_SA8X8 */

#if !defined(EXCLUDE_VOICE_MESSAGE)
if (uSD_is_attached && uSD.card()->cardSize() > 0 && uSD.volumeBegin()) {
Audio_Gen = new AudioGeneratorWAV();
Expand Down Expand Up @@ -2716,6 +2725,10 @@ static void ESP32_EEPROM_extension(int cmd)
controller.setBand(Band::UHF);
}
}
JsonVariant r22wa = root["r22wa"];
if (r22wa.success()) {
ESP32_R22_workaround = r22wa.as<bool>();
}
JsonVariant dfreq = root["dfreq"];
if (dfreq.success()) {
Data_Frequency = dfreq.as<unsigned int>();
Expand Down Expand Up @@ -2869,11 +2882,12 @@ static void ESP32_swSer_begin(unsigned long baud)
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) {
uint64_t mac = ESP.getEfuseMac();
Serial.println(F("INFO: LilyGO T-TWR rev. 2.0 is detected."));
if (mac == 0x7475ac188534ULL /* || mac == 0x58f8ab188534ULL */) {
#if defined(USE_SA8X8)
if (ESP32_R22_workaround) {
Serial.println(F("INFO: Audio ADC workaround has been applied."));
}
#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) {
Expand Down Expand Up @@ -3610,15 +3624,19 @@ 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_HELTEC_TRACKER ||
esp32_board == ESP32_LILYGO_T_TWR_V2_0) {
if (ESP.getEfuseMac() == 0x58f8ab188534ULL) {
calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL, ADC_ATTEN_DB_0);
} else {
if (esp32_board == ESP32_LILYGO_T_TWR_V2_0) {
#if defined(USE_SA8X8)
if (ESP32_R22_workaround) {
calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL);
} else
#endif /* USE_SA8X8 */
{
calibrate_voltage((adc1_channel_t) ADC1_GPIO1_CHANNEL, ADC_ATTEN_DB_0);
}
} else if (esp32_board == ESP32_LILYGO_T_TWR_V2_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);
} else {
calibrate_voltage((adc1_channel_t) ADC1_GPIO2_CHANNEL);
}
Expand Down
15 changes: 11 additions & 4 deletions software/firmware/source/libraries/LibAPRS_ESP32/AFSK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ typedef struct hardware_info {
} hardware_info_t;

extern hardware_info_t hw_info;
extern bool ESP32_R22_workaround;

enum
{
Expand Down Expand Up @@ -379,12 +380,18 @@ void AFSK_hw_init(void)
#if defined(SOFTRF_SKETCH)
if (hw_info.model == SOFTRF_MODEL_HAM) {
if (hw_info.revision == 20) {
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
} else {
//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
//} else {
// /* work around wrong R22 value (should be 47K) issue on very first T-TWR Plus batches */
// adc1_config_channel_atten((adc1_channel_t) SPK_PIN, ADC_ATTEN_DB_11); // Input 3.3Vp-p,Use R 10K divider input power 4.2V
//}
if (ESP32_R22_workaround) {
/* work around wrong R22 value (should be 47K) issue on very first T-TWR Plus batches */
adc1_config_channel_atten((adc1_channel_t) SPK_PIN, ADC_ATTEN_DB_11); // Input 3.3Vp-p,Use R 10K divider input power 4.2V
} else {
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
}
} else {
/* T-TWR Plus V2.1 is expected to use 47 KOhm value for R22 */
Expand Down

0 comments on commit a8d7601

Please sign in to comment.