SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP202Adc.hpp
Go to the documentation of this file.
1
41#pragma once
42#include "AXP202Core.hpp"
43#include "../axp1xx/AXP1xxAdc.hpp"
44#include "AXP202AdcTraits.hpp"
45
52class AXP202Adc : public axp1xx::AXP1xxAdc<AXP202Core, axp1xx::AdcTraitsBase<AXP202Core>>
53{
54public:
55 // Hardware bitmask constants (for direct register control)
56 static constexpr uint32_t ADC_BAT_VOLTAGE_HW = 0x80; // REG82H bit 7
57 static constexpr uint32_t ADC_BAT_CURRENT_HW = 0x40; // REG82H bit 6
58 static constexpr uint32_t ADC_ACIN_VOLTAGE_HW = 0x20; // REG82H bit 5
59 static constexpr uint32_t ADC_ACIN_CURRENT_HW = 0x10; // REG82H bit 4
60 static constexpr uint32_t ADC_VBUS_VOLTAGE_HW = 0x08; // REG82H bit 3
61 static constexpr uint32_t ADC_VBUS_CURRENT_HW = 0x04; // REG82H bit 2
62 static constexpr uint32_t ADC_APS_VOLTAGE_HW = 0x02; // REG82H bit 1
63 static constexpr uint32_t ADC_TS_PIN_HW = 0x01; // REG82H bit 0
64 static constexpr uint32_t ADC_TEMPERATURE_HW = 0x8000; // REG83H bit 7
65 static constexpr uint32_t ADC_GPIO0_HW = 0x0800; // REG83H bit 3
66 static constexpr uint32_t ADC_GPIO1_HW = 0x0400; // REG83H bit 2
67
72 explicit AXP202Adc(AXP202Core &core)
73 : axp1xx::AXP1xxAdc<AXP202Core, axp1xx::AdcTraitsBase<AXP202Core>>(core) {}
74
75 ~AXP202Adc() = default;
76
77 // ---- ADC Configuration ----
83 bool setADCSampleRate(uint8_t rate);
84
89 uint16_t getADCSampleRate();
90
96 bool setADCInputRange(uint8_t val);
97 uint8_t getADCInputRange();
98
104 bool setADCIrqRisingThreshold(uint8_t val);
105 uint8_t getADCIrqRisingThreshold();
106
112 bool setADCIrqFallingThreshold(uint8_t val);
114
119 float getTsVoltage();
120
125 float getGpio0Voltage();
126
131 float getGpio1Voltage();
132
137 float getBatteryPower();
138
139private:
146 uint16_t readRegisterH8L4(uint8_t regH, uint8_t regL);
147};
@license MIT License
@license MIT License
AXP202 ADC channel control and data readout (template wrapper)
Definition AXP202Adc.hpp:53
static constexpr uint32_t ADC_TEMPERATURE_HW
Definition AXP202Adc.hpp:64
bool setADCInputRange(uint8_t val)
Set ADC input range (REG 85H)
Definition AXP202Adc.cpp:59
static constexpr uint32_t ADC_GPIO0_HW
Definition AXP202Adc.hpp:65
static constexpr uint32_t ADC_VBUS_VOLTAGE_HW
Definition AXP202Adc.hpp:60
bool setADCSampleRate(uint8_t rate)
Set ADC sample rate (REG 84H bits 7:6)
Definition AXP202Adc.cpp:45
float getBatteryPower()
Read battery instantaneous power (REG 70H-72H, 24-bit)
float getGpio0Voltage()
Read GPIO0 ADC voltage in mV (REG 64H/65H, 12-bit H8L4)
static constexpr uint32_t ADC_TS_PIN_HW
Definition AXP202Adc.hpp:63
uint8_t getADCIrqRisingThreshold()
Definition AXP202Adc.cpp:75
static constexpr uint32_t ADC_BAT_VOLTAGE_HW
Definition AXP202Adc.hpp:56
static constexpr uint32_t ADC_BAT_CURRENT_HW
Definition AXP202Adc.hpp:57
uint8_t getADCIrqFallingThreshold()
Definition AXP202Adc.cpp:86
static constexpr uint32_t ADC_ACIN_CURRENT_HW
Definition AXP202Adc.hpp:59
bool setADCIrqRisingThreshold(uint8_t val)
Set ADC IRQ rising-edge threshold (REG 86H)
Definition AXP202Adc.cpp:70
~AXP202Adc()=default
bool setADCIrqFallingThreshold(uint8_t val)
Set ADC IRQ falling-edge threshold (REG 87H)
Definition AXP202Adc.cpp:81
static constexpr uint32_t ADC_ACIN_VOLTAGE_HW
Definition AXP202Adc.hpp:58
uint16_t getADCSampleRate()
Get ADC sample rate in Hz.
Definition AXP202Adc.cpp:51
uint8_t getADCInputRange()
Definition AXP202Adc.cpp:64
static constexpr uint32_t ADC_GPIO1_HW
Definition AXP202Adc.hpp:66
static constexpr uint32_t ADC_APS_VOLTAGE_HW
Definition AXP202Adc.hpp:62
static constexpr uint32_t ADC_VBUS_CURRENT_HW
Definition AXP202Adc.hpp:61
AXP202Adc(AXP202Core &core)
Construct AXP202 ADC interface.
Definition AXP202Adc.hpp:72
float getTsVoltage()
Read TS pin voltage in mV (REG 62H/63H, 12-bit H8L4)
Definition AXP202Adc.cpp:93
float getGpio1Voltage()
Read GPIO1 ADC voltage in mV (REG 66H/67H, 12-bit H8L4)
Generic ADC implementation for AXP1xx-based PMICs.
Definition AXP1xxAdc.hpp:52