RAK3401Board.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. #include <helpers/NRF52Board.h>
  5. // LoRa radio module pins for RAK13302
  6. #define P_LORA_SCLK 3
  7. #define P_LORA_MISO 29
  8. #define P_LORA_MOSI 30
  9. #define P_LORA_NSS 26
  10. #define P_LORA_DIO_1 10
  11. #define P_LORA_BUSY 9
  12. #define P_LORA_RESET 4
  13. #ifndef P_LORA_PA_EN
  14. #define P_LORA_PA_EN 31
  15. #endif
  16. //#define PIN_GPS_SDA 13 //GPS SDA pin (output option)
  17. //#define PIN_GPS_SCL 14 //GPS SCL pin (output option)
  18. // #define PIN_GPS_TX 16 //GPS TX pin
  19. // #define PIN_GPS_RX 15 //GPS RX pin
  20. #define PIN_GPS_1PPS 17 //GPS PPS pin
  21. #define GPS_BAUD_RATE 9600
  22. #define GPS_ADDRESS 0x42 //i2c address for GPS
  23. #define SX126X_DIO2_AS_RF_SWITCH
  24. #define SX126X_DIO3_TCXO_VOLTAGE 1.8
  25. // built-ins
  26. #define PIN_VBAT_READ 5
  27. #define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
  28. #define PIN_3V3_EN (34)
  29. #define WB_IO2 PIN_3V3_EN
  30. class RAK3401Board : public NRF52BoardDCDC, public NRF52BoardOTA {
  31. public:
  32. RAK3401Board() : NRF52BoardOTA("RAK3401_OTA") {}
  33. void begin();
  34. #define BATTERY_SAMPLES 8
  35. uint16_t getBattMilliVolts() override {
  36. analogReadResolution(12);
  37. uint32_t raw = 0;
  38. for (int i = 0; i < BATTERY_SAMPLES; i++) {
  39. raw += analogRead(PIN_VBAT_READ);
  40. }
  41. raw = raw / BATTERY_SAMPLES;
  42. return (ADC_MULTIPLIER * raw) / 4096;
  43. }
  44. const char* getManufacturerName() const override {
  45. return "RAK 3401";
  46. }
  47. #ifdef P_LORA_PA_EN
  48. void onBeforeTransmit() override {
  49. digitalWrite(P_LORA_PA_EN, HIGH); // Enable PA before transmission
  50. }
  51. void onAfterTransmit() override {
  52. digitalWrite(P_LORA_PA_EN, LOW); // Disable PA after transmission to save power
  53. }
  54. #endif
  55. };