target.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/ArduinoHelpers.h>
  4. RAK3x72Board 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. // rtc_clock.begin(Wire);
  29. radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
  30. int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, STM32WL_TCXO_VOLTAGE, 0);
  31. if (status != RADIOLIB_ERR_NONE) {
  32. Serial.print("ERROR: radio init failed: ");
  33. Serial.println(status);
  34. return false; // fail
  35. }
  36. #ifdef RX_BOOSTED_GAIN
  37. radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
  38. #endif
  39. radio.setCRC(1);
  40. return true; // success
  41. }
  42. mesh::LocalIdentity radio_new_identity() {
  43. RadioNoiseListener rng(radio);
  44. return mesh::LocalIdentity(&rng); // create new random identity
  45. }