|
| 1 | +#include <Arduino.h> |
| 2 | +#include "target.h" |
| 3 | + |
| 4 | +ESP32Board board; |
| 5 | + |
| 6 | +#if defined(P_LORA_SCLK) |
| 7 | + static SPIClass spi(0); |
| 8 | + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); |
| 9 | +#else |
| 10 | + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); |
| 11 | +#endif |
| 12 | + |
| 13 | +WRAPPER_CLASS radio_driver(radio, board); |
| 14 | + |
| 15 | +ESP32RTCClock fallback_clock; |
| 16 | +AutoDiscoverRTCClock rtc_clock(fallback_clock); |
| 17 | +SensorManager sensors; |
| 18 | + |
| 19 | +bool radio_init() { |
| 20 | + fallback_clock.begin(); |
| 21 | + rtc_clock.begin(Wire); |
| 22 | + |
| 23 | +#if defined(P_LORA_SCLK) |
| 24 | + spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); |
| 25 | + return radio.std_init(&spi); |
| 26 | +#else |
| 27 | + return radio.std_init(); |
| 28 | +#endif |
| 29 | +} |
| 30 | + |
| 31 | +uint32_t radio_get_rng_seed() { |
| 32 | + return radio.random(0x7FFFFFFF); |
| 33 | +} |
| 34 | + |
| 35 | +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
| 36 | + radio.setFrequency(freq); |
| 37 | + radio.setSpreadingFactor(sf); |
| 38 | + radio.setBandwidth(bw); |
| 39 | + radio.setCodingRate(cr); |
| 40 | +} |
| 41 | + |
| 42 | +void radio_set_tx_power(uint8_t dbm) { |
| 43 | + radio.setOutputPower(dbm); |
| 44 | +} |
| 45 | + |
| 46 | +mesh::LocalIdentity radio_new_identity() { |
| 47 | + RadioNoiseListener rng(radio); |
| 48 | + return mesh::LocalIdentity(&rng); // create new random identity |
| 49 | +} |
0 commit comments