Skip to content

Commit 1ffb095

Browse files
committed
Support for GAT562 Mesh Solar Relay device
1 parent bdf1050 commit 1ffb095

8 files changed

Lines changed: 463 additions & 0 deletions

File tree

docs/nrf52_power_management.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Shutdown reason codes (stored in GPREGRET2):
3838
| Seeed Studio XIAO nRF52840 (`xiao_nrf52`) | Yes | Yes | Yes |
3939
| RAK4631 (`rak4631`) | Yes | Yes | Yes |
4040
| Heltec T114 (`heltec_t114`) | Yes | Yes | Yes |
41+
| GAT562 Mesh Solar Relay | Yes | Yes | Yes |
4142
| Promicro nRF52840 | No | No | No |
4243
| RAK WisMesh Tag | No | No | No |
4344
| Heltec Mesh Solar | No | No | No |
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <Arduino.h>
2+
#include <Wire.h>
3+
#include "GAT562MeshSolarRelayBoard.h"
4+
5+
6+
#ifdef NRF52_POWER_MANAGEMENT
7+
// Static configuration for power management
8+
// Values set in variant.h defines
9+
const PowerMgtConfig power_config = {
10+
.lpcomp_ain_channel = PWRMGT_LPCOMP_AIN,
11+
.lpcomp_refsel = PWRMGT_LPCOMP_REFSEL,
12+
.voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK
13+
};
14+
15+
16+
void GAT562MeshSolarRelayBoard::initiateShutdown(uint8_t reason) {
17+
// Disable LoRa module power before shutdown
18+
digitalWrite(SX126X_POWER_EN, LOW);
19+
20+
if (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
21+
reason == SHUTDOWN_REASON_BOOT_PROTECT) {
22+
configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
23+
}
24+
25+
enterSystemOff(reason);
26+
}
27+
#endif // NRF52_POWER_MANAGEMENT
28+
29+
30+
void GAT562MeshSolarRelayBoard::begin() {
31+
NRF52BoardDCDC::begin();
32+
pinMode(PIN_VBAT_READ, INPUT);
33+
34+
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
35+
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
36+
#endif
37+
38+
Wire.begin();
39+
40+
pinMode(SX126X_POWER_EN, OUTPUT);
41+
#ifdef NRF52_POWER_MANAGEMENT
42+
// Boot voltage protection check (may not return if voltage too low)
43+
// We need to call this after we configure SX126X_POWER_EN as output but before we pull high
44+
checkBootVoltage(&power_config);
45+
#endif
46+
digitalWrite(SX126X_POWER_EN, HIGH);
47+
delay(10); // give sx1262 some time to power up
48+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
#include <helpers/NRF52Board.h>
6+
7+
8+
class GAT562MeshSolarRelayBoard : public NRF52BoardDCDC {
9+
protected:
10+
#ifdef NRF52_POWER_MANAGEMENT
11+
void initiateShutdown(uint8_t reason) override;
12+
#endif
13+
14+
public:
15+
GAT562MeshSolarRelayBoard() : 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 Solar Relay";
34+
}
35+
36+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[GAT562_Mesh_Solar_Relay]
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_solar_relay
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 RADIO_CLASS=CustomSX1262
15+
-D WRAPPER_CLASS=CustomSX1262Wrapper
16+
-D LORA_TX_POWER=22
17+
-D SX126X_CURRENT_LIMIT=140
18+
-D SX126X_RX_BOOSTED_GAIN=1
19+
build_src_filter = ${nrf52_base.build_src_filter}
20+
+<../variants/gat562_mesh_solar_relay>
21+
+<helpers/sensors>
22+
lib_deps =
23+
${nrf52_base.lib_deps}
24+
${sensor_base.lib_deps}
25+
26+
[env:GAT562_Mesh_Solar_Relay_repeater]
27+
extends = GAT562_Mesh_Solar_Relay
28+
build_flags =
29+
${GAT562_Mesh_Solar_Relay.build_flags}
30+
-D ADVERT_NAME='"GAT562 Repeater"'
31+
-D ADVERT_LAT=0.0
32+
-D ADVERT_LON=0.0
33+
-D ADMIN_PASSWORD='"password"'
34+
-D MAX_NEIGHBOURS=50
35+
; -D MESH_PACKET_LOGGING=1
36+
; -D MESH_DEBUG=1
37+
build_src_filter = ${GAT562_Mesh_Solar_Relay.build_src_filter}
38+
+<../examples/simple_repeater>
39+
40+
[env:GAT562_Mesh_Solar_Relay_room_server]
41+
extends = GAT562_Mesh_Solar_Relay
42+
build_flags =
43+
${GAT562_Mesh_Solar_Relay.build_flags}
44+
-D ADVERT_NAME='"GAT562 Room"'
45+
-D ADVERT_LAT=0.0
46+
-D ADVERT_LON=0.0
47+
-D ADMIN_PASSWORD='"password"'
48+
-D ROOM_PASSWORD='"hello"'
49+
; -D MESH_PACKET_LOGGING=1
50+
; -D MESH_DEBUG=1
51+
build_src_filter = ${GAT562_Mesh_Solar_Relay.build_src_filter}
52+
+<../examples/simple_room_server>
53+
54+
[env:GAT562_Mesh_Solar_Relay_companion_radio_ble]
55+
extends = GAT562_Mesh_Solar_Relay
56+
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
57+
board_upload.maximum_size = 712704
58+
build_flags =
59+
${GAT562_Mesh_Solar_Relay.build_flags}
60+
-D MAX_CONTACTS=350
61+
-D MAX_GROUP_CHANNELS=40
62+
-D BLE_PIN_CODE=123456
63+
-D BLE_DEBUG_LOGGING=1
64+
-D OFFLINE_QUEUE_SIZE=256
65+
; -D MESH_PACKET_LOGGING=1
66+
; -D MESH_DEBUG=1
67+
build_src_filter = ${GAT562_Mesh_Solar_Relay.build_src_filter}
68+
+<helpers/nrf52/SerialBLEInterface.cpp>
69+
+<../examples/companion_radio/*.cpp>
70+
lib_deps =
71+
${GAT562_Mesh_Solar_Relay.lib_deps}
72+
densaugeo/base64 @ ~1.4.0
73+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <Arduino.h>
2+
#include "target.h"
3+
#include <helpers/ArduinoHelpers.h>
4+
5+
GAT562MeshSolarRelayBoard board;
6+
7+
#ifndef PIN_USER_BTN
8+
#define PIN_USER_BTN (-1)
9+
#endif
10+
11+
EnvironmentSensorManager sensors;
12+
13+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
14+
15+
WRAPPER_CLASS radio_driver(radio, board);
16+
17+
VolatileRTCClock fallback_clock;
18+
AutoDiscoverRTCClock rtc_clock(fallback_clock);
19+
20+
21+
bool radio_init() {
22+
rtc_clock.begin(Wire);
23+
return radio.std_init(&SPI);
24+
}
25+
26+
uint32_t radio_get_rng_seed() {
27+
return radio.random(0x7FFFFFFF);
28+
}
29+
30+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
31+
radio.setFrequency(freq);
32+
radio.setSpreadingFactor(sf);
33+
radio.setBandwidth(bw);
34+
radio.setCodingRate(cr);
35+
}
36+
37+
void radio_set_tx_power(int8_t dbm) {
38+
radio.setOutputPower(dbm);
39+
}
40+
41+
mesh::LocalIdentity radio_new_identity() {
42+
RadioNoiseListener rng(radio);
43+
return mesh::LocalIdentity(&rng); // create new random identity
44+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <RadioLib.h>
5+
#include <helpers/radiolib/RadioLibWrappers.h>
6+
#include <GAT562MeshSolarRelayBoard.h>
7+
#include <helpers/radiolib/CustomSX1262Wrapper.h>
8+
#include <helpers/AutoDiscoverRTCClock.h>
9+
#include <helpers/sensors/EnvironmentSensorManager.h>
10+
11+
12+
extern GAT562MeshSolarRelayBoard board;
13+
extern WRAPPER_CLASS radio_driver;
14+
extern AutoDiscoverRTCClock rtc_clock;
15+
extern EnvironmentSensorManager sensors;
16+
17+
bool radio_init();
18+
uint32_t radio_get_rng_seed();
19+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
20+
void radio_set_tx_power(int8_t dbm);
21+
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)