GAT562EVBProBoard.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <Arduino.h>
  2. #include <Wire.h>
  3. #include "GAT562EVBProBoard.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 GAT562EVBProBoard::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 GAT562EVBProBoard::begin() {
  23. NRF52BoardDCDC::begin();
  24. pinMode(PIN_VBAT_READ, INPUT);
  25. // Set all button pins to INPUT_PULLUP
  26. pinMode(PIN_BUTTON1, INPUT_PULLUP);
  27. #if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
  28. Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
  29. #endif
  30. Wire.begin();
  31. pinMode(SX126X_POWER_EN, OUTPUT);
  32. #ifdef NRF52_POWER_MANAGEMENT
  33. // Boot voltage protection check (may not return if voltage too low)
  34. // We need to call this after we configure SX126X_POWER_EN as output but before we pull high
  35. checkBootVoltage(&power_config);
  36. #endif
  37. digitalWrite(SX126X_POWER_EN, HIGH);
  38. delay(10); // give sx1268 some time to power up
  39. }