|
3 | 3 |
|
4 | 4 | #include "RAK3401Board.h" |
5 | 5 |
|
| 6 | +#ifdef NRF52_POWER_MANAGEMENT |
| 7 | +// Static configuration for power management |
| 8 | +// Values set in variant.h defines |
| 9 | +const PowerMgtConfig power_config = { |
| 10 | + .lpcomp_ain_channel = PWRMGT_LPCOMP_AIN, |
| 11 | + .lpcomp_refsel = PWRMGT_LPCOMP_REFSEL, |
| 12 | + .voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK |
| 13 | +}; |
| 14 | + |
| 15 | +void RAK3401Board::initiateShutdown(uint8_t reason) { |
| 16 | + // Disable SKY66122 FEM (CSD+CPS LOW = shutdown, <1 uA) |
| 17 | + digitalWrite(SX126X_POWER_EN, LOW); |
| 18 | + |
| 19 | + // Disable 3V3 switched peripherals and 5V boost |
| 20 | + digitalWrite(PIN_3V3_EN, LOW); |
| 21 | + |
| 22 | + if (reason == SHUTDOWN_REASON_LOW_VOLTAGE || |
| 23 | + reason == SHUTDOWN_REASON_BOOT_PROTECT) { |
| 24 | + configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel); |
| 25 | + } |
| 26 | + |
| 27 | + enterSystemOff(reason); |
| 28 | +} |
| 29 | +#endif |
| 30 | + |
6 | 31 | void RAK3401Board::begin() { |
7 | 32 | NRF52BoardDCDC::begin(); |
8 | 33 | pinMode(PIN_VBAT_READ, INPUT); |
@@ -31,18 +56,11 @@ void RAK3401Board::begin() { |
31 | 56 | // HIGH = FEM active (LNA for RX, PA path available for TX). |
32 | 57 | // TX/RX switching (CTX) is handled by SX1262 DIO2 via SetDIO2AsRfSwitchCtrl. |
33 | 58 | pinMode(SX126X_POWER_EN, OUTPUT); |
| 59 | +#ifdef NRF52_POWER_MANAGEMENT |
| 60 | + // Boot voltage protection check (may not return if voltage too low) |
| 61 | + // We need to call this after we configure SX126X_POWER_EN as output but before we pull high |
| 62 | + checkBootVoltage(&power_config); |
| 63 | +#endif |
34 | 64 | digitalWrite(SX126X_POWER_EN, HIGH); |
35 | 65 | delay(1); // SKY66122 turn-on settling time (tON = 3us typ) |
36 | 66 | } |
37 | | - |
38 | | -#ifdef NRF52_POWER_MANAGEMENT |
39 | | -void RAK3401Board::initiateShutdown(uint8_t reason) { |
40 | | - // Disable SKY66122 FEM (CSD+CPS LOW = shutdown, <1 uA) |
41 | | - digitalWrite(SX126X_POWER_EN, LOW); |
42 | | - |
43 | | - // Disable 3V3 switched peripherals and 5V boost |
44 | | - digitalWrite(PIN_3V3_EN, LOW); |
45 | | - |
46 | | - enterSystemOff(reason); |
47 | | -} |
48 | | -#endif |
|
0 commit comments