target.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/sensors/MicroNMEALocationProvider.h>
  4. ThinknodeM5Board board;
  5. #if defined(P_LORA_SCLK)
  6. static SPIClass spi;
  7. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
  8. #else
  9. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
  10. #endif
  11. WRAPPER_CLASS radio_driver(radio, board);
  12. ESP32RTCClock fallback_clock;
  13. AutoDiscoverRTCClock rtc_clock(fallback_clock);
  14. #ifdef ENV_INCLUDE_GPS
  15. MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
  16. EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
  17. #else
  18. EnvironmentSensorManager sensors = EnvironmentSensorManager();
  19. #endif
  20. #ifdef DISPLAY_CLASS
  21. DISPLAY_CLASS display;
  22. MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
  23. #endif
  24. bool radio_init() {
  25. fallback_clock.begin();
  26. rtc_clock.begin(Wire);
  27. pinMode(P_LORA_EN, OUTPUT);
  28. digitalWrite(P_LORA_EN, HIGH);
  29. #if defined(P_LORA_SCLK)
  30. spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
  31. return radio.std_init(&spi);
  32. #else
  33. return radio.std_init();
  34. #endif
  35. }
  36. mesh::LocalIdentity radio_new_identity() {
  37. RadioNoiseListener rng(radio);
  38. return mesh::LocalIdentity(&rng); // create new random identity
  39. }