|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
ADC control for the AXP2101 PMIC. More...
#include <AXP2101Adc.hpp>
Public Member Functions | |
| AXP2101Adc (AXP2101Core &core) | |
| ~AXP2101Adc ()=default | |
| bool | enableChannels (uint32_t mask) override |
| Enable one or more ADC channels. | |
| bool | disableChannels (uint32_t mask) override |
| Disable one or more ADC channels (REG 0x30). | |
| bool | read (Channel ch, float &out) override |
| Read an ADC channel value. | |
| float | getTsTemperature (float SteinhartA=1.126e-3f, float SteinhartB=2.38e-4f, float SteinhartC=8.5e-8f) |
| Read TS pin temperature using Steinhart-Hart equation. | |
| bool | enableChannels (Channel mask) |
| Enable one or more ADC channels (REG 0x30). | |
| virtual bool | enableChannels (uint32_t mask)=0 |
| Enable one or more ADC channels (REG 0x30). | |
| bool | disableChannels (Channel mask) |
| Disable one or more ADC channels by Channel enum. | |
| virtual bool | disableChannels (uint32_t mask)=0 |
| Disable one or more ADC channels. | |
Public Member Functions inherited from PmicAdcBase | |
| virtual | ~PmicAdcBase ()=default |
| bool | enableChannels (Channel mask) |
| Enable one or more ADC channels by Channel enum. | |
| bool | disableChannels (Channel mask) |
| Disable one or more ADC channels by Channel enum. | |
Static Public Attributes | |
| static constexpr uint8_t | ADC_DIE_TEMP_HW = 0x10 |
| static constexpr uint8_t | ADC_SYSTEM_VOLTAGE_HW = 0x08 |
| static constexpr uint8_t | ADC_VBUS_VOLTAGE_HW = 0x04 |
| static constexpr uint8_t | ADC_TS_PIN_HW = 0x02 |
| static constexpr uint8_t | ADC_BAT_VOLTAGE_HW = 0x01 |
Additional Inherited Members | |
Public Types inherited from PmicAdcBase | |
| enum class | Channel : uint16_t { VBUS_VOLTAGE = (1 << 0) , VBUS_CURRENT = (1 << 1) , BAT_VOLTAGE = (1 << 2) , BAT_CURRENT = (1 << 3) , VSYS_VOLTAGE = (1 << 4) , DIE_TEMPERATURE = (1 << 5) , BAT_TEMPERATURE = (1 << 6) , BAT_PERCENTAGE = (1 << 7) , ACIN_VOLTAGE = (1 << 8) , ACIN_CURRENT = (1 << 9) } |
| ADC channel bitmask. More... | |
Static Protected Member Functions inherited from PmicAdcBase | |
| template<typename Func > | |
| static void | forEachChannel (uint32_t mask, Func fn) |
| Helper to iterate over set bits in a bitmask. | |
ADC control for the AXP2101 PMIC.
Provides access to the 14-bit SAR ADC for measuring battery voltage, VBUS voltage, VSYS voltage, TS pin voltage (thermistor), die temperature, and battery percentage via the fuel gauge.
| Channel | Register | Resolution | Unit |
|---|---|---|---|
| VBAT voltage | 0x34-0x35 | 14-bit | 1 mV |
| VBUS voltage | 0x38-0x39 | 14-bit | 1 mV |
| VSYS voltage | 0x3A-0x3B | 14-bit | 1 mV |
| TS pin voltage | 0x36-0x37 | 14-bit | 0.5 mV |
| Die temperature | 0x3C-0x3D | 14-bit | formula |
| Battery percentage | 0xA4 | 8-bit | 1 % |
Definition at line 52 of file AXP2101Adc.hpp.
|
explicit |
Definition at line 39 of file AXP2101Adc.cpp.
|
default |
|
inline |
Disable one or more ADC channels by Channel enum.
| mask | Bitwise OR of Channel values to disable. |
Definition at line 94 of file PmicAdcBase.hpp.
|
overridevirtual |
Disable one or more ADC channels (REG 0x30).
| mask | Bitwise OR of Channel values to disable. |
Implements PmicAdcBase.
Definition at line 79 of file AXP2101Adc.cpp.
References axp2101_regs::adc::CHANNEL_CTRL, PmicAdcBase::forEachChannel(), SensorCommWrapper::readReg(), axp2101_regs::ts::TS_PIN_CTRL, and SensorCommWrapper::writeReg().
|
virtual |
Disable one or more ADC channels.
| mask | Bitmask of channels to disable. |
Implements PmicAdcBase.
|
inline |
Enable one or more ADC channels (REG 0x30).
| mask | Bitwise OR of Channel values to enable. |
Definition at line 84 of file PmicAdcBase.hpp.
|
overridevirtual |
Enable one or more ADC channels.
Accepts Channel bitmask values. Common channels (Channel::XXX) can be combined with bitwise OR. Subclasses may also accept chip-specific mask values for channels not in the Channel enum.
| mask | Bitmask of channels to enable. |
Implements PmicAdcBase.
Definition at line 55 of file AXP2101Adc.cpp.
References axp2101_regs::adc::CHANNEL_CTRL, PmicAdcBase::forEachChannel(), SensorCommWrapper::readReg(), axp2101_regs::ts::TS_PIN_CTRL, and SensorCommWrapper::writeReg().
Referenced by setup().
|
virtual |
Enable one or more ADC channels (REG 0x30).
| mask | Bitwise OR of Channel values to enable. |
Implements PmicAdcBase.
| float AXP2101Adc::getTsTemperature | ( | float | SteinhartA = 1.126e-3f, |
| float | SteinhartB = 2.38e-4f, |
||
| float | SteinhartC = 8.5e-8f |
||
| ) |
Read TS pin temperature using Steinhart-Hart equation.
Converts the raw TS ADC voltage to temperature in Celsius using the Steinhart-Hart thermistor equation: 1/T = A + B*ln(R) + C*ln(R)^3 where R = V_ts / I_source (default 50uA).
| SteinhartA | Coefficient A (default 1.126e-3 for 10k NTC). |
| SteinhartB | Coefficient B (default 2.38e-4 for 10k NTC). |
| SteinhartC | Coefficient C (default 8.5e-8 for 10k NTC). |
Definition at line 177 of file AXP2101Adc.cpp.
References PmicAdcBase::BAT_TEMPERATURE, and read().
|
overridevirtual |
Read an ADC channel value.
For VBUS/BAT voltage channels, returns 0.0 if the source is not present. VBUS_CURRENT and BAT_CURRENT are not supported (return 0.0).
| ch | Channel to read. | |
| [out] | out | Result value. Units depend on channel:
|
Implements PmicAdcBase.
Definition at line 102 of file AXP2101Adc.cpp.
References PmicAdcBase::BAT_CURRENT, axp2101_regs::gauge::BAT_PERCENT, PmicAdcBase::BAT_PERCENTAGE, PmicAdcBase::BAT_TEMPERATURE, axp2101_regs::adc::BAT_VOLT_H, PmicAdcBase::BAT_VOLTAGE, axp2101_regs::adc::DIE_TEMP_H, PmicAdcBase::DIE_TEMPERATURE, SensorCommWrapper::readReg(), SensorCommWrapper::readRegBuff(), axp2101_regs::bmu::STATUS1, axp2101_regs::factory::TS_STEP, axp2101_regs::adc::TS_VOLT_H, axp2101_regs::factory::VBAT_STEP, PmicAdcBase::VBUS_CURRENT, axp2101_regs::factory::VBUS_STEP, axp2101_regs::adc::VBUS_VOLT_H, PmicAdcBase::VBUS_VOLTAGE, axp2101_regs::factory::VSYS_STEP, axp2101_regs::adc::VSYS_VOLT_H, and PmicAdcBase::VSYS_VOLTAGE.
Referenced by getTsTemperature().
|
staticconstexpr |
Definition at line 60 of file AXP2101Adc.hpp.
|
staticconstexpr |
Definition at line 56 of file AXP2101Adc.hpp.
|
staticconstexpr |
Definition at line 57 of file AXP2101Adc.hpp.
|
staticconstexpr |
Definition at line 59 of file AXP2101Adc.hpp.
|
staticconstexpr |
Definition at line 58 of file AXP2101Adc.hpp.