axp192

Circuitpython driver for AXP192 power management IC

  • Author(s): Dario Cammi

Implementation Notes

Software and Dependencies:

class axp192.AXP192(i2c: I2C, device_address: int = 0x34)

Circuitpython driver for AXP192 power management IC

This driver class is designed not to be directly instanciated but to be extended. The subclass should not directly expose DCDCs, LDOs and GPIOs but specific properties and methos to interact with connected hardware. For example on M5Stack Core2 the DCDC3 output power the LCD backlight. The subclass instead of expose the DCDC3 voltage control should expose a property to control the DCDC3 brightness

Parameters:
  • i2c (I2C) – The I2C bus AXP192 is connected to

  • device_address (int) – The I2C bus addres. Default to 0x34

Quickstart: Importing and using the device

Here is an example of using the AXP192 class. First you will need to import the libraries to use the sensor

import board
from axp192 import AXP192

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
pmic = AXP192(i2c)

Now you can get the AXP192 battery status

is_battery_connected = pmic.is_battery_connected
battery_voltage = pmic.battery_voltage
property _backup_battery_charging_enable: bool

Enable/disable the LDO1 backup battery charging output

_clear_bit_in_register(register: int, bitmask: int) None

Clear a single or multiple bits in a 8 bit register

Parameters:
  • register (int) – Register number. Allowed range: 0-255

  • bitmask (int) – Bitmask 8 bit wide with the bits to clear

property _dcdc1_setpoint: int

DCDC1 output setpoint in V

DCDC1 can output voltages in range 0.7-3.5V in 25mV steps To disable the output set DCDC1 to 0V

property _dcdc2_setpoint: int

DCDC2 output setpoint in V

DCDC2 can output voltages in range 0.7-2.275V in 25mV steps To disable the output set DCDC2 to 0V

property _dcdc3_setpoint: int

DCDC3 output setpoint in V

DCDC3 can output voltages in range 0.7-3.5V in 25mV steps To disable the output set DCDC3 to 0V

property _exten: bool

Enable/disable EXTEN output (external power boost)

This output is meant to be connected to an external power boost

_get_gpio_ldo_voltage_out(gpio_num: int) float

Return the GPIO voltage setpoint the GPIO is set as an LDO voltage output If the GPIO is not in LDO voltage output mode returns 0

Parameters:

gpio_num (int) – Number of the GPIO to check. Allowed value: 0

Returns:

GPIO output voltage in V

_get_gpio_pwm_out(gpio_num: int) int

Get the GPIO PWM output duty cycle

Parameters:

gpio_num (int) – Number of the GPIO to check. Allowed values: 1, 2

Returns:

PWM duty_cyle in range 0-255. Returns 0 if the GPIO isn’t in PWM output mode

_is_gpio_floating(gpio_num: int) bool

Return True if the GPIO is in floating pin mode

Parameters:

gpio_num (int) – Number of the GPIO to check. Allowed values: 0, 1 or 2

Returns:

True is the GPIO is in floating pin mode

_is_gpio_ldo_voltage_out(gpio_num: int) bool

Returns if the GPIO is in LDO voltage output mode

Parameters:

gpio_num (int) – Number of the GPIO to check. Allowed value: 0

Returns:

True when GPIO is in LDO voltage output mode

_is_gpio_output_low(gpio_num: int) bool

Return True if the GPIO is in low output mode

Parameters:

gpio_num (int) – Number of the GPIO to check. Allowed values: 0, 1 or 2

Returns:

True is the GPIO is in low output mode

_is_gpio_pwm_out(gpio_num: int) bool

Returns if the the GPIO is in PWM output mode

Parameters:

gpio_num (int) – Number of the GPIO to check. Allowed values: 1, 2

Returns:

True when GPIO is in PWM output mode

property _ldo2_setpoint: float

LDO2 output setpoint in V

LDO2 can output voltages in range 1.8-3.3V in 100mV steps To disable the output set LDO2 to 0V

property _ldo3_setpoint: float

LDO3 output setpoint in V

LDO3 can output voltages in range 1.8-3.3V in 100mV steps To disable the output set LDO3 to 0V

_read_register12(register: int) int

Read an AXP192 12bit register

Parameters:

register (int) – Register number. Allowed range: 0-255

Returns:

The register value

_read_register24(register: int) int

Read an AXP192 24bit register

Parameters:

register (int) – Register number. Allowed range: 0-255

Returns:

The register value

_read_register8(register: int) int

Read an AXP192 8bit register

Parameters:

register (int) – Register number. Allowed range: 0-255

Returns:

The register value

_set_bit_in_register(register: int, bitmask: int) None

Set a single or multiple bits in a 8 bit register

Parameters:
  • register (int) – Register number. Allowed range: 0-255

  • bitmask (int) – Bitmask 8 bit wide with the bits to set

_set_gpio_floating(gpio_num: int) None

Set the GPIO as a floting pin

Parameters:

gpio_num (int) – Number of the GPIO to set as floating pin. Allowed values: 0, 1 or 2

_set_gpio_ldo_voltage_out(gpio_num: int, voltage: float) None

Set the GPIO as an LDO voltage output If the request voltage is 0V the GPIO is set to low output mode.

Parameters:
  • gpio_num (int) – Number of the GPIO to set as LDO voltage output. Allowed value: 0

  • voltage (float) – LDO output voltage in V. Output range: 1.8-3.3V in 0.1V steps

_set_gpio_output_low(gpio_num: int) None

Set the GPIO as a digital low value output When the GPIO is set as output low it always output 0V

Parameters:

gpio_num (int) – Number of the GPIO to set as output low. Allowed values: 0, 1 or 2

_set_gpio_pwm_out(gpio_num: int, duty_cycle: int) None

Set the GPIO as a PWM output PWM Output voltage is VINT (2.5V)

Parameters:
  • gpio_num (int) – Number of the GPIO to set as PWM output. Allowed values: 1 or 2

  • duty_cyle (int) – PWM duty cycle. Range 0-255

_write_register8(register: int, value: int) None

Write an AXP192 8bit register

Parameters:
  • register (int) – Register number. Allowed range: 0-255

  • value (int) – Value to write: Allowed range: 0x0 - 0xFF

property acin_current: float

ACIN input line actual current in mA

In order to be able to read this current ADCs must be enable via all_adc_enabled

property acin_voltage: float

ACIN line actual voltage in V

In order to be able to read this voltage ADCs must be enable via all_adc_enabled

property all_adc_enabled: bool

Enable/disable all AXP192 ADCs of register 0x82

Register 0x82 ADCs

AXP192 Property

Battery voltage ADC

battery_voltage

Battery current ADC

battery_charge_current

battery_discharge_current

ACIN voltage ADC

acin_voltage

ACIN Current ADC

acin_current

VBUS voltage ADC

vbus_voltage

VBUS Current ADC

vbus_current

APS Voltage ADC

aps_voltage

TS pin ADC function

property aps_voltage: float

APS (internal power supply) actual voltage in V

In order to be able to read this voltage ADCs must be enable via all_adc_enabled

property battery_charge_current: float

Battery charging current in mA

In order to be able to read this current ADCs must be enable via all_adc_enabled Return 0 if no battery is connected to AXP192

property battery_charge_target_voltage: float

Battery charging target voltage in V

Voltage threshold for status: battery fully charged. For LiPo battery is 4.2V

property battery_charging_enabled: bool

Enable/disable the battery charging

property battery_discharge_current: float

Battery discharging current in mA

In order to be able to read this current ADCs must be enable via all_adc_enabled Return 0 if no battery is connected to AXP192

property battery_level: float

Battery level in range 0-100%

In order to be able to read this power ADCs must be enable via all_adc_enabled Return 0 if no battery is connected to AXP192

property battery_ouput_power: float

Battery istantaneous ouput power in mW

In order to be able to read this power ADCs must be enable via all_adc_enabled Return 0 if no battery is connected to AXP192

property battery_switch_off_voltage: float

AXP192 power off voltage threshold when powered via batterty in V

property battery_voltage: float

Battery voltage in V

In order to be able to read this voltage ADCs must be enable via all_adc_enabled Return 0 if no battery is connected to AXP192

property internal_temperature: float

Internal AXP192 temperature in Celsius degrees

property is_acin_present: bool

True when voltage is present on the ACIN input line

property is_battery_charging: bool

True when the battery is connected to AXP192 and is charging

property is_battery_connected: bool

True when a battery is connected to AXP192

property is_vbus_present: bool

True when voltage is present on the VBUS power input line

property power_key_was_pressed: Tuple[bool, bool]

Power key pressed status

Returns:

Two booleans: Power key is short press and power key is long press

power_off() None

Switch off the AXP192 and the connected devices

property vbus_current: float

VBUS power input line actual current in mA

In order to be able to read this current ADCs must be enable via all_adc_enabled

property vbus_voltage: float

VBUS input line actual voltage in V

In order to be able to read this voltage ADCs must be enable via all_adc_enabled