Skip to content

Commit ae56708

Browse files
author
fm
committed
Add power helper functions
1 parent 2f86b9e commit ae56708

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/AXP2101.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ void write1Byte(uint8_t dev_addr, uint8_t addr, uint8_t data) {
258258
Wire1.endTransmission();
259259
}
260260

261+
uint8_t read1Byte(uint8_t dev_addr, uint8_t addr) {
262+
Wire1.beginTransmission(dev_addr);
263+
Wire1.write(addr);
264+
Wire1.endTransmission();
265+
Wire1.requestFrom(dev_addr, (size_t)1);
266+
return Wire1.read();
267+
}
268+
261269
static constexpr uint8_t AW9523_REG_CONFIG0 = 0x04;
262270
static constexpr uint8_t AW9523_REG_CONFIG1 = 0x05;
263271
static constexpr uint8_t AW9523_REG_GCR = 0x11;
@@ -295,6 +303,34 @@ void AXP2101::coreS3_AW9523_init() {
295303
write1Byte(0x58, 0x02, 0b00000100);
296304
}
297305

306+
void AXP2101::set_BOOST_EN(bool state) {
307+
uint8_t value = read1Byte(AW9523_ADDR, 0x03);
308+
if(state == true) value |= 0b10000000;
309+
else value &= ~0b10000000;
310+
write1Byte(AW9523_ADDR, 0x03, value);
311+
}
312+
313+
void AXP2101::set_BUS_OUT_EN(bool state) {
314+
uint8_t value = read1Byte(AW9523_ADDR, 0x02);
315+
if(state == true) value |= 0b00000010;
316+
else value &= ~0b00000010;
317+
write1Byte(AW9523_ADDR, 0x02, value);
318+
}
319+
320+
void AXP2101::set_BOOST_BUS_OUT_EN(bool state) {
321+
set_BOOST_EN(state);
322+
// delay is required to prevent reverse current flow from VBUS to BUS_OUT
323+
if(state == false) delay(250);
324+
set_BUS_OUT_EN(state);
325+
}
326+
327+
void AXP2101::set_USB_OTG_EN(bool state) {
328+
uint8_t value = read1Byte(AW9523_ADDR, 0x02);
329+
if(state == true) value |= 0b00100000;
330+
else value &= ~0b00100000;
331+
write1Byte(AW9523_ADDR, 0x02, value);
332+
}
333+
298334
/**
299335
* @brief vbus boost state setup
300336
*

src/AXP2101.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ class AXP2101 : public I2C_PORT {
103103

104104
void coreS3_init(); ////
105105
void coreS3_AW9523_init();
106+
107+
void set_BOOST_EN(bool state);
108+
void set_BUS_OUT_EN(bool state);
109+
void set_BOOST_BUS_OUT_EN(bool state);
110+
void set_USB_OTG_EN(bool state);
111+
106112
void coreS3_VBUS_boost(bool state);
107113
};
108114

0 commit comments

Comments
 (0)