This commit is contained in:
commit
fbefa417b9
19 files changed
+972
-21
No files matched your search
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"build": {
|
||||
"arduino": {
|
||||
"ldscript": "nrf52840_s140_v6.ld"
|
||||
},
|
||||
"core": "nRF5",
|
||||
"cpu": "cortex-m4",
|
||||
"extra_flags": "-DNRF52840_XXAA",
|
||||
"f_cpu": "64000000L",
|
||||
"hwids": [
|
||||
["0x239A", "0x8071"],
|
||||
["0x239A", "0x0071"],
|
||||
["0x239A", "0x8072"]
|
||||
],
|
||||
"usb_product": "HT-n5262",
|
||||
"mcu": "nrf52840",
|
||||
"variant": "heltec_rc52",
|
||||
"bsp": {
|
||||
"name": "adafruit"
|
||||
},
|
||||
"softdevice": {
|
||||
"sd_flags": "-DS140",
|
||||
"sd_name": "s140",
|
||||
"sd_version": "6.1.1",
|
||||
"sd_fwid": "0x00B6"
|
||||
},
|
||||
"bootloader": {
|
||||
"settings_addr": "0xFF000"
|
||||
}
|
||||
},
|
||||
"connectivity": [
|
||||
"bluetooth",
|
||||
"lora"
|
||||
],
|
||||
"debug": {
|
||||
"jlink_device": "nRF52840_xxAA",
|
||||
"svd_path": "nrf52840.svd",
|
||||
"openocd_target": "nrf52.cfg"
|
||||
},
|
||||
"frameworks": [
|
||||
"arduino"
|
||||
],
|
||||
"name": "Heltec RC52",
|
||||
"upload": {
|
||||
"maximum_ram_size": 237568,
|
||||
"maximum_size": 815104,
|
||||
"speed": 115200,
|
||||
"protocol": "nrfutil",
|
||||
"protocols": [
|
||||
"jlink",
|
||||
"nrfjprog",
|
||||
"nrfutil",
|
||||
"stlink"
|
||||
],
|
||||
"use_1200bps_touch": true,
|
||||
"require_upload_port": true,
|
||||
"wait_for_upload_port": true
|
||||
},
|
||||
"url": "https://heltec.org/",
|
||||
"vendor": "Heltec"
|
||||
}
|
||||
+15
-1
@@ -1195,7 +1195,21 @@ one attempt) and `GPS_DUTY_RETRY_SECS` (21600, backoff after a window with no fi
|
||||
**Parameters:**
|
||||
- `value`: `0` for continuous tracking, or a period. The value can be postfixed with `s`, `m`, `h` or `d` to specify the unit (seconds by default).
|
||||
|
||||
**Note:** A periodic acquisition stops after receiving a valid fix, then resumes after the configured period.
|
||||
**Note:** A periodic acquisition stops after receiving a valid fix, then resumes after the configured period. Without a fix it stops after 5 minutes (`GPS_PERIODIC_ACQUISITION_TIMEOUT_MS`), or, until the first fix since boot, after the first fix timeout (see `gps firstfix`).
|
||||
|
||||
---
|
||||
|
||||
#### View or change the first fix timeout
|
||||
**Usage:**
|
||||
- `gps firstfix`
|
||||
- `gps firstfix <value>`
|
||||
|
||||
**Parameters:**
|
||||
- `value`: `0` for no limit, or a duration up to `1d`. The value can be postfixed with `s`, `m`, `h` or `d` to specify the unit (seconds by default).
|
||||
|
||||
**Default:** `1h` (`GPS_FIRST_FIX_TIMEOUT_MS`)
|
||||
|
||||
**Note:** In periodic mode, limits an acquisition until the first valid fix since boot. A cold start can take much longer than the usual 5 minutes with a weak sky view; after the limit the GPS sleeps for the period and tries again. Saved with the other GPS settings.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
uint32_t gps_interval = 0; // GPS read interval in seconds
|
||||
uint32_t gps_period = 0; // periodic acquisition interval in seconds
|
||||
int32_t gps_fence = -1; // GPS_GUARD fence in metres, 0 = off, -1 = build default
|
||||
int32_t gps_first_fix = -1; // first-fix timeout in seconds, 0 = no limit, -1 = build default
|
||||
uint8_t gps_guard = 1; // GPS_GUARD on/off
|
||||
uint8_t autoadd_config = 0; // bitmask for auto-add contacts config
|
||||
uint8_t rx_boosted_gain = 0; // SX126x RX boosted gain mode (0=power saving, 1=boosted)
|
||||
@@ -170,6 +171,7 @@ private:
|
||||
def("int", _parent->gps_interval); // interval in seconds
|
||||
def("period", _parent->gps_period); // periodic acquisition interval in seconds
|
||||
def("adv_loc", _parent->advert_loc_policy);
|
||||
def("ffix", _parent->gps_first_fix);
|
||||
#ifdef GPS_GUARD
|
||||
def("fence", _parent->gps_fence);
|
||||
def("guard", _parent->gps_guard);
|
||||
@@ -181,6 +183,12 @@ private:
|
||||
void setGpsEnabled(bool enabled) override { _parent->gps_enabled = enabled; markDirty(); }
|
||||
uint32_t getGpsPeriod() const override { return _parent->gps_period; }
|
||||
void setGpsPeriod(uint32_t seconds) override { _parent->gps_period = seconds; markDirty(); }
|
||||
bool getFirstFixTimeout(uint32_t& seconds) const override {
|
||||
if (_parent->gps_first_fix < 0) return false;
|
||||
seconds = (uint32_t)_parent->gps_first_fix;
|
||||
return true;
|
||||
}
|
||||
void setFirstFixTimeout(uint32_t seconds) override { _parent->gps_first_fix = (int32_t)seconds; markDirty(); }
|
||||
bool getGuardFence(uint32_t& metres) const override {
|
||||
if (_parent->gps_fence < 0) return false;
|
||||
metres = (uint32_t)_parent->gps_fence;
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
uint32_t gps_interval = 0; // in seconds
|
||||
uint32_t gps_period = 0; // periodic acquisition interval in seconds
|
||||
int32_t gps_fence = -1; // GPS_GUARD fence in metres, 0 = off, -1 = build default
|
||||
int32_t gps_first_fix = -1; // first-fix timeout in seconds, 0 = no limit, -1 = build default
|
||||
uint8_t gps_guard = 1; // GPS_GUARD on/off
|
||||
uint8_t advert_loc_policy = 0;
|
||||
uint32_t discovery_mod_timestamp = 0;
|
||||
@@ -204,6 +205,7 @@ private:
|
||||
def("int", _parent->gps_interval); // interval in seconds
|
||||
def("period", _parent->gps_period); // periodic acquisition interval in seconds
|
||||
def("adv_loc", _parent->advert_loc_policy);
|
||||
def("ffix", _parent->gps_first_fix);
|
||||
#ifdef GPS_GUARD
|
||||
def("fence", _parent->gps_fence);
|
||||
def("guard", _parent->gps_guard);
|
||||
@@ -215,6 +217,12 @@ private:
|
||||
void setGpsEnabled(bool enabled) override { _parent->gps_enabled = enabled; markDirty(); }
|
||||
uint32_t getGpsPeriod() const override { return _parent->gps_period; }
|
||||
void setGpsPeriod(uint32_t seconds) override { _parent->gps_period = seconds; markDirty(); }
|
||||
bool getFirstFixTimeout(uint32_t& seconds) const override {
|
||||
if (_parent->gps_first_fix < 0) return false;
|
||||
seconds = (uint32_t)_parent->gps_first_fix;
|
||||
return true;
|
||||
}
|
||||
void setFirstFixTimeout(uint32_t seconds) override { _parent->gps_first_fix = (int32_t)seconds; markDirty(); }
|
||||
bool getGuardFence(uint32_t& metres) const override {
|
||||
if (_parent->gps_fence < 0) return false;
|
||||
metres = (uint32_t)_parent->gps_fence;
|
||||
|
||||
@@ -50,6 +50,8 @@ bool CommonGpsPrefs::apply(SensorManager& sensors) const {
|
||||
LocationProvider* location = sensors.getLocationProvider();
|
||||
if (location == nullptr) return false;
|
||||
applyGuardReference(sensors);
|
||||
uint32_t first_fix;
|
||||
if (getFirstFixTimeout(first_fix)) location->setFirstFixTimeout(first_fix);
|
||||
location->setGpsPeriod(getGpsPeriod());
|
||||
location->setGpsOn(isGpsEnabled());
|
||||
return true;
|
||||
@@ -66,6 +68,20 @@ static void formatDuration(char* buf, size_t size, uint32_t seconds) {
|
||||
}
|
||||
}
|
||||
|
||||
// "<n>[s|m|h|d]", seconds by default
|
||||
static bool parseDuration(const char* text, uint32_t& seconds) {
|
||||
char* end;
|
||||
unsigned long value = strtoul(text, &end, 10);
|
||||
unsigned long mult = 1;
|
||||
if (*end == 'm') mult = 60;
|
||||
else if (*end == 'h') mult = 3600;
|
||||
else if (*end == 'd') mult = 86400;
|
||||
if (mult > 1 || *end == 's') end++; // skip the suffix char
|
||||
if (text[0] == '\0' || *end != '\0') return false;
|
||||
seconds = (uint32_t)(value * mult);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors, char* reply) {
|
||||
if (strcmp(command, "gps") == 0) {
|
||||
LocationProvider* location = sensors.getLocationProvider();
|
||||
@@ -184,17 +200,10 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "gps period ", 11) == 0) {
|
||||
char* end;
|
||||
unsigned long period = strtoul(command + 11, &end, 10);
|
||||
unsigned long mult = 1;
|
||||
if (*end == 'm') mult = 60;
|
||||
else if (*end == 'h') mult = 3600;
|
||||
else if (*end == 'd') mult = 86400;
|
||||
if (mult > 1 || *end == 's') end++; // skip the suffix char
|
||||
|
||||
if (command[11] == '\0' || *end != '\0') {
|
||||
uint32_t period;
|
||||
if (!parseDuration(command + 11, period)) {
|
||||
strcpy(reply, "Error, invalid gps period");
|
||||
} else if (!setGpsPeriod(sensors, (uint32_t)(period * mult)) ||
|
||||
} else if (!setGpsPeriod(sensors, period) ||
|
||||
!setGpsEnabled(sensors, true)) {
|
||||
strcpy(reply, "Error, gps provider not found");
|
||||
} else {
|
||||
@@ -202,6 +211,31 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (strcmp(command, "gps firstfix") == 0) {
|
||||
LocationProvider* location = sensors.getLocationProvider();
|
||||
if (location == nullptr) {
|
||||
strcpy(reply, "Error, gps provider not found");
|
||||
} else if (location->getFirstFixTimeout() == 0) {
|
||||
strcpy(reply, "> 0 (no limit)");
|
||||
} else {
|
||||
sprintf(reply, "> %lu", (unsigned long)location->getFirstFixTimeout());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "gps firstfix ", 13) == 0) {
|
||||
LocationProvider* location = sensors.getLocationProvider();
|
||||
uint32_t seconds;
|
||||
if (location == nullptr) {
|
||||
strcpy(reply, "Error, gps provider not found");
|
||||
} else if (!parseDuration(command + 13, seconds) || seconds > 86400UL) { // at most a day
|
||||
strcpy(reply, "Error, invalid first fix timeout");
|
||||
} else {
|
||||
location->setFirstFixTimeout(seconds);
|
||||
setFirstFixTimeout(seconds); // saved by the caller (isDirty)
|
||||
strcpy(reply, "OK");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "gps sync", 8) == 0) {
|
||||
LocationProvider* location = sensors.getLocationProvider();
|
||||
if (location == nullptr) {
|
||||
|
||||
@@ -18,6 +18,9 @@ public:
|
||||
virtual void setGpsEnabled(bool enabled) = 0;
|
||||
virtual uint32_t getGpsPeriod() const = 0;
|
||||
virtual void setGpsPeriod(uint32_t seconds) = 0;
|
||||
// Saved first-fix timeout in seconds; false = not set, use the build default.
|
||||
virtual bool getFirstFixTimeout(uint32_t& seconds) const { return false; }
|
||||
virtual void setFirstFixTimeout(uint32_t seconds) { }
|
||||
|
||||
// Reference position for the anti-spoofing guard (GPS_GUARD), e.g. the configured node position.
|
||||
virtual bool getGuardReference(double& lat, double& lon) const { return false; }
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
long satellites = 0;
|
||||
long timestamp = 0;
|
||||
unsigned long acquiredAt = 0; // millis() when the fix was stored
|
||||
uint8_t fixMode = 0; // from GSA: 2 = 2D, 3 = 3D, 0 = unknown
|
||||
};
|
||||
|
||||
struct FixStats {
|
||||
@@ -81,6 +82,9 @@ public:
|
||||
}
|
||||
virtual void setGpsPeriod(uint32_t seconds) { }
|
||||
virtual uint32_t getGpsPeriod() const { return 0; }
|
||||
// periodic mode: limit of an acquisition before the first fix since boot, 0 = no limit
|
||||
virtual void setFirstFixTimeout(uint32_t seconds) { }
|
||||
virtual uint32_t getFirstFixTimeout() const { return 0; }
|
||||
virtual uint32_t getLastFixAge() const { // in seconds, UINT32_MAX if never
|
||||
const LastFix f = getLastFix();
|
||||
return f.valid ? (uint32_t)(millis() - f.acquiredAt) / 1000UL : UINT32_MAX;
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
#ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS
|
||||
#define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 300000UL
|
||||
#endif
|
||||
// default limit for the periodic window before the first fix since boot (a cold start
|
||||
// can take up to ~30 min with a weak sky view); 0 = keep searching until a fix.
|
||||
// Can be changed at runtime with `gps firstfix`.
|
||||
#ifndef GPS_FIRST_FIX_TIMEOUT_MS
|
||||
#define GPS_FIRST_FIX_TIMEOUT_MS 3600000UL
|
||||
#endif
|
||||
|
||||
// in periodic mode, keep reading after the first valid fix until enough satellites
|
||||
// are used or the settle time has elapsed
|
||||
@@ -22,6 +28,11 @@
|
||||
#define GPS_FIX_SETTLE_MS 10000UL
|
||||
#endif
|
||||
|
||||
// a 2D fix does not replace a 3D fix younger than this (it is less precise)
|
||||
#ifndef GPS_3D_FIX_PREFERRED_MS
|
||||
#define GPS_3D_FIX_PREFERRED_MS 300000UL
|
||||
#endif
|
||||
|
||||
class MicroNMEALocationProvider : public LocationProvider {
|
||||
// MicroNMEA never writes past the length it is given, but its fixed-width field
|
||||
// skips can read a few bytes past the end of a malformed sentence. The zeroed tail
|
||||
@@ -36,9 +47,11 @@ class MicroNMEALocationProvider : public LocationProvider {
|
||||
long time_valid = 0;
|
||||
unsigned long _last_time_sync = 0;
|
||||
uint32_t _gpsPeriodSeconds = 0;
|
||||
uint32_t _firstFixTimeoutSeconds = GPS_FIRST_FIX_TIMEOUT_MS / 1000UL;
|
||||
unsigned long _nextAcquisition = 0;
|
||||
unsigned long _acquisitionStarted = 0;
|
||||
unsigned long _firstFixInWindow = 0;
|
||||
bool _goodFixInWindow = false; // a fix that lets the GPS sleep (3D, or fix mode unknown)
|
||||
bool _acquiringPeriodically = false;
|
||||
unsigned long _onceDeadline = 0;
|
||||
static const unsigned long TIME_SYNC_INTERVAL = 1800000;
|
||||
@@ -52,6 +65,26 @@ class MicroNMEALocationProvider : public LocationProvider {
|
||||
unsigned long _last_nmea_ms = 0;
|
||||
bool _uart_seen = false;
|
||||
bool _nmea_seen = false;
|
||||
uint8_t _gsa_fix_mode = 0; // fix mode from the last GSA: 1 = none, 2 = 2D, 3 = 3D
|
||||
unsigned long _gsa_ms = 0;
|
||||
|
||||
static bool isGsa(const char* id) { // GPGSA, GNGSA, BDGSA, ...
|
||||
const size_t n = strlen(id);
|
||||
return n >= 3 && strcmp(id + n - 3, "GSA") == 0;
|
||||
}
|
||||
// $--GSA,<mode A/M>,<fix 1/2/3>,...
|
||||
void parseGsa(const char* s) {
|
||||
s = strchr(s, ',');
|
||||
if (s != NULL) s = strchr(s + 1, ',');
|
||||
if (s != NULL && s[1] >= '1' && s[1] <= '3') {
|
||||
_gsa_fix_mode = s[1] - '0';
|
||||
_gsa_ms = millis();
|
||||
}
|
||||
}
|
||||
// 0 (unknown) if the receiver does not send GSA, or sent none recently
|
||||
uint8_t currentFixMode() const {
|
||||
return (_gsa_fix_mode != 0 && (uint32_t)(millis() - _gsa_ms) <= 2000) ? _gsa_fix_mode : 0;
|
||||
}
|
||||
#ifdef GPS_GUARD
|
||||
GpsGuard _guard;
|
||||
#endif
|
||||
@@ -76,6 +109,7 @@ class MicroNMEALocationProvider : public LocationProvider {
|
||||
_acquiringPeriodically = true;
|
||||
_acquisitionStarted = millis();
|
||||
_firstFixInWindow = 0;
|
||||
_goodFixInWindow = false;
|
||||
}
|
||||
|
||||
void finishPeriodicAcquisition() {
|
||||
@@ -89,13 +123,17 @@ class MicroNMEALocationProvider : public LocationProvider {
|
||||
|
||||
bool saveFix() {
|
||||
// only store a fix when the snapshot is coherent (sats > 0).
|
||||
// Returns true if the fix was stored.
|
||||
// Returns true if the fix was accepted (stored, or kept out by a recent 3D fix).
|
||||
if (nmea.getNumSatellites() == 0) return false;
|
||||
#ifdef GPS_GUARD
|
||||
// only plausible, stable fixes become the last fix (position, telemetry, time sync)
|
||||
if (!_guard.acceptFix(nmea.getLatitude(), nmea.getLongitude(), nmea.getNumSatellites(),
|
||||
nmea.getHDOP(), getTimestamp())) return false;
|
||||
#endif
|
||||
const uint8_t mode = currentFixMode();
|
||||
// a 2D fix is valid but less precise: keep a recent 3D fix instead
|
||||
if (mode == 2 && _lastFix.valid && _lastFix.fixMode == 3 &&
|
||||
(uint32_t)(millis() - _lastFix.acquiredAt) < GPS_3D_FIX_PREFERRED_MS) return true;
|
||||
|
||||
LastFix fix;
|
||||
fix.latitude = nmea.getLatitude();
|
||||
@@ -107,6 +145,7 @@ class MicroNMEALocationProvider : public LocationProvider {
|
||||
fix.satellites = nmea.getNumSatellites();
|
||||
fix.timestamp = getTimestamp();
|
||||
fix.acquiredAt = millis();
|
||||
fix.fixMode = mode;
|
||||
fix.valid = true;
|
||||
_lastFix = fix;
|
||||
return true;
|
||||
@@ -150,6 +189,7 @@ public:
|
||||
if (!wasActive) {
|
||||
_acquisitionStarted = millis();
|
||||
_firstFixInWindow = 0;
|
||||
_goodFixInWindow = false;
|
||||
}
|
||||
if (_gpsPeriodSeconds > 0 && _driver->isActive()) {
|
||||
nmea.clear();
|
||||
@@ -157,6 +197,7 @@ public:
|
||||
_acquiringPeriodically = true;
|
||||
_acquisitionStarted = millis();
|
||||
_firstFixInWindow = 0;
|
||||
_goodFixInWindow = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +240,14 @@ public:
|
||||
return _gpsPeriodSeconds;
|
||||
}
|
||||
|
||||
void setFirstFixTimeout(uint32_t seconds) override {
|
||||
_firstFixTimeoutSeconds = seconds;
|
||||
}
|
||||
|
||||
uint32_t getFirstFixTimeout() const override {
|
||||
return _firstFixTimeoutSeconds;
|
||||
}
|
||||
|
||||
uint32_t getAcquisitionAge() const override {
|
||||
return (uint32_t)(millis() - _acquisitionStarted) / 1000UL;
|
||||
}
|
||||
@@ -299,7 +348,7 @@ public:
|
||||
if (_driver->pollGpsSwitch()) _gpsOn = true;
|
||||
|
||||
if (_onceDeadline != 0) {
|
||||
if (_firstFixInWindow != 0 && (long)(_onceDeadline - (millis() + GPS_FIX_SETTLE_MS)) > 0) {
|
||||
if (_goodFixInWindow && (long)(_onceDeadline - (millis() + GPS_FIX_SETTLE_MS)) > 0) {
|
||||
_onceDeadline = millis() + GPS_FIX_SETTLE_MS;
|
||||
}
|
||||
if ((long)(millis() - _onceDeadline) >= 0) {
|
||||
@@ -335,6 +384,7 @@ public:
|
||||
_nmea_seen = true;
|
||||
|
||||
const char* messageId = nmea.getMessageID();
|
||||
if (isGsa(messageId)) parseGsa(nmea.getSentence());
|
||||
#ifdef GPS_GUARD
|
||||
if (parsed && !nmea.isValid() &&
|
||||
(strcmp(messageId, "GGA") == 0 || strcmp(messageId, "RMC") == 0)) {
|
||||
@@ -348,7 +398,11 @@ public:
|
||||
_firstFixInWindow = millis();
|
||||
fixStatsFix((uint32_t)(_firstFixInWindow - _acquisitionStarted));
|
||||
}
|
||||
if (_acquiringPeriodically) {
|
||||
// after a 2D fix the GPS stays on (up to the acquisition timeout)
|
||||
// to give the receiver a chance to get a 3D fix
|
||||
const uint8_t mode = currentFixMode();
|
||||
if (mode == 0 || mode == 3) _goodFixInWindow = true;
|
||||
if (_acquiringPeriodically && _goodFixInWindow) {
|
||||
// stay on until a pending time sync is done (or the settle time is over)
|
||||
const bool synced = _clock == nullptr || !_time_sync_needed;
|
||||
if ((nmea.getNumSatellites() >= GPS_MIN_SATS_FOR_FIX && synced) ||
|
||||
@@ -363,11 +417,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// no timeout until a first fix has been obtained (cold start can be long)
|
||||
if (_acquiringPeriodically && _lastFix.valid &&
|
||||
(uint32_t)(millis() - _acquisitionStarted) >= GPS_PERIODIC_ACQUISITION_TIMEOUT_MS) {
|
||||
// a longer limit until a first fix has been obtained (cold start can be long)
|
||||
if (_acquiringPeriodically) {
|
||||
const uint32_t limit = _lastFix.valid ? GPS_PERIODIC_ACQUISITION_TIMEOUT_MS
|
||||
: _firstFixTimeoutSeconds * 1000UL;
|
||||
if (limit > 0 && (uint32_t)(millis() - _acquisitionStarted) >= limit) {
|
||||
finishPeriodicAcquisition();
|
||||
}
|
||||
}
|
||||
|
||||
updateTime();
|
||||
}
|
||||
@@ -395,5 +452,8 @@ public:
|
||||
fix_age,
|
||||
(unsigned long)_begin_calls,
|
||||
(unsigned long)_stop_calls);
|
||||
// fix mode from GSA (1 none, 2 2D, 3 3D, 0 no recent GSA)
|
||||
const size_t len = strlen(out);
|
||||
if (len < out_size) snprintf(out + len, out_size - len, " fm:%u", currentFixMode());
|
||||
}
|
||||
};
|
||||
@@ -425,7 +425,13 @@ bool NV3001BDisplay::begin() {
|
||||
digitalWrite(PIN_TFT_DC, HIGH);
|
||||
delay(20);
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
spi.begin();
|
||||
#elif defined(ESP_PLATFORM) || defined(ESP32_PLATFORM)
|
||||
spi.begin(PIN_TFT_SCL, PIN_TFT_MISO, PIN_TFT_SDA, PIN_TFT_CS);
|
||||
#else
|
||||
spi.begin();
|
||||
#endif
|
||||
if (PIN_TFT_RST >= 0) {
|
||||
pinMode(PIN_TFT_RST, OUTPUT);
|
||||
digitalWrite(PIN_TFT_RST, HIGH);
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
#define NV3001B_PANEL_HEIGHT 220
|
||||
#endif
|
||||
|
||||
class NV3001BDisplay : public DisplayDriver {
|
||||
#if defined(ESP_PLATFORM) || defined(ESP32_PLATFORM)
|
||||
#ifndef NV3001B_SPI_HOST
|
||||
#define NV3001B_SPI_HOST HSPI
|
||||
#endif
|
||||
|
||||
class NV3001BDisplay : public DisplayDriver {
|
||||
SPIClass spi;
|
||||
SPIClass owned_spi;
|
||||
#endif
|
||||
SPIClass& spi;
|
||||
RefCountedDigitalPin* periph_power;
|
||||
bool is_on = false;
|
||||
uint16_t color = 0xffff;
|
||||
@@ -43,8 +45,18 @@ class NV3001BDisplay : public DisplayDriver {
|
||||
void drawChar(int x, int y, char ch);
|
||||
|
||||
public:
|
||||
#if defined(ESP_PLATFORM) || defined(ESP32_PLATFORM)
|
||||
NV3001BDisplay(RefCountedDigitalPin* power = nullptr) :
|
||||
DisplayDriver(NV3001B_LOGICAL_WIDTH, NV3001B_LOGICAL_HEIGHT), spi(NV3001B_SPI_HOST), periph_power(power) { }
|
||||
DisplayDriver(NV3001B_LOGICAL_WIDTH, NV3001B_LOGICAL_HEIGHT),
|
||||
owned_spi(NV3001B_SPI_HOST), spi(owned_spi), periph_power(power) { }
|
||||
|
||||
NV3001BDisplay(SPIClass* displaySpi, RefCountedDigitalPin* power = nullptr) :
|
||||
DisplayDriver(NV3001B_LOGICAL_WIDTH, NV3001B_LOGICAL_HEIGHT),
|
||||
owned_spi(NV3001B_SPI_HOST), spi(displaySpi ? *displaySpi : owned_spi), periph_power(power) { }
|
||||
#else
|
||||
NV3001BDisplay(SPIClass* displaySpi = &SPI, RefCountedDigitalPin* power = nullptr) :
|
||||
DisplayDriver(NV3001B_LOGICAL_WIDTH, NV3001B_LOGICAL_HEIGHT), spi(displaySpi ? *displaySpi : SPI), periph_power(power) { }
|
||||
#endif
|
||||
|
||||
bool begin();
|
||||
static const char* driverName() { return "NV3001B"; }
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "HeltecRC52Board.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
extern void variant_shutdown();
|
||||
|
||||
#ifdef NRF52_POWER_MANAGEMENT
|
||||
const PowerMgtConfig power_config = {
|
||||
.lpcomp_ain_channel = PWRMGT_LPCOMP_AIN,
|
||||
.lpcomp_refsel = PWRMGT_LPCOMP_REFSEL,
|
||||
.voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK};
|
||||
|
||||
void HeltecRC52Board::initiateShutdown(uint8_t reason)
|
||||
{
|
||||
shutdownPeripherals();
|
||||
|
||||
bool enable_lpcomp = (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
|
||||
reason == SHUTDOWN_REASON_BOOT_PROTECT);
|
||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||
digitalWrite(PIN_ADC_CTRL, enable_lpcomp ? ADC_CTRL_ENABLED : !ADC_CTRL_ENABLED);
|
||||
|
||||
if (enable_lpcomp) {
|
||||
configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
|
||||
}
|
||||
|
||||
enterSystemOff(reason);
|
||||
}
|
||||
#endif
|
||||
|
||||
void HeltecRC52Board::begin()
|
||||
{
|
||||
NRF52BoardDCDC::begin();
|
||||
|
||||
pinMode(PIN_VBAT_READ, INPUT);
|
||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||
digitalWrite(PIN_ADC_CTRL, !ADC_CTRL_ENABLED);
|
||||
|
||||
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
|
||||
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
|
||||
#endif
|
||||
Wire.begin();
|
||||
|
||||
pinMode(SENSOR_RST_PIN, OUTPUT);
|
||||
digitalWrite(SENSOR_RST_PIN, HIGH);
|
||||
pinMode(SENSOR_INT, INPUT);
|
||||
|
||||
|
||||
#ifdef NRF52_POWER_MANAGEMENT
|
||||
checkBootVoltage(&power_config);
|
||||
#endif
|
||||
pinMode(P_LORA_TX_LED, OUTPUT);
|
||||
digitalWrite(P_LORA_TX_LED, LOW); // off by default, active high
|
||||
|
||||
periph_power.begin();
|
||||
periph_power.claim();
|
||||
}
|
||||
|
||||
void HeltecRC52Board::shutdownPeripherals()
|
||||
{
|
||||
NRF52Board::shutdownPeripherals();
|
||||
variant_shutdown();
|
||||
}
|
||||
|
||||
void HeltecRC52Board::onBeforeTransmit() {
|
||||
digitalWrite(P_LORA_TX_LED, HIGH);
|
||||
}
|
||||
|
||||
void HeltecRC52Board::onAfterTransmit() {
|
||||
digitalWrite(P_LORA_TX_LED, LOW);
|
||||
}
|
||||
|
||||
uint16_t HeltecRC52Board::getBattMilliVolts()
|
||||
{
|
||||
analogReadResolution(12);
|
||||
analogReference(AR_INTERNAL_3_0);
|
||||
pinMode(PIN_VBAT_READ, INPUT);
|
||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||
digitalWrite(PIN_ADC_CTRL, ADC_CTRL_ENABLED);
|
||||
|
||||
delay(10);
|
||||
uint32_t raw = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
raw += analogRead(PIN_VBAT_READ);
|
||||
}
|
||||
raw /= 8;
|
||||
digitalWrite(PIN_ADC_CTRL, !ADC_CTRL_ENABLED);
|
||||
|
||||
return (uint16_t)((float)raw * MV_LSB * ADC_MULTIPLIER);
|
||||
}
|
||||
|
||||
const char* HeltecRC52Board::getManufacturerName() const
|
||||
{
|
||||
return "Heltec RC52";
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <MeshCore.h>
|
||||
#include <helpers/NRF52Board.h>
|
||||
#include <helpers/RefCountedDigitalPin.h>
|
||||
|
||||
class HeltecRC52Board : public NRF52BoardDCDC {
|
||||
protected:
|
||||
#ifdef NRF52_POWER_MANAGEMENT
|
||||
void initiateShutdown(uint8_t reason) override;
|
||||
#endif
|
||||
|
||||
public:
|
||||
RefCountedDigitalPin periph_power;
|
||||
|
||||
HeltecRC52Board() : NRF52Board("RC52_OTA"), periph_power(SENSOR_POWER_CTRL_PIN, SENSOR_POWER_ON) {}
|
||||
|
||||
void begin() override;
|
||||
void onBeforeTransmit() override;
|
||||
void onAfterTransmit() override;
|
||||
void shutdownPeripherals() override;
|
||||
uint16_t getBattMilliVolts() override;
|
||||
const char* getManufacturerName() const override;
|
||||
};
|
||||
@@ -0,0 +1,128 @@
|
||||
#include "HeltecRC52RotaryInput.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t TCA6408_ADDR = 0x20;
|
||||
constexpr uint8_t TCA6408_INPUT_REG = 0x00;
|
||||
constexpr uint8_t TCA6408_POLARITY_REG = 0x02;
|
||||
constexpr uint8_t TCA6408_CONFIG_REG = 0x03;
|
||||
constexpr uint8_t TCA6408_ROTARY_A_MASK = 0x01;
|
||||
constexpr uint8_t TCA6408_ROTARY_B_MASK = 0x02;
|
||||
constexpr uint8_t TCA6408_ROTARY_MASK = TCA6408_ROTARY_A_MASK | TCA6408_ROTARY_B_MASK;
|
||||
constexpr uint32_t TCA6408_DEBOUNCE_MS = 5;
|
||||
}
|
||||
|
||||
bool HeltecRC52RotaryInput::begin()
|
||||
{
|
||||
initialized = true;
|
||||
ready = false;
|
||||
input_state = TCA6408_ROTARY_MASK;
|
||||
active_low_phase = false;
|
||||
|
||||
if (periph_power && !power_claimed) {
|
||||
periph_power->claim();
|
||||
power_claimed = true;
|
||||
delay(12);
|
||||
}
|
||||
|
||||
if (!writeRegister(TCA6408_POLARITY_REG, 0x00) || !writeRegister(TCA6408_CONFIG_REG, 0xFF)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t state = 0;
|
||||
if (!readInput(state)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
input_state = state & TCA6408_ROTARY_MASK;
|
||||
ready = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
RotaryInputEvent HeltecRC52RotaryInput::poll()
|
||||
{
|
||||
if (!initialized) {
|
||||
begin();
|
||||
return RotaryInputEvent::None;
|
||||
}
|
||||
|
||||
if (!ready) {
|
||||
return RotaryInputEvent::None;
|
||||
}
|
||||
|
||||
uint8_t new_state = 0;
|
||||
if (!readInput(new_state)) {
|
||||
return RotaryInputEvent::None;
|
||||
}
|
||||
|
||||
new_state &= TCA6408_ROTARY_MASK;
|
||||
RotaryInputEvent event = handleTransition(new_state);
|
||||
input_state = new_state;
|
||||
return event;
|
||||
}
|
||||
|
||||
bool HeltecRC52RotaryInput::writeRegister(uint8_t reg, uint8_t value)
|
||||
{
|
||||
Wire.beginTransmission(TCA6408_ADDR);
|
||||
Wire.write(reg);
|
||||
Wire.write(value);
|
||||
return Wire.endTransmission() == 0;
|
||||
}
|
||||
|
||||
bool HeltecRC52RotaryInput::readInput(uint8_t& value)
|
||||
{
|
||||
Wire.beginTransmission(TCA6408_ADDR);
|
||||
Wire.write(TCA6408_INPUT_REG);
|
||||
if (Wire.endTransmission(false) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Wire.requestFrom(TCA6408_ADDR, static_cast<uint8_t>(1)) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
value = Wire.read();
|
||||
return true;
|
||||
}
|
||||
|
||||
RotaryInputEvent HeltecRC52RotaryInput::handleTransition(uint8_t newState)
|
||||
{
|
||||
uint8_t changed = (input_state ^ newState) & TCA6408_ROTARY_MASK;
|
||||
RotaryInputEvent event = RotaryInputEvent::None;
|
||||
bool a_low = (newState & TCA6408_ROTARY_A_MASK) == 0;
|
||||
bool b_low = (newState & TCA6408_ROTARY_B_MASK) == 0;
|
||||
|
||||
if (!a_low && !b_low) {
|
||||
active_low_phase = false;
|
||||
}
|
||||
|
||||
if (!active_low_phase && (changed & TCA6408_ROTARY_A_MASK) && a_low && !b_low) {
|
||||
event = RotaryInputEvent::Prev;
|
||||
active_low_phase = true;
|
||||
} else if (!active_low_phase && (changed & TCA6408_ROTARY_B_MASK) && b_low && !a_low) {
|
||||
event = RotaryInputEvent::Next;
|
||||
active_low_phase = true;
|
||||
}
|
||||
|
||||
if (event == RotaryInputEvent::None && !active_low_phase && (changed & TCA6408_ROTARY_A_MASK)) {
|
||||
bool a_rising = (newState & TCA6408_ROTARY_A_MASK) != 0;
|
||||
if (a_rising && b_low) {
|
||||
event = RotaryInputEvent::Prev;
|
||||
}
|
||||
}
|
||||
|
||||
if (event == RotaryInputEvent::None && !active_low_phase && (changed & TCA6408_ROTARY_B_MASK)) {
|
||||
bool b_rising = (newState & TCA6408_ROTARY_B_MASK) != 0;
|
||||
if (b_rising && a_low) {
|
||||
event = RotaryInputEvent::Next;
|
||||
}
|
||||
}
|
||||
|
||||
if (event == RotaryInputEvent::None || (millis() - last_event_ms) < TCA6408_DEBOUNCE_MS) {
|
||||
return RotaryInputEvent::None;
|
||||
}
|
||||
|
||||
last_event_ms = millis();
|
||||
return event;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/RefCountedDigitalPin.h>
|
||||
#include <helpers/ui/RotaryInput.h>
|
||||
|
||||
class HeltecRC52RotaryInput : public RotaryInput {
|
||||
public:
|
||||
explicit HeltecRC52RotaryInput(RefCountedDigitalPin* periphPower = nullptr) : periph_power(periphPower) { }
|
||||
|
||||
bool begin() override;
|
||||
RotaryInputEvent poll() override;
|
||||
bool isReady() const override { return ready; }
|
||||
|
||||
private:
|
||||
bool writeRegister(uint8_t reg, uint8_t value);
|
||||
bool readInput(uint8_t& value);
|
||||
RotaryInputEvent handleTransition(uint8_t newState);
|
||||
|
||||
uint8_t input_state = 0x03;
|
||||
uint32_t last_event_ms = 0;
|
||||
bool ready = false;
|
||||
bool initialized = false;
|
||||
bool power_claimed = false;
|
||||
bool active_low_phase = false;
|
||||
RefCountedDigitalPin* periph_power = nullptr;
|
||||
};
|
||||
@@ -0,0 +1,192 @@
|
||||
[heltec_rc52]
|
||||
extends = nrf52_base
|
||||
board = heltec-rc52
|
||||
board_build.ldscript = boards/nrf52840_s140_v6.ld
|
||||
build_flags = ${nrf52_base.build_flags}
|
||||
${sensor_base.build_flags}
|
||||
-I lib/nrf52/s140_nrf52_6.1.1_API/include
|
||||
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
|
||||
-I variants/heltec_rc52
|
||||
-I src/helpers/ui
|
||||
-D HELTEC_RC52
|
||||
-D NRF52_POWER_MANAGEMENT
|
||||
-D USE_SX1262
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D P_LORA_DIO_1=11
|
||||
-D P_LORA_NSS=13
|
||||
-D P_LORA_RESET=32
|
||||
-D P_LORA_BUSY=24
|
||||
-D P_LORA_SCLK=25
|
||||
-D P_LORA_MISO=14
|
||||
-D P_LORA_MOSI=22
|
||||
-D P_LORA_TX_LED=15
|
||||
-D LORA_TX_POWER=22
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D SX126X_DIO2_AS_RF_SWITCH=true
|
||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||
build_src_filter = ${nrf52_base.build_src_filter}
|
||||
+<helpers/*.cpp>
|
||||
+<helpers/sensors>
|
||||
+<../variants/heltec_rc52>
|
||||
lib_deps =
|
||||
${nrf52_base.lib_deps}
|
||||
${sensor_base.lib_deps}
|
||||
debug_tool = jlink
|
||||
upload_protocol = nrfutil
|
||||
|
||||
[env:heltec_rc52_without_display_repeater]
|
||||
extends = heltec_rc52
|
||||
build_src_filter = ${heltec_rc52.build_src_filter}
|
||||
+<../examples/simple_repeater>
|
||||
build_flags =
|
||||
${heltec_rc52.build_flags}
|
||||
-D ADVERT_NAME='"Heltec RC52 Repeater"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MAX_NEIGHBOURS=50
|
||||
|
||||
[env:heltec_rc52_without_display_room_server]
|
||||
extends = heltec_rc52
|
||||
build_src_filter = ${heltec_rc52.build_src_filter}
|
||||
+<../examples/simple_room_server>
|
||||
build_flags =
|
||||
${heltec_rc52.build_flags}
|
||||
-D ADVERT_NAME='"Heltec RC52 Room"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D ROOM_PASSWORD='"hello"'
|
||||
|
||||
[env:heltec_rc52_without_display_companion_radio_ble]
|
||||
extends = heltec_rc52
|
||||
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
|
||||
board_upload.maximum_size = 712704
|
||||
build_flags =
|
||||
${heltec_rc52.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D DISPLAY_CLASS=NullDisplayDriver
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
build_src_filter = ${heltec_rc52.build_src_filter}
|
||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/NullDisplayDriver.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
lib_deps =
|
||||
${heltec_rc52.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
|
||||
[env:heltec_rc52_without_display_companion_radio_usb]
|
||||
extends = heltec_rc52
|
||||
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
|
||||
board_upload.maximum_size = 712704
|
||||
build_flags =
|
||||
${heltec_rc52.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D DISPLAY_CLASS=NullDisplayDriver
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
build_src_filter = ${heltec_rc52.build_src_filter}
|
||||
+<helpers/nrf52/*.cpp>
|
||||
+<helpers/ui/NullDisplayDriver.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
lib_deps =
|
||||
${heltec_rc52.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
|
||||
;
|
||||
; Heltec RC52 with NV3001B display
|
||||
;
|
||||
[heltec_rc52_with_display]
|
||||
extends = heltec_rc52
|
||||
board_build.ldscript = boards/nrf52840_s140_v6.ld
|
||||
build_flags =
|
||||
${heltec_rc52.build_flags}
|
||||
-D HELTEC_RC52_WITH_DISPLAY
|
||||
-D DISPLAY_CLASS=NV3001BDisplay
|
||||
build_src_filter = ${heltec_rc52.build_src_filter}
|
||||
+<helpers/ui/NV3001BDisplay.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
lib_deps =
|
||||
${heltec_rc52.lib_deps}
|
||||
|
||||
[env:heltec_rc52_repeater]
|
||||
extends = heltec_rc52_with_display
|
||||
build_src_filter = ${heltec_rc52_with_display.build_src_filter}
|
||||
+<../examples/simple_repeater>
|
||||
build_flags =
|
||||
${heltec_rc52_with_display.build_flags}
|
||||
-D ADVERT_NAME='"Heltec RC52 Repeater"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MAX_NEIGHBOURS=50
|
||||
|
||||
[env:heltec_rc52_room_server]
|
||||
extends = heltec_rc52_with_display
|
||||
build_src_filter = ${heltec_rc52_with_display.build_src_filter}
|
||||
+<../examples/simple_room_server>
|
||||
build_flags =
|
||||
${heltec_rc52_with_display.build_flags}
|
||||
-D ADVERT_NAME='"Heltec RC52 Room"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D ROOM_PASSWORD='"hello"'
|
||||
|
||||
[env:heltec_rc52_companion_radio_ble]
|
||||
extends = heltec_rc52_with_display
|
||||
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
|
||||
board_upload.maximum_size = 712704
|
||||
build_flags =
|
||||
${heltec_rc52_with_display.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D PIN_BUZZER=5
|
||||
-D UI_HAS_ROTARY_INPUT
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
build_src_filter = ${heltec_rc52_with_display.build_src_filter}
|
||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/buzzer.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
lib_deps =
|
||||
${heltec_rc52_with_display.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
end2endzone/NonBlockingRTTTL@^1.3.0
|
||||
|
||||
[env:heltec_rc52_companion_radio_usb]
|
||||
extends = heltec_rc52_with_display
|
||||
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
|
||||
board_upload.maximum_size = 712704
|
||||
build_flags =
|
||||
${heltec_rc52_with_display.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D PIN_BUZZER=5
|
||||
-D UI_HAS_ROTARY_INPUT
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
build_src_filter = ${heltec_rc52_with_display.build_src_filter}
|
||||
+<helpers/nrf52/*.cpp>
|
||||
+<helpers/ui/buzzer.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
lib_deps =
|
||||
${heltec_rc52_with_display.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
end2endzone/NonBlockingRTTTL@^1.3.0
|
||||
|
||||
[env:heltec_rc52_kiss_modem]
|
||||
extends = heltec_rc52
|
||||
build_src_filter = ${heltec_rc52.build_src_filter}
|
||||
+<../examples/kiss_modem/>
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "target.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <helpers/ArduinoHelpers.h>
|
||||
|
||||
#if defined(UI_HAS_ROTARY_INPUT)
|
||||
#include "HeltecRC52RotaryInput.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENV_INCLUDE_GPS
|
||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||
#endif
|
||||
|
||||
HeltecRC52Board board;
|
||||
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
|
||||
WRAPPER_CLASS radio_driver(radio, board);
|
||||
|
||||
VolatileRTCClock fallback_clock;
|
||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||
|
||||
#if ENV_INCLUDE_GPS
|
||||
NmeaGpsDriver gps_driver(Serial1, PIN_GPS_TX, PIN_GPS_RX, GPS_RESET, GPS_EN,
|
||||
&board.periph_power);
|
||||
MicroNMEALocationProvider nmea(gps_driver, &rtc_clock);
|
||||
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
|
||||
#else
|
||||
EnvironmentSensorManager sensors;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
#ifdef HELTEC_RC52_WITH_DISPLAY
|
||||
DISPLAY_CLASS display(&SPI1);
|
||||
#else
|
||||
DISPLAY_CLASS display;
|
||||
#endif
|
||||
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
||||
#if defined(UI_HAS_ROTARY_INPUT)
|
||||
static HeltecRC52RotaryInput rotaryInputImpl(&board.periph_power);
|
||||
RotaryInput& rotary_input = rotaryInputImpl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool radio_init()
|
||||
{
|
||||
rtc_clock.begin(Wire);
|
||||
return radio.std_init(&SPI);
|
||||
}
|
||||
|
||||
mesh::LocalIdentity radio_new_identity()
|
||||
{
|
||||
RadioNoiseListener rng(radio);
|
||||
return mesh::LocalIdentity(&rng);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#define RADIOLIB_STATIC_ONLY 1
|
||||
#include <RadioLib.h>
|
||||
#include <HeltecRC52Board.h>
|
||||
#include <helpers/AutoDiscoverRTCClock.h>
|
||||
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||
#include <helpers/radiolib/RadioLibWrappers.h>
|
||||
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||
#include <helpers/sensors/LocationProvider.h>
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include <helpers/ui/MomentaryButton.h>
|
||||
#if defined(UI_HAS_ROTARY_INPUT)
|
||||
#include <helpers/ui/RotaryInput.h>
|
||||
#endif
|
||||
#ifdef HELTEC_RC52_WITH_DISPLAY
|
||||
#include <helpers/ui/NV3001BDisplay.h>
|
||||
#else
|
||||
#include <helpers/ui/NullDisplayDriver.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern HeltecRC52Board board;
|
||||
extern WRAPPER_CLASS radio_driver;
|
||||
extern AutoDiscoverRTCClock rtc_clock;
|
||||
extern EnvironmentSensorManager sensors;
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
extern DISPLAY_CLASS display;
|
||||
extern MomentaryButton user_btn;
|
||||
#if defined(UI_HAS_ROTARY_INPUT)
|
||||
extern RotaryInput& rotary_input;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool radio_init();
|
||||
mesh::LocalIdentity radio_new_identity();
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "variant.h"
|
||||
#include "Arduino.h"
|
||||
#include "nrf.h"
|
||||
#include <Wire.h>
|
||||
#include "wiring_constants.h"
|
||||
#include "wiring_digital.h"
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
|
||||
|
||||
void initVariant()
|
||||
{
|
||||
pinMode(PIN_BUTTON1, INPUT_PULLUP);
|
||||
|
||||
pinMode(RADIOCORE_FEM_EN, OUTPUT);
|
||||
digitalWrite(RADIOCORE_FEM_EN, HIGH);
|
||||
|
||||
pinMode(RADIOCORE_VFEM_CTRL, OUTPUT);
|
||||
digitalWrite(RADIOCORE_VFEM_CTRL, HIGH);
|
||||
|
||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||
digitalWrite(PIN_ADC_CTRL, !ADC_CTRL_ENABLED);
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
pinMode(PIN_BUZZER, OUTPUT);
|
||||
digitalWrite(PIN_BUZZER, LOW);
|
||||
#endif
|
||||
|
||||
pinMode(PIN_TFT_EN, OUTPUT);
|
||||
digitalWrite(PIN_TFT_EN, !PIN_TFT_EN_ACTIVE);
|
||||
pinMode(PIN_TFT_BL, OUTPUT);
|
||||
digitalWrite(PIN_TFT_BL, !PIN_TFT_BL_ACTIVE);
|
||||
pinMode(PIN_TFT_CS, OUTPUT);
|
||||
digitalWrite(PIN_TFT_CS, HIGH);
|
||||
}
|
||||
|
||||
void variant_shutdown()
|
||||
{
|
||||
Wire.end();
|
||||
|
||||
digitalWrite(RADIOCORE_FEM_EN, LOW);
|
||||
digitalWrite(RADIOCORE_VFEM_CTRL, LOW);
|
||||
digitalWrite(PIN_ADC_CTRL, !ADC_CTRL_ENABLED);
|
||||
|
||||
digitalWrite(PIN_TFT_BL, !PIN_TFT_BL_ACTIVE);
|
||||
digitalWrite(PIN_TFT_EN, !PIN_TFT_EN_ACTIVE);
|
||||
|
||||
nrf_gpio_cfg_default(PIN_BUTTON1);
|
||||
nrf_gpio_cfg_default(PIN_ADC_CTRL);
|
||||
#ifdef PIN_BUZZER
|
||||
nrf_gpio_cfg_default(PIN_BUZZER);
|
||||
#endif
|
||||
|
||||
nrf_gpio_cfg_default(PIN_TFT_BL);
|
||||
nrf_gpio_cfg_default(PIN_TFT_EN);
|
||||
nrf_gpio_cfg_default(PIN_TFT_CS);
|
||||
nrf_gpio_cfg_default(PIN_TFT_DC);
|
||||
nrf_gpio_cfg_default(PIN_TFT_RST);
|
||||
|
||||
nrf_gpio_cfg_default(PIN_SPI_MISO);
|
||||
nrf_gpio_cfg_default(PIN_SPI_MOSI);
|
||||
nrf_gpio_cfg_default(PIN_SPI_SCK);
|
||||
|
||||
// SPI1 MISO is not connected; its sentinel is not a physical GPIO.
|
||||
nrf_gpio_cfg_default(PIN_SPI1_MOSI);
|
||||
nrf_gpio_cfg_default(PIN_SPI1_SCK);
|
||||
|
||||
nrf_gpio_cfg_default(PIN_GPS_EN);
|
||||
nrf_gpio_cfg_default(PIN_GPS_RESET);
|
||||
nrf_gpio_cfg_default(PIN_GPS_PPS);
|
||||
nrf_gpio_cfg_default(PIN_GPS_RX);
|
||||
nrf_gpio_cfg_default(PIN_GPS_TX);
|
||||
|
||||
nrf_gpio_cfg_default(SENSOR_POWER_CTRL_PIN);
|
||||
nrf_gpio_cfg_default(SENSOR_RST_PIN);
|
||||
nrf_gpio_cfg_default(SENSOR_INT);
|
||||
nrf_gpio_cfg_default(PIN_BOARD_SDA);
|
||||
nrf_gpio_cfg_default(PIN_BOARD_SCL);
|
||||
|
||||
nrf_gpio_cfg_default(RADIOCORE_FEM_EN);
|
||||
nrf_gpio_cfg_default(RADIOCORE_VFEM_CTRL);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
#ifndef _VARIANT_HELTEC_RC52_
|
||||
#define _VARIANT_HELTEC_RC52_
|
||||
|
||||
#define VARIANT_MCK (64000000ul)
|
||||
#define USE_LFXO
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HARD_VERSION_ADDR (0xED000 + 7 * 4096 - 16 - 1)
|
||||
#define HT_LICENSE_ADDR (0xED000 + 7 * 4096 - 16)
|
||||
#define HT_LICENSE_ADDR_BASE (0xED000 + 6 * 4096)
|
||||
|
||||
#define PINS_COUNT (48)
|
||||
#define NUM_DIGITAL_PINS (48)
|
||||
#define NUM_ANALOG_INPUTS (1)
|
||||
#define NUM_ANALOG_OUTPUTS (0)
|
||||
|
||||
#define PIN_LED1 (-1)
|
||||
#define PIN_NEOPIXEL (-1)
|
||||
#define NEOPIXEL_NUM 0
|
||||
#define LED_BUILTIN PIN_LED1
|
||||
#define LED_BLUE PIN_LED1
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define PIN_BUTTON1 (32 + 10) // P1.10, external pull-up, active low
|
||||
#define PIN_BUTTON_USER PIN_BUTTON1
|
||||
#define PIN_USER_BTN PIN_BUTTON1
|
||||
|
||||
#define ADC_RESOLUTION 14
|
||||
#define PIN_VBAT_READ (0 + 31)
|
||||
#define PIN_ADC_CTRL (0 + 4)
|
||||
#define ADC_CTRL_ENABLED HIGH
|
||||
#define ADC_MULTIPLIER 4.9F
|
||||
#define MV_LSB (3000.0F / 4096.0F)
|
||||
|
||||
#define PWRMGT_VOLTAGE_BOOTLOCK 3300
|
||||
#define PWRMGT_LPCOMP_AIN 7
|
||||
#define PWRMGT_LPCOMP_REFSEL 1
|
||||
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
#define PIN_BOARD_SDA (32 + 11) // P1.11
|
||||
#define PIN_BOARD_SCL (0 + 2) // P0.02
|
||||
#define PIN_WIRE_SDA PIN_BOARD_SDA
|
||||
#define PIN_WIRE_SCL PIN_BOARD_SCL
|
||||
#define SENSOR_POWER_CTRL_PIN (0 + 12)
|
||||
#define SENSOR_POWER_ON HIGH
|
||||
#define SENSOR_INT (0 + 20)
|
||||
#define SENSOR_RST_PIN (32 + 15)
|
||||
|
||||
|
||||
#define PIN_GPS_TX (0 + 8)
|
||||
#define PIN_GPS_RX (0 + 7)
|
||||
#define PIN_GPS_EN (32 + 9)
|
||||
#define PIN_GPS_PPS (32 + 1)
|
||||
#define PIN_GPS_RESET (32 + 6)
|
||||
#define PIN_GPS_EN_ACTIVE HIGH
|
||||
#define PIN_GPS_RESET_ACTIVE LOW
|
||||
#define GPS_BAUD_RATE 9600
|
||||
#define GPS_THREAD_INTERVAL 50
|
||||
#define PERIPHERAL_WARMUP_MS 100
|
||||
|
||||
#define PIN_SERIAL1_RX PIN_GPS_RX
|
||||
#define PIN_SERIAL1_TX PIN_GPS_TX
|
||||
|
||||
#define PIN_TFT_CS (32 + 4)
|
||||
#define PIN_TFT_RST (0 + 10)
|
||||
#define PIN_TFT_DC (0 + 28)
|
||||
#define PIN_TFT_SCL (0 + 30)
|
||||
#define PIN_TFT_SDA (32 + 2)
|
||||
#define PIN_TFT_EN (32 + 13)
|
||||
#define PIN_TFT_EN_ACTIVE LOW
|
||||
#define PIN_TFT_BL (0 + 9)
|
||||
#define PIN_TFT_BL_ACTIVE HIGH
|
||||
#define SPI_FREQUENCY 8000000
|
||||
|
||||
#define RADIOCORE_FEM_EN (0 + 26)
|
||||
#define RADIOCORE_VFEM_CTRL (0 + 16)
|
||||
|
||||
#define SPI_INTERFACES_COUNT 2
|
||||
#define SPI_32MHZ_INTERFACE 1
|
||||
|
||||
#define PIN_SPI_MISO (0 + 14)
|
||||
#define PIN_SPI_MOSI (0 + 22)
|
||||
#define PIN_SPI_SCK (0 + 25)
|
||||
|
||||
#define PIN_SPI1_MISO (0) // g_ADigitalPinMap[0] is 0xFF (NRFX_SPIM_PIN_NOT_USED).
|
||||
#define PIN_SPI1_MOSI PIN_TFT_SDA
|
||||
#define PIN_SPI1_SCK PIN_TFT_SCL
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user