XiaoNrf52Board.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. #include <helpers/NRF52Board.h>
  5. #ifdef XIAO_NRF52
  6. class XiaoNrf52Board : public NRF52BoardDCDC, public NRF52BoardOTA {
  7. public:
  8. XiaoNrf52Board() : NRF52BoardOTA("XIAO_NRF52_OTA") {}
  9. void begin();
  10. #if defined(P_LORA_TX_LED)
  11. void onBeforeTransmit() override {
  12. digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
  13. }
  14. void onAfterTransmit() override {
  15. digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
  16. }
  17. #endif
  18. uint16_t getBattMilliVolts() override {
  19. // Please read befor going further ;)
  20. // https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
  21. // We can't drive VBAT_ENABLE to HIGH as long
  22. // as we don't know wether we are charging or not ...
  23. // this is a 3mA loss (4/1500)
  24. digitalWrite(VBAT_ENABLE, LOW);
  25. int adcvalue = 0;
  26. analogReadResolution(12);
  27. analogReference(AR_INTERNAL_3_0);
  28. delay(10);
  29. adcvalue = analogRead(PIN_VBAT);
  30. return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
  31. }
  32. const char* getManufacturerName() const override {
  33. return "Seeed Xiao-nrf52";
  34. }
  35. void powerOff() override {
  36. // set led on and wait for button release before poweroff
  37. digitalWrite(PIN_LED, LOW);
  38. #ifdef PIN_USER_BTN
  39. while(digitalRead(PIN_USER_BTN) == LOW);
  40. #endif
  41. digitalWrite(LED_GREEN, HIGH);
  42. digitalWrite(LED_BLUE, HIGH);
  43. digitalWrite(PIN_LED, HIGH);
  44. #ifdef PIN_USER_BTN
  45. // configure button press to wake up when in powered off state
  46. nrf_gpio_cfg_sense_input(digitalPinToInterrupt(g_ADigitalPinMap[PIN_USER_BTN]), NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
  47. #endif
  48. sd_power_system_off();
  49. }
  50. };
  51. #endif