mirror of https://github.com/meshcore-dev/MeshCore
82 changed files with 1904 additions and 355 deletions
@ -0,0 +1,72 @@ |
|||||
|
{ |
||||
|
"build": { |
||||
|
"arduino": { |
||||
|
"ldscript": "nrf52840_s140_v6.ld" |
||||
|
}, |
||||
|
"core": "nRF5", |
||||
|
"cpu": "cortex-m4", |
||||
|
"extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA", |
||||
|
"f_cpu": "64000000L", |
||||
|
"hwids": [ |
||||
|
[ |
||||
|
"0x239A", |
||||
|
"0x8029" |
||||
|
], |
||||
|
[ |
||||
|
"0x239A", |
||||
|
"0x0029" |
||||
|
], |
||||
|
[ |
||||
|
"0x239A", |
||||
|
"0x002A" |
||||
|
], |
||||
|
[ |
||||
|
"0x239A", |
||||
|
"0x802A" |
||||
|
] |
||||
|
], |
||||
|
"usb_product": "BQ nRF52840", |
||||
|
"mcu": "nrf52840", |
||||
|
"variant": "nano-g2-ultra", |
||||
|
"bsp": { |
||||
|
"name": "adafruit" |
||||
|
}, |
||||
|
"softdevice": { |
||||
|
"sd_flags": "-DS140", |
||||
|
"sd_name": "s140", |
||||
|
"sd_version": "6.1.1", |
||||
|
"sd_fwid": "0x00B6" |
||||
|
}, |
||||
|
"bootloader": { |
||||
|
"settings_addr": "0xFF000" |
||||
|
} |
||||
|
}, |
||||
|
"connectivity": [ |
||||
|
"bluetooth" |
||||
|
], |
||||
|
"debug": { |
||||
|
"jlink_device": "nRF52840_xxAA", |
||||
|
"svd_path": "nrf52840.svd" |
||||
|
}, |
||||
|
"frameworks": [ |
||||
|
"arduino" |
||||
|
], |
||||
|
"name": "BQ nRF52840", |
||||
|
"upload": { |
||||
|
"maximum_ram_size": 248832, |
||||
|
"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://wiki.uniteng.com/en/meshtastic/nano-g2-ultra", |
||||
|
"vendor": "BQ Consulting" |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
{ |
||||
|
"build": { |
||||
|
"arduino": { |
||||
|
"variant_h": "variant_RAK3172_MODULE.h" |
||||
|
}, |
||||
|
"core": "stm32", |
||||
|
"cpu": "cortex-m4", |
||||
|
"extra_flags": "-DSTM32WL -DSTM32WLxx -DSTM32WLE5xx", |
||||
|
"framework_extra_flags": { |
||||
|
"arduino": "-DUSE_CM4_STARTUP_FILE -DARDUINO_RAK3172_MODULE" |
||||
|
}, |
||||
|
"f_cpu": "48000000L", |
||||
|
"mcu": "stm32wle5ccu", |
||||
|
"product_line": "STM32WLE5xx", |
||||
|
"variant": "STM32WLxx/WL54CCU_WL55CCU_WLE4C(8-B-C)U_WLE5C(8-B-C)U" |
||||
|
}, |
||||
|
"debug": { |
||||
|
"default_tools": ["stlink"], |
||||
|
"jlink_device": "STM32WLE5CC", |
||||
|
"openocd_target": "stm32wlx", |
||||
|
"svd_path": "STM32WLE5_CM4.svd" |
||||
|
}, |
||||
|
"frameworks": ["arduino"], |
||||
|
"name": "BB-STM32WL", |
||||
|
"upload": { |
||||
|
"maximum_ram_size": 65536, |
||||
|
"maximum_size": 262144, |
||||
|
"protocol": "stlink", |
||||
|
"protocols": ["stlink", "jlink"] |
||||
|
}, |
||||
|
"url": "https://store.rakwireless.com/products/wisduo-lpwan-module-rak3172", |
||||
|
"vendor": "RAK" |
||||
|
} |
||||
@ -0,0 +1,231 @@ |
|||||
|
#include "EnvironmentSensorManager.h" |
||||
|
|
||||
|
#if ENV_INCLUDE_AHTX0 |
||||
|
#define TELEM_AHTX_ADDRESS 0x38 // AHT10, AHT20 temperature and humidity sensor I2C address
|
||||
|
#include <Adafruit_AHTX0.h> |
||||
|
static Adafruit_AHTX0 AHTX0; |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_BME280 |
||||
|
#define TELEM_BME280_ADDRESS 0x76 // BME280 environmental sensor I2C address
|
||||
|
#define TELEM_BME280_SEALEVELPRESSURE_HPA (1013.25) // Athmospheric pressure at sea level
|
||||
|
#include <Adafruit_BME280.h> |
||||
|
static Adafruit_BME280 BME280; |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_INA3221 |
||||
|
#define TELEM_INA3221_ADDRESS 0x42 // INA3221 3 channel current sensor I2C address
|
||||
|
#define TELEM_INA3221_SHUNT_VALUE 0.100 // most variants will have a 0.1 ohm shunts
|
||||
|
#define TELEM_INA3221_NUM_CHANNELS 3 |
||||
|
#include <Adafruit_INA3221.h> |
||||
|
static Adafruit_INA3221 INA3221; |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_INA219 |
||||
|
#define TELEM_INA219_ADDRESS 0x40 // INA219 single channel current sensor I2C address
|
||||
|
#include <Adafruit_INA219.h> |
||||
|
static Adafruit_INA219 INA219(TELEM_INA219_ADDRESS); |
||||
|
#endif |
||||
|
|
||||
|
bool EnvironmentSensorManager::begin() { |
||||
|
#if ENV_INCLUDE_GPS |
||||
|
initBasicGPS(); |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_AHTX0 |
||||
|
if (AHTX0.begin(&Wire, 0, TELEM_AHTX_ADDRESS)) { |
||||
|
MESH_DEBUG_PRINTLN("Found AHT10/AHT20 at address: %02X", TELEM_AHTX_ADDRESS); |
||||
|
AHTX0_initialized = true; |
||||
|
} else { |
||||
|
AHTX0_initialized = false; |
||||
|
MESH_DEBUG_PRINTLN("AHT10/AHT20 was not found at I2C address %02X", TELEM_AHTX_ADDRESS); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_BME280 |
||||
|
if (BME280.begin(TELEM_BME280_ADDRESS, &Wire)) { |
||||
|
MESH_DEBUG_PRINTLN("Found BME280 at address: %02X", TELEM_BME280_ADDRESS); |
||||
|
MESH_DEBUG_PRINTLN("BME sensor ID: %02X", BME280.sensorID()); |
||||
|
BME280_initialized = true; |
||||
|
} else { |
||||
|
BME280_initialized = false; |
||||
|
MESH_DEBUG_PRINTLN("BME280 was not found at I2C address %02X", TELEM_BME280_ADDRESS); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_INA3221 |
||||
|
if (INA3221.begin(TELEM_INA3221_ADDRESS, &Wire)) { |
||||
|
MESH_DEBUG_PRINTLN("Found INA3221 at address: %02X", TELEM_INA3221_ADDRESS); |
||||
|
MESH_DEBUG_PRINTLN("%04X %04X", INA3221.getDieID(), INA3221.getManufacturerID()); |
||||
|
|
||||
|
for(int i = 0; i < 3; i++) { |
||||
|
INA3221.setShuntResistance(i, TELEM_INA3221_SHUNT_VALUE); |
||||
|
} |
||||
|
INA3221_initialized = true; |
||||
|
} else { |
||||
|
INA3221_initialized = false; |
||||
|
MESH_DEBUG_PRINTLN("INA3221 was not found at I2C address %02X", TELEM_INA3221_ADDRESS); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_INA219 |
||||
|
if (INA219.begin(&Wire)) { |
||||
|
MESH_DEBUG_PRINTLN("Found INA219 at address: %02X", TELEM_INA219_ADDRESS); |
||||
|
INA219_initialized = true; |
||||
|
} else { |
||||
|
INA219_initialized = false; |
||||
|
MESH_DEBUG_PRINTLN("INA219 was not found at I2C address %02X", TELEM_INA219_ADDRESS); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { |
||||
|
next_available_channel = TELEM_CHANNEL_SELF + 1; |
||||
|
|
||||
|
if (requester_permissions & TELEM_PERM_LOCATION) { |
||||
|
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, 0.0f); // allow lat/lon via telemetry even if no GPS is detected
|
||||
|
} |
||||
|
|
||||
|
if (requester_permissions & TELEM_PERM_ENVIRONMENT) { |
||||
|
|
||||
|
#if ENV_INCLUDE_AHTX0 |
||||
|
if (AHTX0_initialized) { |
||||
|
sensors_event_t humidity, temp; |
||||
|
AHTX0.getEvent(&humidity, &temp); |
||||
|
telemetry.addTemperature(TELEM_CHANNEL_SELF, temp.temperature); |
||||
|
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, humidity.relative_humidity); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_BME280 |
||||
|
if (BME280_initialized) { |
||||
|
telemetry.addTemperature(TELEM_CHANNEL_SELF, BME280.readTemperature()); |
||||
|
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, BME280.readHumidity()); |
||||
|
telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, BME280.readPressure()); |
||||
|
telemetry.addAltitude(TELEM_CHANNEL_SELF, BME280.readAltitude(TELEM_BME280_SEALEVELPRESSURE_HPA)); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_INA3221 |
||||
|
if (INA3221_initialized) { |
||||
|
for(int i = 0; i < TELEM_INA3221_NUM_CHANNELS; i++) { |
||||
|
// add only enabled INA3221 channels to telemetry
|
||||
|
if (INA3221.isChannelEnabled(i)) { |
||||
|
float voltage = INA3221.getBusVoltage(i); |
||||
|
float current = INA3221.getCurrentAmps(i); |
||||
|
telemetry.addVoltage(next_available_channel, voltage); |
||||
|
telemetry.addCurrent(next_available_channel, current); |
||||
|
telemetry.addPower(next_available_channel, voltage * current); |
||||
|
next_available_channel++; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#if ENV_INCLUDE_INA219 |
||||
|
if (INA219_initialized) { |
||||
|
telemetry.addVoltage(next_available_channel, INA219.getBusVoltage_V()); |
||||
|
telemetry.addCurrent(next_available_channel, INA219.getCurrent_mA() / 1000); |
||||
|
telemetry.addPower(next_available_channel, INA219.getPower_mW() / 1000); |
||||
|
next_available_channel++; |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
int EnvironmentSensorManager::getNumSettings() const { |
||||
|
#if ENV_INCLUDE_GPS |
||||
|
return gps_detected ? 1 : 0; // only show GPS setting if GPS is detected
|
||||
|
#else |
||||
|
return 0; |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
const char* EnvironmentSensorManager::getSettingName(int i) const { |
||||
|
#if ENV_INCLUDE_GPS |
||||
|
return (gps_detected && i == 0) ? "gps" : NULL; |
||||
|
#else |
||||
|
return NULL; |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
const char* EnvironmentSensorManager::getSettingValue(int i) const { |
||||
|
#if ENV_INCLUDE_GPS |
||||
|
if (gps_detected && i == 0) { |
||||
|
return gps_active ? "1" : "0"; |
||||
|
} |
||||
|
#endif |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
bool EnvironmentSensorManager::setSettingValue(const char* name, const char* value) { |
||||
|
#if ENV_INCLUDE_GPS |
||||
|
if (gps_detected && strcmp(name, "gps") == 0) { |
||||
|
if (strcmp(value, "0") == 0) { |
||||
|
stop_gps(); |
||||
|
} else { |
||||
|
start_gps(); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
#endif |
||||
|
return false; // not supported
|
||||
|
} |
||||
|
|
||||
|
#if ENV_INCLUDE_GPS |
||||
|
void EnvironmentSensorManager::initBasicGPS() { |
||||
|
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX); |
||||
|
Serial1.begin(9600); |
||||
|
|
||||
|
// Try to detect if GPS is physically connected to determine if we should expose the setting
|
||||
|
pinMode(PIN_GPS_EN, OUTPUT); |
||||
|
digitalWrite(PIN_GPS_EN, HIGH); // Power on GPS
|
||||
|
|
||||
|
// Give GPS a moment to power up and send data
|
||||
|
delay(1000); |
||||
|
|
||||
|
// We'll consider GPS detected if we see any data on Serial1
|
||||
|
gps_detected = (Serial1.available() > 0); |
||||
|
|
||||
|
if (gps_detected) { |
||||
|
MESH_DEBUG_PRINTLN("GPS detected"); |
||||
|
digitalWrite(PIN_GPS_EN, LOW); // Power off GPS until the setting is changed
|
||||
|
} else { |
||||
|
MESH_DEBUG_PRINTLN("No GPS detected"); |
||||
|
digitalWrite(PIN_GPS_EN, LOW); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void EnvironmentSensorManager::start_gps() { |
||||
|
gps_active = true; |
||||
|
pinMode(PIN_GPS_EN, OUTPUT); |
||||
|
digitalWrite(PIN_GPS_EN, HIGH); |
||||
|
} |
||||
|
|
||||
|
void EnvironmentSensorManager::stop_gps() { |
||||
|
gps_active = false; |
||||
|
pinMode(PIN_GPS_EN, OUTPUT); |
||||
|
digitalWrite(PIN_GPS_EN, LOW); |
||||
|
} |
||||
|
|
||||
|
void EnvironmentSensorManager::loop() { |
||||
|
static long next_gps_update = 0; |
||||
|
|
||||
|
_location->loop(); |
||||
|
|
||||
|
if (millis() > next_gps_update) { |
||||
|
if (_location->isValid()) { |
||||
|
node_lat = ((double)_location->getLatitude())/1000000.; |
||||
|
node_lon = ((double)_location->getLongitude())/1000000.; |
||||
|
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon); |
||||
|
} |
||||
|
next_gps_update = millis() + 1000; |
||||
|
} |
||||
|
} |
||||
|
#endif |
||||
@ -0,0 +1,42 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <Mesh.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
#include <helpers/sensors/LocationProvider.h> |
||||
|
|
||||
|
class EnvironmentSensorManager : public SensorManager { |
||||
|
protected: |
||||
|
int next_available_channel = TELEM_CHANNEL_SELF + 1; |
||||
|
|
||||
|
bool AHTX0_initialized = false; |
||||
|
bool BME280_initialized = false; |
||||
|
bool INA3221_initialized = false; |
||||
|
bool INA219_initialized = false; |
||||
|
|
||||
|
bool gps_detected = false; |
||||
|
bool gps_active = false; |
||||
|
|
||||
|
#if ENV_INCLUDE_GPS |
||||
|
LocationProvider* _location; |
||||
|
void start_gps(); |
||||
|
void stop_gps(); |
||||
|
void initBasicGPS(); |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
public: |
||||
|
#if ENV_INCLUDE_GPS |
||||
|
EnvironmentSensorManager(LocationProvider &location): _location(&location){}; |
||||
|
#else |
||||
|
EnvironmentSensorManager(){}; |
||||
|
#endif |
||||
|
bool begin() override; |
||||
|
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; |
||||
|
#if ENV_INCLUDE_GPS |
||||
|
void loop() override; |
||||
|
#endif |
||||
|
int getNumSettings() const override; |
||||
|
const char* getSettingName(int i) const override; |
||||
|
const char* getSettingValue(int i) const override; |
||||
|
bool setSettingValue(const char* name, const char* value) override; |
||||
|
}; |
||||
@ -0,0 +1,54 @@ |
|||||
|
#ifdef PIN_BUZZER |
||||
|
#include "buzzer.h" |
||||
|
|
||||
|
void genericBuzzer::begin() { |
||||
|
// Serial.print("DBG: Setting up buzzer on pin ");
|
||||
|
// Serial.println(PIN_BUZZER);
|
||||
|
#ifdef PIN_BUZZER_EN |
||||
|
pinMode(PIN_BUZZER_EN, OUTPUT); |
||||
|
digitalWrite(PIN_BUZZER_EN, HIGH); |
||||
|
#endif |
||||
|
|
||||
|
quiet(false); |
||||
|
pinMode(PIN_BUZZER, OUTPUT); |
||||
|
startup(); |
||||
|
} |
||||
|
|
||||
|
void genericBuzzer::play(const char *melody) { |
||||
|
if (isPlaying()) // interrupt existing
|
||||
|
{ |
||||
|
rtttl::stop(); |
||||
|
} |
||||
|
|
||||
|
if (_is_quiet) return; |
||||
|
|
||||
|
rtttl::begin(PIN_BUZZER,melody); |
||||
|
// Serial.print("DBG: Playing melody - isQuiet: ");
|
||||
|
// Serial.println(isQuiet());
|
||||
|
} |
||||
|
|
||||
|
bool genericBuzzer::isPlaying() { |
||||
|
return rtttl::isPlaying(); |
||||
|
} |
||||
|
|
||||
|
void genericBuzzer::loop() { |
||||
|
if (!rtttl::done()) rtttl::play(); |
||||
|
} |
||||
|
|
||||
|
void genericBuzzer::startup() { |
||||
|
play(startup_song); |
||||
|
} |
||||
|
|
||||
|
void genericBuzzer::shutdown() { |
||||
|
play(shutdown_song); |
||||
|
} |
||||
|
|
||||
|
void genericBuzzer::quiet(bool buzzer_state) { |
||||
|
_is_quiet = buzzer_state; |
||||
|
} |
||||
|
|
||||
|
bool genericBuzzer::isQuiet() { |
||||
|
return _is_quiet; |
||||
|
} |
||||
|
|
||||
|
#endif // ifdef PIN_BUZZER
|
||||
@ -0,0 +1,37 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
#include <NonBlockingRtttl.h> |
||||
|
|
||||
|
/* class abstracts underlying RTTTL library
|
||||
|
|
||||
|
Just a simple imlementation to start. At the moment use same |
||||
|
melody for message and discovery |
||||
|
Suggest enum type for different sounds |
||||
|
- on message |
||||
|
- on discovery |
||||
|
|
||||
|
TODO |
||||
|
- make message ring tone configurable |
||||
|
|
||||
|
*/ |
||||
|
|
||||
|
class genericBuzzer |
||||
|
{ |
||||
|
public: |
||||
|
void begin(); // set up buzzer port
|
||||
|
void play(const char *melody); // Generic play function
|
||||
|
void loop(); // loop driven-nonblocking
|
||||
|
void startup(); // play startup sound
|
||||
|
void shutdown(); // play shutdown sound
|
||||
|
bool isPlaying(); // returns true if a sound is still playing else false
|
||||
|
void quiet(bool buzzer_state); // enables or disables the buzzer
|
||||
|
bool isQuiet(); // get buzzer state on/off
|
||||
|
|
||||
|
private: |
||||
|
// gemini's picks:
|
||||
|
const char *startup_song = "Startup:d=4,o=5,b=160:16c6,16e6,8g6"; |
||||
|
const char *shutdown_song = "Shutdown:d=4,o=5,b=100:8g5,16e5,16c5"; |
||||
|
|
||||
|
bool _is_quiet = true; |
||||
|
}; |
||||
@ -0,0 +1,102 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "nano-g2.h" |
||||
|
|
||||
|
#ifdef NANO_G2_ULTRA |
||||
|
|
||||
|
#include <bluefruit.h> |
||||
|
#include <Wire.h> |
||||
|
|
||||
|
static BLEDfu bledfu; |
||||
|
|
||||
|
static void connect_callback(uint16_t conn_handle) |
||||
|
{ |
||||
|
(void)conn_handle; |
||||
|
MESH_DEBUG_PRINTLN("BLE client connected"); |
||||
|
} |
||||
|
|
||||
|
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) |
||||
|
{ |
||||
|
(void)conn_handle; |
||||
|
(void)reason; |
||||
|
|
||||
|
MESH_DEBUG_PRINTLN("BLE client disconnected"); |
||||
|
} |
||||
|
|
||||
|
void NanoG2Ultra::begin() |
||||
|
{ |
||||
|
// for future use, sub-classes SHOULD call this from their begin()
|
||||
|
startup_reason = BD_STARTUP_NORMAL; |
||||
|
|
||||
|
// set user button
|
||||
|
pinMode(PIN_BUTTON1, INPUT); |
||||
|
|
||||
|
// the external notification circuit is shared for both buzzer and led
|
||||
|
pinMode(EXT_NOTIFY_OUT, OUTPUT); |
||||
|
digitalWrite(EXT_NOTIFY_OUT, LOW); |
||||
|
|
||||
|
Wire.begin(); |
||||
|
pinMode(SX126X_POWER_EN, OUTPUT); |
||||
|
digitalWrite(SX126X_POWER_EN, HIGH); |
||||
|
|
||||
|
delay(10); |
||||
|
} |
||||
|
|
||||
|
uint16_t NanoG2Ultra::getBattMilliVolts() |
||||
|
{ |
||||
|
int adcvalue = 0; |
||||
|
|
||||
|
analogReference(AR_INTERNAL_3_0); |
||||
|
analogReadResolution(12); |
||||
|
delay(10); |
||||
|
|
||||
|
// ADC range is 0..3000mV and resolution is 12-bit (0..4095)
|
||||
|
adcvalue = analogRead(PIN_VBAT_READ); |
||||
|
// Convert the raw value to compensated mv, taking the resistor-
|
||||
|
// divider into account (providing the actual LIPO voltage)
|
||||
|
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB); |
||||
|
} |
||||
|
|
||||
|
bool NanoG2Ultra::startOTAUpdate(const char *id, char reply[]) |
||||
|
{ |
||||
|
// Config the peripheral connection with maximum bandwidth
|
||||
|
// more SRAM required by SoftDevice
|
||||
|
// Note: All config***() function must be called before begin()
|
||||
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); |
||||
|
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); |
||||
|
|
||||
|
Bluefruit.begin(1, 0); |
||||
|
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
||||
|
Bluefruit.setTxPower(4); |
||||
|
// Set the BLE device name
|
||||
|
Bluefruit.setName("TECHO_OTA"); |
||||
|
|
||||
|
Bluefruit.Periph.setConnectCallback(connect_callback); |
||||
|
Bluefruit.Periph.setDisconnectCallback(disconnect_callback); |
||||
|
|
||||
|
// To be consistent OTA DFU should be added first if it exists
|
||||
|
bledfu.begin(); |
||||
|
|
||||
|
// Set up and start advertising
|
||||
|
// Advertising packet
|
||||
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); |
||||
|
Bluefruit.Advertising.addTxPower(); |
||||
|
Bluefruit.Advertising.addName(); |
||||
|
|
||||
|
/* Start Advertising
|
||||
|
- Enable auto advertising if disconnected |
||||
|
- Interval: fast mode = 20 ms, slow mode = 152.5 ms |
||||
|
- Timeout for fast mode is 30 seconds |
||||
|
- Start(timeout) with timeout = 0 will advertise forever (until connected) |
||||
|
|
||||
|
For recommended advertising interval |
||||
|
https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||
|
*/ |
||||
|
Bluefruit.Advertising.restartOnDisconnect(true); |
||||
|
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||
|
|
||||
|
strcpy(reply, "OK - started"); |
||||
|
return true; |
||||
|
} |
||||
|
#endif |
||||
@ -0,0 +1,57 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <MeshCore.h> |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
// LoRa radio module pins
|
||||
|
#define P_LORA_DIO_1 (32 + 10) |
||||
|
#define P_LORA_NSS (32 + 13) |
||||
|
#define P_LORA_RESET (32 + 15) |
||||
|
#define P_LORA_BUSY (32 + 11) |
||||
|
#define P_LORA_SCLK (0 + 12) |
||||
|
#define P_LORA_MISO (32 + 9) |
||||
|
#define P_LORA_MOSI (0 + 11) |
||||
|
|
||||
|
#define SX126X_DIO2_AS_RF_SWITCH true |
||||
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8 |
||||
|
#define SX126X_POWER_EN 37 |
||||
|
|
||||
|
// buttons
|
||||
|
#define PIN_BUTTON1 (32 + 6) |
||||
|
#define BUTTON_PIN PIN_BUTTON1 |
||||
|
#define PIN_USER_BTN BUTTON_PIN |
||||
|
|
||||
|
// built-ins
|
||||
|
#define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
|
||||
|
|
||||
|
#define VBAT_DIVIDER (0.5F) // 150K + 150K voltage divider on VBAT, actually 100K + 100K
|
||||
|
#define VBAT_DIVIDER_COMP (2.0F) // Compensation factor for the VBAT divider
|
||||
|
|
||||
|
#define PIN_VBAT_READ (0 + 2) |
||||
|
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) |
||||
|
|
||||
|
class NanoG2Ultra : public mesh::MainBoard |
||||
|
{ |
||||
|
protected: |
||||
|
uint8_t startup_reason; |
||||
|
|
||||
|
public: |
||||
|
void begin(); |
||||
|
uint16_t getBattMilliVolts() override; |
||||
|
bool startOTAUpdate(const char *id, char reply[]) override; |
||||
|
|
||||
|
uint8_t getStartupReason() const override |
||||
|
{ |
||||
|
return startup_reason; |
||||
|
} |
||||
|
|
||||
|
const char *getManufacturerName() const override |
||||
|
{ |
||||
|
return "Nano G2 Ultra"; |
||||
|
} |
||||
|
|
||||
|
void reboot() override |
||||
|
{ |
||||
|
NVIC_SystemReset(); |
||||
|
} |
||||
|
}; |
||||
@ -0,0 +1,59 @@ |
|||||
|
[nrf52840_g2_ultra] |
||||
|
extends = nrf52_base |
||||
|
platform_packages = framework-arduinoadafruitnrf52 |
||||
|
build_flags = ${nrf52_base.build_flags} |
||||
|
-I src/helpers/nrf52 |
||||
|
-I lib/nrf52/s140_nrf52_6.1.1_API/include |
||||
|
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 |
||||
|
lib_deps = |
||||
|
${nrf52_base.lib_deps} |
||||
|
rweather/Crypto @ ^0.4.0 |
||||
|
lewisxhe/PCF8563_Library@^1.0.1 |
||||
|
|
||||
|
[Nano_G2_Ultra] |
||||
|
extends = nrf52840_g2_ultra |
||||
|
board = nano-g2-ultra |
||||
|
board_build.ldscript = boards/nrf52840_s140_v6.ld |
||||
|
build_flags = ${nrf52840_g2_ultra.build_flags} |
||||
|
-I variants/nano_g2_ultra |
||||
|
-D NANO_G2_ULTRA |
||||
|
-D RADIO_CLASS=CustomSX1262 |
||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D SX126X_CURRENT_LIMIT=140 |
||||
|
-D SX126X_RX_BOOSTED_GAIN=1 |
||||
|
-D PIN_USER_BTN=38 |
||||
|
build_src_filter = ${nrf52840_g2_ultra.build_src_filter} |
||||
|
+<helpers/*.cpp> |
||||
|
+<../variants/nano_g2_ultra> |
||||
|
debug_tool = jlink |
||||
|
upload_protocol = nrfutil |
||||
|
|
||||
|
[env:Nano_G2_Ultra_companion_radio_ble] |
||||
|
extends = Nano_G2_Ultra |
||||
|
build_flags = |
||||
|
${Nano_G2_Ultra.build_flags} |
||||
|
-I src/helpers/ui |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
-D BLE_PIN_CODE=0 |
||||
|
-D BLE_DEBUG_LOGGING=1 |
||||
|
-D OFFLINE_QUEUE_SIZE=256 |
||||
|
-D DISPLAY_CLASS=SH1106Display |
||||
|
-D PIN_BUZZER=4 |
||||
|
; -D ENABLE_PRIVATE_KEY_IMPORT=1 |
||||
|
; -D ENABLE_PRIVATE_KEY_EXPORT=1 |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${Nano_G2_Ultra.build_src_filter} |
||||
|
+<helpers/nrf52/SerialBLEInterface.cpp> |
||||
|
+<helpers/ui/SH1106Display.cpp> |
||||
|
+<helpers/ui/buzzer.cpp> |
||||
|
+<../examples/companion_radio> |
||||
|
lib_deps = |
||||
|
${Nano_G2_Ultra.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
|
adafruit/Adafruit SH110X @ ~2.1.13 |
||||
|
adafruit/Adafruit GFX Library @ ^1.12.1 |
||||
|
stevemarple/MicroNMEA @ ^2.0.6 |
||||
|
end2endzone/NonBlockingRTTTL@^1.3.0 |
||||
@ -0,0 +1,183 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "target.h" |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
#include <helpers/sensors/MicroNMEALocationProvider.h> |
||||
|
|
||||
|
NanoG2Ultra 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); |
||||
|
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1); |
||||
|
NanoG2UltraSensorManager sensors = NanoG2UltraSensorManager(nmea); |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
#ifndef LORA_CR |
||||
|
#define LORA_CR 5 |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init() |
||||
|
{ |
||||
|
rtc_clock.begin(Wire); |
||||
|
|
||||
|
#ifdef SX126X_DIO3_TCXO_VOLTAGE |
||||
|
float tcxo = SX126X_DIO3_TCXO_VOLTAGE; |
||||
|
#else |
||||
|
float tcxo = 1.6f; |
||||
|
#endif |
||||
|
|
||||
|
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); |
||||
|
SPI.begin(); |
||||
|
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); |
||||
|
if (status != RADIOLIB_ERR_NONE) |
||||
|
{ |
||||
|
Serial.print("ERROR: radio init failed: "); |
||||
|
Serial.println(status); |
||||
|
return false; // fail
|
||||
|
} |
||||
|
|
||||
|
radio.setCRC(1); |
||||
|
|
||||
|
#ifdef SX126X_CURRENT_LIMIT |
||||
|
radio.setCurrentLimit(SX126X_CURRENT_LIMIT); |
||||
|
#endif |
||||
|
#ifdef SX126X_DIO2_AS_RF_SWITCH |
||||
|
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); |
||||
|
#endif |
||||
|
#ifdef SX126X_RX_BOOSTED_GAIN |
||||
|
radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); |
||||
|
#endif |
||||
|
|
||||
|
return true; // success
|
||||
|
} |
||||
|
|
||||
|
uint32_t radio_get_rng_seed() |
||||
|
{ |
||||
|
return radio.random(0x7FFFFFFF); |
||||
|
} |
||||
|
|
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) |
||||
|
{ |
||||
|
radio.setFrequency(freq); |
||||
|
radio.setSpreadingFactor(sf); |
||||
|
radio.setBandwidth(bw); |
||||
|
radio.setCodingRate(cr); |
||||
|
} |
||||
|
|
||||
|
void radio_set_tx_power(uint8_t dbm) |
||||
|
{ |
||||
|
radio.setOutputPower(dbm); |
||||
|
} |
||||
|
|
||||
|
void NanoG2UltraSensorManager::start_gps() |
||||
|
{ |
||||
|
if (!gps_active) |
||||
|
{ |
||||
|
MESH_DEBUG_PRINTLN("starting GPS"); |
||||
|
digitalWrite(PIN_GPS_STANDBY, HIGH); |
||||
|
gps_active = true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void NanoG2UltraSensorManager::stop_gps() |
||||
|
{ |
||||
|
if (gps_active) |
||||
|
{ |
||||
|
MESH_DEBUG_PRINTLN("stopping GPS"); |
||||
|
digitalWrite(PIN_GPS_STANDBY, LOW); |
||||
|
gps_active = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool NanoG2UltraSensorManager::begin() |
||||
|
{ |
||||
|
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX); // be sure to tx into rx and rx into tx
|
||||
|
Serial1.begin(115200); |
||||
|
|
||||
|
pinMode(PIN_GPS_STANDBY, OUTPUT); |
||||
|
digitalWrite(PIN_GPS_STANDBY, HIGH); // Wake GPS from standby
|
||||
|
delay(500); |
||||
|
|
||||
|
// We'll consider GPS detected if we see any data on Serial1
|
||||
|
if (Serial1.available() > 0) |
||||
|
{ |
||||
|
MESH_DEBUG_PRINTLN("GPS detected"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
MESH_DEBUG_PRINTLN("No GPS detected"); |
||||
|
} |
||||
|
digitalWrite(GPS_EN, LOW); // Put GPS back into standby mode
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool NanoG2UltraSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP &telemetry) |
||||
|
{ |
||||
|
if (requester_permissions & TELEM_PERM_LOCATION) |
||||
|
{ // does requester have permission?
|
||||
|
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void NanoG2UltraSensorManager::loop() |
||||
|
{ |
||||
|
static long next_gps_update = 0; |
||||
|
_location->loop(); |
||||
|
if (millis() > next_gps_update && gps_active) // don't bother if gps position is not enabled
|
||||
|
{ |
||||
|
if (_location->isValid()) |
||||
|
{ |
||||
|
node_lat = ((double)_location->getLatitude()) / 1000000.; |
||||
|
node_lon = ((double)_location->getLongitude()) / 1000000.; |
||||
|
node_altitude = ((double)_location->getAltitude()) / 1000.0; |
||||
|
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon); |
||||
|
} |
||||
|
next_gps_update = millis() + (1000 * 60); // after initial update, only check every minute TODO: should be configurable
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int NanoG2UltraSensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch)
|
||||
|
|
||||
|
const char *NanoG2UltraSensorManager::getSettingName(int i) const |
||||
|
{ |
||||
|
return i == 0 ? "gps" : NULL; |
||||
|
} |
||||
|
|
||||
|
const char *NanoG2UltraSensorManager::getSettingValue(int i) const |
||||
|
{ |
||||
|
if (i == 0) |
||||
|
{ |
||||
|
return gps_active ? "1" : "0"; |
||||
|
} |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
bool NanoG2UltraSensorManager::setSettingValue(const char *name, const char *value) |
||||
|
{ |
||||
|
if (strcmp(name, "gps") == 0) |
||||
|
{ |
||||
|
if (strcmp(value, "0") == 0) |
||||
|
{ |
||||
|
stop_gps(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
start_gps(); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
return false; // not supported
|
||||
|
} |
||||
|
|
||||
|
mesh::LocalIdentity radio_new_identity() |
||||
|
{ |
||||
|
RadioNoiseListener rng(radio); |
||||
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include "nano-g2.h" |
||||
|
#include <helpers/RadioLibWrappers.h> |
||||
|
#include <helpers/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
#ifdef DISPLAY_CLASS |
||||
|
#include <helpers/ui/SH1106Display.h> |
||||
|
#endif |
||||
|
#include <helpers/sensors/LocationProvider.h> |
||||
|
|
||||
|
class NanoG2UltraSensorManager : public SensorManager |
||||
|
{ |
||||
|
bool gps_active = false; |
||||
|
LocationProvider *_location; |
||||
|
|
||||
|
void start_gps(); |
||||
|
void stop_gps(); |
||||
|
|
||||
|
public: |
||||
|
NanoG2UltraSensorManager(LocationProvider &location) : _location(&location) {} |
||||
|
bool begin() override; |
||||
|
bool querySensors(uint8_t requester_permissions, CayenneLPP &telemetry) override; |
||||
|
void loop() override; |
||||
|
int getNumSettings() const override; |
||||
|
const char *getSettingName(int i) const override; |
||||
|
const char *getSettingValue(int i) const override; |
||||
|
bool setSettingValue(const char *name, const char *value) override; |
||||
|
}; |
||||
|
|
||||
|
extern NanoG2Ultra board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern AutoDiscoverRTCClock rtc_clock; |
||||
|
extern NanoG2UltraSensorManager sensors; |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
extern DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init(); |
||||
|
uint32_t radio_get_rng_seed(); |
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
|
void radio_set_tx_power(uint8_t dbm); |
||||
|
mesh::LocalIdentity radio_new_identity(); |
||||
@ -0,0 +1,36 @@ |
|||||
|
/*
|
||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved. |
||||
|
Copyright (c) 2016 Sandeep Mistry All right reserved. |
||||
|
Copyright (c) 2018, Adafruit Industries (adafruit.com) |
||||
|
|
||||
|
This library is free software; you can redistribute it and/or |
||||
|
modify it under the terms of the GNU Lesser General Public |
||||
|
License as published by the Free Software Foundation; either |
||||
|
version 2.1 of the License, or (at your option) any later version. |
||||
|
|
||||
|
This library is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
See the GNU Lesser General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the GNU Lesser General Public |
||||
|
License along with this library; if not, write to the Free Software |
||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
*/ |
||||
|
|
||||
|
#include "variant.h" |
||||
|
#include "nrf.h" |
||||
|
#include "wiring_constants.h" |
||||
|
#include "wiring_digital.h" |
||||
|
|
||||
|
const uint32_t g_ADigitalPinMap[] = { |
||||
|
// P0 - pins 0 and 1 are hardwired for xtal and should never be enabled
|
||||
|
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, |
||||
|
|
||||
|
// P1
|
||||
|
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; |
||||
|
|
||||
|
void initVariant() |
||||
|
{ |
||||
|
// Nothing need to be inited for now
|
||||
|
} |
||||
@ -0,0 +1,193 @@ |
|||||
|
/*
|
||||
|
Copyright (c) 2014-2015 Arduino LLC. All right reserved. |
||||
|
Copyright (c) 2016 Sandeep Mistry All right reserved. |
||||
|
Copyright (c) 2018, Adafruit Industries (adafruit.com) |
||||
|
|
||||
|
This library is free software; you can redistribute it and/or |
||||
|
modify it under the terms of the GNU Lesser General Public |
||||
|
License as published by the Free Software Foundation; either |
||||
|
version 2.1 of the License, or (at your option) any later version. |
||||
|
This library is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
See the GNU Lesser General Public License for more details. |
||||
|
You should have received a copy of the GNU Lesser General Public |
||||
|
License along with this library; if not, write to the Free Software |
||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
*/ |
||||
|
|
||||
|
#ifndef _VARIANT_Nano_G2_ |
||||
|
#define _VARIANT_Nano_G2_ |
||||
|
|
||||
|
/** Master clock frequency */ |
||||
|
#define VARIANT_MCK (64000000ul) |
||||
|
|
||||
|
#define USE_LFXO // Board uses 32khz crystal for LF
|
||||
|
// #define USE_LFRC // Board uses 32khz RC for LF
|
||||
|
|
||||
|
/*----------------------------------------------------------------------------
|
||||
|
* Headers |
||||
|
*----------------------------------------------------------------------------*/ |
||||
|
|
||||
|
#include "WVariant.h" |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" |
||||
|
{ |
||||
|
#endif // __cplusplus
|
||||
|
|
||||
|
// Number of pins defined in PinDescription array
|
||||
|
#define PINS_COUNT (48) |
||||
|
#define NUM_DIGITAL_PINS (48) |
||||
|
#define NUM_ANALOG_INPUTS (1) |
||||
|
#define NUM_ANALOG_OUTPUTS (0) |
||||
|
|
||||
|
// LEDs
|
||||
|
#define PIN_LED1 (-1) |
||||
|
#define PIN_LED2 (-1) |
||||
|
#define PIN_LED3 (-1) |
||||
|
|
||||
|
#define LED_RED PIN_LED3 |
||||
|
#define LED_BLUE PIN_LED1 |
||||
|
#define LED_GREEN PIN_LED2 |
||||
|
|
||||
|
#define LED_BUILTIN LED_BLUE |
||||
|
#define LED_CONN PIN_GREEN |
||||
|
|
||||
|
#define LED_STATE_ON 0 // State when LED is lit
|
||||
|
|
||||
|
/*
|
||||
|
* Buttons |
||||
|
*/ |
||||
|
#define PIN_BUTTON1 (32 + 6) |
||||
|
|
||||
|
#define EXT_NOTIFY_OUT (0 + 4) // Default pin to use for Ext Notify Module.
|
||||
|
|
||||
|
/*
|
||||
|
* Analog pins |
||||
|
*/ |
||||
|
#define PIN_A4 (0 + 2) // Battery ADC
|
||||
|
|
||||
|
#define BATTERY_PIN PIN_A4 |
||||
|
|
||||
|
static const uint8_t A4 = PIN_A4; |
||||
|
|
||||
|
#define ADC_RESOLUTION 14 |
||||
|
|
||||
|
/*
|
||||
|
* Serial interfaces |
||||
|
*/ |
||||
|
#define PIN_SERIAL2_RX (0 + 22) |
||||
|
#define PIN_SERIAL2_TX (0 + 20) |
||||
|
|
||||
|
/**
|
||||
|
Wire Interfaces |
||||
|
*/ |
||||
|
#define WIRE_INTERFACES_COUNT 1 |
||||
|
|
||||
|
#define PIN_WIRE_SDA (0 + 17) |
||||
|
#define PIN_WIRE_SCL (0 + 15) |
||||
|
|
||||
|
#define PIN_RTC_INT (0 + 14) // Interrupt from the PCF8563 RTC
|
||||
|
|
||||
|
/*
|
||||
|
External serial flash W25Q16JV_IQ |
||||
|
*/ |
||||
|
|
||||
|
// QSPI Pins
|
||||
|
#define PIN_QSPI_SCK (0 + 8) |
||||
|
#define PIN_QSPI_CS (32 + 7) |
||||
|
#define PIN_QSPI_IO0 (0 + 6) // MOSI if using two bit interface
|
||||
|
#define PIN_QSPI_IO1 (0 + 26) // MISO if using two bit interface
|
||||
|
#define PIN_QSPI_IO2 (32 + 4) // WP if using two bit interface (i.e. not used)
|
||||
|
#define PIN_QSPI_IO3 (32 + 2) // HOLD if using two bit interface (i.e. not used)
|
||||
|
|
||||
|
// On-board QSPI Flash
|
||||
|
#define EXTERNAL_FLASH_DEVICES W25Q16JV_IQ |
||||
|
#define EXTERNAL_FLASH_USE_QSPI |
||||
|
|
||||
|
/*
|
||||
|
* Lora radio |
||||
|
*/ |
||||
|
|
||||
|
#define USE_SX1262 |
||||
|
#define SX126X_CS (32 + 13) // FIXME - we really should define LORA_CS instead
|
||||
|
#define SX126X_DIO1 (32 + 10) |
||||
|
// Note DIO2 is attached internally to the module to an analog switch for TX/RX switching
|
||||
|
// #define SX1262_DIO3 (0 + 21)
|
||||
|
// This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not drive from the main CPU?
|
||||
|
#define SX126X_BUSY (32 + 11) |
||||
|
#define SX126X_RESET (32 + 15) |
||||
|
// DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3
|
||||
|
#define SX126X_DIO2_AS_RF_SWITCH |
||||
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8 |
||||
|
|
||||
|
// #define LORA_DISABLE_SENDING // Define this to disable transmission for testing (power testing etc...)
|
||||
|
|
||||
|
// #undef SX126X_CS
|
||||
|
|
||||
|
/*
|
||||
|
* GPS pins |
||||
|
*/ |
||||
|
|
||||
|
#define HAS_GPS 1 |
||||
|
#define GPS_L76K |
||||
|
|
||||
|
#define PIN_GPS_STANDBY (0 + 13) // An output to wake GPS, low means allow sleep, high means force wake STANDBY
|
||||
|
#define PIN_GPS_TX (0 + 9) // This is for bits going TOWARDS the CPU
|
||||
|
#define PIN_GPS_RX (0 + 10) // This is for bits going TOWARDS the GPS
|
||||
|
#define GPS_RX_PIN PIN_GPS_RX |
||||
|
#define GPS_TX_PIN PIN_GPS_TX |
||||
|
|
||||
|
|
||||
|
// #define GPS_THREAD_INTERVAL 50
|
||||
|
|
||||
|
#define PIN_SERIAL1_RX PIN_GPS_TX |
||||
|
#define PIN_SERIAL1_TX PIN_GPS_RX |
||||
|
|
||||
|
// PCF8563 RTC Module
|
||||
|
#define PCF8563_RTC 0x51 |
||||
|
|
||||
|
/*
|
||||
|
* SPI Interfaces |
||||
|
*/ |
||||
|
#define SPI_INTERFACES_COUNT 1 |
||||
|
|
||||
|
// For LORA, spi 0
|
||||
|
#define PIN_SPI_MISO (32 + 9) |
||||
|
#define PIN_SPI_MOSI (0 + 11) |
||||
|
#define PIN_SPI_SCK (0 + 12) |
||||
|
|
||||
|
// #define PIN_PWR_EN (0 + 6)
|
||||
|
|
||||
|
// To debug via the segger JLINK console rather than the CDC-ACM serial device
|
||||
|
// #define USE_SEGGER
|
||||
|
|
||||
|
// Battery
|
||||
|
// The battery sense is hooked to pin A0 (2)
|
||||
|
// it is defined in the anlaolgue pin section of this file
|
||||
|
// and has 12 bit resolution
|
||||
|
#define BATTERY_SENSE_RESOLUTION_BITS 12 |
||||
|
#define BATTERY_SENSE_RESOLUTION 4096.0 |
||||
|
#undef AREF_VOLTAGE |
||||
|
#define AREF_VOLTAGE 3.0 |
||||
|
#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 |
||||
|
#define ADC_MULTIPLIER (2.0F) |
||||
|
|
||||
|
#define HAS_RTC 1 |
||||
|
|
||||
|
/**
|
||||
|
OLED Screen Model |
||||
|
*/ |
||||
|
#define ARDUINO_ARCH_AVR |
||||
|
#define USE_SH1107_128_64 |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
/*----------------------------------------------------------------------------
|
||||
|
* Arduino objects - C++ only |
||||
|
*----------------------------------------------------------------------------*/ |
||||
|
|
||||
|
#endif |
||||
@ -0,0 +1,33 @@ |
|||||
|
[rak3x72] |
||||
|
extends = stm32_base |
||||
|
board = rak3172 |
||||
|
board_upload.maximum_size = 229376 ; 32kb for FS |
||||
|
build_flags = ${stm32_base.build_flags} |
||||
|
-D RADIO_CLASS=CustomSTM32WLx |
||||
|
-D WRAPPER_CLASS=CustomSTM32WLxWrapper |
||||
|
-D SPI_INTERFACES_COUNT=0 |
||||
|
-D RX_BOOSTED_GAIN=true |
||||
|
-I variants/rak3x72 |
||||
|
build_src_filter = ${stm32_base.build_src_filter} |
||||
|
+<../variants/rak3x72> |
||||
|
|
||||
|
[env:rak3x72-repeater] |
||||
|
extends = rak3x72 |
||||
|
build_flags = ${rak3x72.build_flags} |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D ADVERT_NAME='"RAK3x72 Repeater"' |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
build_src_filter = ${rak3x72.build_src_filter} |
||||
|
+<../examples/simple_repeater/main.cpp> |
||||
|
|
||||
|
[env:rak3x72_companion_radio_usb] |
||||
|
extends = rak3x72 |
||||
|
build_flags = ${rak3x72.build_flags} |
||||
|
; -D FORMAT_FS=true |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
build_src_filter = ${rak3x72.build_src_filter} |
||||
|
+<../examples/companion_radio/*.cpp> |
||||
|
lib_deps = ${rak3x72.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
@ -0,0 +1,67 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "target.h" |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
|
||||
|
RAK3x72Board board; |
||||
|
|
||||
|
RADIO_CLASS radio = new STM32WLx_Module(); |
||||
|
|
||||
|
WRAPPER_CLASS radio_driver(radio, board); |
||||
|
|
||||
|
static const uint32_t rfswitch_pins[] = {LORAWAN_RFSWITCH_PINS, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC}; |
||||
|
static const Module::RfSwitchMode_t rfswitch_table[] = { |
||||
|
{STM32WLx::MODE_IDLE, {LOW, LOW}}, |
||||
|
{STM32WLx::MODE_RX, {HIGH, LOW}}, |
||||
|
{STM32WLx::MODE_TX_LP, {LOW, HIGH}}, |
||||
|
{STM32WLx::MODE_TX_HP, {LOW, HIGH}}, |
||||
|
END_OF_MODE_TABLE, |
||||
|
}; |
||||
|
|
||||
|
VolatileRTCClock rtc_clock; |
||||
|
SensorManager sensors; |
||||
|
|
||||
|
#ifndef LORA_CR |
||||
|
#define LORA_CR 5 |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init() { |
||||
|
// rtc_clock.begin(Wire);
|
||||
|
|
||||
|
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table); |
||||
|
|
||||
|
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, 0, 0); // TCXO set to 0 for RAK3172
|
||||
|
|
||||
|
if (status != RADIOLIB_ERR_NONE) { |
||||
|
Serial.print("ERROR: radio init failed: "); |
||||
|
Serial.println(status); |
||||
|
return false; // fail
|
||||
|
} |
||||
|
|
||||
|
#ifdef RX_BOOSTED_GAIN |
||||
|
radio.setRxBoostedGainMode(RX_BOOSTED_GAIN); |
||||
|
#endif |
||||
|
|
||||
|
radio.setCRC(1); |
||||
|
|
||||
|
return true; // success
|
||||
|
} |
||||
|
|
||||
|
uint32_t radio_get_rng_seed() { |
||||
|
return radio.random(0x7FFFFFFF); |
||||
|
} |
||||
|
|
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
||||
|
radio.setFrequency(freq); |
||||
|
radio.setSpreadingFactor(sf); |
||||
|
radio.setBandwidth(bw); |
||||
|
radio.setCodingRate(cr); |
||||
|
} |
||||
|
|
||||
|
void radio_set_tx_power(uint8_t dbm) { |
||||
|
radio.setOutputPower(dbm); |
||||
|
} |
||||
|
|
||||
|
mesh::LocalIdentity radio_new_identity() { |
||||
|
RadioNoiseListener rng(radio); |
||||
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include <helpers/RadioLibWrappers.h> |
||||
|
#include <helpers/stm32/STM32Board.h> |
||||
|
#include <helpers/CustomSTM32WLxWrapper.h> |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
|
||||
|
#define PIN_VBAT_READ A0 |
||||
|
#define ADC_MULTIPLIER (5 * 1.73 * 1000) |
||||
|
|
||||
|
class RAK3x72Board : public STM32Board { |
||||
|
public: |
||||
|
const char* getManufacturerName() const override { |
||||
|
return "RAK 3x72"; |
||||
|
} |
||||
|
|
||||
|
uint16_t getBattMilliVolts() override { |
||||
|
uint32_t raw = analogRead(PIN_VBAT_READ); |
||||
|
return (ADC_MULTIPLIER * raw) / 1024; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
extern RAK3x72Board board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern VolatileRTCClock rtc_clock; |
||||
|
extern SensorManager sensors; |
||||
|
|
||||
|
bool radio_init(); |
||||
|
uint32_t radio_get_rng_seed(); |
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
|
void radio_set_tx_power(uint8_t dbm); |
||||
|
mesh::LocalIdentity radio_new_identity(); |
||||
@ -0,0 +1,5 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <variant_RAK3172_MODULE.h> |
||||
|
|
||||
|
#undef RNG |
||||
@ -0,0 +1,24 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <helpers/ui/DisplayDriver.h> |
||||
|
|
||||
|
class NullDisplayDriver : public DisplayDriver { |
||||
|
public: |
||||
|
NullDisplayDriver() : DisplayDriver(128, 64) { } |
||||
|
bool begin() { return false; } // not present
|
||||
|
|
||||
|
bool isOn() override { return false; } |
||||
|
void turnOn() override { } |
||||
|
void turnOff() override { } |
||||
|
void clear() override { } |
||||
|
void startFrame(Color bkg = DARK) override { } |
||||
|
void setTextSize(int sz) override { } |
||||
|
void setColor(Color c) override { } |
||||
|
void setCursor(int x, int y) override { } |
||||
|
void print(const char* str) override { } |
||||
|
void fillRect(int x, int y, int w, int h) override { } |
||||
|
void drawRect(int x, int y, int w, int h) override { } |
||||
|
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { } |
||||
|
uint16_t getTextWidth(const char* str) override { return 0; } |
||||
|
void endFrame() { } |
||||
|
}; |
||||
Loading…
Reference in new issue