Skip to content

Commit 8e8a672

Browse files
authored
Add power helper functions
Add power helper functions
2 parents 2f86b9e + b797603 commit 8e8a672

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/AXP2101.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static constexpr uint8_t AW9523_REG_LEDMODE1 = 0x13;
267267
void AXP2101::coreS3_init() {
268268
write1Byte(0x69, 0b00110101); // AXP CHG_LED
269269
// write1Byte(0x97, (0b11110 - 2));
270-
write1Byte(0x90, 0xBF); // AXP ALDO~4,BLDO0~2,DIDO1 Enable
270+
write1Byte(0x90, 0xBF); // AXP ALDO~4,BLDO0~2,DIDO1 Enable
271271
write1Byte(0x95, 0b00011100); // AXP ALDO4 voltage / SD card / 3.3 V
272272

273273
write1Byte(AW9523_ADDR, 0x02, 0b00000101); // P0
@@ -295,6 +295,40 @@ void AXP2101::coreS3_AW9523_init() {
295295
write1Byte(0x58, 0x02, 0b00000100);
296296
}
297297

298+
void AXP2101::setBoostEn(bool state) {
299+
uint8_t value = read8Bit(AW9523_ADDR, 0x03);
300+
if (state == true)
301+
value |= 0b10000000;
302+
else
303+
value &= ~0b10000000;
304+
write1Byte(AW9523_ADDR, 0x03, value);
305+
}
306+
307+
void AXP2101::setBusOutEn(bool state) {
308+
uint8_t value = read8Bit(AW9523_ADDR, 0x02);
309+
if (state == true)
310+
value |= 0b00000010;
311+
else
312+
value &= ~0b00000010;
313+
write1Byte(AW9523_ADDR, 0x02, value);
314+
}
315+
316+
void AXP2101::setBoostBusOutEn(bool state) {
317+
setBoostEn(state);
318+
// delay is required to prevent reverse current flow from VBUS to BUS_OUT
319+
if (state == false) delay(250);
320+
setBusOutEn(state);
321+
}
322+
323+
void AXP2101::setUsbOtgEn(bool state) {
324+
uint8_t value = read8Bit(AW9523_ADDR, 0x02);
325+
if (state == true)
326+
value |= 0b00100000;
327+
else
328+
value &= ~0b00100000;
329+
write1Byte(AW9523_ADDR, 0x02, value);
330+
}
331+
298332
/**
299333
* @brief vbus boost state setup
300334
*

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 setBoostEn(bool state);
108+
void setBusOutEn(bool state);
109+
void setBoostBusOutEn(bool state);
110+
void setUsbOtgEn(bool state);
111+
106112
void coreS3_VBUS_boost(bool state);
107113
};
108114

src/utility/I2C_PORT.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ uint8_t I2C_PORT::read8Bit(uint8_t subAddress) {
3434
return _wire->read();
3535
}
3636

37+
uint8_t I2C_PORT::read8Bit(uint8_t address, uint8_t subAddress) {
38+
_wire->beginTransmission(address);
39+
_wire->write(subAddress);
40+
_wire->endTransmission();
41+
_wire->requestFrom(address, (size_t)1);
42+
return _wire->read();
43+
}
44+
3745
uint16_t I2C_PORT::read12Bit(uint8_t subAddress) {
3846
uint8_t buff[2];
3947
readBuff(subAddress, 2, buff);

src/utility/I2C_PORT.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class I2C_PORT {
2121
void write1Byte(uint8_t address, uint8_t subAddress, uint8_t data);
2222
void write16Bit(uint8_t subAddress, uint8_t data_1, uint8_t data_2);
2323
uint8_t read8Bit(uint8_t subAddress);
24+
uint8_t read8Bit(uint8_t address, uint8_t subAddress);
2425
uint16_t read12Bit(uint8_t subAddress);
2526
uint16_t read13Bit(uint8_t subAddress);
2627
uint16_t read16Bit(uint8_t subAddress);

0 commit comments

Comments
 (0)