From fc06754e1f9e66b88ed47dab86b6bdb20a8cd78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 5 Oct 2023 05:24:25 +0200 Subject: [PATCH] Possibly fix #2704 "Heltec Wireless Tracker screen doesn't display anything" (#2749) * fix #2704 Co-authored-by: Ben Meadors Co-authored-by: Jonathan Bennett --- src/Power.cpp | 12 ++++ src/graphics/TFTDisplay.cpp | 49 ++++++++++++++- src/main.cpp | 73 +++++++++++++++++++++- src/main.h | 2 + src/sleep.cpp | 8 ++- variants/heltec_wireless_tracker/variant.h | 20 ++++-- 6 files changed, 155 insertions(+), 9 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 57d6513a75..da2c9da93f 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -175,9 +175,21 @@ class AnalogBatteryLevel : public HasBatteryLevel uint32_t raw = 0; #ifdef ARCH_ESP32 #ifndef BAT_MEASURE_ADC_UNIT // ADC1 +#ifdef ADC_CTRL + if (heltec_version == 5) { + pinMode(ADC_CTRL, OUTPUT); + digitalWrite(ADC_CTRL, HIGH); + delay(10); + } +#endif for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { raw += adc1_get_raw(adc_channel); } +#ifdef ADC_CTRL + if (heltec_version == 5) { + digitalWrite(ADC_CTRL, LOW); + } +#endif #else // ADC2 int32_t adc_buf = 0; for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 71ce35e824..5eec2b200b 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -1,4 +1,5 @@ #include "configuration.h" +#include "main.h" #ifndef TFT_BACKLIGHT_ON #define TFT_BACKLIGHT_ON HIGH @@ -81,8 +82,16 @@ class LGFX : public lgfx::LGFX_Device { auto cfg = _light_instance.config(); // Gets a structure for backlight settings. +#ifdef ST7735_BL_V03 + if (heltec_version == 3) { + cfg.pin_bl = ST7735_BL_V03; + } else { + cfg.pin_bl = ST7735_BL_V05; + } +#else cfg.pin_bl = ST7735_BL; // Pin number to which the backlight is connected - cfg.invert = true; // true to invert the brightness of the backlight +#endif + cfg.invert = true; // true to invert the brightness of the backlight // cfg.freq = 44100; // PWM frequency of backlight // cfg.pwm_channel = 1; // PWM channel number to use @@ -364,9 +373,23 @@ void TFTDisplay::sendCommand(uint8_t com) // handle display on/off directly switch (com) { case DISPLAYON: { +#if defined(ST7735_BACKLIGHT_EN_V03) && defined(TFT_BACKLIGHT_ON) + if (heltec_version == 3) { + digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); + } else { + digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); + } +#endif #if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); #endif +#ifdef VTFT_CTRL_V03 + if (heltec_version == 3) { + digitalWrite(VTFT_CTRL_V03, LOW); + } else { + digitalWrite(VTFT_CTRL_V05, LOW); + } +#endif #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, LOW); #endif @@ -376,9 +399,23 @@ void TFTDisplay::sendCommand(uint8_t com) break; } case DISPLAYOFF: { +#if defined(ST7735_BACKLIGHT_EN_V03) && defined(TFT_BACKLIGHT_ON) + if (heltec_version == 3) { + digitalWrite(ST7735_BACKLIGHT_EN_V03, !TFT_BACKLIGHT_ON); + } else { + digitalWrite(ST7735_BACKLIGHT_EN_V05, !TFT_BACKLIGHT_ON); + } +#endif #if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON); #endif +#ifdef VTFT_CTRL_V03 + if (heltec_version == 3) { + digitalWrite(VTFT_CTRL_V03, HIGH); + } else { + digitalWrite(VTFT_CTRL_V05, HIGH); + } +#endif #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, HIGH); #endif @@ -436,6 +473,16 @@ bool TFTDisplay::connect() pinMode(TFT_BL, OUTPUT); #endif +#ifdef ST7735_BACKLIGHT_EN_V03 + if (heltec_version == 3) { + digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); + pinMode(ST7735_BACKLIGHT_EN_V03, OUTPUT); + } else { + digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); + pinMode(ST7735_BACKLIGHT_EN_V05, OUTPUT); + } +#endif + tft.init(); #if defined(M5STACK) tft.setRotation(0); diff --git a/src/main.cpp b/src/main.cpp index a4caad3fd9..c9ba4c7956 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,6 +146,25 @@ const char *getDeviceName() return name; } +#ifdef VEXT_ENABLE_V03 + +#include + +static uint32_t calibrate_one(rtc_cal_sel_t cal_clk, const char *name) +{ + const uint32_t cal_count = 1000; + uint32_t cali_val; + for (int i = 0; i < 5; ++i) { + cali_val = rtc_clk_cal(cal_clk, cal_count); + } + return cali_val; +} + +int heltec_version = 3; + +#define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) +#endif + static int32_t ledBlinker() { static bool ledOn; @@ -216,11 +235,63 @@ void setup() digitalWrite(PIN_EINK_PWR_ON, HIGH); #endif -#ifdef VEXT_ENABLE +#ifdef ST7735_BL_V03 // Heltec Wireless Tracker PCB Change Detect/Hack + + rtc_clk_32k_enable(true); + CALIBRATE_ONE(RTC_CAL_RTC_MUX); + if (CALIBRATE_ONE(RTC_CAL_32K_XTAL) != 0) { + rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL); + CALIBRATE_ONE(RTC_CAL_RTC_MUX); + CALIBRATE_ONE(RTC_CAL_32K_XTAL); + } + + if (rtc_clk_slow_freq_get() != RTC_SLOW_FREQ_32K_XTAL) { + heltec_version = 3; + } else { + heltec_version = 5; + } +#endif + +#if defined(VEXT_ENABLE_V03) + if (heltec_version == 3) { + pinMode(VEXT_ENABLE_V03, OUTPUT); + digitalWrite(VEXT_ENABLE_V03, 0); // turn on the display power + LOG_DEBUG("HELTEC Detect Tracker V1.0\n"); + } else { + pinMode(VEXT_ENABLE_V05, OUTPUT); + digitalWrite(VEXT_ENABLE_V05, 1); // turn on the display power + LOG_DEBUG("HELTEC Detect Tracker V1.1\n"); + } +#elif defined(VEXT_ENABLE) pinMode(VEXT_ENABLE, OUTPUT); digitalWrite(VEXT_ENABLE, 0); // turn on the display power #endif +#if defined(VGNSS_CTRL_V03) + if (heltec_version == 3) { + pinMode(VGNSS_CTRL_V03, OUTPUT); + digitalWrite(VGNSS_CTRL_V03, LOW); + } else { + pinMode(VGNSS_CTRL_V05, OUTPUT); + digitalWrite(VGNSS_CTRL_V05, LOW); + } +#endif + +#if defined(VTFT_CTRL_V03) + if (heltec_version == 3) { + pinMode(VTFT_CTRL_V03, OUTPUT); + digitalWrite(VTFT_CTRL_V03, LOW); + } else { + pinMode(VTFT_CTRL_V05, OUTPUT); + digitalWrite(VTFT_CTRL_V05, LOW); + } +#endif + +#if defined(VGNSS_CTRL) + pinMode(VGNSS_CTRL, OUTPUT); + digitalWrite(VGNSS_CTRL, LOW); +#endif + #if defined(VTFT_CTRL) pinMode(VTFT_CTRL, OUTPUT); digitalWrite(VTFT_CTRL, LOW); diff --git a/src/main.h b/src/main.h index 301e8a10c1..3f01204069 100644 --- a/src/main.h +++ b/src/main.h @@ -64,6 +64,8 @@ extern uint32_t shutdownAtMsec; extern uint32_t serialSinceMsec; +extern int heltec_version; + // If a thread does something that might need for it to be rescheduled ASAP it can set this flag // This will suppress the current delay and instead try to run ASAP. extern bool runASAP; diff --git a/src/sleep.cpp b/src/sleep.cpp index da3e43dcb7..b0f4aec88a 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -202,7 +202,13 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) digitalWrite(RESET_OLED, 1); // put the display in reset before killing its power #endif -#ifdef VEXT_ENABLE +#if defined(VEXT_ENABLE_V03) + if (heltec_version == 3) { + digitalWrite(VEXT_ENABLE_V03, 1); // turn off the display power + } else { + digitalWrite(VEXT_ENABLE_V05, 0); // turn off the display power + } +#elif defined(VEXT_ENABLE) digitalWrite(VEXT_ENABLE, 1); // turn off the display power #endif diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index cfb752d03e..4a1b610388 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -9,9 +9,11 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL 45 +#define ST7735_BL_V03 45 +#define ST7735_BL_V05 21 /* V1.1 PCB marking */ #define ST7735_SPI_HOST SPI3_HOST -#define ST7735_BACKLIGHT_EN 45 +#define ST7735_BACKLIGHT_EN_V03 45 +#define ST7735_BACKLIGHT_EN_V05 21 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define SCREEN_ROTATE @@ -19,17 +21,20 @@ #define TFT_WIDTH 80 #define TFT_OFFSET_X 26 #define TFT_OFFSET_Y 0 -#define VTFT_CTRL 46 // Heltec Tracker needs this pulled low for TFT +#define VTFT_CTRL_V03 46 // Heltec Tracker needs this pulled low for TFT +#define VTFT_CTRL_V05 -1 #define SCREEN_TRANSITION_FRAMERATE 1 // fps #define DISPLAY_FORCE_SMALL_FONTS -#define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost +#define VEXT_ENABLE_V03 Vext // active low, powers the oled display and the lora antenna boost +#define VEXT_ENABLE_V05 3 // active HIGH, powers the oled display #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider #define ADC_MULTIPLIER 4.9 +#define ADC_CTRL 2 // active HIGH, powers the voltage divider. Only on 1.1 #undef GPS_RX_PIN #undef GPS_TX_PIN @@ -37,9 +42,12 @@ #define GPS_TX_PIN 34 #define PIN_GPS_RESET 35 #define PIN_GPS_PPS 36 -#define VGNSS_CTRL 37 // Heltec Tracker needs this pulled low for GPS -#define PIN_GPS_EN VGNSS_CTRL + +#define VGNSS_CTRL_V03 37 // Heltec Tracker needs this pulled low for GPS +#define VGNSS_CTRL_V05 -1 // Heltec Tracker needs this pulled low for GPS +#define PIN_GPS_EN VGNSS_CTRL_V03 #define GPS_EN_ACTIVE LOW + #define GPS_RESET_MODE LOW #define GPS_UC6580