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

#include <SY6970Adc.hpp>

Inheritance diagram for SY6970Adc:
[legend]

Public Member Functions

 SY6970Adc (SY6970Core &core)
 Construct ADC interface.
 
 ~SY6970Adc ()=default
 
bool enableChannels (uint32_t mask) override
 Enable one or more ADC channels.
 
bool disableChannels (uint32_t mask) override
 Disable ADC channels (no-op for SY6970)
 
bool read (Channel ch, float &out) override
 Read ADC value for specified channel.
 
bool startConversion ()
 Start a single ADC conversion.
 
bool setContinuousMode (bool enable)
 Enable or disable continuous ADC mode.
 
bool enableChannels (Channel mask)
 Enable ADC channels (no-op for SY6970)
 
virtual bool enableChannels (uint32_t mask)=0
 Enable ADC channels (no-op for SY6970)
 
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_CONV_START = 0x80
 ADC control flags.
 
static constexpr uint8_t ADC_CONV_RATE = 0x40
 Enable continuous conversion mode.
 

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.
 

Detailed Description

Definition at line 71 of file SY6970Adc.hpp.

Constructor & Destructor Documentation

◆ SY6970Adc()

SY6970Adc::SY6970Adc ( SY6970Core core)
explicit

Construct ADC interface.

Parameters
coreReference to SY6970 core communication

Definition at line 38 of file SY6970Adc.cpp.

◆ ~SY6970Adc()

SY6970Adc::~SY6970Adc ( )
default

Member Function Documentation

◆ disableChannels() [1/3]

bool PmicAdcBase::disableChannels ( Channel  mask)
inline

Disable one or more ADC channels by Channel enum.

Parameters
maskBitwise OR of Channel values to disable.
Returns
True on success, false on failure.

Definition at line 94 of file PmicAdcBase.hpp.

◆ disableChannels() [2/3]

bool SY6970Adc::disableChannels ( uint32_t  mask)
overridevirtual

Disable ADC channels (no-op for SY6970)

Parameters
maskChannel mask (ignored)
Returns
true always

Implements PmicAdcBase.

Definition at line 46 of file SY6970Adc.cpp.

◆ disableChannels() [3/3]

virtual bool PmicAdcBase::disableChannels ( uint32_t  mask)
virtual

Disable one or more ADC channels.

Parameters
maskBitmask of channels to disable.
Returns
True on success, false on failure.

Implements PmicAdcBase.

◆ enableChannels() [1/3]

bool PmicAdcBase::enableChannels ( Channel  mask)
inline

Enable ADC channels (no-op for SY6970)

The SY6970 has no per-channel enable control. All ADC channels are always available. Use startConversion() or setContinuousMode() to control ADC operation.

Parameters
maskChannel mask (ignored)
Returns
true always

Definition at line 84 of file PmicAdcBase.hpp.

◆ enableChannels() [2/3]

bool SY6970Adc::enableChannels ( uint32_t  mask)
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.

Parameters
maskBitmask of channels to enable.
Returns
True on success, false on failure.

Implements PmicAdcBase.

Definition at line 40 of file SY6970Adc.cpp.

Referenced by setup().

◆ enableChannels() [3/3]

virtual bool PmicAdcBase::enableChannels ( uint32_t  mask)
virtual

Enable ADC channels (no-op for SY6970)

The SY6970 has no per-channel enable control. All ADC channels are always available. Use startConversion() or setContinuousMode() to control ADC operation.

Parameters
maskChannel mask (ignored)
Returns
true always

Implements PmicAdcBase.

◆ read()

bool SY6970Adc::read ( Channel  ch,
float &  out 
)
overridevirtual

Read ADC value for specified channel.

Reads the raw ADC value from the appropriate register and converts it to the physical value using the step values defined in SY6970Regs.hpp.

Parameters
chADC channel to read
outReference to store the converted value
  • Voltage channels: millivolts (mV)
  • Current channels: milliamps (mA)
  • Temperature: percentage (0-100%) or flag
Returns
true on success, false on I2C error or unsupported channel

Details

  • VBUS_VOLTAGE: Returns 0 if VBUS not present
  • BAT_VOLTAGE: Returns 0 if battery not connected (ADC value = 0)
  • BAT_CURRENT: Returns 0 if not charging
  • BAT_TEMPERATURE: NTC percentage (21-100%)
  • DIE_TEMPERATURE: 1.0 if thermal warning, 0.0 otherwise

Implements PmicAdcBase.

Definition at line 52 of file SY6970Adc.cpp.

References PmicAdcBase::BAT_CURRENT, PmicAdcBase::BAT_PERCENTAGE, PmicAdcBase::BAT_TEMPERATURE, PmicAdcBase::BAT_VOLTAGE, PmicAdcBase::DIE_TEMPERATURE, SY6970Core::isCharging(), SY6970Core::isVbusPresent(), SensorCommWrapper::readReg(), startConversion(), PmicAdcBase::VBUS_CURRENT, PmicAdcBase::VBUS_VOLTAGE, and PmicAdcBase::VSYS_VOLTAGE.

Referenced by loop().

◆ setContinuousMode()

bool SY6970Adc::setContinuousMode ( bool  enable)

Enable or disable continuous ADC mode.

In continuous mode, the ADC performs conversions automatically at 1Hz. This is useful for real-time monitoring applications.

Parameters
enabletrue to enable continuous mode, false for one-shot mode
Returns
true on success, false on I2C error
Note
Continuous mode consumes more power - disable when not needed.

Definition at line 130 of file SY6970Adc.cpp.

References SensorCommWrapper::updateBits().

◆ startConversion()

bool SY6970Adc::startConversion ( )

Start a single ADC conversion.

Sets the CONV_START bit to trigger a one-shot ADC conversion. This is automatically called by read() if needed.

Returns
true on success, false on I2C error
Note
For continuous readings, use setContinuousMode(true) instead.

Definition at line 125 of file SY6970Adc.cpp.

References SensorCommWrapper::updateBits().

Referenced by read().

Member Data Documentation

◆ ADC_CONV_RATE

constexpr uint8_t SY6970Adc::ADC_CONV_RATE = 0x40
staticconstexpr

Enable continuous conversion mode.

Definition at line 79 of file SY6970Adc.hpp.

◆ ADC_CONV_START

constexpr uint8_t SY6970Adc::ADC_CONV_START = 0x80
staticconstexpr

ADC control flags.

Start ADC conversion

Definition at line 78 of file SY6970Adc.hpp.

Referenced by setup().


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