target.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. bool radio_init() {
  21. // rtc_clock.begin(Wire);
  22. radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
  23. int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, 0, 0); // TCXO set to 0 for RAK3172
  24. if (status != RADIOLIB_ERR_NONE) {
  25. Serial.print("ERROR: radio init failed: ");
  26. Serial.println(status);
  27. return false; // fail
  28. }
  29. #ifdef RX_BOOSTED_GAIN
  30. radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
  31. #endif
  32. radio.setCRC(1);
  33. return true; // success
  34. }
  35. uint32_t radio_get_rng_seed() {
  36. return radio.random(0x7FFFFFFF);
  37. }
  38. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  39. radio.setFrequency(freq);
  40. radio.setSpreadingFactor(sf);
  41. radio.setBandwidth(bw);
  42. radio.setCodingRate(cr);
  43. }
  44. void radio_set_tx_power(uint8_t dbm) {
  45. radio.setOutputPower(dbm);
  46. }
  47. mesh::LocalIdentity radio_new_identity() {
  48. RadioNoiseListener rng(radio);
  49. return mesh::LocalIdentity(&rng); // create new random identity
  50. }