| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include <Arduino.h>
- #include "target.h"
- #include <helpers/ArduinoHelpers.h>
- RAK3401Board board;
- #ifndef PIN_USER_BTN
- #define PIN_USER_BTN (-1)
- #endif
- #ifdef DISPLAY_CLASS
- DISPLAY_CLASS display;
- MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true);
- #if defined(PIN_USER_BTN_ANA)
- MomentaryButton analog_btn(PIN_USER_BTN_ANA, 1000, 20);
- #endif
- #endif
- // RAK3401 uses SPI1 for the RAK13302 LoRa module
- // Note: nRF52 doesn't have a separate SPI1 object, so we use SPI but configure it with SPI1 pins
- RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
- WRAPPER_CLASS radio_driver(radio, board);
- VolatileRTCClock fallback_clock;
- AutoDiscoverRTCClock rtc_clock(fallback_clock);
- #if ENV_INCLUDE_GPS
- #include <helpers/sensors/MicroNMEALocationProvider.h>
- MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
- EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
- #else
- EnvironmentSensorManager sensors;
- #endif
- bool radio_init() {
- rtc_clock.begin(Wire);
- // Configure SPI with SPI1 pins for RAK13302
- // nRF52 uses the same SPI peripheral but with different pin assignments
- SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
- SPI.begin();
- return radio.std_init(&SPI);
- }
- uint32_t radio_get_rng_seed() {
- return radio.random(0x7FFFFFFF);
- }
- void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
- radio.setFrequency(freq);
- radio.setSpreadingFactor(sf);
- radio.setBandwidth(bw);
- radio.setCodingRate(cr);
- }
- void radio_set_tx_power(uint8_t dbm) {
- radio.setOutputPower(dbm);
- }
- mesh::LocalIdentity radio_new_identity() {
- RadioNoiseListener rng(radio);
- return mesh::LocalIdentity(&rng); // create new random identity
- }
|