Skip to content

Commit 810fc8b

Browse files
author
Scott Powell
committed
* Heltec tracker: new 'periph_power' shared pin (between Display & GPS)
1 parent 997261a commit 810fc8b

File tree

8 files changed

+86
-27
lines changed

8 files changed

+86
-27
lines changed

examples/companion_radio/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
#define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg=="
6262

63-
#ifdef DISPLAY_CLASS
63+
#ifdef DISPLAY_CLASS // TODO: refactor this -- move to variants/*/target
6464
#include "UITask.h"
6565
#ifdef ST7735
6666
#include <helpers/ui/ST7735Display.h>
@@ -71,7 +71,13 @@
7171
#else
7272
#include <helpers/ui/SSD1306Display.h>
7373
#endif
74-
static DISPLAY_CLASS display;
74+
75+
#if defined(HELTEC_LORA_V3) && defined(ST7735)
76+
static DISPLAY_CLASS display(&board.periph_power); // peripheral power pin is shared
77+
#else
78+
static DISPLAY_CLASS display;
79+
#endif
80+
7581
#define HAS_UI
7682
#endif
7783

src/helpers/HeltecV3Board.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <Arduino.h>
4+
#include <helpers/RefCountedDigitalPin.h>
45

56
// LoRa radio module pins for Heltec V3
67
// Also for Heltec Wireless Tracker
@@ -20,7 +21,6 @@
2021
#define PIN_ADC_CTRL_ACTIVE LOW
2122
#define PIN_ADC_CTRL_INACTIVE HIGH
2223
//#define PIN_LED_BUILTIN 35
23-
#define PIN_VEXT_EN 36
2424

2525
#include "ESP32Board.h"
2626

@@ -31,6 +31,10 @@ class HeltecV3Board : public ESP32Board {
3131
bool adc_active_state;
3232

3333
public:
34+
RefCountedDigitalPin periph_power;
35+
36+
HeltecV3Board() : periph_power(PIN_VEXT_EN) { }
37+
3438
void begin() {
3539
ESP32Board::begin();
3640

@@ -41,8 +45,7 @@ class HeltecV3Board : public ESP32Board {
4145
pinMode(PIN_ADC_CTRL, OUTPUT);
4246
digitalWrite(PIN_ADC_CTRL, !adc_active_state); // Initially inactive
4347

44-
pinMode(PIN_VEXT_EN, OUTPUT);
45-
digitalWrite(PIN_VEXT_EN, LOW); // for V3.2 boards
48+
periph_power.begin();
4649

4750
esp_reset_reason_t reason = esp_reset_reason();
4851
if (reason == ESP_RST_DEEPSLEEP) {

src/helpers/RefCountedDigitalPin.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <Arduino.h>
4+
5+
class RefCountedDigitalPin {
6+
uint8_t _pin;
7+
int8_t _claims = 0;
8+
9+
public:
10+
RefCountedDigitalPin(uint8_t pin): _pin(pin) { }
11+
12+
void begin() {
13+
pinMode(_pin, OUTPUT);
14+
digitalWrite(_pin, LOW); // initial state
15+
}
16+
17+
void claim() {
18+
_claims++;
19+
if (_claims > 0) {
20+
digitalWrite(_pin, HIGH);
21+
}
22+
}
23+
void release() {
24+
_claims--;
25+
if (_claims == 0) {
26+
digitalWrite(_pin, LOW);
27+
}
28+
}
29+
};

src/helpers/ui/ST7735Display.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ bool ST7735Display::i2c_probe(TwoWire& wire, uint8_t addr) {
1919
}
2020

2121
bool ST7735Display::begin() {
22-
if(!_isOn) {
23-
pinMode(PIN_TFT_VDD_CTL, OUTPUT);
22+
if (!_isOn) {
23+
if (_peripher_power) _peripher_power->claim();
24+
2425
pinMode(PIN_TFT_LEDA_CTL, OUTPUT);
25-
digitalWrite(PIN_TFT_VDD_CTL, HIGH);
2626
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
2727
digitalWrite(PIN_TFT_RST, HIGH);
2828

@@ -40,18 +40,18 @@ bool ST7735Display::begin() {
4040
}
4141

4242
void ST7735Display::turnOn() {
43-
4443
ST7735Display::begin();
45-
4644
}
4745

4846
void ST7735Display::turnOff() {
49-
digitalWrite(PIN_TFT_VDD_CTL, HIGH);
50-
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
51-
digitalWrite(PIN_TFT_RST, LOW);
52-
digitalWrite(PIN_TFT_VDD_CTL, LOW);
53-
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
54-
_isOn = false;
47+
if (_isOn) {
48+
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
49+
digitalWrite(PIN_TFT_RST, LOW);
50+
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
51+
_isOn = false;
52+
53+
if (_peripher_power) _peripher_power->release();
54+
}
5555
}
5656

5757
void ST7735Display::clear() {

src/helpers/ui/ST7735Display.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,30 @@
55
#include <SPI.h>
66
#include <Adafruit_GFX.h>
77
#include <Adafruit_ST7735.h>
8+
#include <helpers/RefCountedDigitalPin.h>
89

910
class ST7735Display : public DisplayDriver {
1011
Adafruit_ST7735 display;
1112
bool _isOn;
1213
uint16_t _color;
14+
RefCountedDigitalPin* _peripher_power;
1315

1416
bool i2c_probe(TwoWire& wire, uint8_t addr);
1517
public:
1618
#ifdef USE_PIN_TFT
17-
ST7735Display() : DisplayDriver(128, 64), display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST) { _isOn = false; }
19+
ST7735Display(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
20+
display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST),
21+
_peripher_power(peripher_power)
22+
{
23+
_isOn = false;
24+
}
1825
#else
19-
ST7735Display() : DisplayDriver(128, 64), display(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST) { _isOn = false; }
26+
ST7735Display(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
27+
display(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST),
28+
_peripher_power(peripher_power)
29+
{
30+
_isOn = false;
31+
}
2032
#endif
2133
bool begin();
2234

variants/heltec_tracker/platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ build_flags =
1919
-D PIN_TFT_RST=39 ; RES
2020
-D PIN_TFT_CS=38
2121
-D USE_PIN_TFT=1
22-
-D PIN_TFT_VDD_CTL=3 ; Vext is connected to VDD which is also connected to LEDA
22+
-D PIN_VEXT_EN=3 ; Vext is connected to VDD which is also connected to OLED & GPS
2323
-D PIN_TFT_LEDA_CTL=21 ; LEDK (switches on/off via mosfet to create the ground)
2424
-D PIN_GPS_RX=33
2525
-D PIN_GPS_TX=34

variants/heltec_tracker/target.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <Arduino.h>
22
#include "target.h"
3+
34
#include <helpers/sensors/MicroNMEALocationProvider.h>
45

56
HeltecV3Board board;
@@ -78,18 +79,25 @@ mesh::LocalIdentity radio_new_identity() {
7879
}
7980

8081
void HWTSensorManager::start_gps() {
81-
gps_active = true;
82-
// init GPS
83-
Serial1.begin(115200, SERIAL_8N1, PIN_GPS_RX, PIN_GPS_TX);
84-
Serial1.println("$CFGSYS,h35155*68");
82+
if (!gps_active) {
83+
board.periph_power.claim();
84+
85+
gps_active = true;
86+
Serial1.println("$CFGSYS,h35155*68");
87+
}
8588
}
8689

8790
void HWTSensorManager::stop_gps() {
88-
gps_active = false;
89-
Serial1.end();
91+
if (gps_active) {
92+
gps_active = false;
93+
94+
board.periph_power.release();
95+
}
9096
}
9197

9298
bool HWTSensorManager::begin() {
99+
// init GPS port
100+
Serial1.begin(115200, SERIAL_8N1, PIN_GPS_RX, PIN_GPS_TX);
93101
return true;
94102
}
95103

@@ -106,10 +114,10 @@ void HWTSensorManager::loop() {
106114
_location->loop();
107115

108116
if (millis() > next_gps_update) {
109-
if (_location->isValid()) {
117+
if (gps_active && _location->isValid()) {
110118
node_lat = ((double)_location->getLatitude())/1000000.;
111119
node_lon = ((double)_location->getLongitude())/1000000.;
112-
//Serial.printf("lat %f lon %f\r\n", _lat, _lon);
120+
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
113121
}
114122
next_gps_update = millis() + 1000;
115123
}

variants/heltec_v3/platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ build_flags =
1212
-D PIN_BOARD_SDA=17
1313
-D PIN_BOARD_SCL=18
1414
-D PIN_USER_BTN=0
15+
-D PIN_VEXT_EN=36
1516
-D SX126X_DIO2_AS_RF_SWITCH=true
1617
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
1718
-D SX126X_CURRENT_LIMIT=130.0f ; for best TX power!

0 commit comments

Comments
 (0)