target.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <Arduino.h>
  2. #include "target.h"
  3. TBeam1WBoard board;
  4. #ifdef DISPLAY_CLASS
  5. DISPLAY_CLASS display;
  6. MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
  7. #endif
  8. static SPIClass spi;
  9. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
  10. WRAPPER_CLASS radio_driver(radio, board);
  11. ESP32RTCClock fallback_clock;
  12. AutoDiscoverRTCClock rtc_clock(fallback_clock);
  13. #if ENV_INCLUDE_GPS
  14. #include <helpers/sensors/MicroNMEALocationProvider.h>
  15. MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
  16. EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
  17. #else
  18. EnvironmentSensorManager sensors;
  19. #endif
  20. bool radio_init() {
  21. fallback_clock.begin();
  22. rtc_clock.begin(Wire);
  23. // Initialize SPI for radio
  24. spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
  25. // GPS serial initialized by EnvironmentSensorManager::begin()
  26. bool success = radio.std_init(&spi);
  27. if (success) {
  28. // T-Beam 1W has external PA requiring longer ramp time (>800us recommended)
  29. // RADIOLIB_SX126X_PA_RAMP_800U = 0x05
  30. radio.setTxParams(LORA_TX_POWER, RADIOLIB_SX126X_PA_RAMP_800U);
  31. }
  32. return success;
  33. }
  34. mesh::LocalIdentity radio_new_identity() {
  35. RadioNoiseListener rng(radio);
  36. return mesh::LocalIdentity(&rng);
  37. }