Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions boards/heltec_v4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"build": {
"arduino": {
"ldscript": "esp32s3_out.ld",
"partitions": "default_16MB.csv",
"memory_type": "qio_qspi"
},
"core": "esp32",
"extra_flags": [
"-DBOARD_HAS_PSRAM",
"-DARDUINO_USB_CDC_ON_BOOT=1",
"-DARDUINO_USB_MODE=0",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "qio",
"psram_type": "qspi",
"hwids": [["0x303A", "0x1001"]],
"mcu": "esp32s3",
"variant": "heltec_v4"
},
"connectivity": ["wifi", "bluetooth", "lora"],
"debug": {
"default_tool": "esp-builtin",
"onboard_tools": ["esp-builtin"],
"openocd_target": "esp32s3.cfg"
},
"frameworks": ["arduino", "espidf"],
"name": "heltec_wifi_lora_32 v4 (16 MB FLASH, 2 MB PSRAM)",
"upload": {
"flash_size": "16MB",
"maximum_ram_size": 2097152,
"maximum_size": 16777216,
"use_1200bps_touch": true,
"wait_for_upload_port": true,
"require_upload_port": true,
"speed": 921600
},
"url": "https://heltec.org/",
"vendor": "heltec"
}
35 changes: 34 additions & 1 deletion src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,19 @@ void EnvironmentSensorManager::initBasicGPS() {
// Try to detect if GPS is physically connected to determine if we should expose the setting
#ifdef PIN_GPS_EN
pinMode(PIN_GPS_EN, OUTPUT);
#ifdef PIN_GPS_EN_ACTIVE
digitalWrite(PIN_GPS_EN, PIN_GPS_EN_ACTIVE); // Power on GPS
#else
digitalWrite(PIN_GPS_EN, HIGH); // Power on GPS
#endif
#endif

#ifdef PIN_GPS_RESET
pinMode(PIN_GPS_RESET, OUTPUT);
digitalWrite(PIN_GPS_RESET, PIN_GPS_RESET_ACTIVE); // assert for 10ms

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been nice to give a default value to PIN_GPS_RESET_ACTIVE ... ;)
Because now compilation breaks on TEcho (at least)

I think reset is handled in MicroNMEALocationProvider ...

I'll see how I can clean this mess

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where gps reset is done

void reset() override {
if (_pin_reset != -1) {
digitalWrite(_pin_reset, GPS_RESET_FORCE);
delay(100);
digitalWrite(_pin_reset, !GPS_RESET_FORCE);
}
}

I agree the GPS_RESET_FORCE symbol could be changed to PIN_GPS_RESET_ACTIVE but it has been here for a long time now ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the big issue is that EnvironmentSensorManager is a big mess regarding GPS management ...

I won't be able to fix everything ... will just try to make things work, but there is a need for some rewriting here ...

@fdlamotte fdlamotte Sep 23, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #820

I've tried to use the symbols introduced in this PR ... so it should work on heltec_v4, but would need to be verified

delay(10);
digitalWrite(PIN_GPS_RESET, !PIN_GPS_RESET_ACTIVE);
#endif

#ifndef PIN_GPS_EN
MESH_DEBUG_PRINTLN("No GPS wake/reset pin found for this board. Continuing on...");
Expand All @@ -456,8 +467,12 @@ void EnvironmentSensorManager::initBasicGPS() {
MESH_DEBUG_PRINTLN("No GPS detected");
}
#ifdef PIN_GPS_EN
#ifdef PIN_GPS_EN_ACTIVE
digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE);
#else
digitalWrite(PIN_GPS_EN, LOW); // Power off GPS until the setting is changed
#endif
#endif
gps_active = false; //Set GPS visibility off until setting is changed
}

Expand Down Expand Up @@ -542,9 +557,23 @@ void EnvironmentSensorManager::start_gps() {
#endif
#ifdef PIN_GPS_EN
pinMode(PIN_GPS_EN, OUTPUT);
#ifdef PIN_GPS_EN_ACTIVE
digitalWrite(PIN_GPS_EN, PIN_GPS_EN_ACTIVE);
#else
digitalWrite(PIN_GPS_EN, HIGH);
#endif
#ifndef PIN_GPS_RESET
return;
#endif
#endif

#ifdef PIN_GPS_RESET
pinMode(PIN_GPS_RESET, OUTPUT);
digitalWrite(PIN_GPS_RESET, PIN_GPS_RESET_ACTIVE); // assert for 10ms
delay(10);
digitalWrite(PIN_GPS_RESET, !PIN_GPS_RESET_ACTIVE);
return;
#endif

MESH_DEBUG_PRINTLN("Start GPS is N/A on this board. Actual GPS state unchanged");
}
Expand All @@ -558,8 +587,12 @@ void EnvironmentSensorManager::stop_gps() {
#endif
#ifdef PIN_GPS_EN
pinMode(PIN_GPS_EN, OUTPUT);
#ifdef PIN_GPS_EN_ACTIVE
digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE);
#else
digitalWrite(PIN_GPS_EN, LOW);
return;
#endif
return;
#endif

MESH_DEBUG_PRINTLN("Stop GPS is N/A on this board. Actual GPS state unchanged");
Expand Down
90 changes: 90 additions & 0 deletions variants/heltec_v4/HeltecV4Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "HeltecV4Board.h"

void HeltecV4Board::begin() {
ESP32Board::begin();


pinMode(PIN_ADC_CTRL, OUTPUT);
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive

pinMode(P_LORA_PA_POWER, OUTPUT);
digitalWrite(P_LORA_PA_POWER,HIGH);

rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
pinMode(P_LORA_PA_EN, OUTPUT);
digitalWrite(P_LORA_PA_EN,HIGH);
pinMode(P_LORA_PA_TX_EN, OUTPUT);
digitalWrite(P_LORA_PA_TX_EN,LOW);


periph_power.begin();

esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) {
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
startup_reason = BD_STARTUP_RX_PACKET;
}

rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
}
}

void HeltecV4Board::onBeforeTransmit(void) {
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
digitalWrite(P_LORA_PA_TX_EN,HIGH);
}

void HeltecV4Board::onAfterTransmit(void) {
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
digitalWrite(P_LORA_PA_TX_EN,LOW);
}

void HeltecV4Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);

// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);

rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);

rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN); //It also needs to be enabled in receive mode

if (pin_wake_btn < 0) {
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
} else {
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
}

if (secs > 0) {
esp_sleep_enable_timer_wakeup(secs * 1000000);
}

// Finally set ESP32 into sleep
esp_deep_sleep_start(); // CPU halts here and never returns!
}

void HeltecV4Board::powerOff() {
enterDeepSleep(0);
}

uint16_t HeltecV4Board::getBattMilliVolts() {
analogReadResolution(10);
digitalWrite(PIN_ADC_CTRL, HIGH);
delay(10);
uint32_t raw = 0;
for (int i = 0; i < 8; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / 8;

digitalWrite(PIN_ADC_CTRL, LOW);

return (5.42 * (3.3 / 1024.0) * raw) * 1000;
}

const char* HeltecV4Board::getManufacturerName() const {
return "Heltec V4";
}
23 changes: 23 additions & 0 deletions variants/heltec_v4/HeltecV4Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <Arduino.h>
#include <helpers/RefCountedDigitalPin.h>
#include <helpers/ESP32Board.h>
#include <driver/rtc_io.h>

class HeltecV4Board : public ESP32Board {

public:
RefCountedDigitalPin periph_power;

HeltecV4Board() : periph_power(PIN_VEXT_EN,PIN_VEXT_EN_ACTIVE) { }

void begin();
void onBeforeTransmit(void) override;
void onAfterTransmit(void) override;
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1);
void powerOff() override;
uint16_t getBattMilliVolts() override;
const char* getManufacturerName() const override ;

};
67 changes: 67 additions & 0 deletions variants/heltec_v4/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

static const uint8_t LED_BUILTIN = 35;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN

static const uint8_t TX = 43;
static const uint8_t RX = 44;

static const uint8_t SDA = 3;
static const uint8_t SCL = 4;

static const uint8_t SS = 8;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;
static const uint8_t SCK = 9;

static const uint8_t A0 = 1;
static const uint8_t A1 = 2;
static const uint8_t A2 = 3;
static const uint8_t A3 = 4;
static const uint8_t A4 = 5;
static const uint8_t A5 = 6;
static const uint8_t A6 = 7;
static const uint8_t A7 = 8;
static const uint8_t A8 = 9;
static const uint8_t A9 = 10;
static const uint8_t A10 = 11;
static const uint8_t A11 = 12;
static const uint8_t A12 = 13;
static const uint8_t A13 = 14;
static const uint8_t A14 = 15;
static const uint8_t A15 = 16;
static const uint8_t A16 = 17;
static const uint8_t A17 = 18;
static const uint8_t A18 = 19;
static const uint8_t A19 = 20;

static const uint8_t T1 = 1;
static const uint8_t T2 = 2;
static const uint8_t T3 = 3;
static const uint8_t T4 = 4;
static const uint8_t T5 = 5;
static const uint8_t T6 = 6;
static const uint8_t T7 = 7;
static const uint8_t T8 = 8;
static const uint8_t T9 = 9;
static const uint8_t T10 = 10;
static const uint8_t T11 = 11;
static const uint8_t T12 = 12;
static const uint8_t T13 = 13;
static const uint8_t T14 = 14;

static const uint8_t Vext = 36;
static const uint8_t LED = 35;
static const uint8_t RST_OLED = 21;
static const uint8_t SCL_OLED = 18;
static const uint8_t SDA_OLED = 17;

static const uint8_t RST_LoRa = 12;
static const uint8_t BUSY_LoRa = 13;
static const uint8_t DIO0 = 14;

#endif /* Pins_Arduino_h */
Loading