target.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/ArduinoHelpers.h>
  4. WIOE5Board board;
  5. RADIO_CLASS radio = new STM32WLx_Module();
  6. WRAPPER_CLASS radio_driver(radio, board);
  7. static const uint32_t rfswitch_pins[] = {PA4, PA5, 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_HP, {LOW, HIGH}}, // for LoRa-E5 mini
  12. // {STM32WLx::MODE_TX_LP, {HIGH, HIGH}}, // for LoRa-E5-LE mini
  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. // #ifdef SX126X_DIO3_TCXO_VOLTAGE
  23. // float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
  24. // #else
  25. // float tcxo = 1.6f;
  26. // #endif
  27. radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
  28. int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, 1.7, 0);
  29. if (status != RADIOLIB_ERR_NONE) {
  30. Serial.print("ERROR: radio init failed: ");
  31. Serial.println(status);
  32. return false; // fail
  33. }
  34. #ifdef RX_BOOSTED_GAIN
  35. radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
  36. #endif
  37. radio.setCRC(1);
  38. return true; // success
  39. }
  40. uint32_t radio_get_rng_seed() {
  41. return radio.random(0x7FFFFFFF);
  42. }
  43. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  44. radio.setFrequency(freq);
  45. radio.setSpreadingFactor(sf);
  46. radio.setBandwidth(bw);
  47. radio.setCodingRate(cr);
  48. }
  49. void radio_set_tx_power(int8_t dbm) {
  50. radio.setOutputPower(dbm);
  51. }
  52. mesh::LocalIdentity radio_new_identity() {
  53. RadioNoiseListener rng(radio);
  54. return mesh::LocalIdentity(&rng); // create new random identity
  55. }