target.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/ArduinoHelpers.h>
  4. RAK4631Board board;
  5. #ifndef PIN_USER_BTN
  6. #define PIN_USER_BTN (-1)
  7. #endif
  8. #ifdef DISPLAY_CLASS
  9. DISPLAY_CLASS display;
  10. MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
  11. #if defined(PIN_USER_BTN_ANA)
  12. MomentaryButton analog_btn(PIN_USER_BTN_ANA, 1000, 20);
  13. #endif
  14. #endif
  15. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
  16. WRAPPER_CLASS radio_driver(radio, board);
  17. VolatileRTCClock fallback_clock;
  18. AutoDiscoverRTCClock rtc_clock(fallback_clock);
  19. #if ENV_INCLUDE_GPS
  20. #include <helpers/sensors/MicroNMEALocationProvider.h>
  21. MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
  22. EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
  23. #else
  24. EnvironmentSensorManager sensors;
  25. #endif
  26. bool radio_init() {
  27. rtc_clock.begin(Wire);
  28. return radio.std_init(&SPI);
  29. }
  30. uint32_t radio_get_rng_seed() {
  31. return radio.random(0x7FFFFFFF);
  32. }
  33. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  34. radio.setFrequency(freq);
  35. radio.setSpreadingFactor(sf);
  36. radio.setBandwidth(bw);
  37. radio.setCodingRate(cr);
  38. }
  39. void radio_set_tx_power(uint8_t dbm) {
  40. radio.setOutputPower(dbm);
  41. }
  42. mesh::LocalIdentity radio_new_identity() {
  43. RadioNoiseListener rng(radio);
  44. return mesh::LocalIdentity(&rng); // create new random identity
  45. }