Skip to content

Commit 687525d

Browse files
committed
Use new standby enum
1 parent e2d1729 commit 687525d

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

Diff for: src/Board.cpp

+8-19
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,7 @@ void Board::enableWakeupFromPin(uint8_t pin, PinStatus direction){
122122

123123
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
124124
void Board::enableWakeupFromPin(){
125-
// If no wake up method is selected yet, set it to wake up from pin activity
126-
if(standbyType == LowPowerStandbyType::None){
127-
standbyType = LowPowerStandbyType::UntilPinActivity;
128-
// If there is already a wake up method selected, set it to wake up from both pin activity and time elapsed
129-
} else if (standbyType == LowPowerStandbyType::UntilTimeElapsed){
130-
standbyType = LowPowerStandbyType::UntilBothAreTrue;
131-
}
125+
standbyType |= StandbyType::untilPinActivity;
132126
}
133127

134128
void Board::enableSleepWhenIdle(){
@@ -141,12 +135,7 @@ void Board::enableWakeupFromRTC(){
141135
#if defined(ARDUINO_PORTENTA_C33)
142136
lowPower->enableWakeupFromRTC();
143137
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
144-
// If no wake up method is selected yet, set it to wake up from RTC
145-
if(standbyType == LowPowerStandbyType::None){
146-
standbyType = LowPowerStandbyType::UntilTimeElapsed;
147-
} else if (standbyType == LowPowerStandbyType::UntilPinActivity){
148-
standbyType = LowPowerStandbyType::UntilBothAreTrue;
149-
}
138+
standbyType |= StandbyType::untilTimeElapsed;
150139
#endif
151140
}
152141

@@ -210,12 +199,12 @@ void Board::deepSleepUntilWakeupEvent(){
210199
#if defined(ARDUINO_PORTENTA_C33)
211200
lowPower -> deepSleep();
212201
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
213-
if(standbyType == LowPowerStandbyType::UntilBothAreTrue)
214-
LowPower.standbyM7(LowPowerStandbyType::UntilPinActivity | LowPowerStandbyType::UntilTimeElapsed, rtcWakeupDelay);
215-
else if (standbyType == LowPowerStandbyType::UntilPinActivity)
216-
LowPower.standbyM7(LowPowerStandbyType::UntilPinActivity);
217-
else if (standbyType == LowPowerStandbyType::UntilTimeElapsed)
218-
LowPower.standbyM7(LowPowerStandbyType::UntilTimeElapsed, rtcWakeupDelay);
202+
if(standbyType == StandbyType::untilEither)
203+
LowPower.standbyM7(LowPowerStandbyType::untilPinActivity | LowPowerStandbyType::untilTimeElapsed, rtcWakeupDelay);
204+
else if (standbyType == StandbyType::untilPinActivity)
205+
LowPower.standbyM7(LowPowerStandbyType::untilPinActivity);
206+
else if (standbyType == StandbyType::untilTimeElapsed)
207+
LowPower.standbyM7(LowPowerStandbyType::untilTimeElapsed, rtcWakeupDelay);
219208
#endif
220209
}
221210

Diff for: src/Board.h

+15-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@
1717
#define CONTEXT_SW1 3
1818
#define CONTEXT_SW2 4
1919

20-
enum class LowPowerStandbyType {
21-
None = 0,
22-
UntilPinActivity = 1,
23-
UntilTimeElapsed = 2,
24-
UntilBothAreTrue = 3
20+
enum class StandbyType : uint8_t {
21+
none = 0,
22+
untilPinActivity = 1,
23+
untilTimeElapsed = 2,
24+
untilEither = 3
25+
2526
};
2627

28+
inline constexpr StandbyType operator|(StandbyType x, StandbyType y){
29+
return static_cast<StandbyType>(static_cast<int>(x) | static_cast<int>(y));
30+
}
31+
32+
inline constexpr StandbyType operator|=(StandbyType& x, StandbyType y){
33+
return x = x | y;
34+
}
35+
2736
constexpr int EMPTY_REGISTER = 0xFF;
2837

2938
/**
@@ -225,7 +234,7 @@ class Board {
225234
#if defined(ARDUINO_PORTENTA_C33)
226235
LowPower * lowPower;
227236
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
228-
LowPowerStandbyType standbyType = LowPowerStandbyType::None;
237+
StandbyType standbyType = StandbyType::none;
229238
RTCWakeupDelay rtcWakeupDelay = RTCWakeupDelay(0, 0, 0);
230239
#endif
231240
};

0 commit comments

Comments
 (0)