|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
AXP192 GPIO Interface. More...
#include <AXP192Gpio.hpp>
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) |
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.
Definition at line 70 of file AXP192Gpio.hpp.
|
explicit |
Construct GPIO interface.
| core | Reference to AXP192 core communication object |
Definition at line 8 of file AXP192Gpio.cpp.
|
default |
|
overridevirtual |
Get GPIO pin direction.
| pin | GPIO pin number (0-5) |
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().
|
overridevirtual |
Get GPIO pin drive type.
| pin | GPIO pin number (0-5) |
Implements PmicGpioBase.
Definition at line 111 of file AXP192Gpio.cpp.
References PmicGpioBase::OpenDrain.
|
overridevirtual |
Get current GPIO pin function mode.
| pin | GPIO pin number (0-5) |
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().
|
overridevirtual |
Get number of GPIO pins (6: GPIO0-GPIO5)
Implements PmicGpioBase.
Definition at line 12 of file AXP192Gpio.cpp.
Referenced by setDrive(), and setPull().
|
overridevirtual |
Get current pull-down setting.
| pin | GPIO pin number (0-2) |
Reimplemented from PmicGpioBase.
Definition at line 254 of file AXP192Gpio.cpp.
References PmicGpioBase::Down, SensorCommWrapper::getRegBit(), axp192_regs::gpio::GPIO012_PULLDOWN, and PmicGpioBase::None.
|
overridevirtual |
Read digital level of a GPIO pin.
| pin | GPIO pin number (0-5) | |
| [out] | high | true if pin is high, false if low |
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.
|
overridevirtual |
Set GPIO pin direction.
| pin | GPIO pin number (0-5) |
| dir | Direction (Input or Output) |
Implements PmicGpioBase.
Definition at line 17 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::Input, PmicGpioBase::InvalidPin, PmicGpioBase::Ok, SensorCommWrapper::readReg(), SensorCommWrapper::updateBits(), and SensorCommWrapper::writeReg().
Referenced by setPwm().
|
overridevirtual |
Set GPIO pin drive type.
| pin | GPIO pin number (0-5) |
| drive | Drive type |
Implements PmicGpioBase.
Definition at line 102 of file AXP192Gpio.cpp.
References PmicGpioBase::Failed, getPinCount(), and PmicGpioBase::InvalidPin.
|
overridevirtual |
Set GPIO pin function mode.
| pin | GPIO pin number (0-5) |
| func | Function mode value (see GPIO0-2 Function Select Values (REG 90H/92H/93H [2:0]) for valid values) |
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().
|
overridevirtual |
Set internal pull-down resistor.
| pin | GPIO pin number (0-2, only GPIO0-2 support pull-down) |
| pull | Pull::Down to enable, Pull::None to disable |
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.
| bool AXP192Gpio::setPwm | ( | uint8_t | pin, |
| uint8_t | x, | ||
| uint8_t | y1, | ||
| uint8_t | y2 | ||
| ) |
Configure PWM output parameters in one call.
| pin | GPIO pin number (1 for PWM1, 2 for PWM2) |
| x | Frequency divisor X (0-255) |
| y1 | Duty cycle period Y1 (1-255) |
| y2 | Duty cycle high-time Y2 (0-255, must be <= 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.
| bool AXP192Gpio::setPwmDutyCycle | ( | uint8_t | pin, |
| uint8_t | y1, | ||
| uint8_t | y2 | ||
| ) |
Set PWM duty cycle for GPIO1 (PWM1) or GPIO2 (PWM2)
| pin | GPIO pin number (1 for PWM1, 2 for PWM2) |
| y1 | Duty cycle period Y1 (1-255, must be > y2) |
| y2 | Duty cycle high-time Y2 (0-255, must be <= y1) |
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
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().
| bool AXP192Gpio::setPwmFrequency | ( | uint8_t | pin, |
| uint8_t | x | ||
| ) |
Set PWM output frequency for GPIO1 (PWM1) or GPIO2 (PWM2)
| pin | GPIO pin number (1 for PWM1, 2 for PWM2) |
| x | Frequency divisor X (0-255) |
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().
|
overridevirtual |
Write digital level to a GPIO pin.
| pin | GPIO pin number (0-5) |
| level | Level to set (High or Low) |
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().