IkokaNanoNRFBoard.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. #ifdef XIAO_NRF52
  5. class IkokaNanoNRFBoard : public mesh::MainBoard {
  6. protected:
  7. uint8_t startup_reason;
  8. public:
  9. void begin();
  10. uint8_t getStartupReason() const override { return startup_reason; }
  11. #if defined(P_LORA_TX_LED)
  12. void onBeforeTransmit() override {
  13. digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
  14. #if defined(LED_BLUE)
  15. // turn off that annoying blue LED before transmitting
  16. digitalWrite(LED_BLUE, HIGH);
  17. #endif
  18. }
  19. void onAfterTransmit() override {
  20. digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
  21. #if defined(LED_BLUE)
  22. // do it after transmitting too, just in case
  23. digitalWrite(LED_BLUE, HIGH);
  24. #endif
  25. }
  26. #endif
  27. uint16_t getBattMilliVolts() override {
  28. // Please read befor going further ;)
  29. // https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
  30. // We can't drive VBAT_ENABLE to HIGH as long
  31. // as we don't know wether we are charging or not ...
  32. // this is a 3mA loss (4/1500)
  33. digitalWrite(VBAT_ENABLE, LOW);
  34. int adcvalue = 0;
  35. analogReadResolution(12);
  36. analogReference(AR_INTERNAL_3_0);
  37. delay(10);
  38. adcvalue = analogRead(PIN_VBAT);
  39. return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
  40. }
  41. const char *getManufacturerName() const override {
  42. return MANUFACTURER_STRING;
  43. }
  44. void reboot() override {
  45. NVIC_SystemReset();
  46. }
  47. bool startOTAUpdate(const char *id, char reply[]) override;
  48. };
  49. #endif