SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP517Power.cpp
Go to the documentation of this file.
1
30#include "../../../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_PMIC_AXP517
32
33#include "AXP517Power.hpp"
34#include "AXP517Regs.hpp"
35
36
38{
39}
40
42{
43 if (mv < 1000) mv = 1000;
44 if (mv > 3800) mv = 3800;
45 uint8_t code = (mv - 1000) / 100;
46 return _core.updateBits(axp517_regs::ctrl::MIN_SYS_VOLTAGE, 0x1F, code) >= 0;
47}
48
50{
52 if (regVal < 0) return 0;
53 uint8_t code = regVal & 0x1F;
54 return 1000 + code * 100;
55}
56
58{
59 if (mv < 3600) mv = 3600;
60 if (mv > 16200) mv = 16200;
61 uint8_t code = (mv - 3600) / 100 + 1;
62 return _core.updateBits(axp517_regs::ctrl::INPUT_VOLT_LIMIT, 0x7F, code) >= 0;
63}
64
66{
68 if (regVal < 0) return 0;
69 uint8_t code = regVal & 0x7F;
70 if (code == 0) return 3600;
71 return 3600 + (code - 1) * 100;
72}
73
75{
76 if (mA < 100) mA = 100;
77 if (mA > 3250) mA = 3250;
78 uint8_t code = (mA - 100) / 50;
79 return _core.updateBits(axp517_regs::ctrl::INPUT_CURR_LIMIT, 0xFC, code << 2) >= 0;
80}
81
83{
85 if (regVal < 0) return 0;
86 uint8_t code = (regVal >> 2) & 0x3F;
87 return 100 + code * 50;
88}
89
90bool AXP517Power::enableBoost(bool enable)
91{
92 return _core.updateBits(axp517_regs::ctrl::MODULE_EN1, 0x10, enable ? 0x10 : 0x00) >= 0;
93}
94
99
101{
102 if (mv < 4550) mv = 4550;
103 if (mv > 5510) mv = 5510;
104 uint8_t n = ((mv - 4550) / 64);
105 if (n > 15) n = 15;
106 int regVal = _core.readReg(axp517_regs::ctrl::BOOST_CFG);
107 if (regVal < 0) return false;
108 return _core.updateBits(axp517_regs::ctrl::BOOST_CFG, 0xF0, n << 4) >= 0;
109}
110
112{
113 int regVal = _core.readReg(axp517_regs::ctrl::BOOST_CFG);
114 if (regVal < 0) return 0;
115 uint8_t n = (regVal >> 4) & 0x0F;
116 return 4550 + n * 64;
117}
118
120{
122}
123
125{
126 return _core.getRegBit(axp517_regs::bmu::STATUS0, 4);
127}
128
129bool AXP517Power::enableRBFET(bool enable) const
130{
131 // CHECK VBUS IS NOT PRESENT,IF VBUS PRESENT, RETURN FALSE
132 if (_core.getRegBit(axp517_regs::bmu::STATUS0, 5)) {
133 return false;
134 }
135 return _core.updateBits(axp517_regs::ctrl::RBFET_CTRL, 0x01, enable ? 0x01 : 0x00) >= 0;
136}
137
139{
141}
142
143
144#endif
@license MIT License
@license MIT License
AXP517 low-level core driver.
uint32_t getInputCurrentLimit() const override
Get the input current limit.
bool isRBFETEnabled() const
Check if RBFET is enabled.
bool setBoostVoltage(uint16_t mv) override
Set the boost voltage.
bool enableBoost(bool enable) override
Enable boost functionality.
bool setInputCurrentLimit(uint32_t mA) override
Set the input current limit.
uint32_t getMinimumSystemVoltage() const override
Get the minimum system voltage.
bool isBoostEnabled() const override
Check if boost functionality is enabled.
uint32_t getInputVoltageLimit() const override
Get the input voltage limit.
bool setMinimumSystemVoltage(uint32_t mv) override
Set the minimum system voltage.
bool isShipModeEnabled() const override
Check if ship mode is enabled.
bool setInputVoltageLimit(uint32_t mv) override
Set the input voltage limit.
AXP517Power(AXP517Core &core)
Construct an AXP517 power-path driver.
uint16_t getBoostVoltage() const override
Get the boost voltage.
bool enableRBFET(bool enable) const
Enable or disable the RBFET.
bool enableShipMode(bool enable) override
Enter ship mode.
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
bool setRegBit(uint8_t reg, uint8_t bit)
static constexpr uint8_t STATUS0
BMU status0.
static constexpr uint8_t RBFET_CTRL
RBFET control.
static constexpr uint8_t INPUT_VOLT_LIMIT
Input voltage limit control.
static constexpr uint8_t MIN_SYS_VOLTAGE
Minimum system voltage control.
static constexpr uint8_t INPUT_CURR_LIMIT
Input current limit control.
static constexpr uint8_t MODULE_EN1
Module enable control1.
static constexpr uint8_t BOOST_CFG
Boost configure.
static constexpr uint8_t BATFET_CTRL
BATFET control.