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

#include <PmicGpioBase.hpp>

Inheritance diagram for PmicGpioBase:
[legend]

Public Types

enum class  Direction : uint8_t { Input = 0 , Output = 1 }
 GPIO pin direction. More...
 
enum class  DriveType : uint8_t { PushPull = 0 , OpenDrain = 1 , Keep = 0xFF }
 GPIO drive type. More...
 
enum class  Level : uint8_t { Low = 0 , HiZ = 1 , High = 2 }
 Output level control. More...
 
enum class  Pull : uint8_t { None = 0 , Down = 1 , Up = 2 , Keep = 0xFF }
 Internal pull resistor configuration. More...
 
enum class  Status : uint8_t { Ok = 0 , InvalidPin = 1 , Failed = 2 }
 GPIO operation status code. More...
 

Public Member Functions

virtual ~PmicGpioBase ()=default
 Virtual destructor.
 
Status pinMode (uint8_t pin, Direction dir, DriveType drive=DriveType::Keep, Pull pull=Pull::Keep, uint8_t func=0xFF)
 Configure a pin with a single high-level call.
 
virtual uint8_t getPinCount () const =0
 Get number of GPIO pins supported by this PMIC.
 
virtual Status setDirection (uint8_t pin, Direction dir)=0
 Set GPIO pin direction.
 
virtual Direction getDirection (uint8_t pin)=0
 Get current GPIO pin direction.
 
virtual Status setDrive (uint8_t pin, DriveType drive)=0
 Set GPIO drive type.
 
virtual DriveType getDrive (uint8_t pin)=0
 Get current GPIO drive type.
 
virtual Status read (uint8_t pin, bool &high)=0
 Read input level.
 
virtual Status write (uint8_t pin, Level level)=0
 Set output level.
 
virtual Status setFunction (uint8_t pin, uint8_t func)
 Set GPIO pin function mode (chip-specific multiplexing)
 
virtual uint8_t getFunction (uint8_t pin)
 Get current GPIO pin function mode.
 
virtual Status setPull (uint8_t pin, Pull pull)
 Set internal pull resistor.
 
virtual Pull getPull (uint8_t pin)
 Get current internal pull resistor setting.
 

Static Public Member Functions

static constexpr bool isOk (Status s)
 

Detailed Description

Definition at line 34 of file PmicGpioBase.hpp.

Member Enumeration Documentation

◆ Direction

enum class PmicGpioBase::Direction : uint8_t
strong

GPIO pin direction.

Enumerator
Input 

Configure pin as input (read external signals)

Output 

Configure pin as output (drive external circuits)

Definition at line 45 of file PmicGpioBase.hpp.

◆ DriveType

enum class PmicGpioBase::DriveType : uint8_t
strong

GPIO drive type.

Enumerator
PushPull 

Push-pull output: actively drives high or low.

OpenDrain 

Open-drain output: only pulls low, high-impedance for high.

Keep 

Keep current drive type (do not change)

Definition at line 53 of file PmicGpioBase.hpp.

◆ Level

enum class PmicGpioBase::Level : uint8_t
strong

Output level control.

Some PMICs support Hi-Z/Low/High; others only Low/Hi-Z for open-drain.

Enumerator
Low 

Logic low (active drive low or open-drain pulled low)

HiZ 

High-impedance (input mode or open-drain not pulling low)

High 

Logic high (active drive high)

Definition at line 64 of file PmicGpioBase.hpp.

◆ Pull

enum class PmicGpioBase::Pull : uint8_t
strong

Internal pull resistor configuration.

Enumerator
None 

No pull resistor.

Down 

Pull-down enabled.

Up 

Pull-up enabled.

Keep 

Keep current pull setting (do not change)

Definition at line 73 of file PmicGpioBase.hpp.

◆ Status

enum class PmicGpioBase::Status : uint8_t
strong

GPIO operation status code.

Enumerator
Ok 
InvalidPin 
Failed 

Definition at line 83 of file PmicGpioBase.hpp.

Constructor & Destructor Documentation

◆ ~PmicGpioBase()

virtual PmicGpioBase::~PmicGpioBase ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ getDirection()

virtual Direction PmicGpioBase::getDirection ( uint8_t  pin)
pure virtual

Get current GPIO pin direction.

Parameters
pinGPIO pin number
Returns
Current direction setting
Note
On I2C error, returns Direction::Input as a safe default. Callers cannot distinguish this from a genuine Input setting.
See also
setDirection()

Implemented in AXP192Gpio, AXP202Gpio, and AXP517Gpio.

◆ getDrive()

virtual DriveType PmicGpioBase::getDrive ( uint8_t  pin)
pure virtual

Get current GPIO drive type.

Parameters
pinGPIO pin number
Returns
Current drive type setting
See also
setDrive()

Implemented in AXP192Gpio, AXP202Gpio, and AXP517Gpio.

Referenced by pinMode().

◆ getFunction()

virtual uint8_t PmicGpioBase::getFunction ( uint8_t  pin)
inlinevirtual

Get current GPIO pin function mode.

Parameters
pinGPIO pin number
Returns
Function mode value, or 0xFF if not supported

Reimplemented in AXP192Gpio, and AXP202Gpio.

Definition at line 211 of file PmicGpioBase.hpp.

◆ getPinCount()

virtual uint8_t PmicGpioBase::getPinCount ( ) const
pure virtual

Get number of GPIO pins supported by this PMIC.

Returns
Number of GPIO pins

Implemented in AXP192Gpio, AXP202Gpio, and AXP517Gpio.

◆ getPull()

virtual Pull PmicGpioBase::getPull ( uint8_t  pin)
inlinevirtual

Get current internal pull resistor setting.

Parameters
pinGPIO pin number
Returns
Current pull configuration

Reimplemented in AXP192Gpio.

Definition at line 239 of file PmicGpioBase.hpp.

References None.

Referenced by pinMode().

◆ isOk()

static constexpr bool PmicGpioBase::isOk ( Status  s)
inlinestaticconstexpr

Definition at line 89 of file PmicGpioBase.hpp.

References Ok.

Referenced by configurePdIrqOutput(), pinMode(), and AXP192Gpio::setPwm().

◆ pinMode()

Status PmicGpioBase::pinMode ( uint8_t  pin,
Direction  dir,
DriveType  drive = DriveType::Keep,
Pull  pull = Pull::Keep,
uint8_t  func = 0xFF 
)
inline

Configure a pin with a single high-level call.

Parameters
pinGPIO pin number
dirDirection
driveDrive type. Use DriveType::Keep to skip drive configuration.

Definition at line 100 of file PmicGpioBase.hpp.

References getDrive(), getPull(), isOk(), Keep, Ok, setDrive(), and setPull().

◆ read()

virtual Status PmicGpioBase::read ( uint8_t  pin,
bool &  high 
)
pure virtual

Read input level.

Parameters
pinGPIO pin number
highReference to store the read level (true = high, false = low)
Returns
Operation status
Note
Pin must be configured as Input direction first

Implemented in AXP192Gpio, AXP202Gpio, and AXP517Gpio.

◆ setDirection()

virtual Status PmicGpioBase::setDirection ( uint8_t  pin,
Direction  dir 
)
pure virtual

Set GPIO pin direction.

Parameters
pinGPIO pin number (if multiple pins are supported by the PMIC)
dirDirection to set (Input or Output)
Returns
Operation status
Note
Must be called before reading or writing the pin
See also
getDirection()

Implemented in AXP192Gpio, AXP202Gpio, and AXP517Gpio.

◆ setDrive()

virtual Status PmicGpioBase::setDrive ( uint8_t  pin,
DriveType  drive 
)
pure virtual

Set GPIO drive type.

Parameters
pinGPIO pin number
driveDrive type (PushPull or OpenDrain)
Returns
Operation status
Note
Some PMICs have fixed drive type (e.g. AXP192 is always open-drain, AXP202 is always push-pull). In such cases, unsupported drive types return Status::Failed.
See also
getDrive()

Implemented in AXP192Gpio, AXP202Gpio, and AXP517Gpio.

Referenced by pinMode().

◆ setFunction()

virtual Status PmicGpioBase::setFunction ( uint8_t  pin,
uint8_t  func 
)
inlinevirtual

Set GPIO pin function mode (chip-specific multiplexing)

Parameters
pinGPIO pin number
funcFunction mode value (chip-specific, see chip header for valid values)
Returns
Operation status
Note
Default implementation returns Status::Failed (no function select support). Chip-specific subclasses define valid function values. For AXP192 GPIO0-2: 0=NMOS open-drain, 1=input, 2=LDO/PWM, 4=ADC, 5=output low, 7=floating For AXP202 GPIO0-2: 0=output low, 1=output high, 2=input, 3=LDO, 4=ADC, 7=floating

Reimplemented in AXP192Gpio, and AXP202Gpio.

Definition at line 199 of file PmicGpioBase.hpp.

References Failed.

◆ setPull()

virtual Status PmicGpioBase::setPull ( uint8_t  pin,
Pull  pull 
)
inlinevirtual

Set internal pull resistor.

Parameters
pinGPIO pin number
pullPull configuration (None, Down, or Up)
Returns
Operation status
Note
Default implementation returns Status::Failed (no pull resistor support). Currently only AXP192 supports pull-down on GPIO0-2.

Reimplemented in AXP192Gpio.

Definition at line 227 of file PmicGpioBase.hpp.

References Failed.

Referenced by pinMode().

◆ write()

virtual Status PmicGpioBase::write ( uint8_t  pin,
Level  level 
)
pure virtual

Set output level.

Parameters
pinGPIO pin number
levelLevel to set (HiZ, Low, or High)
Returns
Operation status
Note
Only meaningful if pin is configured as Output direction
See also
setDirection()

Implemented in AXP192Gpio, AXP202Gpio, and AXP517Gpio.


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