|
| 1 | +#include "target.h" |
| 2 | +#include <Arduino.h> |
| 3 | +#include <helpers/ArduinoHelpers.h> |
| 4 | + |
| 5 | +TinyRelayBoard board; |
| 6 | + |
| 7 | +RADIO_CLASS radio = new STM32WLx_Module(); |
| 8 | + |
| 9 | +WRAPPER_CLASS radio_driver(radio, board); |
| 10 | + |
| 11 | +static const uint32_t rfswitch_pins[] = {LORAWAN_RFSWITCH_PINS, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC}; |
| 12 | +static const Module::RfSwitchMode_t rfswitch_table[] = { |
| 13 | + {STM32WLx::MODE_IDLE, {LOW, LOW}}, |
| 14 | + {STM32WLx::MODE_RX, {HIGH, LOW}}, |
| 15 | + {STM32WLx::MODE_TX_LP, {LOW, HIGH}}, |
| 16 | + {STM32WLx::MODE_TX_HP, {LOW, HIGH}}, |
| 17 | + END_OF_MODE_TABLE, |
| 18 | +}; |
| 19 | + |
| 20 | +VolatileRTCClock rtc_clock; |
| 21 | +SensorManager sensors; |
| 22 | + |
| 23 | +#ifndef LORA_CR |
| 24 | +#define LORA_CR 5 |
| 25 | +#endif |
| 26 | + |
| 27 | +#ifndef STM32WL_TCXO_VOLTAGE |
| 28 | +// TCXO set to 0 for RAK3172 |
| 29 | +#define STM32WL_TCXO_VOLTAGE 0 |
| 30 | +#endif |
| 31 | + |
| 32 | +#ifndef LORA_TX_POWER |
| 33 | +#define LORA_TX_POWER 22 |
| 34 | +#endif |
| 35 | + |
| 36 | +bool radio_init() |
| 37 | +{ |
| 38 | + // rtc_clock.begin(Wire); |
| 39 | + |
| 40 | + radio.setRfSwitchTable(rfswitch_pins, rfswitch_table); |
| 41 | + |
| 42 | + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, |
| 43 | + STM32WL_TCXO_VOLTAGE, 0); |
| 44 | + |
| 45 | + if (status != RADIOLIB_ERR_NONE) { |
| 46 | + Serial.print("ERROR: radio init failed: "); |
| 47 | + Serial.println(status); |
| 48 | + return false; // fail |
| 49 | + } |
| 50 | + |
| 51 | +#ifdef RX_BOOSTED_GAIN |
| 52 | + radio.setRxBoostedGainMode(RX_BOOSTED_GAIN); |
| 53 | +#endif |
| 54 | + |
| 55 | + radio.setCRC(1); |
| 56 | + |
| 57 | + return true; // success |
| 58 | +} |
| 59 | + |
| 60 | +uint32_t radio_get_rng_seed() |
| 61 | +{ |
| 62 | + return radio.random(0x7FFFFFFF); |
| 63 | +} |
| 64 | + |
| 65 | +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) |
| 66 | +{ |
| 67 | + radio.setFrequency(freq); |
| 68 | + radio.setSpreadingFactor(sf); |
| 69 | + radio.setBandwidth(bw); |
| 70 | + radio.setCodingRate(cr); |
| 71 | +} |
| 72 | + |
| 73 | +void radio_set_tx_power(uint8_t dbm) |
| 74 | +{ |
| 75 | + radio.setOutputPower(dbm); |
| 76 | +} |
| 77 | + |
| 78 | +mesh::LocalIdentity radio_new_identity() |
| 79 | +{ |
| 80 | + RadioNoiseListener rng(radio); |
| 81 | + return mesh::LocalIdentity(&rng); // create new random identity |
| 82 | +} |
0 commit comments