RAK11310Board.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <MeshCore.h>
  4. // from https://github.com/RAKWireless/RAK11300-AT-Command-Firmware/blob/9c48409a43620a828d653501d536473200aa33af/RAK11300-AT-Arduino/batt.cpp#L17-L19
  5. #define VBAT_MV_PER_LSB (0.806F) // 3.0V ADC range and 12 - bit ADC resolution = 3300mV / 4096
  6. #define VBAT_DIVIDER (0.6F) // 1.5M + 1M voltage divider on VBAT = (1.5M / (1M + 1.5M))
  7. #define VBAT_DIVIDER_COMP (1.846F) // // Compensation factor for the VBAT divider
  8. #define PIN_VBAT_READ 26
  9. #define BATTERY_SAMPLES 8
  10. #define ADC_MULTIPLIER (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
  11. class RAK11310Board : public mesh::MainBoard {
  12. protected:
  13. uint8_t startup_reason;
  14. public:
  15. void begin();
  16. uint8_t getStartupReason() const override { return startup_reason; }
  17. #ifdef P_LORA_TX_LED
  18. void onBeforeTransmit() override { digitalWrite(P_LORA_TX_LED, HIGH); }
  19. void onAfterTransmit() override { digitalWrite(P_LORA_TX_LED, LOW); }
  20. #endif
  21. uint16_t getBattMilliVolts() override {
  22. #if defined(PIN_VBAT_READ) && defined(ADC_MULTIPLIER)
  23. analogReadResolution(12);
  24. uint32_t raw = 0;
  25. for (int i = 0; i < BATTERY_SAMPLES; i++) {
  26. raw += analogRead(PIN_VBAT_READ);
  27. }
  28. raw = raw / BATTERY_SAMPLES;
  29. return (ADC_MULTIPLIER * raw);
  30. #else
  31. return 0;
  32. #endif
  33. }
  34. const char *getManufacturerName() const override { return "RAK 11310"; }
  35. void reboot() override { rp2040.reboot(); }
  36. bool startOTAUpdate(const char *id, char reply[]) override;
  37. };