33
44#include " SenseCapSolarBoard.h"
55
6+ #ifdef NRF52_POWER_MANAGEMENT
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+
13+ void SenseCapSolarBoard::initiateShutdown (uint8_t reason) {
14+ bool enable_lpcomp = (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
15+ reason == SHUTDOWN_REASON_BOOT_PROTECT);
16+
17+ pinMode (VBAT_ENABLE, OUTPUT);
18+ digitalWrite (VBAT_ENABLE, enable_lpcomp ? LOW : HIGH);
19+
20+ if (enable_lpcomp) {
21+ configureVoltageWake (power_config.lpcomp_ain_channel , power_config.lpcomp_refsel );
22+ }
23+
24+ enterSystemOff (reason);
25+ }
26+ #endif // NRF52_POWER_MANAGEMENT
27+
628void SenseCapSolarBoard::begin () {
7- NRF52Board::begin ();
29+ NRF52BoardDCDC::begin ();
30+
31+ pinMode (BATTERY_PIN, INPUT);
32+ pinMode (VBAT_ENABLE, OUTPUT);
33+ digitalWrite (VBAT_ENABLE, LOW);
34+ analogReadResolution (12 );
35+ analogReference (AR_INTERNAL_3_0);
36+ delay (50 );
37+
38+ #ifdef PIN_USER_BTN
39+ pinMode (PIN_USER_BTN, INPUT_PULLUP);
40+ #elif defined(PIN_BUTTON1)
41+ pinMode (PIN_BUTTON1, INPUT_PULLUP);
42+ #endif
843
944#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
1045 Wire.setPins (PIN_WIRE_SDA, PIN_WIRE_SCL);
1146#endif
1247
1348 Wire.begin ();
1449
50+ #ifdef LED_GREEN
51+ pinMode (LED_GREEN, OUTPUT);
52+ digitalWrite (LED_GREEN, HIGH);
53+ #endif
54+ #ifdef LED_BLUE
55+ pinMode (LED_BLUE, OUTPUT);
56+ digitalWrite (LED_BLUE, LOW);
57+ #endif
58+
1559#ifdef P_LORA_TX_LED
1660 pinMode (P_LORA_TX_LED, OUTPUT);
1761 digitalWrite (P_LORA_TX_LED, LOW);
1862#endif
1963
64+ #ifdef NRF52_POWER_MANAGEMENT
65+ checkBootVoltage (&power_config);
66+ #endif
67+
2068 delay (10 ); // give sx1262 some time to power up
21- }
69+ }
0 commit comments