Skip to content

Commit 3af5ffe

Browse files
committed
Fix GPS and LEDs on ThinkNode M3
GPS support was implemented incorrectly for the ThinkNode M3. The reset pin was being driven when it should be left floating for this unit. The enable pin also wasn't being picked up by `MicroNMEALocationProvider` because of a mismatch in constant naming conventions. I did a general cleanup of the GPS and ThinkNode M3 bring-up code so that constant names line up and "*_ACTIVE" constants are used consistently vs hardcoding `HIGH`/`LOW`. After making these changes, serial data immediately starts streaming in from the NMEA on boot and GPS detection just works. LED handling was also not quite right for the ThinkNode M3. The LoRa TX LED was being driven high to turn it on when it should actually be driven low. I changed the code to use the `LED_STATE_ON` constant and also added a little code to the shutdown path to properly make sure that all LEDs are turned off. Tested and confirmed working on real hardware. Resolves both #1864 and #2879.
1 parent acdf4e5 commit 3af5ffe

5 files changed

Lines changed: 34 additions & 29 deletions

File tree

src/helpers/sensors/MicroNMEALocationProvider.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
#endif
1414
#endif
1515

16-
#ifndef PIN_GPS_EN_ACTIVE
17-
#define PIN_GPS_EN_ACTIVE HIGH
16+
#ifndef GPS_EN_ACTIVE
17+
#ifdef PIN_GPS_EN_ACTIVE
18+
#define GPS_EN_ACTIVE PIN_GPS_EN_ACTIVE
19+
#else
20+
#define GPS_EN_ACTIVE HIGH
21+
#endif
1822
#endif
1923

2024
#ifndef GPS_RESET
@@ -25,11 +29,11 @@
2529
#endif
2630
#endif
2731

28-
#ifndef GPS_RESET_FORCE
32+
#ifndef GPS_RESET_ACTIVE
2933
#ifdef PIN_GPS_RESET_ACTIVE
30-
#define GPS_RESET_FORCE PIN_GPS_RESET_ACTIVE
34+
#define GPS_RESET_ACTIVE PIN_GPS_RESET_ACTIVE
3135
#else
32-
#define GPS_RESET_FORCE LOW
36+
#define GPS_RESET_ACTIVE LOW
3337
#endif
3438
#endif
3539

@@ -52,11 +56,11 @@ public :
5256
_gps_serial(&ser), nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _pin_reset(pin_reset), _pin_en(pin_en), _clock(clock), _peripher_power(peripher_power) {
5357
if (_pin_reset != -1) {
5458
pinMode(_pin_reset, OUTPUT);
55-
digitalWrite(_pin_reset, GPS_RESET_FORCE);
59+
digitalWrite(_pin_reset, GPS_RESET_ACTIVE);
5660
}
5761
if (_pin_en != -1) {
5862
pinMode(_pin_en, OUTPUT);
59-
digitalWrite(_pin_en, LOW);
63+
digitalWrite(_pin_en, !GPS_EN_ACTIVE);
6064
}
6165
}
6266

@@ -76,27 +80,27 @@ public :
7680
void begin() override {
7781
claim();
7882
if (_pin_en != -1) {
79-
digitalWrite(_pin_en, PIN_GPS_EN_ACTIVE);
83+
digitalWrite(_pin_en, GPS_EN_ACTIVE);
8084
}
8185
if (_pin_reset != -1) {
82-
digitalWrite(_pin_reset, !GPS_RESET_FORCE);
86+
digitalWrite(_pin_reset, !GPS_RESET_ACTIVE);
8387
}
8488
}
8589

8690
void reset() override {
8791
if (_pin_reset != -1) {
88-
digitalWrite(_pin_reset, GPS_RESET_FORCE);
92+
digitalWrite(_pin_reset, GPS_RESET_ACTIVE);
8993
delay(10);
90-
digitalWrite(_pin_reset, !GPS_RESET_FORCE);
94+
digitalWrite(_pin_reset, !GPS_RESET_ACTIVE);
9195
}
9296
}
9397

9498
void stop() override {
9599
if (_pin_en != -1) {
96-
digitalWrite(_pin_en, !PIN_GPS_EN_ACTIVE);
100+
digitalWrite(_pin_en, !GPS_EN_ACTIVE);
97101
}
98102
if (_pin_reset != -1) {
99-
digitalWrite(_pin_reset, GPS_RESET_FORCE);
103+
digitalWrite(_pin_reset, GPS_RESET_ACTIVE);
100104
}
101105
release();
102106
}
@@ -105,7 +109,7 @@ public :
105109
// directly read the enable pin if present as gps can be
106110
// activated/deactivated outside of here ...
107111
if (_pin_en != -1) {
108-
return digitalRead(_pin_en) == PIN_GPS_EN_ACTIVE;
112+
return digitalRead(_pin_en) == GPS_EN_ACTIVE;
109113
} else {
110114
return true; // no enable so must be active
111115
}

variants/thinknode_m3/ThinkNodeM3Board.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class ThinkNodeM3Board : public NRF52BoardDCDC {
1818
void begin();
1919
uint16_t getBattMilliVolts() override;
2020

21-
#if defined(P_LORA_TX_LED)
21+
#ifdef P_LORA_TX_LED
2222
void onBeforeTransmit() override {
23-
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
23+
digitalWrite(P_LORA_TX_LED, LED_STATE_ON); // turn TX LED on
2424
}
2525
void onAfterTransmit() override {
26-
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
26+
digitalWrite(P_LORA_TX_LED, !LED_STATE_ON); // turn TX LED off
2727
}
2828
#endif
2929

@@ -44,9 +44,9 @@ class ThinkNodeM3Board : public NRF52BoardDCDC {
4444

4545
void powerOff() override {
4646
// turn off all leds, sd_power_system_off will not do this for us
47-
#ifdef P_LORA_TX_LED
48-
digitalWrite(P_LORA_TX_LED, LOW);
49-
#endif
47+
digitalWrite(PIN_LED_BLUE, !LED_STATE_ON);
48+
digitalWrite(PIN_LED_GREEN, !LED_STATE_ON);
49+
digitalWrite(PIN_LED_RED, !LED_STATE_ON);
5050

5151
// power off board
5252
sd_power_system_off();

variants/thinknode_m3/platformio.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ build_flags = ${nrf52_base.build_flags}
2424
-D P_LORA_MOSI=46
2525
-D P_LORA_RESET=42
2626
-D P_LORA_TX_LED=PIN_LED_BLUE
27-
-D P_LORA_TX_LED_ON=LOW
2827
-D LR11X0_DIO_AS_RF_SWITCH=true
2928
-D LR11X0_DIO3_TCXO_VOLTAGE=3.3
3029
-D MESH_DEBUG=1
@@ -105,7 +104,6 @@ build_flags = ${ThinkNode_M3.build_flags}
105104
-D BLE_TX_POWER=0
106105
; -D BLE_DEBUG_LOGGING=1
107106
; -D MESH_PACKET_LOGGING=1
108-
-D GPS_NMEA_DEBUG
109107
-D OFFLINE_QUEUE_SIZE=256
110108
-D DISPLAY_CLASS=NullDisplayDriver
111109
-D PIN_BUZZER=23

variants/thinknode_m3/variant.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,18 @@ void initVariant()
8080
digitalWrite(LED_POWER, HIGH);
8181

8282
pinMode(PIN_LED_BLUE, OUTPUT);
83+
digitalWrite(PIN_LED_BLUE, !LED_STATE_ON);
8384
pinMode(PIN_LED_GREEN, OUTPUT);
85+
digitalWrite(PIN_LED_GREEN, !LED_STATE_ON);
8486
pinMode(PIN_LED_RED, OUTPUT);
87+
digitalWrite(PIN_LED_RED, !LED_STATE_ON);
8588

8689
pinMode(BUTTON_PIN, INPUT_PULLUP);
8790

8891
pinMode(PIN_GPS_POWER, OUTPUT);
8992
pinMode(PIN_GPS_EN, OUTPUT);
90-
pinMode(PIN_GPS_RESET, OUTPUT);
9193

9294
// Power on gps but in standby
93-
digitalWrite(PIN_GPS_EN, LOW);
94-
digitalWrite(PIN_GPS_POWER, HIGH);
95+
digitalWrite(PIN_GPS_EN, !GPS_EN_ACTIVE);
96+
digitalWrite(PIN_GPS_POWER, GPS_POWER_ACTIVE);
9597
}

variants/thinknode_m3/variant.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define EXT_CHRG_DETECT (32) // P1.3
3333
#define EXT_PWR_DETECT (31) // P0.5
3434

35-
#define PIN_VBAT_READ (5)
35+
#define PIN_VBAT_READ (5)
3636
#define AREF_VOLTAGE (2.4f)
3737
#define ADC_MULTIPLIER (2.0) //(1.75f)
3838
// 2.0 gives more coherent value, 4.2V when charged, needs tweaking
@@ -92,18 +92,19 @@
9292
// GPS
9393

9494
#define HAS_GPS 1
95-
#define PIN_GPS_RX (22)
95+
#define PIN_GPS_RX (22)
9696
#define PIN_GPS_TX (20)
9797

9898
#define PIN_GPS_POWER (14)
9999
#define PIN_GPS_EN (21) // STANDBY
100100
#define PIN_GPS_RESET (25) // REINIT
101-
#define GPS_RESET_ACTIVE LOW
101+
#define GPS_POWER_ACTIVE HIGH
102102
#define GPS_EN_ACTIVE HIGH
103+
#define GPS_RESET (-1)
103104
#define GPS_BAUDRATE 9600
104105

105106
////////////////////////////////////////////////////////////////////////////////
106107
// Buzzer
107108

108109
#define BUZZER_EN (37) // P1.5
109-
#define BUZZER_PIN (25) // P0.25
110+
#define BUZZER_PIN (25) // P0.25

0 commit comments

Comments
 (0)