Skip to content

Commit 4579a1b

Browse files
authored
Merge pull request #813 from Quency-D/dev-heltec_v4
add heltec v4 board.
2 parents d85d364 + 669bea0 commit 4579a1b

File tree

8 files changed

+555
-1
lines changed

8 files changed

+555
-1
lines changed

boards/heltec_v4.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "esp32s3_out.ld",
5+
"partitions": "default_16MB.csv",
6+
"memory_type": "qio_qspi"
7+
},
8+
"core": "esp32",
9+
"extra_flags": [
10+
"-DBOARD_HAS_PSRAM",
11+
"-DARDUINO_USB_CDC_ON_BOOT=1",
12+
"-DARDUINO_USB_MODE=0",
13+
"-DARDUINO_RUNNING_CORE=1",
14+
"-DARDUINO_EVENT_RUNNING_CORE=1"
15+
],
16+
"f_cpu": "240000000L",
17+
"f_flash": "80000000L",
18+
"flash_mode": "qio",
19+
"psram_type": "qspi",
20+
"hwids": [["0x303A", "0x1001"]],
21+
"mcu": "esp32s3",
22+
"variant": "heltec_v4"
23+
},
24+
"connectivity": ["wifi", "bluetooth", "lora"],
25+
"debug": {
26+
"default_tool": "esp-builtin",
27+
"onboard_tools": ["esp-builtin"],
28+
"openocd_target": "esp32s3.cfg"
29+
},
30+
"frameworks": ["arduino", "espidf"],
31+
"name": "heltec_wifi_lora_32 v4 (16 MB FLASH, 2 MB PSRAM)",
32+
"upload": {
33+
"flash_size": "16MB",
34+
"maximum_ram_size": 2097152,
35+
"maximum_size": 16777216,
36+
"use_1200bps_touch": true,
37+
"wait_for_upload_port": true,
38+
"require_upload_port": true,
39+
"speed": 921600
40+
},
41+
"url": "https://heltec.org/",
42+
"vendor": "heltec"
43+
}

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,19 @@ void EnvironmentSensorManager::initBasicGPS() {
433433
// Try to detect if GPS is physically connected to determine if we should expose the setting
434434
#ifdef PIN_GPS_EN
435435
pinMode(PIN_GPS_EN, OUTPUT);
436+
#ifdef PIN_GPS_EN_ACTIVE
437+
digitalWrite(PIN_GPS_EN, PIN_GPS_EN_ACTIVE); // Power on GPS
438+
#else
436439
digitalWrite(PIN_GPS_EN, HIGH); // Power on GPS
437440
#endif
441+
#endif
442+
443+
#ifdef PIN_GPS_RESET
444+
pinMode(PIN_GPS_RESET, OUTPUT);
445+
digitalWrite(PIN_GPS_RESET, PIN_GPS_RESET_ACTIVE); // assert for 10ms
446+
delay(10);
447+
digitalWrite(PIN_GPS_RESET, !PIN_GPS_RESET_ACTIVE);
448+
#endif
438449

439450
#ifndef PIN_GPS_EN
440451
MESH_DEBUG_PRINTLN("No GPS wake/reset pin found for this board. Continuing on...");
@@ -456,8 +467,12 @@ void EnvironmentSensorManager::initBasicGPS() {
456467
MESH_DEBUG_PRINTLN("No GPS detected");
457468
}
458469
#ifdef PIN_GPS_EN
470+
#ifdef PIN_GPS_EN_ACTIVE
471+
digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE);
472+
#else
459473
digitalWrite(PIN_GPS_EN, LOW); // Power off GPS until the setting is changed
460474
#endif
475+
#endif
461476
gps_active = false; //Set GPS visibility off until setting is changed
462477
}
463478

@@ -542,9 +557,23 @@ void EnvironmentSensorManager::start_gps() {
542557
#endif
543558
#ifdef PIN_GPS_EN
544559
pinMode(PIN_GPS_EN, OUTPUT);
560+
#ifdef PIN_GPS_EN_ACTIVE
561+
digitalWrite(PIN_GPS_EN, PIN_GPS_EN_ACTIVE);
562+
#else
545563
digitalWrite(PIN_GPS_EN, HIGH);
564+
#endif
565+
#ifndef PIN_GPS_RESET
546566
return;
547567
#endif
568+
#endif
569+
570+
#ifdef PIN_GPS_RESET
571+
pinMode(PIN_GPS_RESET, OUTPUT);
572+
digitalWrite(PIN_GPS_RESET, PIN_GPS_RESET_ACTIVE); // assert for 10ms
573+
delay(10);
574+
digitalWrite(PIN_GPS_RESET, !PIN_GPS_RESET_ACTIVE);
575+
return;
576+
#endif
548577

549578
MESH_DEBUG_PRINTLN("Start GPS is N/A on this board. Actual GPS state unchanged");
550579
}
@@ -558,8 +587,12 @@ void EnvironmentSensorManager::stop_gps() {
558587
#endif
559588
#ifdef PIN_GPS_EN
560589
pinMode(PIN_GPS_EN, OUTPUT);
590+
#ifdef PIN_GPS_EN_ACTIVE
591+
digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE);
592+
#else
561593
digitalWrite(PIN_GPS_EN, LOW);
562-
return;
594+
#endif
595+
return;
563596
#endif
564597

565598
MESH_DEBUG_PRINTLN("Stop GPS is N/A on this board. Actual GPS state unchanged");
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "HeltecV4Board.h"
2+
3+
void HeltecV4Board::begin() {
4+
ESP32Board::begin();
5+
6+
7+
pinMode(PIN_ADC_CTRL, OUTPUT);
8+
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
9+
10+
pinMode(P_LORA_PA_POWER, OUTPUT);
11+
digitalWrite(P_LORA_PA_POWER,HIGH);
12+
13+
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
14+
pinMode(P_LORA_PA_EN, OUTPUT);
15+
digitalWrite(P_LORA_PA_EN,HIGH);
16+
pinMode(P_LORA_PA_TX_EN, OUTPUT);
17+
digitalWrite(P_LORA_PA_TX_EN,LOW);
18+
19+
20+
periph_power.begin();
21+
22+
esp_reset_reason_t reason = esp_reset_reason();
23+
if (reason == ESP_RST_DEEPSLEEP) {
24+
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
25+
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
26+
startup_reason = BD_STARTUP_RX_PACKET;
27+
}
28+
29+
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
30+
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
31+
}
32+
}
33+
34+
void HeltecV4Board::onBeforeTransmit(void) {
35+
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
36+
digitalWrite(P_LORA_PA_TX_EN,HIGH);
37+
}
38+
39+
void HeltecV4Board::onAfterTransmit(void) {
40+
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
41+
digitalWrite(P_LORA_PA_TX_EN,LOW);
42+
}
43+
44+
void HeltecV4Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
45+
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
46+
47+
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
48+
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
49+
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
50+
51+
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
52+
53+
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN); //It also needs to be enabled in receive mode
54+
55+
if (pin_wake_btn < 0) {
56+
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
57+
} else {
58+
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
59+
}
60+
61+
if (secs > 0) {
62+
esp_sleep_enable_timer_wakeup(secs * 1000000);
63+
}
64+
65+
// Finally set ESP32 into sleep
66+
esp_deep_sleep_start(); // CPU halts here and never returns!
67+
}
68+
69+
void HeltecV4Board::powerOff() {
70+
enterDeepSleep(0);
71+
}
72+
73+
uint16_t HeltecV4Board::getBattMilliVolts() {
74+
analogReadResolution(10);
75+
digitalWrite(PIN_ADC_CTRL, HIGH);
76+
delay(10);
77+
uint32_t raw = 0;
78+
for (int i = 0; i < 8; i++) {
79+
raw += analogRead(PIN_VBAT_READ);
80+
}
81+
raw = raw / 8;
82+
83+
digitalWrite(PIN_ADC_CTRL, LOW);
84+
85+
return (5.42 * (3.3 / 1024.0) * raw) * 1000;
86+
}
87+
88+
const char* HeltecV4Board::getManufacturerName() const {
89+
return "Heltec V4";
90+
}

variants/heltec_v4/HeltecV4Board.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <Arduino.h>
4+
#include <helpers/RefCountedDigitalPin.h>
5+
#include <helpers/ESP32Board.h>
6+
#include <driver/rtc_io.h>
7+
8+
class HeltecV4Board : public ESP32Board {
9+
10+
public:
11+
RefCountedDigitalPin periph_power;
12+
13+
HeltecV4Board() : periph_power(PIN_VEXT_EN,PIN_VEXT_EN_ACTIVE) { }
14+
15+
void begin();
16+
void onBeforeTransmit(void) override;
17+
void onAfterTransmit(void) override;
18+
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1);
19+
void powerOff() override;
20+
uint16_t getBattMilliVolts() override;
21+
const char* getManufacturerName() const override ;
22+
23+
};

variants/heltec_v4/pins_arduino.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef Pins_Arduino_h
2+
#define Pins_Arduino_h
3+
4+
#include <stdint.h>
5+
6+
static const uint8_t LED_BUILTIN = 35;
7+
#define BUILTIN_LED LED_BUILTIN // backward compatibility
8+
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN
9+
10+
static const uint8_t TX = 43;
11+
static const uint8_t RX = 44;
12+
13+
static const uint8_t SDA = 3;
14+
static const uint8_t SCL = 4;
15+
16+
static const uint8_t SS = 8;
17+
static const uint8_t MOSI = 10;
18+
static const uint8_t MISO = 11;
19+
static const uint8_t SCK = 9;
20+
21+
static const uint8_t A0 = 1;
22+
static const uint8_t A1 = 2;
23+
static const uint8_t A2 = 3;
24+
static const uint8_t A3 = 4;
25+
static const uint8_t A4 = 5;
26+
static const uint8_t A5 = 6;
27+
static const uint8_t A6 = 7;
28+
static const uint8_t A7 = 8;
29+
static const uint8_t A8 = 9;
30+
static const uint8_t A9 = 10;
31+
static const uint8_t A10 = 11;
32+
static const uint8_t A11 = 12;
33+
static const uint8_t A12 = 13;
34+
static const uint8_t A13 = 14;
35+
static const uint8_t A14 = 15;
36+
static const uint8_t A15 = 16;
37+
static const uint8_t A16 = 17;
38+
static const uint8_t A17 = 18;
39+
static const uint8_t A18 = 19;
40+
static const uint8_t A19 = 20;
41+
42+
static const uint8_t T1 = 1;
43+
static const uint8_t T2 = 2;
44+
static const uint8_t T3 = 3;
45+
static const uint8_t T4 = 4;
46+
static const uint8_t T5 = 5;
47+
static const uint8_t T6 = 6;
48+
static const uint8_t T7 = 7;
49+
static const uint8_t T8 = 8;
50+
static const uint8_t T9 = 9;
51+
static const uint8_t T10 = 10;
52+
static const uint8_t T11 = 11;
53+
static const uint8_t T12 = 12;
54+
static const uint8_t T13 = 13;
55+
static const uint8_t T14 = 14;
56+
57+
static const uint8_t Vext = 36;
58+
static const uint8_t LED = 35;
59+
static const uint8_t RST_OLED = 21;
60+
static const uint8_t SCL_OLED = 18;
61+
static const uint8_t SDA_OLED = 17;
62+
63+
static const uint8_t RST_LoRa = 12;
64+
static const uint8_t BUSY_LoRa = 13;
65+
static const uint8_t DIO0 = 14;
66+
67+
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)