target.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/ArduinoHelpers.h>
  4. RAK3401Board board;
  5. #ifndef PIN_USER_BTN
  6. #define PIN_USER_BTN (-1)
  7. #endif
  8. #ifdef DISPLAY_CLASS
  9. DISPLAY_CLASS display;
  10. MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true);
  11. #if defined(PIN_USER_BTN_ANA)
  12. MomentaryButton analog_btn(PIN_USER_BTN_ANA, 1000, 20);
  13. #endif
  14. #endif
  15. // RAK3401 uses SPI1 for the RAK13302 LoRa module
  16. // Note: nRF52 doesn't have a separate SPI1 object, so we use SPI but configure it with SPI1 pins
  17. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
  18. WRAPPER_CLASS radio_driver(radio, board);
  19. VolatileRTCClock fallback_clock;
  20. AutoDiscoverRTCClock rtc_clock(fallback_clock);
  21. #if ENV_INCLUDE_GPS
  22. #include <helpers/sensors/MicroNMEALocationProvider.h>
  23. MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
  24. EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
  25. #else
  26. EnvironmentSensorManager sensors;
  27. #endif
  28. bool radio_init() {
  29. rtc_clock.begin(Wire);
  30. // Configure SPI with SPI1 pins for RAK13302
  31. // nRF52 uses the same SPI peripheral but with different pin assignments
  32. SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
  33. SPI.begin();
  34. return radio.std_init(&SPI);
  35. }
  36. uint32_t radio_get_rng_seed() {
  37. return radio.random(0x7FFFFFFF);
  38. }
  39. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  40. radio.setFrequency(freq);
  41. radio.setSpreadingFactor(sf);
  42. radio.setBandwidth(bw);
  43. radio.setCodingRate(cr);
  44. }
  45. void radio_set_tx_power(uint8_t dbm) {
  46. radio.setOutputPower(dbm);
  47. }
  48. mesh::LocalIdentity radio_new_identity() {
  49. RadioNoiseListener rng(radio);
  50. return mesh::LocalIdentity(&rng); // create new random identity
  51. }