XiaoNrf52Board.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. #ifdef XIAO_NRF52
  5. // redefine lora pins if using the S3 variant of SX1262 board
  6. #ifdef SX1262_XIAO_S3_VARIANT
  7. #undef P_LORA_DIO_1
  8. #undef P_LORA_BUSY
  9. #undef P_LORA_RESET
  10. #undef P_LORA_NSS
  11. #undef SX126X_RXEN
  12. #define P_LORA_DIO_1 D0
  13. #define P_LORA_BUSY D1
  14. #define P_LORA_RESET D2
  15. #define P_LORA_NSS D3
  16. #define SX126X_RXEN D4
  17. #endif
  18. class XiaoNrf52Board : public mesh::MainBoard {
  19. protected:
  20. uint8_t startup_reason;
  21. public:
  22. void begin();
  23. uint8_t getStartupReason() const override { return startup_reason; }
  24. #if defined(P_LORA_TX_LED)
  25. void onBeforeTransmit() override {
  26. digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
  27. }
  28. void onAfterTransmit() override {
  29. digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
  30. }
  31. #endif
  32. uint16_t getBattMilliVolts() override {
  33. // Please read befor going further ;)
  34. // https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
  35. // We can't drive VBAT_ENABLE to HIGH as long
  36. // as we don't know wether we are charging or not ...
  37. // this is a 3mA loss (4/1500)
  38. digitalWrite(VBAT_ENABLE, LOW);
  39. int adcvalue = 0;
  40. analogReadResolution(12);
  41. analogReference(AR_INTERNAL_3_0);
  42. delay(10);
  43. adcvalue = analogRead(PIN_VBAT);
  44. return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
  45. }
  46. const char* getManufacturerName() const override {
  47. return "Seeed Xiao-nrf52";
  48. }
  49. void reboot() override {
  50. NVIC_SystemReset();
  51. }
  52. bool startOTAUpdate(const char* id, char reply[]) override;
  53. };
  54. #endif