R1NeoBoard.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <Arduino.h>
  2. #include <Wire.h>
  3. #include "R1NeoBoard.h"
  4. #ifdef NRF52_POWER_MANAGEMENT
  5. // Static configuration for power management
  6. // Values set in variant.h defines
  7. const PowerMgtConfig power_config = {
  8. .lpcomp_ain_channel = PWRMGT_LPCOMP_AIN,
  9. .lpcomp_refsel = PWRMGT_LPCOMP_REFSEL,
  10. .voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK
  11. };
  12. void R1NeoBoard::initiateShutdown(uint8_t reason) {
  13. // Disable LoRa module power before shutdown
  14. MESH_DEBUG_PRINTLN("R1Neo: shutting down");
  15. digitalWrite(SX126X_POWER_EN, LOW);
  16. if (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
  17. reason == SHUTDOWN_REASON_BOOT_PROTECT) {
  18. configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
  19. }
  20. enterSystemOff(reason);
  21. }
  22. #endif // NRF52_POWER_MANAGEMENT
  23. void R1NeoBoard::begin() {
  24. // R1 Neo peculiarity: tell DCDC converter to stay powered.
  25. // Must be done as soon as practical during boot.
  26. pinMode(PIN_DCDC_EN_MCU_HOLD, OUTPUT);
  27. digitalWrite(PIN_DCDC_EN_MCU_HOLD, HIGH);
  28. // R1 Neo peculiarity: Tell I/O Controller device is on
  29. // Enables passthrough of buttons and LEDs
  30. pinMode(PIN_SOFT_SHUTDOWN, OUTPUT);
  31. digitalWrite(PIN_SOFT_SHUTDOWN, HIGH);
  32. NRF52BoardDCDC::begin();
  33. // button is active high and passed through from I/O controller
  34. pinMode(PIN_USER_BTN, INPUT);
  35. pinMode(PIN_BUZZER, OUTPUT);
  36. digitalWrite(PIN_BUZZER, LOW);
  37. // battery pins
  38. pinMode(PIN_BAT_CHG, INPUT);
  39. pinMode(PIN_VBAT_READ, INPUT);
  40. Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
  41. Wire.begin();
  42. pinMode(SX126X_POWER_EN, OUTPUT);
  43. #ifdef NRF52_POWER_MANAGEMENT
  44. // Boot voltage protection check (may not return if voltage too low)
  45. // We need to call this after we configure SX126X_POWER_EN as output but before we pull high
  46. checkBootVoltage(&power_config);
  47. #endif
  48. digitalWrite(SX126X_POWER_EN, HIGH);
  49. delay(10); // give sx1262 some time to power up
  50. }