SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP202Adc Class Reference

AXP202 ADC channel control and data readout (template wrapper) More...

#include <AXP202Adc.hpp>

Inheritance diagram for AXP202Adc:
[legend]

Public Member Functions

 AXP202Adc (AXP202Core &core)
 Construct AXP202 ADC interface.
 
 ~AXP202Adc ()=default
 
bool setADCSampleRate (uint8_t rate)
 Set ADC sample rate (REG 84H bits 7:6)
 
uint16_t getADCSampleRate ()
 Get ADC sample rate in Hz.
 
bool setADCInputRange (uint8_t val)
 Set ADC input range (REG 85H)
 
uint8_t getADCInputRange ()
 
bool setADCIrqRisingThreshold (uint8_t val)
 Set ADC IRQ rising-edge threshold (REG 86H)
 
uint8_t getADCIrqRisingThreshold ()
 
bool setADCIrqFallingThreshold (uint8_t val)
 Set ADC IRQ falling-edge threshold (REG 87H)
 
uint8_t getADCIrqFallingThreshold ()
 
float getTsVoltage ()
 Read TS pin voltage in mV (REG 62H/63H, 12-bit H8L4)
 
float getGpio0Voltage ()
 Read GPIO0 ADC voltage in mV (REG 64H/65H, 12-bit H8L4)
 
float getGpio1Voltage ()
 Read GPIO1 ADC voltage in mV (REG 66H/67H, 12-bit H8L4)
 
float getBatteryPower ()
 Read battery instantaneous power (REG 70H-72H, 24-bit)
 
- Public Member Functions inherited from axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >
 AXP1xxAdc (AXP202Core &core)
 Construct ADC interface.
 
 ~AXP1xxAdc ()=default
 
bool enableChannels (uint32_t mask) override
 Enable one or more ADC channels.
 
bool enableChannels (Channel mask)
 Enable one or more ADC channels by Channel enum.
 
virtual bool enableChannels (uint32_t mask)=0
 Enable one or more ADC channels.
 
bool disableChannels (uint32_t mask) override
 Disable one or more ADC channels.
 
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.
 
bool read (Channel ch, float &out) override
 Read a single ADC channel value.
 
- 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 uint32_t ADC_BAT_VOLTAGE_HW = 0x80
 
static constexpr uint32_t ADC_BAT_CURRENT_HW = 0x40
 
static constexpr uint32_t ADC_ACIN_VOLTAGE_HW = 0x20
 
static constexpr uint32_t ADC_ACIN_CURRENT_HW = 0x10
 
static constexpr uint32_t ADC_VBUS_VOLTAGE_HW = 0x08
 
static constexpr uint32_t ADC_VBUS_CURRENT_HW = 0x04
 
static constexpr uint32_t ADC_APS_VOLTAGE_HW = 0x02
 
static constexpr uint32_t ADC_TS_PIN_HW = 0x01
 
static constexpr uint32_t ADC_TEMPERATURE_HW = 0x8000
 
static constexpr uint32_t ADC_GPIO0_HW = 0x0800
 
static constexpr uint32_t ADC_GPIO1_HW = 0x0400
 

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.
 
- Protected Attributes inherited from axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >
AXP202Core_core
 Reference to I2C communication core.
 

Detailed Description

AXP202 ADC channel control and data readout (template wrapper)

Instantiates the generic AXP1xxAdc template with AXP202Core and AXP202 traits. Provides the same interface as before while benefiting from reduced code duplication.

Definition at line 52 of file AXP202Adc.hpp.

Constructor & Destructor Documentation

◆ AXP202Adc()

AXP202Adc::AXP202Adc ( AXP202Core core)
inlineexplicit

Construct AXP202 ADC interface.

Parameters
coreReference to AXP202 core communication

Definition at line 72 of file AXP202Adc.hpp.

◆ ~AXP202Adc()

AXP202Adc::~AXP202Adc ( )
default

Member Function Documentation

◆ getADCInputRange()

◆ getADCIrqFallingThreshold()

uint8_t AXP202Adc::getADCIrqFallingThreshold ( )

◆ getADCIrqRisingThreshold()

◆ getADCSampleRate()

uint16_t AXP202Adc::getADCSampleRate ( )

Get ADC sample rate in Hz.

Returns
Sample rate: 25, 50, 100, or 200 Hz

Definition at line 51 of file AXP202Adc.cpp.

References axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >::_core, axp202_regs::adc::ADC_SPEED, and SensorCommWrapper::readReg().

◆ getBatteryPower()

float AXP202Adc::getBatteryPower ( )

Read battery instantaneous power (REG 70H-72H, 24-bit)

Returns
Power value (raw * 0.5 * 1.1 mW), or 0 on error

Definition at line 120 of file AXP202Adc.cpp.

References axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >::_core, axp202_regs::adc::BAT_POWER_H, buf, and SensorCommWrapper::readRegBuff().

◆ getGpio0Voltage()

float AXP202Adc::getGpio0Voltage ( )

Read GPIO0 ADC voltage in mV (REG 64H/65H, 12-bit H8L4)

Returns
Voltage in mV, or 0 on error

Definition at line 102 of file AXP202Adc.cpp.

References axp202_regs::factory::FACTORY_GPIO_VOLTAGE, axp202_regs::adc::GPIO0_ADC_H, and axp202_regs::adc::GPIO0_ADC_L.

◆ getGpio1Voltage()

float AXP202Adc::getGpio1Voltage ( )

Read GPIO1 ADC voltage in mV (REG 66H/67H, 12-bit H8L4)

Returns
Voltage in mV, or 0 on error

Definition at line 111 of file AXP202Adc.cpp.

References axp202_regs::factory::FACTORY_GPIO_VOLTAGE, axp202_regs::adc::GPIO1_ADC_H, and axp202_regs::adc::GPIO1_ADC_L.

◆ getTsVoltage()

float AXP202Adc::getTsVoltage ( )

Read TS pin voltage in mV (REG 62H/63H, 12-bit H8L4)

Returns
Voltage in mV, or 0 on error

Definition at line 93 of file AXP202Adc.cpp.

References axp202_regs::factory::FACTORY_TS_VOLTAGE, axp202_regs::adc::TS_IN_H, and axp202_regs::adc::TS_IN_L.

◆ setADCInputRange()

bool AXP202Adc::setADCInputRange ( uint8_t  val)

Set ADC input range (REG 85H)

Parameters
valRaw register value
Returns
true on success

Definition at line 59 of file AXP202Adc.cpp.

References axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >::_core, axp202_regs::adc::ADC_INPUTRANGE, and SensorCommWrapper::writeReg().

◆ setADCIrqFallingThreshold()

bool AXP202Adc::setADCIrqFallingThreshold ( uint8_t  val)

Set ADC IRQ falling-edge threshold (REG 87H)

Parameters
valRaw register value
Returns
true on success

Definition at line 81 of file AXP202Adc.cpp.

References axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >::_core, axp202_regs::adc::ADC_IRQ_FETFSET, and SensorCommWrapper::writeReg().

◆ setADCIrqRisingThreshold()

bool AXP202Adc::setADCIrqRisingThreshold ( uint8_t  val)

Set ADC IRQ rising-edge threshold (REG 86H)

Parameters
valRaw register value
Returns
true on success

Definition at line 70 of file AXP202Adc.cpp.

References axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >::_core, axp202_regs::adc::ADC_IRQ_RETFSET, and SensorCommWrapper::writeReg().

◆ setADCSampleRate()

bool AXP202Adc::setADCSampleRate ( uint8_t  rate)

Set ADC sample rate (REG 84H bits 7:6)

Parameters
rate0=25Hz, 1=50Hz, 2=100Hz, 3=200Hz
Returns
true on success

Definition at line 45 of file AXP202Adc.cpp.

References axp1xx::AXP1xxAdc< AXP202Core, axp1xx::AdcTraitsBase< AXP202Core > >::_core, axp202_regs::adc::ADC_SPEED, and SensorCommWrapper::updateBits().

Member Data Documentation

◆ ADC_ACIN_CURRENT_HW

constexpr uint32_t AXP202Adc::ADC_ACIN_CURRENT_HW = 0x10
staticconstexpr

Definition at line 59 of file AXP202Adc.hpp.

◆ ADC_ACIN_VOLTAGE_HW

constexpr uint32_t AXP202Adc::ADC_ACIN_VOLTAGE_HW = 0x20
staticconstexpr

Definition at line 58 of file AXP202Adc.hpp.

◆ ADC_APS_VOLTAGE_HW

constexpr uint32_t AXP202Adc::ADC_APS_VOLTAGE_HW = 0x02
staticconstexpr

Definition at line 62 of file AXP202Adc.hpp.

◆ ADC_BAT_CURRENT_HW

constexpr uint32_t AXP202Adc::ADC_BAT_CURRENT_HW = 0x40
staticconstexpr

Definition at line 57 of file AXP202Adc.hpp.

◆ ADC_BAT_VOLTAGE_HW

constexpr uint32_t AXP202Adc::ADC_BAT_VOLTAGE_HW = 0x80
staticconstexpr

Definition at line 56 of file AXP202Adc.hpp.

◆ ADC_GPIO0_HW

constexpr uint32_t AXP202Adc::ADC_GPIO0_HW = 0x0800
staticconstexpr

Definition at line 65 of file AXP202Adc.hpp.

◆ ADC_GPIO1_HW

constexpr uint32_t AXP202Adc::ADC_GPIO1_HW = 0x0400
staticconstexpr

Definition at line 66 of file AXP202Adc.hpp.

◆ ADC_TEMPERATURE_HW

constexpr uint32_t AXP202Adc::ADC_TEMPERATURE_HW = 0x8000
staticconstexpr

Definition at line 64 of file AXP202Adc.hpp.

◆ ADC_TS_PIN_HW

constexpr uint32_t AXP202Adc::ADC_TS_PIN_HW = 0x01
staticconstexpr

Definition at line 63 of file AXP202Adc.hpp.

◆ ADC_VBUS_CURRENT_HW

constexpr uint32_t AXP202Adc::ADC_VBUS_CURRENT_HW = 0x04
staticconstexpr

Definition at line 61 of file AXP202Adc.hpp.

◆ ADC_VBUS_VOLTAGE_HW

constexpr uint32_t AXP202Adc::ADC_VBUS_VOLTAGE_HW = 0x08
staticconstexpr

Definition at line 60 of file AXP202Adc.hpp.


The documentation for this class was generated from the following files: