mirror of https://github.com/meshcore-dev/MeshCore
6 changed files with 101 additions and 40 deletions
@ -1,56 +1,74 @@ |
|||||
#include <Arduino.h> |
#include <Arduino.h> |
||||
#include "target.h" |
#include "target.h" |
||||
#include <helpers/ArduinoHelpers.h> |
|
||||
|
|
||||
ESP32Board board; |
ESP32Board board; |
||||
|
//SenseCapIndicatorBoard board;
|
||||
|
|
||||
ESPNOWRadio radio_driver; |
static SPIClass spi(FSPI); |
||||
|
|
||||
ESP32RTCClock rtc_clock; |
// SX1262 pins για SenseCAP Indicator Meshtastic edition
|
||||
#if defined(ENV_INCLUDE_GPS) |
#define LORA_SCLK 5 |
||||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, (mesh::RTCClock*)&rtc_clock); |
#define LORA_MISO 4 |
||||
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); |
#define LORA_MOSI 6 |
||||
#else |
#define LORA_NSS 7 |
||||
EnvironmentSensorManager sensors = EnvironmentSensorManager(); |
#define LORA_DIO1 2 |
||||
#endif |
#define LORA_RESET 8 |
||||
|
#define LORA_BUSY 3 |
||||
|
|
||||
|
Module* module = new Module( |
||||
|
LORA_NSS, |
||||
|
LORA_DIO1, |
||||
|
LORA_RESET, |
||||
|
LORA_BUSY, |
||||
|
spi |
||||
|
); |
||||
|
|
||||
|
SX1262 radio(module); |
||||
|
|
||||
|
WRAPPER_CLASS radio_driver(&radio, board); |
||||
|
|
||||
|
ESP32RTCClock fallback_clock; |
||||
|
// AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||
|
|
||||
|
EnvironmentSensorManager sensors; |
||||
|
|
||||
|
// #ifdef DISPLAY_CLASS
|
||||
|
// DISPLAY_CLASS display(&(board.periph_power));
|
||||
|
// MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
||||
|
// #endif
|
||||
|
|
||||
#ifdef DISPLAY_CLASS |
|
||||
DISPLAY_CLASS display; |
|
||||
#ifdef PIN_USER_BTN |
|
||||
MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true); |
|
||||
#endif |
|
||||
#endif |
|
||||
|
|
||||
bool radio_init() { |
bool radio_init() { |
||||
rtc_clock.begin(); |
fallback_clock.begin(); |
||||
|
rtc_clock.begin(Wire); |
||||
|
|
||||
|
spi.begin(LORA_SCLK, LORA_MISO, LORA_MOSI); |
||||
|
|
||||
radio_driver.init(); |
return radio_driver.std_init(&spi); |
||||
|
|
||||
return true; // success
|
#if defined(P_LORA_SCLK) |
||||
|
return radio.std_init(&spi); |
||||
|
#else |
||||
|
return radio.std_init(); |
||||
|
#endif |
||||
} |
} |
||||
|
|
||||
uint32_t radio_get_rng_seed() { |
uint32_t radio_get_rng_seed() { |
||||
return millis() + radio_driver.intID(); // TODO: where to get some entropy?
|
return radio.random(0x7FFFFFFF); |
||||
} |
} |
||||
|
|
||||
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
||||
// no-op
|
radio.setFrequency(freq); |
||||
|
radio.setSpreadingFactor(sf); |
||||
|
radio.setBandwidth(bw); |
||||
|
radio.setCodingRate(cr); |
||||
} |
} |
||||
|
|
||||
void radio_set_tx_power(uint8_t dbm) { |
void radio_set_tx_power(uint8_t dbm) { |
||||
radio_driver.setTxPower(dbm); |
radio.setOutputPower(dbm); |
||||
} |
} |
||||
|
|
||||
// NOTE: as we are using the WiFi radio, the ESP_IDF will have enabled hardware RNG:
|
|
||||
// https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html
|
|
||||
class ESP_RNG : public mesh::RNG { |
|
||||
public: |
|
||||
void random(uint8_t* dest, size_t sz) override { |
|
||||
esp_fill_random(dest, sz); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
mesh::LocalIdentity radio_new_identity() { |
mesh::LocalIdentity radio_new_identity() { |
||||
ESP_RNG rng; |
RadioNoiseListener rng(radio); |
||||
return mesh::LocalIdentity(&rng); // create new random identity
|
return mesh::LocalIdentity(&rng); |
||||
} |
} |
||||
@ -1,29 +1,64 @@ |
|||||
#pragma once |
#pragma once |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
#include <RadioLib.h> |
||||
|
|
||||
#include <helpers/ESP32Board.h> |
#include <helpers/ESP32Board.h> |
||||
#include <helpers/esp32/ESPNOWRadio.h> |
#include <helpers/radiolib/RadioLibWrappers.h> |
||||
|
#include <helpers/radiolib/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
|
||||
#include <helpers/SensorManager.h> |
#include <helpers/SensorManager.h> |
||||
#include <helpers/sensors/EnvironmentSensorManager.h> |
#include <helpers/sensors/EnvironmentSensorManager.h> |
||||
|
|
||||
#ifdef ENV_INCLUDE_GPS |
#ifdef ENV_INCLUDE_GPS |
||||
#include <helpers/sensors/MicroNMEALocationProvider.h> |
#include <helpers/sensors/MicroNMEALocationProvider.h> |
||||
#endif |
#endif |
||||
|
|
||||
#ifdef DISPLAY_CLASS |
#ifdef DISPLAY_CLASS |
||||
#include "SCIndicatorDisplay.h" |
#include "SCIndicatorDisplay.h" |
||||
#include <helpers/ui/MomentaryButton.h> |
#include <helpers/ui/MomentaryButton.h> |
||||
#endif |
#endif |
||||
|
|
||||
|
|
||||
|
// -------------------------------------------------
|
||||
|
// Board
|
||||
|
// -------------------------------------------------
|
||||
extern ESP32Board board; |
extern ESP32Board board; |
||||
extern ESPNOWRadio radio_driver; |
|
||||
|
|
||||
|
// -------------------------------------------------
|
||||
|
// Radio (SX1262 - SenseCAP uses SX1262)
|
||||
|
// -------------------------------------------------
|
||||
|
extern CustomSX1262Wrapper radio_driver; |
||||
|
|
||||
|
|
||||
|
// -------------------------------------------------
|
||||
|
// RTC
|
||||
|
// -------------------------------------------------
|
||||
extern ESP32RTCClock rtc_clock; |
extern ESP32RTCClock rtc_clock; |
||||
|
|
||||
|
|
||||
|
// -------------------------------------------------
|
||||
|
// Sensors
|
||||
|
// -------------------------------------------------
|
||||
extern EnvironmentSensorManager sensors; |
extern EnvironmentSensorManager sensors; |
||||
|
|
||||
|
|
||||
|
// -------------------------------------------------
|
||||
|
// Display + Button
|
||||
|
// -------------------------------------------------
|
||||
#ifdef DISPLAY_CLASS |
#ifdef DISPLAY_CLASS |
||||
extern DISPLAY_CLASS display; |
extern DISPLAY_CLASS display; |
||||
extern MomentaryButton user_btn; |
extern MomentaryButton user_btn; |
||||
#endif |
#endif |
||||
|
|
||||
|
|
||||
|
// -------------------------------------------------
|
||||
|
// Functions
|
||||
|
// -------------------------------------------------
|
||||
bool radio_init(); |
bool radio_init(); |
||||
uint32_t radio_get_rng_seed(); |
uint32_t radio_get_rng_seed(); |
||||
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
void radio_set_tx_power(uint8_t dbm); |
void radio_set_tx_power(uint8_t dbm); |
||||
mesh::LocalIdentity radio_new_identity(); |
mesh::LocalIdentity radio_new_identity(); |
||||
Loading…
Reference in new issue