Refactored AXP192 code and moved under ports/espressif
This commit is contained in:
parent
a9a58f29be
commit
ed86f710c2
|
@ -98,6 +98,9 @@ msgstr ""
|
|||
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
|
||||
#: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c
|
||||
#: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c
|
||||
#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c
|
||||
#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c
|
||||
#: shared-bindings/keypad/ShiftRegisterKeys.c
|
||||
msgid "%q"
|
||||
msgstr ""
|
||||
|
||||
|
@ -193,7 +196,7 @@ msgstr ""
|
|||
msgid "%q must be array of type 'H'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c
|
||||
#: shared-module/synthio/__init__.c
|
||||
msgid "%q must be array of type 'h'"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1117,10 +1120,6 @@ msgstr ""
|
|||
msgid "I2C peripheral in use"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/audiobusio/I2SOut.c
|
||||
msgid "I2SOut not available"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
|
||||
msgid "In-buffer elements must be <= 4 bytes long"
|
||||
msgstr ""
|
||||
|
@ -1708,10 +1707,6 @@ msgstr ""
|
|||
msgid "Oversample must be multiple of 8."
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/audiobusio/PDMIn.c
|
||||
msgid "PDMIn not available"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/pwmio/PWMOut.c
|
||||
msgid ""
|
||||
"PWM frequency not writable when variable_frequency is False on construction."
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "components/hal/include/hal/gpio_hal.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
#include "axp192.h"
|
||||
#include "../../pmic/axp192/axp192.h"
|
||||
|
||||
displayio_fourwire_obj_t board_display_obj;
|
||||
|
||||
|
@ -65,7 +65,7 @@ uint8_t display_init_sequence[] = {
|
|||
0x29,DELAY,0x78, // Display on then delay 0x78 (120ms)
|
||||
};
|
||||
|
||||
static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) {
|
||||
static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
@ -75,24 +75,24 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c)
|
|||
case PMIC_POWER_SOURCE_USB:
|
||||
// Set GPIO to 3.3V (when LDO OUTPUT mode is active)
|
||||
write_buf[0] = AXP192_GPIO0_LDO_VOLTAGE;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_LDO_VOLTAGE_MASK) | AXP192_GPIO0_LDO_VOLTAGE_3_3V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
// Set GPIO0 to LDO_OUTPUT to set N_VBUSEN high
|
||||
// When N_VBUSEN is high IPSOUT do not select VBUS as source (BUS_5V)
|
||||
write_buf[0] = AXP192_GPIO0_FUNCTION;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_LDO_OUTPUT;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -100,12 +100,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c)
|
|||
#if M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT
|
||||
// Set EXTENT output high to enable 5V power boost
|
||||
write_buf[0] = AXP192_EXTEN_DCDC2_CTRL;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = read_buf[0] | AXP192_EXTEN_DCDC2_CTRL_EXTEN;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -113,12 +113,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c)
|
|||
|
||||
// Enable VBUS-IPSOUT when N_VBUSEN is high
|
||||
write_buf[0] = AXP192_VBUS_IPSOUT;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = read_buf[0] & ~AXP192_VBUS_IPSOUT_IGNORE_VBUSEN;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -128,24 +128,24 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c)
|
|||
case PMIC_POWER_SOURCE_M_BUS:
|
||||
// Enable VBUS-IPSOUT regardless of f N_VBUSEN
|
||||
write_buf[0] = AXP192_VBUS_IPSOUT;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = read_buf[0] | AXP192_VBUS_IPSOUT_IGNORE_VBUSEN;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set EXTENT output low to disable 5V power boost
|
||||
write_buf[0] = AXP192_EXTEN_DCDC2_CTRL;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = read_buf[0] & ~AXP192_EXTEN_DCDC2_CTRL_EXTEN;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -153,12 +153,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c)
|
|||
// Set GPIO0 to float and the pull down resistor set N_VBUSEN low
|
||||
// When N_VBUSEN is low IPSOUT select VBUS as source (BUS_5V)
|
||||
write_buf[0] = AXP192_GPIO0_FUNCTION;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_FLOATING;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -170,148 +170,15 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c)
|
|||
}
|
||||
}
|
||||
|
||||
static bool pmic_disable_all_irq(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
// uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 40h
|
||||
// IRQ enable control register 1
|
||||
write_buf[0] = AXP192_IRQ_1_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 41h
|
||||
// IRQ enable control register 2
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 42h
|
||||
// IRQ enable control register 3
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_3_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 43h
|
||||
// IRQ enable control register 4
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_4_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 4Ah
|
||||
// IRQ enable control register 5
|
||||
write_buf[0] = AXP192_IRQ_5_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pmic_clear_all_irq(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
// uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 44h
|
||||
// IRQ enable control register 1
|
||||
write_buf[0] = AXP192_IRQ_1_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 45h
|
||||
// IRQ enable control register 2
|
||||
write_buf[0] = AXP192_IRQ_2_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 46h
|
||||
// IRQ enable control register 3
|
||||
write_buf[0] = AXP192_IRQ_3_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 47h
|
||||
// IRQ enable control register 4
|
||||
write_buf[0] = AXP192_IRQ_4_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 4Ah
|
||||
// IRQ enable control register 5
|
||||
write_buf[0] = AXP192_IRQ_5_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pmic_enable_default_irq(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
// uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 42h
|
||||
// IRQ enable control register 3
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS |
|
||||
AXP192_IRQ_3_PEK_LONG_PRESS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 43h
|
||||
// IRQ enable control register 4
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
||||
static bool pmic_init(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
||||
if (!pmic_common_init(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 30h
|
||||
// The VBUS-IPSOUT path can be selected to be opened regardless of the status of N_VBUSEN
|
||||
// VBUS VHOLD pressure limit control disabled
|
||||
|
@ -319,29 +186,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
write_buf[0] = AXP192_VBUS_IPSOUT;
|
||||
write_buf[1] = AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT |
|
||||
AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 31h
|
||||
// VOFF Shutdown voltage setting ( 3.0V )
|
||||
write_buf[0] = AXP192_POWER_OFF_VOLTAGE;
|
||||
write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 32h
|
||||
// Charge function enable control bit, including internal and external channels
|
||||
// Charging target voltage: 4.2V
|
||||
// Charging end current: End charging when charging current is less than 10% setting
|
||||
// Internal path charging current: 100mA
|
||||
write_buf[0] = AXP192_POWER_OFF_BATT_CHGLED_CTRL;
|
||||
write_buf[1] = AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON |
|
||||
AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -356,89 +201,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
AXP192_CHARGING_CTRL1_VOLTAGE_4_20V |
|
||||
AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC |
|
||||
AXP192_CHARGING_CTRL1_CURRENT_360mA;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 35h
|
||||
// Enable RTC battery charge: 3.0V, 200uA
|
||||
write_buf[0] = AXP192_BACKUP_BATT;
|
||||
write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE |
|
||||
AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V |
|
||||
AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 36h
|
||||
// Power on: Short press 128ms
|
||||
// Power off: Long press 1s
|
||||
// Power OK delay 64ms
|
||||
// Power off delay 4s
|
||||
write_buf[0] = AXP192_PEK;
|
||||
write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS |
|
||||
AXP192_PEK_LONG_PRESS_1_0S |
|
||||
AXP192_PEK_LONG_PRESS_POWER_OFF |
|
||||
AXP192_PEK_PWROK_DELAY_64mS |
|
||||
AXP192_PEK_POWER_OFF_TIME_4S;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 3Ah
|
||||
// APS Low battery warning level 1: 3.695V
|
||||
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1;
|
||||
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 3Bh
|
||||
// APS Low battery warning level 2: 3.600V
|
||||
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2;
|
||||
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 82h
|
||||
// ADC all on
|
||||
write_buf[0] = AXP192_ADC_ENABLE_1;
|
||||
write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL |
|
||||
AXP192_ADC_ENABLE_1_BATT_CUR |
|
||||
AXP192_ADC_ENABLE_1_ACIN_VOL |
|
||||
AXP192_ADC_ENABLE_1_ACIN_CUR |
|
||||
AXP192_ADC_ENABLE_1_VBUS_VOL |
|
||||
AXP192_ADC_ENABLE_1_VBUS_CUR |
|
||||
AXP192_ADC_ENABLE_1_APS_VOL |
|
||||
AXP192_ADC_ENABLE_1_TS_PIN;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 83h
|
||||
// ADC temperature on
|
||||
write_buf[0] = AXP192_ADC_ENABLE_2;
|
||||
write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 84h
|
||||
// ADC 25Hz
|
||||
write_buf[0] = AXP192_ADC_TS;
|
||||
write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ |
|
||||
AXP192_ADC_TS_OUT_CUR_80uA |
|
||||
AXP192_ADC_TS_PIN_TEMP_MON |
|
||||
AXP192_ADC_TS_PIN_OUT_SAVE_ENG;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -447,7 +210,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
// PWM1 frequency
|
||||
write_buf[0] = AXP192_PWM1_OUTPUT_FREQUECY;
|
||||
write_buf[1] = 0x00;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -456,7 +219,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
// PWM1 duty cycle Y1
|
||||
write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y1;
|
||||
write_buf[1] = 0xFF;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -465,7 +228,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
// PWM1 duty cycle Y2
|
||||
write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y2;
|
||||
write_buf[1] = 0xFF;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -474,7 +237,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
// Speaker off (GPIO2 output low)
|
||||
write_buf[0] = AXP192_GPIO2_FUNCTION;
|
||||
write_buf[1] = AXP192_GPIO2_FUNCTION_LOW_OUTPUT;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -485,7 +248,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
write_buf[0] = AXP192_LDO23_OUT_VOLTAGE;
|
||||
write_buf[1] = AXP192_LDO23_OUT_VOLTAGE_LDO2_3_3V |
|
||||
AXP192_LDO23_OUT_VOLTAGE_LDO3_1_8V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -494,7 +257,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
// DCDC1 (ESP32 VDD): 3.350V
|
||||
write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE;
|
||||
write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -503,7 +266,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
// DCDC3 (TFT backlight): 3.0V
|
||||
write_buf[0] = AXP192_DCDC3_OUT_VOLTAGE;
|
||||
write_buf[1] = AXP192_DCDC3_OUT_VOLTAGE_3_0V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -517,7 +280,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
write_buf[1] = AXP192_DCDC13_LDO23_CTRL_LDO2 |
|
||||
AXP192_DCDC13_LDO23_CTRL_DCDC3 |
|
||||
AXP192_DCDC13_LDO23_CTRL_DCDC1;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -527,7 +290,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
// PWM duty cycle is set to 100% therefore sys led is off
|
||||
write_buf[0] = AXP192_GPIO1_FUNCTION;
|
||||
write_buf[1] = AXP192_GPIO1_FUNCTION_PWM1_OUTPUT;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -539,25 +302,29 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) {
|
|||
* disable VBUS and rely on ACIN (USB_5V) as power source.
|
||||
*/
|
||||
write_buf[0] = AXP192_INPUT_POWER_STATE;
|
||||
rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
uint8_t powersource = (read_buf[0] & AXP192_INPUT_POWER_STATE_VBUS_AVAILABLE) ?
|
||||
PMIC_POWER_SOURCE_M_BUS : PMIC_POWER_SOURCE_USB;
|
||||
if (!pmic_set_power_source(powersource, internal_i2c)) {
|
||||
if (!pmic_set_power_source(powersource, i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pmic_disable_all_irq(internal_i2c)) {
|
||||
if (!pmic_disable_all_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pmic_clear_all_irq(internal_i2c)) {
|
||||
if (!pmic_clear_all_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pmic_enable_default_irq(internal_i2c)) {
|
||||
if (!pmic_enable_power_key_press_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pmic_enable_low_battery_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT = 1
|
|||
|
||||
CFLAGS += -DM5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT=$(M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT)
|
||||
|
||||
SRC_C += pmic/axp192/axp192.c
|
||||
|
||||
# Include these Python libraries in firmware.
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text
|
||||
|
|
|
@ -1,263 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 Stephen Oliver
|
||||
* Copyright (c) 2023 CDarius
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MICROPY_AXP192_H
|
||||
#define MICROPY_AXP192_H
|
||||
|
||||
#define AXP192_I2C_ADDRESS 0x34
|
||||
|
||||
#define AXP192_EXTEN_DCDC2_CTRL 0x10
|
||||
#define AXP192_EXTEN_DCDC2_CTRL_EXTEN 0b00000100
|
||||
#define AXP192_EXTEN_DCDC2_CTRL_DCDC2 0b00000001
|
||||
|
||||
#define AXP192_DCDC13_LDO23_CTRL 0x12
|
||||
#define AXP192_DCDC13_LDO23_CTRL_EXTEN 0b01000000
|
||||
#define AXP192_DCDC13_LDO23_CTRL_LDO3 0b00001000
|
||||
#define AXP192_DCDC13_LDO23_CTRL_LDO2 0b00000100
|
||||
#define AXP192_DCDC13_LDO23_CTRL_DCDC3 0b00000010
|
||||
#define AXP192_DCDC13_LDO23_CTRL_DCDC1 0b00000001
|
||||
|
||||
#define AXP192_DCDC2_OUT_VOLTAGE 0x25
|
||||
|
||||
#define AXP192_DCDC1_OUT_VOLTAGE 0x26
|
||||
#define AXP192_DCDC1_OUT_VOLTAGE_3_350V 0b01101010
|
||||
|
||||
#define AXP192_DCDC3_OUT_VOLTAGE 0x27
|
||||
|
||||
|
||||
#define AXP192_LDO23_OUT_VOLTAGE 0x28
|
||||
#define AXP192_LDO23_OUT_VOLTAGE_LDO2_3_0V 0b11000000
|
||||
#define AXP192_LDO23_OUT_VOLTAGE_LDO2_2_8V 0b10100000
|
||||
#define AXP192_LDO23_OUT_VOLTAGE_LDO2_MASK 0b11110000
|
||||
#define AXP192_LDO23_OUT_VOLTAGE_LDO3_3_0V 0b00001100
|
||||
#define AXP192_LDO23_OUT_VOLTAGE_LDO3_2_8V 0b00001010
|
||||
#define AXP192_LDO23_OUT_VOLTAGE_LDO3_MASK 0b00001111
|
||||
|
||||
#define AXP192_VBUS_IPSOUT 0x30
|
||||
#define AXP192_VBUS_IPSOUT_IGNORE_VBUSEN 0b10000000
|
||||
#define AXP192_VBUS_IPSOUT_VHOLD_LIMIT 0b01000000
|
||||
#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_4_4V 0b00100000
|
||||
#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_MASK 0b00111000
|
||||
#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT 0b00000010
|
||||
#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA 0b00000001
|
||||
#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_100mA 0b00000000
|
||||
|
||||
#define AXP192_POWER_OFF_VOLTAGE 0x31
|
||||
#define AXP192_POWER_OFF_VOLTAGE_2_6V 0b0000
|
||||
#define AXP192_POWER_OFF_VOLTAGE_2_7V 0b0001
|
||||
#define AXP192_POWER_OFF_VOLTAGE_2_8V 0b0010
|
||||
#define AXP192_POWER_OFF_VOLTAGE_2_9V 0b0011
|
||||
#define AXP192_POWER_OFF_VOLTAGE_3_0V 0b0100
|
||||
#define AXP192_POWER_OFF_VOLTAGE_3_1V 0b0101
|
||||
#define AXP192_POWER_OFF_VOLTAGE_3_2V 0b0110
|
||||
#define AXP192_POWER_OFF_VOLTAGE_3_3V 0b0111
|
||||
#define AXP192_POWER_OFF_VOLTAGE_MASK 0b0111
|
||||
|
||||
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL 0x32
|
||||
#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_OFF 0b10000000
|
||||
|
||||
#define AXP192_CHARGING_CTRL1 0x33
|
||||
#define AXP192_CHARGING_CTRL1_ENABLE 0b10000000
|
||||
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_36V 0b01100000
|
||||
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_20V 0b01000000
|
||||
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_15V 0b00100000
|
||||
#define AXP192_CHARGING_CTRL1_VOLTAGE_4_10V 0b00000000
|
||||
#define AXP192_CHARGING_CTRL1_VOLTAGE_MASK 0b01100000
|
||||
#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_15PERC 0b00010000
|
||||
#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC 0b00000000
|
||||
#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_MASK 0b00010000
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_100mA 0b00000000
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_190mA 0b00000001
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_280mA 0b00000010
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_360mA 0b00000011
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_450mA 0b00000100
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_550mA 0b00000101
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_630mA 0b00000110
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_700mA 0b00000111
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_780mA 0b00001000
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_880mA 0b00001001
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_960mA 0b00001010
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_1000mA 0b00001011
|
||||
|
||||
#define AXP192_CHARGING_CTRL1_CURRENT_MASK 0b00001111
|
||||
|
||||
#define AXP192_CHARGING_CTRL2 0x34
|
||||
|
||||
#define AXP192_BACKUP_BATT 0x35
|
||||
#define AXP192_BACKUP_BATT_CHARGING_ENABLE 0b10000000
|
||||
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_2_5V 0b01100000
|
||||
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V 0b00100000
|
||||
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_1V 0b00000000
|
||||
#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_MASK 0b01100000
|
||||
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_400uA 0b00000011
|
||||
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA 0b00000010
|
||||
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_100uA 0b00000001
|
||||
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_50uA 0b00000000
|
||||
#define AXP192_BACKUP_BATT_CHARGING_CURRENT_MASK 0b00000011
|
||||
|
||||
#define AXP192_PEK 0x36
|
||||
#define AXP192_PEK_SHORT_PRESS_1S 0b11000000
|
||||
#define AXP192_PEK_SHORT_PRESS_512mS 0b10000000
|
||||
#define AXP192_PEK_SHORT_PRESS_256mS 0b01000000
|
||||
#define AXP192_PEK_SHORT_PRESS_128mS 0b00000000
|
||||
#define AXP192_PEK_SHORT_PRESS_MASK 0b11000000
|
||||
#define AXP192_PEK_LONG_PRESS_2_5S 0b00110000
|
||||
#define AXP192_PEK_LONG_PRESS_2_0S 0b00100000
|
||||
#define AXP192_PEK_LONG_PRESS_1_5S 0b00010000
|
||||
#define AXP192_PEK_LONG_PRESS_1_0S 0b00000000
|
||||
#define AXP192_PEK_LONG_PRESS_MASK 0b00110000
|
||||
#define AXP192_PEK_LONG_PRESS_POWER_OFF 0b00001000
|
||||
#define AXP192_PEK_PWROK_DELAY_64mS 0b00000100
|
||||
#define AXP192_PEK_PWROK_DELAY_32mS 0b00000000
|
||||
#define AXP192_PEK_PWROK_DELAY_MASK 0b00000100
|
||||
#define AXP192_PEK_POWER_OFF_TIME_12S 0b00000011
|
||||
#define AXP192_PEK_POWER_OFF_TIME_8S 0b00000010
|
||||
#define AXP192_PEK_POWER_OFF_TIME_6S 0b00000001
|
||||
#define AXP192_PEK_POWER_OFF_TIME_4S 0b00000000
|
||||
#define AXP192_PEK_POWER_OFF_TIME_MASK 0b00000011
|
||||
|
||||
#define AXP192_BATT_TEMP_LOW_THRESH 0x38
|
||||
#define AXP192_BATT_TEMP_HIGH_THRESH 0x39
|
||||
#define AXP192_BATT_TEMP_HIGH_THRESH_DEFAULT 0b11111100
|
||||
|
||||
#define AXP192_APS_LOW_BATT_LEVEL_1 0x3A
|
||||
#define AXP192_APS_LOW_BATT_LEVEL_2 0x3B
|
||||
#define AXP192_APS_LOW_BATT_VOLTAGE_3_695V 0b10010100
|
||||
#define AXP192_APS_LOW_BATT_VOLTAGE_3_600V 0b10000011
|
||||
|
||||
#define AXP192_IRQ_1_ENABLE 0x40
|
||||
#define AXP192_IRQ_2_ENABLE 0x41
|
||||
#define AXP192_IRQ_3_ENABLE 0x42
|
||||
#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010
|
||||
#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001
|
||||
#define AXP192_IRQ_4_ENABLE 0x43
|
||||
#define AXP192_IRQ_4_LOW_VOLTAGE_WARNING 0b00000001
|
||||
#define AXP192_IRQ_5_ENABLE 0x4a
|
||||
|
||||
#define AXP192_IRQ_X_DISABLE_ALL 0b00000000
|
||||
|
||||
#define AXP192_IRQ_1_STATUS 0x44
|
||||
#define AXP192_IRQ_2_STATUS 0x45
|
||||
#define AXP192_IRQ_3_STATUS 0x46
|
||||
#define AXP192_IRQ_4_STATUS 0x47
|
||||
#define AXP192_IRQ_5_STATUS 0x4d
|
||||
|
||||
#define AXP192_ADC_ACIN_VOLTAGE_H 0x56
|
||||
#define AXP192_ADC_ACIN_VOLTAGE_L 0x57
|
||||
#define AXP192_ADC_ACIN_CURRENT_H 0x58
|
||||
#define AXP192_ADC_ACIN_CURRENT_L 0x59
|
||||
#define AXP192_ADC_VBUS_VOLTAGE_H 0x5a
|
||||
#define AXP192_ADC_VBUS_VOLTAGE_L 0x5b
|
||||
#define AXP192_ADC_VBUS_CURRENT_H 0x5c
|
||||
#define AXP192_ADC_VBUS_CURRENT_L 0x5d
|
||||
#define AXP192_ADC_INTERNAL_TEMP_H 0x5e
|
||||
#define AXP192_ADC_INTERNAL_TEMP_L 0x5f
|
||||
|
||||
#define AXP192_ADC_BATT_VOLTAGE_H 0x78
|
||||
#define AXP192_ADC_BATT_VOLTAGE_L 0x79
|
||||
|
||||
#define AXP192_ADC_BATT_POWER_H 0x70
|
||||
#define AXP192_ADC_BATT_POWER_M 0x71
|
||||
#define AXP192_ADC_BATT_POWER_L 0x72
|
||||
|
||||
#define AXP192_ADC_BATT_CHARGE_CURRENT_H 0x7a
|
||||
#define AXP192_ADC_BATT_CHARGE_CURRENT_L 0x7b
|
||||
#define AXP192_ADC_BATT_DISCHARGE_CURRENT_H 0x7c
|
||||
#define AXP192_ADC_BATT_DISCHARGE_CURRENT_L 0x7d
|
||||
#define AXP192_ADC_APS_VOLTAGE_H 0x7e
|
||||
#define AXP192_ADC_APS_VOLTAGE_L 0x7f
|
||||
|
||||
#define AXP192_ADC_ENABLE_1 0x82
|
||||
#define AXP192_ADC_ENABLE_1_BATT_VOL 0b10000000
|
||||
#define AXP192_ADC_ENABLE_1_BATT_CUR 0b01000000
|
||||
#define AXP192_ADC_ENABLE_1_ACIN_VOL 0b00100000
|
||||
#define AXP192_ADC_ENABLE_1_ACIN_CUR 0b00010000
|
||||
#define AXP192_ADC_ENABLE_1_VBUS_VOL 0b00001000
|
||||
#define AXP192_ADC_ENABLE_1_VBUS_CUR 0b00000100
|
||||
#define AXP192_ADC_ENABLE_1_APS_VOL 0b00000010
|
||||
#define AXP192_ADC_ENABLE_1_TS_PIN 0b00000001
|
||||
|
||||
#define AXP192_ADC_ENABLE_2 0x83
|
||||
#define AXP192_ADC_ENABLE_2_TEMP_MON 0b10000000
|
||||
#define AXP192_ADC_ENABLE_2_GPIO0 0b00001000
|
||||
#define AXP192_ADC_ENABLE_2_GPIO1 0b00000100
|
||||
#define AXP192_ADC_ENABLE_2_GPIO2 0b00000010
|
||||
#define AXP192_ADC_ENABLE_2_GPIO3 0b00000001
|
||||
|
||||
#define AXP192_ADC_TS 0x84
|
||||
#define AXP192_ADC_TS_SAMPLE_200HZ 0b11000000
|
||||
#define AXP192_ADC_TS_SAMPLE_100HZ 0b10000000
|
||||
#define AXP192_ADC_TS_SAMPLE_50HZ 0b01000000
|
||||
#define AXP192_ADC_TS_SAMPLE_25HZ 0b00000000
|
||||
#define AXP192_ADC_TS_SAMPLE_MASK 0b11000000
|
||||
#define AXP192_ADC_TS_OUT_CUR_80uA 0b00110000
|
||||
#define AXP192_ADC_TS_OUT_CUR_60uA 0b00100000
|
||||
#define AXP192_ADC_TS_OUT_CUR_40uA 0b00010000
|
||||
#define AXP192_ADC_TS_OUT_CUR_20uA 0b00000000
|
||||
#define AXP192_ADC_TS_OUT_CUR_MASK 0b00110000
|
||||
#define AXP192_ADC_TS_PIN_TEMP_MON 0b00000000
|
||||
#define AXP192_ADC_TS_PIN_EXTERN_ADC 0b00000100
|
||||
#define AXP192_ADC_TS_PIN_OUT_ALWAYS 0b00000011
|
||||
#define AXP192_ADC_TS_PIN_OUT_SAVE_ENG 0b00000010
|
||||
#define AXP192_ADC_TS_PIN_OUT_CHG 0b00000001
|
||||
#define AXP192_ADC_TS_PIN_OUT_DIS 0b00000000
|
||||
#define AXP192_ADC_TS_PIN_OUT_MASK 0b00000011
|
||||
|
||||
#define AXP192_GPIO0_FUNCTION 0x90
|
||||
#define AXP192_GPIO0_FUNCTION_FLOATING 0b00000111
|
||||
#define AXP192_GPIO0_FUNCTION_LOW_OUTPUT 0b00000101
|
||||
#define AXP192_GPIO0_FUNCTION_ADC_INPUT 0b00000100
|
||||
#define AXP192_GPIO0_FUNCTION_LDO_OUTPUT 0b00000010
|
||||
#define AXP192_GPIO0_FUNCTION_GENERAL_INPUT 0b00000001
|
||||
#define AXP192_GPIO0_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000
|
||||
|
||||
#define AXP192_GPIO0_LDO_VOLTAGE 0x91
|
||||
#define AXP192_GPIO0_LDO_VOLTAGE_3_3V 0b11110000
|
||||
#define AXP192_GPIO0_LDO_VOLTAGE_2_8V 0b10100000
|
||||
#define AXP192_GPIO0_LDO_VOLTAGE_1_8V 0b00000000
|
||||
|
||||
|
||||
#define AXP192_GPIO1_FUNCTION 0x92
|
||||
#define AXP192_GPIO1_FUNCTION_FLOATING 0b00000111
|
||||
#define AXP192_GPIO1_FUNCTION_LOW_OUTPUT 0b00000101
|
||||
#define AXP192_GPIO1_FUNCTION_ADC_INPUT 0b00000100
|
||||
#define AXP192_GPIO1_FUNCTION_PWM1_OUTPUT 0b00000010
|
||||
#define AXP192_GPIO1_FUNCTION_GENERAL_INPUT 0b00000001
|
||||
#define AXP192_GPIO1_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000
|
||||
|
||||
|
||||
#define AXP192_GPIO2_FUNCTION 0x93
|
||||
#define AXP192_GPIO2_FUNCTION_FLOATING 0b00000111
|
||||
#define AXP192_GPIO2_FUNCTION_LOW_OUTPUT 0b00000101
|
||||
#define AXP192_GPIO2_FUNCTION_ADC_INPUT 0b00000100
|
||||
#define AXP192_GPIO1_FUNCTION_PWM2_OUTPUT 0b00000010
|
||||
#define AXP192_GPIO2_FUNCTION_GENERAL_INPUT 0b00000001
|
||||
#define AXP192_GPIO2_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000
|
||||
|
||||
#define AXP192_PWM1_DUTY_RATIO 0x9A
|
||||
|
||||
#endif
|
|
@ -29,12 +29,15 @@
|
|||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/busio/I2C.h"
|
||||
#include "shared-bindings/displayio/FourWire.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-module/displayio/__init__.h"
|
||||
#include "shared-module/displayio/mipi_constants.h"
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "components/driver/include/driver/gpio.h"
|
||||
#include "components/hal/include/hal/gpio_hal.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
#include "axp192.h"
|
||||
#include "../../pmic/axp192/axp192.h"
|
||||
|
||||
// display init sequence according to adafruit_st7735r.py library
|
||||
uint8_t display_init_sequence[] = {
|
||||
|
@ -59,12 +62,13 @@ uint8_t display_init_sequence[] = {
|
|||
0x29,0x80,0x64 // _DISPON
|
||||
};
|
||||
|
||||
static bool pmic_init(void) {
|
||||
static bool pmic_init(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
// uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
||||
busio_i2c_obj_t *internal_i2c = common_hal_board_create_i2c(0);
|
||||
if (!pmic_common_init(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 30h
|
||||
// The VBUS-IPSOUT path can be selected to be opened regardless of the status of N_VBUSEN
|
||||
|
@ -72,16 +76,7 @@ static bool pmic_init(void) {
|
|||
// VBUS current limit control disabled
|
||||
write_buf[0] = AXP192_VBUS_IPSOUT;
|
||||
write_buf[1] = AXP192_VBUS_IPSOUT_IGNORE_VBUSEN;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 31h
|
||||
// VOFF Shutdown voltage setting ( 3.0V )
|
||||
write_buf[0] = AXP192_POWER_OFF_VOLTAGE;
|
||||
write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -95,88 +90,7 @@ static bool pmic_init(void) {
|
|||
write_buf[1] = AXP192_CHARGING_CTRL1_ENABLE |
|
||||
AXP192_CHARGING_CTRL1_VOLTAGE_4_20V |
|
||||
AXP192_CHARGING_CTRL1_CURRENT_100mA;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 35h
|
||||
// Enable RTC battery charge: 3.0V, 200uA
|
||||
write_buf[0] = AXP192_BACKUP_BATT;
|
||||
write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE |
|
||||
AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V |
|
||||
AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 36h
|
||||
// Power on: Short press 128ms
|
||||
// Power off: Long press 1s
|
||||
// Power OK delay 64ms
|
||||
// Power off delay 4s
|
||||
write_buf[0] = AXP192_PEK;
|
||||
write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS |
|
||||
AXP192_PEK_LONG_PRESS_1_0S |
|
||||
AXP192_PEK_LONG_PRESS_POWER_OFF |
|
||||
AXP192_PEK_PWROK_DELAY_64mS |
|
||||
AXP192_PEK_POWER_OFF_TIME_4S;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 3Ah
|
||||
// APS Low battery warning level 1: 3.695V
|
||||
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1;
|
||||
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 3Bh
|
||||
// APS Low battery warning level 2: 3.600V
|
||||
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2;
|
||||
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 82h
|
||||
// ADC all on
|
||||
write_buf[0] = AXP192_ADC_ENABLE_1;
|
||||
write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL |
|
||||
AXP192_ADC_ENABLE_1_BATT_CUR |
|
||||
AXP192_ADC_ENABLE_1_ACIN_VOL |
|
||||
AXP192_ADC_ENABLE_1_ACIN_CUR |
|
||||
AXP192_ADC_ENABLE_1_VBUS_VOL |
|
||||
AXP192_ADC_ENABLE_1_VBUS_CUR |
|
||||
AXP192_ADC_ENABLE_1_APS_VOL |
|
||||
AXP192_ADC_ENABLE_1_TS_PIN;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 83h
|
||||
// ADC temperature on
|
||||
write_buf[0] = AXP192_ADC_ENABLE_2;
|
||||
write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 84h
|
||||
// ADC 25Hz
|
||||
write_buf[0] = AXP192_ADC_TS;
|
||||
write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ |
|
||||
AXP192_ADC_TS_OUT_CUR_80uA |
|
||||
AXP192_ADC_TS_PIN_OUT_SAVE_ENG;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -185,7 +99,7 @@ static bool pmic_init(void) {
|
|||
// GPIO0(LDOio0) floating
|
||||
write_buf[0] = AXP192_GPIO0_FUNCTION;
|
||||
write_buf[1] = AXP192_GPIO0_FUNCTION_FLOATING;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -194,7 +108,7 @@ static bool pmic_init(void) {
|
|||
// GPIO0(LDOio0) 2.8V
|
||||
write_buf[0] = AXP192_GPIO0_LDO_VOLTAGE;
|
||||
write_buf[1] = AXP192_GPIO0_LDO_VOLTAGE_2_8V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -205,7 +119,7 @@ static bool pmic_init(void) {
|
|||
write_buf[0] = AXP192_LDO23_OUT_VOLTAGE;
|
||||
write_buf[1] = AXP192_LDO23_OUT_VOLTAGE_LDO2_2_8V |
|
||||
AXP192_LDO23_OUT_VOLTAGE_LDO3_3_0V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -217,7 +131,7 @@ static bool pmic_init(void) {
|
|||
AXP192_DCDC13_LDO23_CTRL_LDO3 |
|
||||
AXP192_DCDC13_LDO23_CTRL_LDO2 |
|
||||
AXP192_DCDC13_LDO23_CTRL_DCDC1;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -226,56 +140,24 @@ static bool pmic_init(void) {
|
|||
// DCDC1 (ESP32 VDD): 3.350V
|
||||
write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE;
|
||||
write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 40h
|
||||
// IRQ enable control register 1
|
||||
write_buf[0] = AXP192_IRQ_1_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
if (!pmic_disable_all_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 41h
|
||||
// IRQ enable control register 2
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
if (!pmic_clear_all_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 42h
|
||||
// IRQ enable control register 3
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS |
|
||||
AXP192_IRQ_3_PEK_LONG_PRESS;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
if (!pmic_enable_power_key_press_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 43h
|
||||
// IRQ enable control register 4
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 44h
|
||||
// IRQ enable control register 5
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
if (!pmic_enable_low_battery_irq(i2c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -339,7 +221,9 @@ static bool display_init(void) {
|
|||
}
|
||||
|
||||
void board_init(void) {
|
||||
if (!pmic_init()) {
|
||||
busio_i2c_obj_t *internal_i2c = common_hal_board_create_i2c(0);
|
||||
|
||||
if (!pmic_init(internal_i2c)) {
|
||||
mp_printf(&mp_plat_print, "could not initialize axp192 pmic\n");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -7,3 +7,5 @@ CIRCUITPY_ESP_FLASH_MODE = qio
|
|||
CIRCUITPY_ESP_FLASH_FREQ = 80m
|
||||
CIRCUITPY_ESP_FLASH_SIZE = 4MB
|
||||
CIRCUITPY_ESPCAMERA = 0
|
||||
|
||||
SRC_C += pmic/axp192/axp192.c
|
||||
|
|
|
@ -0,0 +1,255 @@
|
|||
#include "axp192.h"
|
||||
|
||||
bool pmic_common_init(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 31h
|
||||
// VOFF Shutdown voltage setting ( 3.0V )
|
||||
write_buf[0] = AXP192_POWER_OFF_VOLTAGE;
|
||||
write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 32h
|
||||
// Enable battery monitoring
|
||||
// N_OE shout down delay 2 seconds
|
||||
write_buf[0] = AXP192_POWER_OFF_BATT_CHGLED_CTRL;
|
||||
write_buf[1] = AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON |
|
||||
AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 35h
|
||||
// Enable RTC battery charge: 3.0V, 200uA
|
||||
write_buf[0] = AXP192_BACKUP_BATT;
|
||||
write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE |
|
||||
AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V |
|
||||
AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 36h
|
||||
// Power on: Short press 128ms
|
||||
// Power off: Long press 1s
|
||||
// Power OK delay 64ms
|
||||
// Power off delay 4s
|
||||
write_buf[0] = AXP192_PEK;
|
||||
write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS |
|
||||
AXP192_PEK_LONG_PRESS_1_0S |
|
||||
AXP192_PEK_LONG_PRESS_POWER_OFF |
|
||||
AXP192_PEK_PWROK_DELAY_64mS |
|
||||
AXP192_PEK_POWER_OFF_TIME_4S;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 3Ah
|
||||
// APS Low battery warning level 1: 3.695V
|
||||
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1;
|
||||
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 3Bh
|
||||
// APS Low battery warning level 2: 3.600V
|
||||
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2;
|
||||
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 82h
|
||||
// ADC all on
|
||||
write_buf[0] = AXP192_ADC_ENABLE_1;
|
||||
write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL |
|
||||
AXP192_ADC_ENABLE_1_BATT_CUR |
|
||||
AXP192_ADC_ENABLE_1_ACIN_VOL |
|
||||
AXP192_ADC_ENABLE_1_ACIN_CUR |
|
||||
AXP192_ADC_ENABLE_1_VBUS_VOL |
|
||||
AXP192_ADC_ENABLE_1_VBUS_CUR |
|
||||
AXP192_ADC_ENABLE_1_APS_VOL |
|
||||
AXP192_ADC_ENABLE_1_TS_PIN;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 83h
|
||||
// ADC temperature on
|
||||
write_buf[0] = AXP192_ADC_ENABLE_2;
|
||||
write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 84h
|
||||
// ADC 25Hz
|
||||
write_buf[0] = AXP192_ADC_TS;
|
||||
write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ |
|
||||
AXP192_ADC_TS_OUT_CUR_80uA |
|
||||
AXP192_ADC_TS_PIN_TEMP_MON |
|
||||
AXP192_ADC_TS_PIN_OUT_SAVE_ENG;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pmic_disable_all_irq(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 40h
|
||||
// IRQ enable control register 1
|
||||
write_buf[0] = AXP192_IRQ_1_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 41h
|
||||
// IRQ enable control register 2
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 42h
|
||||
// IRQ enable control register 3
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_3_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 43h
|
||||
// IRQ enable control register 4
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_4_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 4Ah
|
||||
// IRQ enable control register 5
|
||||
write_buf[0] = AXP192_IRQ_5_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pmic_clear_all_irq(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 44h
|
||||
// IRQ enable control register 1
|
||||
write_buf[0] = AXP192_IRQ_1_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 45h
|
||||
// IRQ enable control register 2
|
||||
write_buf[0] = AXP192_IRQ_2_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 46h
|
||||
// IRQ enable control register 3
|
||||
write_buf[0] = AXP192_IRQ_3_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 47h
|
||||
// IRQ enable control register 4
|
||||
write_buf[0] = AXP192_IRQ_4_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reg: 4Ah
|
||||
// IRQ enable control register 5
|
||||
write_buf[0] = AXP192_IRQ_5_STATUS;
|
||||
write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pmic_enable_power_key_press_irq(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
uint8_t read_buf[1];
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 42h
|
||||
// IRQ enable control register 3
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
write_buf[1] = read_buf[0] | AXP192_IRQ_3_PEK_SHORT_PRESS | AXP192_IRQ_3_PEK_LONG_PRESS;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pmic_enable_low_battery_irq(busio_i2c_obj_t *i2c) {
|
||||
int rc;
|
||||
uint8_t write_buf[2];
|
||||
|
||||
// Reg: 43h
|
||||
// IRQ enable control register 4
|
||||
// Enable power on key short and long press interrupt
|
||||
write_buf[0] = AXP192_IRQ_2_ENABLE;
|
||||
write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING;
|
||||
rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -28,6 +28,8 @@
|
|||
#ifndef MICROPY_AXP192_H
|
||||
#define MICROPY_AXP192_H
|
||||
|
||||
#include "shared-bindings/busio/I2C.h"
|
||||
|
||||
#define AXP192_I2C_ADDRESS 0x34
|
||||
|
||||
#define AXP192_INPUT_POWER_STATE 0x00
|
||||
|
@ -283,4 +285,10 @@
|
|||
#define AXP192_PWM1_DUTY_RATIO_Y1 0x99
|
||||
#define AXP192_PWM1_DUTY_RATIO_Y2 0x9A
|
||||
|
||||
bool pmic_common_init(busio_i2c_obj_t *i2c);
|
||||
bool pmic_disable_all_irq(busio_i2c_obj_t *i2c);
|
||||
bool pmic_clear_all_irq(busio_i2c_obj_t *i2c);
|
||||
bool pmic_enable_power_key_press_irq(busio_i2c_obj_t *i2c);
|
||||
bool pmic_enable_low_battery_irq(busio_i2c_obj_t *i2c);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue