Skip to content

Commit 856df24

Browse files
authored
Merge pull request #2138 from MGJ520/dev_GAT562_Mesh_Watch13
Support for GAT562 Mesh Watch13 device
2 parents 7fc3263 + 76be69d commit 856df24

8 files changed

Lines changed: 509 additions & 0 deletions

File tree

docs/nrf52_power_management.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ Shutdown reason codes (stored in GPREGRET2):
3333

3434
## Supported Boards
3535

36+
3637
| Board | Implemented | LPCOMP wake | VBUS wake |
3738
|-------|-------------|-------------|-----------|
3839
| Seeed Studio XIAO nRF52840 (`xiao_nrf52`) | Yes | Yes | Yes |
3940
| RAK4631 (`rak4631`) | Yes | Yes | Yes |
4041
| Heltec T114 (`heltec_t114`) | Yes | Yes | Yes |
42+
| GAT562 Mesh Watch13 | Yes | Yes | Yes |
4143
| Promicro nRF52840 | No | No | No |
4244
| RAK WisMesh Tag | No | No | No |
4345
| Heltec Mesh Solar | No | No | No |
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <Arduino.h>
2+
#include <Wire.h>
3+
4+
#include "GAT56MeshWatch13Board.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 GAT56MeshWatch13Board::initiateShutdown(uint8_t reason) {
18+
if (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
19+
reason == SHUTDOWN_REASON_BOOT_PROTECT) {
20+
configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
21+
}
22+
enterSystemOff(reason);
23+
}
24+
#endif // NRF52_POWER_MANAGEMENT
25+
26+
27+
void GAT56MeshWatch13Board::begin() {
28+
NRF52BoardDCDC::begin();
29+
pinMode(PIN_VBAT_READ, INPUT);
30+
31+
32+
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
33+
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
34+
#endif
35+
36+
Wire.begin();
37+
38+
pinMode(SX126X_POWER_EN, OUTPUT);
39+
#ifdef NRF52_POWER_MANAGEMENT
40+
// Boot voltage protection check (may not return if voltage too low)
41+
// We need to call this after we configure SX126X_POWER_EN as output but before we pull high
42+
checkBootVoltage(&power_config);
43+
#endif
44+
digitalWrite(SX126X_POWER_EN, HIGH);
45+
delay(10); // give sx1262 some time to power up
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
#include <helpers/NRF52Board.h>
6+
7+
8+
class GAT56MeshWatch13Board : public NRF52BoardDCDC {
9+
protected:
10+
#ifdef NRF52_POWER_MANAGEMENT
11+
void initiateShutdown(uint8_t reason) override;
12+
#endif
13+
14+
public:
15+
GAT56MeshWatch13Board() : 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 Watch 13";
34+
}
35+
36+
37+
void powerOff() override {
38+
uint32_t button_pin = PIN_BUTTON2;
39+
nrf_gpio_cfg_input(button_pin, NRF_GPIO_PIN_PULLUP);
40+
nrf_gpio_cfg_sense_set(button_pin, NRF_GPIO_PIN_SENSE_LOW);
41+
sd_power_system_off();
42+
}
43+
44+
};
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
[GAT562_Mesh_Watch13]
2+
extends = nrf52_base
3+
board = rak4631
4+
board_check = true
5+
build_flags = ${nrf52_base.build_flags}
6+
${sensor_base.build_flags}
7+
-UENV_INCLUDE_GPS
8+
-I variants/gat562_mesh_watch13
9+
-D RAK_4631
10+
-D RAK_BOARD
11+
-D NRF52_POWER_MANAGEMENT
12+
-D PIN_BOARD_SCL=14
13+
-D PIN_BOARD_SDA=13
14+
-D PIN_OLED_RESET=-1
15+
-D RADIO_CLASS=CustomSX1262
16+
-D WRAPPER_CLASS=CustomSX1262Wrapper
17+
-D LORA_TX_POWER=19
18+
-D SX126X_CURRENT_LIMIT=140
19+
-D SX126X_RX_BOOSTED_GAIN=1
20+
-D QSPIFLASH=1
21+
build_src_filter = ${nrf52_base.build_src_filter}
22+
+<../variants/gat562_mesh_watch13>
23+
+<helpers/ui/SSD1306Display.cpp>
24+
+<helpers/ui/MomentaryButton.cpp>
25+
+<helpers/sensors>
26+
lib_deps =
27+
${nrf52_base.lib_deps}
28+
${sensor_base.lib_deps}
29+
adafruit/Adafruit SSD1306 @ ^2.5.13
30+
31+
32+
;[env:GAT562_Mesh_Watch13_repeater]
33+
;extends = GAT562_Mesh_Watch13
34+
;build_flags =
35+
; ${GAT562_Mesh_Watch13.build_flags}
36+
; -D DISPLAY_CLASS=SSD1306Display
37+
; -D ADVERT_NAME='"GAT562 Repeater"'
38+
; -D ADVERT_LAT=0.0
39+
; -D ADVERT_LON=0.0
40+
; -D ADMIN_PASSWORD='"password"'
41+
; -D MAX_NEIGHBOURS=50
42+
;; -D MESH_PACKET_LOGGING=1
43+
;; -D MESH_DEBUG=1
44+
;build_src_filter = ${GAT562_Mesh_Watch13.build_src_filter}
45+
; +<helpers/ui/SSD1306Display.cpp>
46+
; +<../examples/simple_repeater>
47+
48+
;[env:GAT562_Mesh_Watch13_room_server]
49+
;extends = GAT562_Mesh_Watch13
50+
;build_flags =
51+
; ${GAT562_Mesh_Watch13.build_flags}
52+
; -D DISPLAY_CLASS=SSD1306Display
53+
; -D ADVERT_NAME='"GAT562 Room"'
54+
; -D ADVERT_LAT=0.0
55+
; -D ADVERT_LON=0.0
56+
; -D ADMIN_PASSWORD='"password"'
57+
; -D ROOM_PASSWORD='"hello"'
58+
;; -D MESH_PACKET_LOGGING=1
59+
;; -D MESH_DEBUG=1
60+
;build_src_filter = ${GAT562_Mesh_Watch13.build_src_filter}
61+
; +<helpers/ui/SSD1306Display.cpp>
62+
; +<../examples/simple_room_server>
63+
64+
[env:GAT562_Mesh_Watch13_companion_radio_ble]
65+
extends = GAT562_Mesh_Watch13
66+
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
67+
board_upload.maximum_size = 712704
68+
build_flags =
69+
${GAT562_Mesh_Watch13.build_flags}
70+
-I examples/companion_radio/ui-new
71+
-D DISPLAY_CLASS=SSD1306Display
72+
-D MAX_CONTACTS=350
73+
-D MAX_GROUP_CHANNELS=40
74+
-D BLE_PIN_CODE=123456
75+
-D BLE_DEBUG_LOGGING=1
76+
-D OFFLINE_QUEUE_SIZE=256
77+
; -D PIN_VIBRATION=36
78+
; -D MESH_PACKET_LOGGING=1
79+
; -D MESH_DEBUG=1
80+
build_src_filter = ${GAT562_Mesh_Watch13.build_src_filter}
81+
+<helpers/nrf52/SerialBLEInterface.cpp>
82+
+<helpers/ui/MomentaryButton.cpp>
83+
+<helpers/ui/GenericVibration.cpp>
84+
+<../examples/companion_radio/*.cpp>
85+
+<../examples/companion_radio/ui-new/*.cpp>
86+
lib_deps =
87+
${GAT562_Mesh_Watch13.lib_deps}
88+
densaugeo/base64 @ ~1.4.0
89+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <Arduino.h>
2+
#include "target.h"
3+
#include <helpers/ArduinoHelpers.h>
4+
5+
GAT56MeshWatch13Board 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 back_btn(PIN_BACK_BTN, 1000, true, false, true);
16+
#endif
17+
18+
19+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
20+
21+
WRAPPER_CLASS radio_driver(radio, board);
22+
23+
VolatileRTCClock fallback_clock;
24+
AutoDiscoverRTCClock rtc_clock(fallback_clock);
25+
EnvironmentSensorManager sensors;
26+
27+
28+
bool radio_init() {
29+
rtc_clock.begin(Wire);
30+
return radio.std_init(&SPI);
31+
}
32+
33+
uint32_t radio_get_rng_seed() {
34+
return radio.random(0x7FFFFFFF);
35+
}
36+
37+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
38+
radio.setFrequency(freq);
39+
radio.setSpreadingFactor(sf);
40+
radio.setBandwidth(bw);
41+
radio.setCodingRate(cr);
42+
}
43+
44+
void radio_set_tx_power(int8_t dbm) {
45+
radio.setOutputPower(dbm);
46+
}
47+
48+
mesh::LocalIdentity radio_new_identity() {
49+
RadioNoiseListener rng(radio);
50+
return mesh::LocalIdentity(&rng); // create new random identity
51+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <RadioLib.h>
5+
#include <helpers/radiolib/RadioLibWrappers.h>
6+
#include <GAT56MeshWatch13Board.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 back_btn;
17+
#endif
18+
19+
#ifdef PIN_VIBRATION
20+
#include <helpers/ui/GenericVibration.h>
21+
#endif
22+
23+
extern GAT56MeshWatch13Board board;
24+
extern WRAPPER_CLASS radio_driver;
25+
extern AutoDiscoverRTCClock rtc_clock;
26+
extern EnvironmentSensorManager sensors;
27+
28+
bool radio_init();
29+
uint32_t radio_get_rng_seed();
30+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
31+
void radio_set_tx_power(int8_t dbm);
32+
mesh::LocalIdentity radio_new_identity();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
43+
}
44+

0 commit comments

Comments
 (0)