target.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <Arduino.h>
  2. #include "target.h"
  3. TBeamBoard board;
  4. #if defined(P_LORA_SCLK)
  5. static SPIClass spi;
  6. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
  7. #else
  8. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
  9. #endif
  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);
  16. EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
  17. #else
  18. EnvironmentSensorManager sensors;
  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. return radio.std_init(&spi);
  28. }
  29. uint32_t radio_get_rng_seed() {
  30. return radio.random(0x7FFFFFFF);
  31. }
  32. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  33. radio.setFrequency(freq);
  34. radio.setSpreadingFactor(sf);
  35. radio.setBandwidth(bw);
  36. radio.setCodingRate(cr);
  37. }
  38. void radio_set_tx_power(int8_t dbm) {
  39. radio.setOutputPower(dbm);
  40. }
  41. mesh::LocalIdentity radio_new_identity() {
  42. RadioNoiseListener rng(radio);
  43. return mesh::LocalIdentity(&rng); // create new random identity
  44. }