target.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "target.h"
  2. #include <Arduino.h>
  3. #include <helpers/ArduinoHelpers.h>
  4. TinyRelayBoard board;
  5. RADIO_CLASS radio = new STM32WLx_Module();
  6. WRAPPER_CLASS radio_driver(radio, board);
  7. static const uint32_t rfswitch_pins[] = {LORAWAN_RFSWITCH_PINS, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC};
  8. static const Module::RfSwitchMode_t rfswitch_table[] = {
  9. {STM32WLx::MODE_IDLE, {LOW, LOW}},
  10. {STM32WLx::MODE_RX, {HIGH, LOW}},
  11. {STM32WLx::MODE_TX_LP, {LOW, HIGH}},
  12. {STM32WLx::MODE_TX_HP, {LOW, HIGH}},
  13. END_OF_MODE_TABLE,
  14. };
  15. VolatileRTCClock rtc_clock;
  16. SensorManager sensors;
  17. #ifndef LORA_CR
  18. #define LORA_CR 5
  19. #endif
  20. #ifndef STM32WL_TCXO_VOLTAGE
  21. // TCXO set to 0 for RAK3172
  22. #define STM32WL_TCXO_VOLTAGE 0
  23. #endif
  24. #ifndef LORA_TX_POWER
  25. #define LORA_TX_POWER 22
  26. #endif
  27. bool radio_init()
  28. {
  29. // rtc_clock.begin(Wire);
  30. radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
  31. int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16,
  32. STM32WL_TCXO_VOLTAGE, 0);
  33. if (status != RADIOLIB_ERR_NONE) {
  34. Serial.print("ERROR: radio init failed: ");
  35. Serial.println(status);
  36. return false; // fail
  37. }
  38. #ifdef RX_BOOSTED_GAIN
  39. radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
  40. #endif
  41. radio.setCRC(1);
  42. return true; // success
  43. }
  44. mesh::LocalIdentity radio_new_identity()
  45. {
  46. RadioNoiseListener rng(radio);
  47. return mesh::LocalIdentity(&rng); // create new random identity
  48. }