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

#include <SY6970Core.hpp>

Inheritance diagram for SY6970Core:
[legend]

Public Member Functions

 SY6970Core ()=default
 
 ~SY6970Core ()=default
 
void end ()
 Deinitialize and release resources.
 
bool isValid () const
 Check if device is valid/present.
 
uint8_t getDeviceRevision () const
 Get device revision.
 
void reset ()
 Reset device to default state.
 
bool isVbusPresent ()
 Check if VBUS (USB power) is present.
 
uint8_t getBusStatus ()
 Get USB port type status.
 
uint8_t getChargeStatus ()
 Get charging status.
 
bool isPowerGood ()
 Check if power is good.
 
bool isCharging ()
 Check if actively charging.
 
bool isChargeDone ()
 Check if charging is complete.
 
bool isOtg ()
 Check if in OTG (boost) mode.
 
bool getFaultStatus (uint8_t &fault)
 Get fault status.
 
- Public Member Functions inherited from I2CDeviceWithHal
bool begin (SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
 Initialize the sensor using custom callback interface.
 
- Public Member Functions inherited from DeviceBeginCommon
virtual ~DeviceBeginCommon ()
 
uint8_t getAddress () const
 
uint8_t getInterface () const
 
- Public Member Functions inherited from SensorCommWrapper
 SensorCommWrapper ()=default
 
int readReg (uint8_t reg) const
 
int readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const
 
int readBuff (uint8_t *buf, size_t len) const
 
int writeReg (uint8_t reg, uint8_t val)
 
int writeRegBuff (uint8_t reg, uint8_t *buf, size_t len)
 
int writeBuff (uint8_t *buf, size_t len)
 
int writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)
 
bool setRegBit (uint8_t reg, uint8_t bit)
 
bool clrRegBit (uint8_t reg, uint8_t bit)
 
bool getRegBit (uint8_t reg, uint8_t bit)
 
int updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted)
 
void setAddress (uint8_t address)
 
void setAck (bool enable)
 
- Public Member Functions inherited from SensorCommInterface
virtual ~SensorCommInterface ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from I2CDeviceWithHal
bool ensureValid () const override
 Ensure the communication interface is valid.
 
- Protected Member Functions inherited from DeviceBeginCommon
 DeviceBeginCommon ()=default
 
virtual SensorCommBasegetComm () const override
 
virtual void beforeBegin ()
 
virtual void afterCommReady ()
 
virtual void afterInitSuccess (uint8_t param)
 
virtual void onBeginFail ()
 
bool fail ()
 
void clearCommState ()
 
template<typename CreateComm >
bool beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm)
 
- Protected Attributes inherited from DeviceBeginCommon
std::unique_ptr< SensorCommBasecomm
 
std::unique_ptr< SensorHalhal
 
std::unique_ptr< SensorCommStaticstaticComm
 
uint8_t _addr = 0
 
uint8_t _iface = COMM_CUSTOM
 

Detailed Description

Definition at line 95 of file SY6970Core.hpp.

Constructor & Destructor Documentation

◆ SY6970Core()

SY6970Core::SY6970Core ( )
default

◆ ~SY6970Core()

SY6970Core::~SY6970Core ( )
default

Member Function Documentation

◆ end()

void SY6970Core::end ( )

Deinitialize and release resources.

Called when shutting down the device. Currently a no-op but may be used for cleanup in derived implementations.

Definition at line 38 of file SY6970Core.cpp.

Referenced by PmicSY6970::end().

◆ getBusStatus()

uint8_t SY6970Core::getBusStatus ( )

Get USB port type status.

Returns the detected USB port type from REG_STATUS (0x0B). This is updated after BC1.2/HVDCP detection.

Returns
Bus state:
  • 0: No input
  • 1: USB SDP (Standard Downstream Port)
  • 2: USB CDP (Charging Downstream Port)
  • 3: USB DCP (Dedicated Charging Port)
  • 4: HVDCP (High Voltage DCP)
  • 5: Adapter
  • 6: Non-standard adapter
  • 7: OTG mode

Definition at line 63 of file SY6970Core.cpp.

References SensorCommWrapper::readReg().

Referenced by isOtg().

◆ getChargeStatus()

uint8_t SY6970Core::getChargeStatus ( )

Get charging status.

Returns the current charging state from REG_STATUS (0x0B).

Returns
Charge state:
  • 0: No charge
  • 1: Pre-charge (weak battery)
  • 2: Fast charge (CC/CV)
  • 3: Charge done

Definition at line 69 of file SY6970Core.cpp.

References SensorCommWrapper::readReg().

Referenced by SY6970Charger::getStatus(), isChargeDone(), and isCharging().

◆ getDeviceRevision()

uint8_t SY6970Core::getDeviceRevision ( ) const

Get device revision.

Reads the device revision from REG_DEVICE_REV (0x14). The SY6970 returns 0x00 for the base revision.

Returns
Device revision byte (0x00 for SY6970)

Definition at line 46 of file SY6970Core.cpp.

References SensorCommWrapper::readReg().

Referenced by isValid().

◆ getFaultStatus()

bool SY6970Core::getFaultStatus ( uint8_t &  fault)

Get fault status.

Reads the fault register REG_FAULT (0x0C) and returns the raw fault byte for detailed fault analysis.

Parameters
faultReference to store fault byte
Returns
true on success, false on I2C error

Bits

  • Bit 7: Watchdog timeout fault
  • Bit 6: Boost fault
  • Bits 5-4: Charge fault (00: normal, 01: input fault, 10: thermal, 11: timer fault)
  • Bit 3: Battery fault
  • Bits 2-0: NTC fault

Definition at line 96 of file SY6970Core.cpp.

References SensorCommWrapper::readReg().

Referenced by SY6970Charger::getStatus().

◆ isChargeDone()

bool SY6970Core::isChargeDone ( )

Check if charging is complete.

Returns true when charge status is DONE (3). Indicates the battery has reached full charge.

Returns
true if charge cycle complete

Definition at line 86 of file SY6970Core.cpp.

References getChargeStatus().

Referenced by SY6970Charger::getStatus().

◆ isCharging()

bool SY6970Core::isCharging ( )

Check if actively charging.

Returns true when charge status is not NO_CHARGE. This includes both pre-charge and fast-charge phases.

Returns
true if charging is in progress
Note
Use isChargeDone() to check for charge complete.

Definition at line 81 of file SY6970Core.cpp.

References getChargeStatus().

Referenced by SY6970Charger::getStatus(), SY6970Charger::isCharging(), and SY6970Adc::read().

◆ isOtg()

bool SY6970Core::isOtg ( )

Check if in OTG (boost) mode.

Returns true when bus status is OTG (7). Indicates the SY6970 is supplying power to VBUS.

Returns
true if OTG mode active

Definition at line 91 of file SY6970Core.cpp.

References getBusStatus().

◆ isPowerGood()

bool SY6970Core::isPowerGood ( )

Check if power is good.

Reads the PG_STAT bit from REG_STATUS (0x0B). Indicates valid input power (VBUS > VBUS_VALID).

Returns
true if power good

Definition at line 75 of file SY6970Core.cpp.

References SensorCommWrapper::readReg().

◆ isValid()

bool SY6970Core::isValid ( ) const

Check if device is valid/present.

Verifies communication by reading the device revision register and comparing against expected value (0x00).

Returns
true if device responds correctly
Note
This should be called after begin() to verify the SY6970 is properly connected.

Definition at line 40 of file SY6970Core.cpp.

References getDeviceRevision().

Referenced by SY6970Charger::getStatus().

◆ isVbusPresent()

bool SY6970Core::isVbusPresent ( )

Check if VBUS (USB power) is present.

Reads the BUS_GD bit from the VBUS ADC register. Returns true when VBUS voltage is above the valid threshold.

Returns
true if VBUS is present and valid
See also
getVbusVoltage() for actual voltage reading

Definition at line 57 of file SY6970Core.cpp.

References SensorCommWrapper::readReg().

Referenced by SY6970Power::enableBoost(), SY6970Charger::getStatus(), and SY6970Adc::read().

◆ reset()

void SY6970Core::reset ( )

Reset device to default state.

Performs a register reset by setting the REG_RST bit in REG_DEVICE_REV (0x14). This resets all registers to their default values.

Definition at line 52 of file SY6970Core.cpp.

References SensorCommWrapper::setRegBit().


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