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

AXP192 GPIO Interface. More...

#include <AXP192Gpio.hpp>

Inheritance diagram for AXP192Gpio:
[legend]

Public Member Functions

 AXP192Gpio (AXP192Core &core)
 Construct GPIO interface.
 
 ~AXP192Gpio ()=default
 
uint8_t getPinCount () const override
 Get number of GPIO pins (6: GPIO0-GPIO5)
 
Status setDirection (uint8_t pin, Direction dir) override
 Set GPIO pin direction.
 
Direction getDirection (uint8_t pin) override
 Get GPIO pin direction.
 
Status setDrive (uint8_t pin, DriveType drive) override
 Set GPIO pin drive type.
 
DriveType getDrive (uint8_t pin) override
 Get GPIO pin drive type.
 
Status read (uint8_t pin, bool &high) override
 Read digital level of a GPIO pin.
 
Status write (uint8_t pin, Level level) override
 Write digital level to a GPIO pin.
 
Status setFunction (uint8_t pin, uint8_t func) override
 Set GPIO pin function mode.
 
uint8_t getFunction (uint8_t pin) override
 Get current GPIO pin function mode.
 
Status setPull (uint8_t pin, Pull pull) override
 Set internal pull-down resistor.
 
Pull getPull (uint8_t pin) override
 Get current pull-down setting.
 
bool setPwmFrequency (uint8_t pin, uint8_t x)
 Set PWM output frequency for GPIO1 (PWM1) or GPIO2 (PWM2)
 
bool setPwmDutyCycle (uint8_t pin, uint8_t y1, uint8_t y2)
 Set PWM duty cycle for GPIO1 (PWM1) or GPIO2 (PWM2)
 
bool setPwm (uint8_t pin, uint8_t x, uint8_t y1, uint8_t y2)
 Configure PWM output parameters in one call.
 
- Public Member Functions inherited from PmicGpioBase
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.
 

Additional Inherited Members

- Public Types inherited from PmicGpioBase
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...
 
- Static Public Member Functions inherited from PmicGpioBase
static constexpr bool isOk (Status s)
 

Detailed Description

AXP192 GPIO Interface.

Provides pin-level control for AXP192 GPIO0 through GPIO5, including direction, drive strength, digital read/write, function multiplexing, and pull-down settings.

GPIO0-2 Function Select Values (REG 90H/92H/93H [2:0])

  • 0x00: NMOS open-drain output
  • 0x01: Input
  • 0x02: Low-noise LDO (GPIO0) / PWM1 output (GPIO1) / PWM2 output (GPIO2)
  • 0x04: ADC input
  • 0x05: Output low
  • 0x06/0x07: Floating (high-impedance)

GPIO3-4 Function Select (REG 95H)

  • bit7=1 enables GPIO mode
  • GPIO3 [1:0]: 00=ext charge, 01=NMOS out, 10=input, 11=ADC
  • GPIO4 [3:2]: 00=ext charge, 01=NMOS out, 10=input, 11=undefined

GPIO5 / N_RSTO (REG 9EH)

  • bit7: 0=N_RSTO/LDO1 monitor, 1=GPIO5 mode
  • bit6: 0=NMOS open-drain output, 1=input

Definition at line 70 of file AXP192Gpio.hpp.

Constructor & Destructor Documentation

◆ AXP192Gpio()

AXP192Gpio::AXP192Gpio ( AXP192Core core)
explicit

Construct GPIO interface.

Parameters
coreReference to AXP192 core communication object

Definition at line 8 of file AXP192Gpio.cpp.

◆ ~AXP192Gpio()

AXP192Gpio::~AXP192Gpio ( )
default

Member Function Documentation

◆ getDirection()

PmicGpioBase::Direction AXP192Gpio::getDirection ( uint8_t  pin)
overridevirtual

Get GPIO pin direction.

Parameters
pinGPIO pin number (0-5)
Returns
Current direction setting

Implements PmicGpioBase.

Definition at line 69 of file AXP192Gpio.cpp.

References axp192_regs::gpio::GPIO0_CTL, axp192_regs::gpio::GPIO1_CTL, axp192_regs::gpio::GPIO2_CTL, axp192_regs::gpio::GPIO34_CTL, axp192_regs::gpio::GPIO5_CTL, PmicGpioBase::Input, PmicGpioBase::Output, and SensorCommWrapper::readReg().

◆ getDrive()

PmicGpioBase::DriveType AXP192Gpio::getDrive ( uint8_t  pin)
overridevirtual

Get GPIO pin drive type.

Parameters
pinGPIO pin number (0-5)
Returns
DriveType::OpenDrain — AXP192 GPIOs are NMOS open-drain when in GPIO output mode

Implements PmicGpioBase.

Definition at line 111 of file AXP192Gpio.cpp.

References PmicGpioBase::OpenDrain.

◆ getFunction()

uint8_t AXP192Gpio::getFunction ( uint8_t  pin)
overridevirtual

Get current GPIO pin function mode.

Parameters
pinGPIO pin number (0-5)
Returns
Function mode value, or 0xFF on error

Reimplemented from PmicGpioBase.

Definition at line 206 of file AXP192Gpio.cpp.

References axp192_regs::gpio::GPIO0_CTL, axp192_regs::gpio::GPIO1_CTL, axp192_regs::gpio::GPIO2_CTL, axp192_regs::gpio::GPIO34_CTL, axp192_regs::gpio::GPIO5_CTL, and SensorCommWrapper::readReg().

◆ getPinCount()

uint8_t AXP192Gpio::getPinCount ( ) const
overridevirtual

Get number of GPIO pins (6: GPIO0-GPIO5)

Returns
6

Implements PmicGpioBase.

Definition at line 12 of file AXP192Gpio.cpp.

Referenced by setDrive(), and setPull().

◆ getPull()

PmicGpioBase::Pull AXP192Gpio::getPull ( uint8_t  pin)
overridevirtual

Get current pull-down setting.

Parameters
pinGPIO pin number (0-2)
Returns
Current pull configuration

Reimplemented from PmicGpioBase.

Definition at line 254 of file AXP192Gpio.cpp.

References PmicGpioBase::Down, SensorCommWrapper::getRegBit(), axp192_regs::gpio::GPIO012_PULLDOWN, and PmicGpioBase::None.

◆ read()

PmicGpioBase::Status AXP192Gpio::read ( uint8_t  pin,
bool &  high 
)
overridevirtual

Read digital level of a GPIO pin.

Parameters
pinGPIO pin number (0-5)
[out]hightrue if pin is high, false if low
Returns
Status::Ok on success, Status::InvalidPin for invalid pin, Status::Failed on I2C/register error

Implements PmicGpioBase.

Definition at line 118 of file AXP192Gpio.cpp.

References SensorCommWrapper::getRegBit(), axp192_regs::gpio::GPIO012_SIGNAL, axp192_regs::gpio::GPIO34_SIGNAL, axp192_regs::gpio::GPIO5_CTL, PmicGpioBase::InvalidPin, and PmicGpioBase::Ok.

◆ setDirection()

PmicGpioBase::Status AXP192Gpio::setDirection ( uint8_t  pin,
Direction  dir 
)
overridevirtual

◆ setDrive()

PmicGpioBase::Status AXP192Gpio::setDrive ( uint8_t  pin,
DriveType  drive 
)
overridevirtual

Set GPIO pin drive type.

Parameters
pinGPIO pin number (0-5)
driveDrive type
Returns
Status::Failed — AXP192 GPIO drive type is implicit in function select and cannot be independently configured

Implements PmicGpioBase.

Definition at line 102 of file AXP192Gpio.cpp.

References PmicGpioBase::Failed, getPinCount(), and PmicGpioBase::InvalidPin.

◆ setFunction()

PmicGpioBase::Status AXP192Gpio::setFunction ( uint8_t  pin,
uint8_t  func 
)
overridevirtual

Set GPIO pin function mode.

Parameters
pinGPIO pin number (0-5)
funcFunction mode value (see GPIO0-2 Function Select Values (REG 90H/92H/93H [2:0]) for valid values)
Returns
Status::Ok on success, Status::InvalidPin for invalid pin, Status::Failed on I2C/register error or unsupported function

Reimplemented from PmicGpioBase.

Definition at line 157 of file AXP192Gpio.cpp.

References PmicGpioBase::Failed, axp192_regs::gpio::GPIO0_CTL, axp192_regs::gpio::GPIO1_CTL, axp192_regs::gpio::GPIO2_CTL, axp192_regs::gpio::GPIO34_CTL, axp192_regs::gpio::GPIO5_CTL, PmicGpioBase::InvalidPin, PmicGpioBase::Ok, SensorCommWrapper::readReg(), SensorCommWrapper::updateBits(), and SensorCommWrapper::writeReg().

Referenced by setPwm().

◆ setPull()

PmicGpioBase::Status AXP192Gpio::setPull ( uint8_t  pin,
Pull  pull 
)
overridevirtual

Set internal pull-down resistor.

Parameters
pinGPIO pin number (0-2, only GPIO0-2 support pull-down)
pullPull::Down to enable, Pull::None to disable
Returns
Status::Ok on success, Status::InvalidPin for invalid pin, Status::Failed if pull unsupported or on I2C/register error

Reimplemented from PmicGpioBase.

Definition at line 239 of file AXP192Gpio.cpp.

References SensorCommWrapper::clrRegBit(), PmicGpioBase::Down, PmicGpioBase::Failed, getPinCount(), axp192_regs::gpio::GPIO012_PULLDOWN, PmicGpioBase::InvalidPin, PmicGpioBase::Ok, SensorCommWrapper::setRegBit(), and PmicGpioBase::Up.

◆ setPwm()

bool AXP192Gpio::setPwm ( uint8_t  pin,
uint8_t  x,
uint8_t  y1,
uint8_t  y2 
)

Configure PWM output parameters in one call.

Parameters
pinGPIO pin number (1 for PWM1, 2 for PWM2)
xFrequency divisor X (0-255)
y1Duty cycle period Y1 (1-255)
y2Duty cycle high-time Y2 (0-255, must be <= y1)
Returns
true on success
Note
Convenience wrapper. Also sets pin function to PWM mode (0x02). Frequency = 2.25MHz / (X+1) / Y1 Duty cycle = Y2 / Y1

Examples: setPwm(pin, 0, 100, 50) → 22.5kHz, 50% setPwm(pin, 0, 100, 10) → 22.5kHz, 10% setPwm(pin, 4, 100, 50) → 4.5kHz, 50%

Definition at line 294 of file AXP192Gpio.cpp.

References PmicGpioBase::isOk(), PmicGpioBase::Output, setDirection(), setFunction(), setPwmDutyCycle(), setPwmFrequency(), and x.

◆ setPwmDutyCycle()

bool AXP192Gpio::setPwmDutyCycle ( uint8_t  pin,
uint8_t  y1,
uint8_t  y2 
)

Set PWM duty cycle for GPIO1 (PWM1) or GPIO2 (PWM2)

Parameters
pinGPIO pin number (1 for PWM1, 2 for PWM2)
y1Duty cycle period Y1 (1-255, must be > y2)
y2Duty cycle high-time Y2 (0-255, must be <= y1)
Returns
true on success, false if pin is not 1 or 2, y2 > y1, or on I2C error
Note
Duty cycle = Y2 / Y1 REG 99H/9CH [7:0] = Y1 REG 9AH/9DH [7:6] = Y2 (only bits [7:6] are used in REG 9AH/9DH!)

Actually per datasheet: Y2 is in REG 9AH[7:6] (2 bits, not 8 bits). So Y2 range is 0-3 when using REG 9AH/9DH directly. For fine-grained duty cycle, use the full register layout.

Default: Y1=0x16(22), Y2=0x0B(11) → 50% duty

See also
setPwmFrequency()

Definition at line 273 of file AXP192Gpio.cpp.

References axp192_regs::gpio::PWM1_DUTY1, axp192_regs::gpio::PWM1_DUTY2, axp192_regs::gpio::PWM2_DUTY1, axp192_regs::gpio::PWM2_DUTY2, and SensorCommWrapper::writeReg().

Referenced by setPwm().

◆ setPwmFrequency()

bool AXP192Gpio::setPwmFrequency ( uint8_t  pin,
uint8_t  x 
)

Set PWM output frequency for GPIO1 (PWM1) or GPIO2 (PWM2)

Parameters
pinGPIO pin number (1 for PWM1, 2 for PWM2)
xFrequency divisor X (0-255)
Returns
true on success, false if pin is not 1 or 2, or on I2C error
Note
PWM frequency = 2.25MHz / (X + 1) / Y1 Default X=0 → X+1=1
See also
setPwmDutyCycle()

Definition at line 261 of file AXP192Gpio.cpp.

References axp192_regs::gpio::PWM1_FREQ, axp192_regs::gpio::PWM2_FREQ, SensorCommWrapper::writeReg(), and x.

Referenced by setPwm().

◆ write()

PmicGpioBase::Status AXP192Gpio::write ( uint8_t  pin,
Level  level 
)
overridevirtual

Write digital level to a GPIO pin.

Parameters
pinGPIO pin number (0-5)
levelLevel to set (High or Low)
Returns
Status::Ok on success, Status::InvalidPin for invalid pin, Status::Failed on I2C/register error

Implements PmicGpioBase.

Definition at line 135 of file AXP192Gpio.cpp.

References SensorCommWrapper::clrRegBit(), PmicGpioBase::Failed, axp192_regs::gpio::GPIO012_SIGNAL, axp192_regs::gpio::GPIO34_SIGNAL, axp192_regs::gpio::GPIO5_CTL, PmicGpioBase::High, PmicGpioBase::HiZ, PmicGpioBase::InvalidPin, level, PmicGpioBase::Ok, and SensorCommWrapper::setRegBit().


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