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 "target.h" |
|||
#include <helpers/ArduinoHelpers.h> |
|||
|
|||
ESP32Board board; |
|||
//SenseCapIndicatorBoard board;
|
|||
|
|||
ESPNOWRadio radio_driver; |
|||
static SPIClass spi(FSPI); |
|||
|
|||
ESP32RTCClock rtc_clock; |
|||
#if defined(ENV_INCLUDE_GPS) |
|||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, (mesh::RTCClock*)&rtc_clock); |
|||
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); |
|||
#else |
|||
EnvironmentSensorManager sensors = EnvironmentSensorManager(); |
|||
#endif |
|||
// SX1262 pins για SenseCAP Indicator Meshtastic edition
|
|||
#define LORA_SCLK 5 |
|||
#define LORA_MISO 4 |
|||
#define LORA_MOSI 6 |
|||
#define LORA_NSS 7 |
|||
#define LORA_DIO1 2 |
|||
#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() { |
|||
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() { |
|||
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) { |
|||
// no-op
|
|||
radio.setFrequency(freq); |
|||
radio.setSpreadingFactor(sf); |
|||
radio.setBandwidth(bw); |
|||
radio.setCodingRate(cr); |
|||
} |
|||
|
|||
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() { |
|||
ESP_RNG rng; |
|||
return mesh::LocalIdentity(&rng); // create new random identity
|
|||
} |
|||
RadioNoiseListener rng(radio); |
|||
return mesh::LocalIdentity(&rng); |
|||
} |
|||
@ -1,29 +1,64 @@ |
|||
#pragma once |
|||
|
|||
#include <Arduino.h> |
|||
#include <RadioLib.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/sensors/EnvironmentSensorManager.h> |
|||
|
|||
#ifdef ENV_INCLUDE_GPS |
|||
#include <helpers/sensors/MicroNMEALocationProvider.h> |
|||
#endif |
|||
|
|||
#ifdef DISPLAY_CLASS |
|||
#include "SCIndicatorDisplay.h" |
|||
#include <helpers/ui/MomentaryButton.h> |
|||
#endif |
|||
|
|||
|
|||
// -------------------------------------------------
|
|||
// Board
|
|||
// -------------------------------------------------
|
|||
extern ESP32Board board; |
|||
extern ESPNOWRadio radio_driver; |
|||
|
|||
|
|||
// -------------------------------------------------
|
|||
// Radio (SX1262 - SenseCAP uses SX1262)
|
|||
// -------------------------------------------------
|
|||
extern CustomSX1262Wrapper radio_driver; |
|||
|
|||
|
|||
// -------------------------------------------------
|
|||
// RTC
|
|||
// -------------------------------------------------
|
|||
extern ESP32RTCClock rtc_clock; |
|||
|
|||
|
|||
// -------------------------------------------------
|
|||
// Sensors
|
|||
// -------------------------------------------------
|
|||
extern EnvironmentSensorManager sensors; |
|||
|
|||
|
|||
// -------------------------------------------------
|
|||
// Display + Button
|
|||
// -------------------------------------------------
|
|||
#ifdef DISPLAY_CLASS |
|||
extern DISPLAY_CLASS display; |
|||
extern MomentaryButton user_btn; |
|||
#endif |
|||
|
|||
|
|||
// -------------------------------------------------
|
|||
// Functions
|
|||
// -------------------------------------------------
|
|||
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(); |
|||
mesh::LocalIdentity radio_new_identity(); |
|||
Loading…
Reference in new issue