R1NeoBoard.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. digitalWrite(SX126X_POWER_EN, LOW);
  15. if (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
  16. reason == SHUTDOWN_REASON_BOOT_PROTECT) {
  17. configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
  18. }
  19. enterSystemOff(reason);
  20. }
  21. #endif // NRF52_POWER_MANAGEMENT
  22. void R1NeoBoard::begin() {
  23. // R1 Neo peculiarity: tell DCDC converter to stay powered.
  24. // Must be done as soon as practical during boot.
  25. pinMode(PIN_DCDC_EN_MCU_HOLD, OUTPUT);
  26. digitalWrite(PIN_DCDC_EN_MCU_HOLD, HIGH);
  27. // R1 Neo peculiarity: Tell I/O Controller device is on
  28. // Enables passthrough of buttons and LEDs
  29. pinMode(PIN_SOFT_SHUTDOWN, OUTPUT);
  30. digitalWrite(PIN_SOFT_SHUTDOWN, HIGH);
  31. NRF52BoardDCDC::begin();
  32. // button is active high and passed through from I/O controller
  33. pinMode(PIN_USER_BTN, INPUT);
  34. pinMode(PIN_BUZZER, OUTPUT);
  35. digitalWrite(PIN_BUZZER, LOW);
  36. // battery pins
  37. pinMode(PIN_BAT_CHG, INPUT);
  38. pinMode(PIN_VBAT_READ, INPUT);
  39. Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
  40. Wire.begin();
  41. pinMode(SX126X_POWER_EN, OUTPUT);
  42. #ifdef NRF52_POWER_MANAGEMENT
  43. // Boot voltage protection check (may not return if voltage too low)
  44. // We need to call this after we configure SX126X_POWER_EN as output but before we pull high
  45. checkBootVoltage(&power_config);
  46. #endif
  47. digitalWrite(SX126X_POWER_EN, HIGH);
  48. delay(10); // give sx1262 some time to power up
  49. }