Skip to content

Commit 6eb9112

Browse files
committed
Not changing VBus state if not needed
1 parent 84a8902 commit 6eb9112

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/uNode/peripherals/Power.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323
*
2424
*******************************************************************************/
25-
25+
2626
// 13/01/2019 Gijs Mos. Put UPIN_RFM_EN in high Z when LoRa not used to prevent power leak
2727
// through R2 when VBUS is high (for GPIO without LoRa). LoRa vendor library will make it
2828
// an output again and drive it appropriately when LoRa is in use.
29-
29+
3030
#include <Arduino.h>
3131
#include <SPI.h>
3232
#include "Power.hpp"
@@ -88,15 +88,19 @@ void PowerClass::begin() {
8888
*/
8989
void PowerClass::apply() {
9090
if (state.gpio || state.lora || state.ovrd) {
91-
logDebug("Enabling VBus");
92-
digitalWrite(UPIN_VBUS_EN, HIGH);
93-
state.vbus = 1;
91+
if (!state.vbus) {
92+
logDebug("Enabling VBus");
93+
digitalWrite(UPIN_VBUS_EN, HIGH);
94+
state.vbus = 1;
95+
}
9496
}
9597

9698
else {
97-
logDebug("Disabling VBus");
98-
digitalWrite(UPIN_VBUS_EN, LOW);
99-
state.vbus = 0;
99+
if (state.vbus) {
100+
logDebug("Disabling VBus");
101+
digitalWrite(UPIN_VBUS_EN, LOW);
102+
state.vbus = 0;
103+
}
100104
}
101105
}
102106

@@ -129,9 +133,10 @@ void PowerClass::setLoRaRadio(uint8_t enabled) {
129133
digitalWrite(UPIN_RFM_DIO1, LOW);
130134
pinMode(UPIN_RFM_DIO0, OUTPUT);
131135
digitalWrite(UPIN_RFM_DIO0, LOW);
132-
// UPIN_RFM_EN to high Z. R2 will pull low when VBUS off. And high when VBUS on for GPIO,
133-
// disabling the LoRa SPI and preventing leak through R2.
134-
pinMode(UPIN_RFM_EN, INPUT);
136+
137+
// UPIN_RFM_EN to high Z. R2 will pull low when VBUS off. And high when VBUS on for GPIO,
138+
// disabling the LoRa SPI and preventing leak through R2.
139+
pinMode(UPIN_RFM_EN, INPUT);
135140

136141
// Disable module and VBus
137142
state.lora = 0;

0 commit comments

Comments
 (0)