Skip to content

Commit 34b9a1c

Browse files
authored
Merge pull request #916 from Quency-D/dev-heltec_tracker_v2
add heltec tracker v2
2 parents ca5dcf2 + ad2894a commit 34b9a1c

File tree

9 files changed

+534
-4
lines changed

9 files changed

+534
-4
lines changed

boards/heltec_tracker_v2.json

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

src/helpers/sensors/MicroNMEALocationProvider.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "LocationProvider.h"
44
#include <MicroNMEA.h>
55
#include <RTClib.h>
6+
#include <helpers/RefCountedDigitalPin.h>
67

78
#ifndef GPS_EN
89
#ifdef PIN_GPS_EN
@@ -37,14 +38,15 @@ class MicroNMEALocationProvider : public LocationProvider {
3738
MicroNMEA nmea;
3839
mesh::RTCClock* _clock;
3940
Stream* _gps_serial;
41+
RefCountedDigitalPin* _peripher_power;
4042
int _pin_reset;
4143
int _pin_en;
4244
long next_check = 0;
4345
long time_valid = 0;
4446

4547
public :
46-
MicroNMEALocationProvider(Stream& ser, mesh::RTCClock* clock = NULL, int pin_reset = GPS_RESET, int pin_en = GPS_EN) :
47-
_gps_serial(&ser), nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _pin_reset(pin_reset), _pin_en(pin_en), _clock(clock) {
48+
MicroNMEALocationProvider(Stream& ser, mesh::RTCClock* clock = NULL, int pin_reset = GPS_RESET, int pin_en = GPS_EN,RefCountedDigitalPin* peripher_power=NULL) :
49+
_gps_serial(&ser), nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _pin_reset(pin_reset), _pin_en(pin_en), _clock(clock), _peripher_power(peripher_power) {
4850
if (_pin_reset != -1) {
4951
pinMode(_pin_reset, OUTPUT);
5052
digitalWrite(_pin_reset, GPS_RESET_FORCE);
@@ -56,6 +58,7 @@ public :
5658
}
5759

5860
void begin() override {
61+
if (_peripher_power) _peripher_power->claim();
5962
if (_pin_en != -1) {
6063
digitalWrite(_pin_en, PIN_GPS_EN_ACTIVE);
6164
}
@@ -75,7 +78,8 @@ public :
7578
void stop() override {
7679
if (_pin_en != -1) {
7780
digitalWrite(_pin_en, !PIN_GPS_EN_ACTIVE);
78-
}
81+
}
82+
if (_peripher_power) _peripher_power->release();
7983
}
8084

8185
bool isEnabled() override {

src/helpers/ui/ST7735Display.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ bool ST7735Display::begin() {
2424
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
2525
digitalWrite(PIN_TFT_RST, HIGH);
2626

27+
#if defined(HELTEC_TRACKER_V2)
28+
display.initR(INITR_MINI160x80);
29+
display.setRotation(DISPLAY_ROTATION);
30+
uint8_t madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV |ST7735_MADCTL_BGR;//Adjust color to BGR
31+
display.sendCommand(ST77XX_MADCTL, &madctl, 1);
32+
#else
2733
display.initR(INITR_MINI160x80_PLUGIN);
2834
display.setRotation(DISPLAY_ROTATION);
35+
#endif
2936
display.setSPISpeed(40000000);
3037
display.fillScreen(ST77XX_BLACK);
3138
display.setTextColor(ST77XX_WHITE);
3239
display.setTextSize(2);
3340
display.cp437(true); // Use full 256 char 'Code Page 437' font
34-
41+
3542
_isOn = true;
3643
}
3744
return true;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include "HeltecTrackerV2Board.h"
2+
3+
void HeltecTrackerV2Board::begin() {
4+
ESP32Board::begin();
5+
6+
pinMode(PIN_ADC_CTRL, OUTPUT);
7+
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
8+
9+
pinMode(P_LORA_PA_POWER, OUTPUT);
10+
digitalWrite(P_LORA_PA_POWER,HIGH);
11+
12+
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
13+
pinMode(P_LORA_PA_EN, OUTPUT);
14+
digitalWrite(P_LORA_PA_EN,HIGH);
15+
pinMode(P_LORA_PA_TX_EN, OUTPUT);
16+
digitalWrite(P_LORA_PA_TX_EN,LOW);
17+
18+
periph_power.begin();
19+
20+
esp_reset_reason_t reason = esp_reset_reason();
21+
if (reason == ESP_RST_DEEPSLEEP) {
22+
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
23+
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
24+
startup_reason = BD_STARTUP_RX_PACKET;
25+
}
26+
27+
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
28+
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
29+
}
30+
}
31+
32+
void HeltecTrackerV2Board::onBeforeTransmit(void) {
33+
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
34+
digitalWrite(P_LORA_PA_TX_EN,HIGH);
35+
}
36+
37+
void HeltecTrackerV2Board::onAfterTransmit(void) {
38+
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
39+
digitalWrite(P_LORA_PA_TX_EN,LOW);
40+
}
41+
42+
void HeltecTrackerV2Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
43+
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
44+
45+
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
46+
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
47+
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
48+
49+
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
50+
51+
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN); //It also needs to be enabled in receive mode
52+
53+
if (pin_wake_btn < 0) {
54+
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
55+
} else {
56+
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
57+
}
58+
59+
if (secs > 0) {
60+
esp_sleep_enable_timer_wakeup(secs * 1000000);
61+
}
62+
63+
// Finally set ESP32 into sleep
64+
esp_deep_sleep_start(); // CPU halts here and never returns!
65+
}
66+
67+
void HeltecTrackerV2Board::powerOff() {
68+
enterDeepSleep(0);
69+
}
70+
71+
uint16_t HeltecTrackerV2Board::getBattMilliVolts() {
72+
analogReadResolution(10);
73+
digitalWrite(PIN_ADC_CTRL, HIGH);
74+
delay(10);
75+
uint32_t raw = 0;
76+
for (int i = 0; i < 8; i++) {
77+
raw += analogRead(PIN_VBAT_READ);
78+
}
79+
raw = raw / 8;
80+
81+
digitalWrite(PIN_ADC_CTRL, LOW);
82+
83+
return (5.42 * (3.3 / 1024.0) * raw) * 1000;
84+
}
85+
86+
const char* HeltecTrackerV2Board::getManufacturerName() const {
87+
return "Heltec Tracker V2";
88+
}
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 HeltecTrackerV2Board : public ESP32Board {
9+
10+
public:
11+
RefCountedDigitalPin periph_power;
12+
13+
HeltecTrackerV2Board() : 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+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef Pins_Arduino_h
2+
#define Pins_Arduino_h
3+
4+
#include <stdint.h>
5+
6+
static const uint8_t LED_BUILTIN = 18;
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 = 5;
14+
static const uint8_t SCL = 6;
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 = 3;
58+
static const uint8_t LED = 18;
59+
60+
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)