Skip to content

Commit b47b857

Browse files
authored
Merge pull request #1980 from MGJ520/dev
Add support for the GAT562 Mesh Tracker Pro device
2 parents 2715d3a + 011c5ba commit b47b857

7 files changed

Lines changed: 588 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <Arduino.h>
2+
#include <Wire.h>
3+
4+
#include "GAT562MeshTrackerProBoard.h"
5+
6+
7+
#ifdef NRF52_POWER_MANAGEMENT
8+
// Static configuration for power management
9+
// Values set in variant.h defines
10+
const PowerMgtConfig power_config = {
11+
.lpcomp_ain_channel = PWRMGT_LPCOMP_AIN,
12+
.lpcomp_refsel = PWRMGT_LPCOMP_REFSEL,
13+
.voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK
14+
};
15+
16+
17+
void GAT562MeshTrackerProBoard::initiateShutdown(uint8_t reason) {
18+
// Disable LoRa module power before shutdown
19+
digitalWrite(SX126X_POWER_EN, LOW);
20+
21+
if (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
22+
reason == SHUTDOWN_REASON_BOOT_PROTECT) {
23+
configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
24+
}
25+
26+
enterSystemOff(reason);
27+
}
28+
#endif // NRF52_POWER_MANAGEMENT
29+
30+
31+
void GAT562MeshTrackerProBoard::begin() {
32+
NRF52BoardDCDC::begin();
33+
pinMode(PIN_VBAT_READ, INPUT);
34+
35+
// Set all button pins to INPUT_PULLUP
36+
pinMode(PIN_BUTTON1, INPUT_PULLUP);
37+
pinMode(PIN_BUTTON2, INPUT_PULLUP);
38+
pinMode(PIN_BUTTON3, INPUT_PULLUP);
39+
pinMode(PIN_BUTTON4, INPUT_PULLUP);
40+
pinMode(PIN_BUTTON5, INPUT_PULLUP);
41+
pinMode(PIN_BUTTON6, INPUT_PULLUP);
42+
43+
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
44+
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
45+
#endif
46+
47+
Wire.begin();
48+
49+
pinMode(SX126X_POWER_EN, OUTPUT);
50+
#ifdef NRF52_POWER_MANAGEMENT
51+
// Boot voltage protection check (may not return if voltage too low)
52+
// We need to call this after we configure SX126X_POWER_EN as output but before we pull high
53+
checkBootVoltage(&power_config);
54+
#endif
55+
digitalWrite(SX126X_POWER_EN, HIGH);
56+
delay(10); // give sx1268 some time to power up
57+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
#include <helpers/NRF52Board.h>
6+
7+
8+
class GAT562MeshTrackerProBoard : public NRF52BoardDCDC {
9+
protected:
10+
#ifdef NRF52_POWER_MANAGEMENT
11+
void initiateShutdown(uint8_t reason) override;
12+
#endif
13+
14+
public:
15+
GAT562MeshTrackerProBoard() : NRF52Board("GAT562_OTA") {}
16+
void begin();
17+
18+
#define BATTERY_SAMPLES 8
19+
20+
uint16_t getBattMilliVolts() override {
21+
analogReadResolution(12);
22+
23+
uint32_t raw = 0;
24+
for (int i = 0; i < BATTERY_SAMPLES; i++) {
25+
raw += analogRead(PIN_VBAT_READ);
26+
}
27+
raw = raw / BATTERY_SAMPLES;
28+
29+
return (ADC_MULTIPLIER * raw) / 4096;
30+
}
31+
32+
const char* getManufacturerName() const override {
33+
return "GAT562 Mesh Tracker Pro";
34+
}
35+
36+
#if defined(P_LORA_TX_LED)
37+
void onBeforeTransmit() override {
38+
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
39+
}
40+
41+
void onAfterTransmit() override {
42+
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
43+
}
44+
#endif
45+
46+
void powerOff() override {
47+
uint32_t button_pin = PIN_BUTTON1;
48+
nrf_gpio_cfg_input(button_pin, NRF_GPIO_PIN_PULLUP);
49+
nrf_gpio_cfg_sense_set(button_pin, NRF_GPIO_PIN_SENSE_LOW);
50+
sd_power_system_off();
51+
}
52+
53+
};
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
[GAT562_Mesh_Tracker_Pro]
2+
extends = nrf52_base
3+
board = rak4631
4+
board_check = true
5+
build_flags = ${nrf52_base.build_flags}
6+
${sensor_base.build_flags}
7+
-I variants/gat562_mesh_tracker_pro
8+
-D RAK_4631
9+
-D RAK_BOARD
10+
-D NRF52_POWER_MANAGEMENT
11+
-D LORA_FREQ=475
12+
-D LORA_BW=125
13+
-D LORA_SF=10
14+
-D LORA_CR=6
15+
-D PIN_BOARD_SCL=14
16+
-D PIN_BOARD_SDA=13
17+
-D PIN_OLED_RESET=-1
18+
-D UI_HAS_JOYSTICK=1
19+
-D RADIO_CLASS=CustomSX1262
20+
-D WRAPPER_CLASS=CustomSX1262Wrapper
21+
-D LORA_TX_POWER=22
22+
-D SX126X_CURRENT_LIMIT=140
23+
-D SX126X_RX_BOOSTED_GAIN=1
24+
build_src_filter = ${nrf52_base.build_src_filter}
25+
+<../variants/gat562_mesh_tracker_pro>
26+
+<helpers/ui/SSD1306Display.cpp>
27+
+<helpers/ui/MomentaryButton.cpp>
28+
+<helpers/sensors>
29+
lib_deps =
30+
${nrf52_base.lib_deps}
31+
${sensor_base.lib_deps}
32+
adafruit/Adafruit SSD1306 @ ^2.5.13
33+
sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.27
34+
35+
36+
[env:GAT562_Mesh_Tracker_Pro_repeater]
37+
extends = GAT562_Mesh_Tracker_Pro
38+
build_flags =
39+
${GAT562_Mesh_Tracker_Pro.build_flags}
40+
-D DISPLAY_CLASS=SSD1306Display
41+
-D ADVERT_NAME='"GAT562 Repeater"'
42+
-D ADVERT_LAT=0.0
43+
-D ADVERT_LON=0.0
44+
-D ADMIN_PASSWORD='"password"'
45+
-D MAX_NEIGHBOURS=50
46+
; -D MESH_PACKET_LOGGING=1
47+
; -D MESH_DEBUG=1
48+
build_src_filter = ${GAT562_Mesh_Tracker_Pro.build_src_filter}
49+
+<helpers/ui/SSD1306Display.cpp>
50+
+<../examples/simple_repeater>
51+
52+
53+
[env:GAT562_Mesh_Tracker_Pro_room_server]
54+
extends = GAT562_Mesh_Tracker_Pro
55+
build_flags =
56+
${GAT562_Mesh_Tracker_Pro.build_flags}
57+
-D DISPLAY_CLASS=SSD1306Display
58+
-D ADVERT_NAME='"GAT562 Room"'
59+
-D ADVERT_LAT=0.0
60+
-D ADVERT_LON=0.0
61+
-D ADMIN_PASSWORD='"password"'
62+
-D ROOM_PASSWORD='"hello"'
63+
; -D MESH_PACKET_LOGGING=1
64+
; -D MESH_DEBUG=1
65+
build_src_filter = ${GAT562_Mesh_Tracker_Pro.build_src_filter}
66+
+<helpers/ui/SSD1306Display.cpp>
67+
+<../examples/simple_room_server>
68+
69+
70+
[env:GAT562_Mesh_Tracker_Pro_companion_radio_usb]
71+
extends = GAT562_Mesh_Tracker_Pro
72+
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
73+
board_upload.maximum_size = 712704
74+
build_flags =
75+
${GAT562_Mesh_Tracker_Pro.build_flags}
76+
-I examples/companion_radio/ui-new
77+
-D DISPLAY_CLASS=SSD1306Display
78+
-D MAX_CONTACTS=350
79+
-D MAX_GROUP_CHANNELS=40
80+
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
81+
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
82+
build_src_filter = ${GAT562_Mesh_Tracker_Pro.build_src_filter}
83+
+<../examples/companion_radio/*.cpp>
84+
+<../examples/companion_radio/ui-new/*.cpp>
85+
lib_deps =
86+
${GAT562_Mesh_Tracker_Pro.lib_deps}
87+
densaugeo/base64 @ ~1.4.0
88+
89+
90+
91+
[env:GAT562_Mesh_Tracker_Pro_companion_radio_ble]
92+
extends = GAT562_Mesh_Tracker_Pro
93+
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
94+
board_upload.maximum_size = 712704
95+
build_flags =
96+
${GAT562_Mesh_Tracker_Pro.build_flags}
97+
-I examples/companion_radio/ui-new
98+
-D DISPLAY_CLASS=SSD1306Display
99+
-D MAX_CONTACTS=350
100+
-D MAX_GROUP_CHANNELS=40
101+
-D BLE_PIN_CODE=123456
102+
-D BLE_DEBUG_LOGGING=1
103+
-D OFFLINE_QUEUE_SIZE=256
104+
; -D MESH_PACKET_LOGGING=1
105+
; -D MESH_DEBUG=1
106+
build_src_filter = ${GAT562_Mesh_Tracker_Pro.build_src_filter}
107+
+<helpers/nrf52/SerialBLEInterface.cpp>
108+
+<helpers/ui/MomentaryButton.cpp>
109+
+<../examples/companion_radio/*.cpp>
110+
+<../examples/companion_radio/ui-new/*.cpp>
111+
lib_deps =
112+
${GAT562_Mesh_Tracker_Pro.lib_deps}
113+
densaugeo/base64 @ ~1.4.0
114+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <Arduino.h>
2+
#include "target.h"
3+
#include <helpers/ArduinoHelpers.h>
4+
5+
GAT562MeshTrackerProBoard board;
6+
7+
#ifndef PIN_USER_BTN
8+
#define PIN_USER_BTN (-1)
9+
#endif
10+
11+
12+
#ifdef DISPLAY_CLASS
13+
DISPLAY_CLASS display;
14+
MomentaryButton user_btn(PIN_USER_BTN, 1000, true, false, false);
15+
MomentaryButton joystick_left(JOYSTICK_LEFT, 1000, true, false, false);
16+
MomentaryButton joystick_right(JOYSTICK_RIGHT, 1000, true, false, false);
17+
MomentaryButton back_btn(PIN_BACK_BTN, 1000, true, false, true);
18+
#endif
19+
20+
21+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
22+
23+
WRAPPER_CLASS radio_driver(radio, board);
24+
25+
VolatileRTCClock fallback_clock;
26+
AutoDiscoverRTCClock rtc_clock(fallback_clock);
27+
28+
#if ENV_INCLUDE_GPS
29+
#include <helpers/sensors/MicroNMEALocationProvider.h>
30+
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
31+
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
32+
#else
33+
EnvironmentSensorManager sensors;
34+
#endif
35+
36+
bool radio_init() {
37+
rtc_clock.begin(Wire);
38+
return radio.std_init(&SPI);
39+
}
40+
41+
uint32_t radio_get_rng_seed() {
42+
return radio.random(0x7FFFFFFF);
43+
}
44+
45+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
46+
radio.setFrequency(freq);
47+
radio.setSpreadingFactor(sf);
48+
radio.setBandwidth(bw);
49+
radio.setCodingRate(cr);
50+
}
51+
52+
void radio_set_tx_power(int8_t dbm) {
53+
radio.setOutputPower(dbm);
54+
}
55+
56+
mesh::LocalIdentity radio_new_identity() {
57+
RadioNoiseListener rng(radio);
58+
return mesh::LocalIdentity(&rng); // create new random identity
59+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <RadioLib.h>
5+
#include <helpers/radiolib/RadioLibWrappers.h>
6+
#include <GAT562MeshTrackerProBoard.h>
7+
#include <helpers/radiolib/CustomSX1262Wrapper.h>
8+
#include <helpers/AutoDiscoverRTCClock.h>
9+
#include <helpers/sensors/EnvironmentSensorManager.h>
10+
11+
#ifdef DISPLAY_CLASS
12+
#include <helpers/ui/SSD1306Display.h>
13+
extern DISPLAY_CLASS display;
14+
#include <helpers/ui/MomentaryButton.h>
15+
extern MomentaryButton user_btn;
16+
extern MomentaryButton joystick_left;
17+
extern MomentaryButton joystick_right;
18+
extern MomentaryButton back_btn;
19+
#endif
20+
21+
extern GAT562MeshTrackerProBoard board;
22+
extern WRAPPER_CLASS radio_driver;
23+
extern AutoDiscoverRTCClock rtc_clock;
24+
extern EnvironmentSensorManager sensors;
25+
26+
bool radio_init();
27+
uint32_t radio_get_rng_seed();
28+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
29+
void radio_set_tx_power(int8_t dbm);
30+
mesh::LocalIdentity radio_new_identity();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
3+
Copyright (c) 2016 Sandeep Mistry All right reserved.
4+
Copyright (c) 2018, Adafruit Industries (adafruit.com)
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
See the GNU Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "variant.h"
22+
#include "wiring_constants.h"
23+
#include "wiring_digital.h"
24+
#include "nrf.h"
25+
26+
const uint32_t g_ADigitalPinMap[] =
27+
{
28+
// P0
29+
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
30+
8 , 9 , 10, 11, 12, 13, 14, 15,
31+
16, 17, 18, 19, 20, 21, 22, 23,
32+
24, 25, 26, 27, 28, 29, 30, 31,
33+
34+
// P1
35+
32, 33, 34, 35, 36, 37, 38, 39,
36+
40, 41, 42, 43, 44, 45, 46, 47
37+
};
38+
39+
40+
void initVariant()
41+
{
42+
// LED1 & LED2
43+
pinMode(PIN_LED1, OUTPUT);
44+
ledOff(PIN_LED1);
45+
46+
// pinMode(PIN_LED2, OUTPUT);
47+
// ledOff(PIN_LED2);;
48+
}
49+

0 commit comments

Comments
 (0)