Compare commits
33 Commits
Author | SHA1 | Date |
---|---|---|
|
7e7ddb84ab | 1 year ago |
|
5ba5e028c5 | 1 year ago |
|
201cd10a36 | 1 year ago |
|
d36d902b1f | 1 year ago |
|
e6e4a17c07 | 1 year ago |
|
633e4d84fa | 1 year ago |
|
143fdbe324 | 1 year ago |
|
22e45eb083 | 1 year ago |
|
dfb058dbc9 | 1 year ago |
|
c97fd0f611 | 1 year ago |
|
b48740d99e | 1 year ago |
|
2ad4c0df2e | 1 year ago |
|
9fabc58dc2 | 1 year ago |
|
e6576de2ab | 1 year ago |
|
74442ebf12 | 1 year ago |
|
2a46d4d438 | 1 year ago |
|
04a705520e | 1 year ago |
|
05abffafe3 | 1 year ago |
|
0cae1f75cf | 1 year ago |
|
0f3df6df71 | 1 year ago |
|
6f02517eff | 1 year ago |
|
0ad9aed5d5 | 1 year ago |
|
24719c759f | 1 year ago |
|
3fc013ea64 | 1 year ago |
|
b8a2c5b5d6 | 1 year ago |
|
c0275e1946 | 1 year ago |
|
f964289f6d | 1 year ago |
|
ce8b02cabd | 1 year ago |
|
5fdc8b10bb | 1 year ago |
|
3ae7e9ab89 | 1 year ago |
|
713614ec11 | 1 year ago |
|
b558cc1243 | 1 year ago |
|
d1e51d8039 | 1 year ago |
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 148 KiB |
@ -1,10 +0,0 @@
|
||||
|
||||
#ifndef BUILD_NUMBER
|
||||
#define BUILD_NUMBER "17"
|
||||
#endif
|
||||
#ifndef VERSION
|
||||
#define VERSION "v0.4.6.17-0a01171 - 2021-12-28 21:20:22.015464"
|
||||
#endif
|
||||
#ifndef VERSION_SHORT
|
||||
#define VERSION_SHORT "v0.4.6.17-0a01171"
|
||||
#endif
|
@ -0,0 +1,2 @@
|
||||
.vscode
|
||||
.DS_Store
|
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 lewis he
|
||||
|
||||
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.
|
@ -0,0 +1,22 @@
|
||||
AXP202X_Library
|
||||
=====================================
|
||||
- How to program **AXP20x_Library** with ESP-IDF [ESP_IDF_AXP20x_Library](https://github.com/lewisxhe/ESP_IDF_AXP20x_Library)
|
||||
|
||||
- The `setPowerOutPut` function has forced DCDC3 to be turned on and cannot be controlled because T-Watch uses DCDC3 as the esp32 to power the main chip. If it is turned off, the hardware cannot be programmed.
|
||||
|
||||
|
||||
TTGO invests time and resources to provide this open source code, please support TTGO and open source hardware by purchasing products from TTGO!
|
||||
|
||||
Written by Lewis He for TTGO. MIT license, all text above must be included in any redistribution
|
||||
|
||||
## Chip resource table
|
||||
| CHIP | AXP173 | AXP192 | AXP202 |
|
||||
| -------- | ---------------- | ---------------- | ---------------- |
|
||||
| DC1 | 0v7~3v5 /1200mA | 0v7~3v5 /1200mA | X |
|
||||
| DC2 | 0v7~2v275/1600mA | 0v7~2v275/1600mA | 0v7~2v275/1600mA |
|
||||
| DC3 | X | 0v7~3v5 /700mA | 0v7~3v5 /1200mA |
|
||||
| LDO1 | 3v3 /30mA | 3v3 /30mA | 3v3 /30mA |
|
||||
| LDO2 | 1v8~3v3 /200mA | 1v8~3v3 /200mA | 1v8~3v3 /200mA |
|
||||
| LDO3 | 1v8~3v3 /200mA | 1v8~3v3 /200mA | 0v7~3v3 /200mA |
|
||||
| LDO4 | 0v7~3v5 /500mA | X | 1v8~3v3 /200mA |
|
||||
| LDO5/IO0 | X | 1v8~3v3 /50mA | 1v8~3v3 /50mA |
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 lewis he
|
||||
|
||||
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.
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
AXP20X_Class axp;
|
||||
|
||||
const uint8_t i2c_sda = 21;
|
||||
const uint8_t i2c_scl = 22;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Wire.begin(i2c_sda, i2c_scl);
|
||||
|
||||
int ret = axp.begin(Wire);
|
||||
|
||||
if (ret == AXP_FAIL) {
|
||||
Serial.println("AXP Power begin failed");
|
||||
while (1);
|
||||
}
|
||||
//! AXP202 GPIO has no internal pull-up or pull-down.
|
||||
//! For stability, external pull-up or pull-down resistors are required.
|
||||
ret = axp.setGPIOMode(AXP_GPIO_0, AXP_IO_INPUT_MODE);
|
||||
Serial.printf("AXP_GPIO_0 %d\n", ret);
|
||||
ret = axp.setGPIOMode(AXP_GPIO_1, AXP_IO_INPUT_MODE);
|
||||
Serial.printf("AXP_GPIO_1 %d\n", ret);
|
||||
ret = axp.setGPIOMode(AXP_GPIO_2, AXP_IO_INPUT_MODE);
|
||||
Serial.printf("AXP_GPIO_2 %d\n", ret);
|
||||
ret = axp.setGPIOMode(AXP_GPIO_3, AXP_IO_INPUT_MODE);
|
||||
Serial.printf("AXP_GPIO_3 %d\n", ret);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.printf("GPIO: [0]:%d [1]:%d [2]:%d [3]:%d\n",
|
||||
axp.gpioRead(AXP_GPIO_0),
|
||||
axp.gpioRead(AXP_GPIO_1),
|
||||
axp.gpioRead(AXP_GPIO_2),
|
||||
axp.gpioRead(AXP_GPIO_3)
|
||||
);
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 lewis he
|
||||
|
||||
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.
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
AXP20X_Class axp;
|
||||
|
||||
const uint8_t i2c_sda = 21;
|
||||
const uint8_t i2c_scl = 22;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Wire.begin(i2c_sda, i2c_scl);
|
||||
|
||||
int ret = axp.begin(Wire);
|
||||
|
||||
if (ret == AXP_FAIL) {
|
||||
Serial.println("AXP Power begin failed");
|
||||
while (1);
|
||||
}
|
||||
|
||||
axp.setGPIOMode(AXP_GPIO_0, AXP_IO_OUTPUT_HIGH_MODE);
|
||||
axp.setGPIOMode(AXP_GPIO_1, AXP_IO_OUTPUT_HIGH_MODE);
|
||||
|
||||
//! GPIO2, GPIO3 is only allowed to be configured to output low
|
||||
axp.gpioWrite(AXP_GPIO_2, LOW);
|
||||
axp.gpioWrite(AXP_GPIO_3, LOW);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//! GPIO0, GPIO1 allows output high and low
|
||||
axp.gpioWrite(AXP_GPIO_0, HIGH);
|
||||
axp.gpioWrite(AXP_GPIO_1, HIGH);
|
||||
delay(1000);
|
||||
axp.gpioWrite(AXP_GPIO_0, LOW);
|
||||
axp.gpioWrite(AXP_GPIO_1, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 lewis he
|
||||
|
||||
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.
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
|
||||
AXP20X_Class axp;
|
||||
bool axpIrq = 0;
|
||||
uint8_t second = 0;
|
||||
uint32_t timer = 0;
|
||||
|
||||
const uint8_t i2c_sda = 21;
|
||||
const uint8_t i2c_scl = 22;
|
||||
const uint8_t axp_irq_pin = 35;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Wire.begin(i2c_sda, i2c_scl);
|
||||
|
||||
int ret = axp.begin(Wire);
|
||||
|
||||
if (ret == AXP_FAIL) {
|
||||
Serial.println("AXP Power begin failed");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//! enable timer irq and pek key press irq channel
|
||||
axp.enableIRQ(AXP202_TIMER_TIMEOUT_IRQ | AXP202_PEK_SHORTPRESS_IRQ, true);
|
||||
|
||||
//! attachInterrupt to gpio 35
|
||||
pinMode(axp_irq_pin, INPUT);
|
||||
attachInterrupt(axp_irq_pin, [] {
|
||||
axpIrq = 1;
|
||||
}, FALLING);
|
||||
axp.clearIRQ();
|
||||
|
||||
axp.setTimer(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - timer > 1000) {
|
||||
second++;
|
||||
Serial.printf("%u second\n", second);
|
||||
timer = millis();
|
||||
}
|
||||
if (axpIrq) {
|
||||
axpIrq = 0;
|
||||
axp.readIRQ();
|
||||
if (axp.isPEKShortPressIRQ()) {
|
||||
Serial.printf("AXP202 PEK key Click\n");
|
||||
}
|
||||
if (axp.isTimerTimeoutIRQ()) {
|
||||
Serial.printf("AXP202 timer timeout\n");
|
||||
axp.clearTimerStatus();
|
||||
while (1) {
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
axp.clearIRQ();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,153 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 lewis he
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "axp20x.h"
|
||||
|
||||
AXP20X_Class axp;
|
||||
const uint8_t i2c_sda = 21;
|
||||
const uint8_t i2c_scl = 22;
|
||||
const uint8_t slave_address = AXP192_SLAVE_ADDRESS; //use axp192
|
||||
// const uint8_t slave_address = AXP202_SLAVE_ADDRESS; //use axp202
|
||||
|
||||
void printPowerChannel();
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Wire.begin(i2c_sda, i2c_scl);
|
||||
|
||||
Serial.println("AXP192/AXP202 ADC Test");
|
||||
|
||||
/* Initialise the pmu */
|
||||
int ret = axp.begin(Wire, slave_address);
|
||||
if (ret) {
|
||||
/* There was a problem detecting the AXP202/192 ... check your connections */
|
||||
Serial.println("Ooops, AXP202/AXP192 power chip detected ... Check your wiring!");
|
||||
while (1);
|
||||
}
|
||||
|
||||
/*Enable AXP ADC function*/
|
||||
axp.adc1Enable(AXP202_VBUS_VOL_ADC1 |
|
||||
AXP202_VBUS_CUR_ADC1 |
|
||||
AXP202_BATT_CUR_ADC1 |
|
||||
AXP202_BATT_VOL_ADC1,
|
||||
true);
|
||||
|
||||
Serial.println("");
|
||||
|
||||
printPowerChannel();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
Serial.println("=========================");
|
||||
Serial.print("VBUS STATUS: ");
|
||||
// You can use isVBUSPlug to check whether the USB connection is normal
|
||||
if (axp.isVBUSPlug()) {
|
||||
|
||||
Serial.println("CONNECT");
|
||||
|
||||
// Get USB voltage
|
||||
Serial.print("VBUS Volate:");
|
||||
Serial.print(axp.getVbusVoltage());
|
||||
Serial.println(" mV");
|
||||
|
||||
// Get USB current
|
||||
Serial.print("VBUS Current: ");
|
||||
Serial.print(axp.getVbusCurrent());
|
||||
Serial.println(" mA");
|
||||
|
||||
} else {
|
||||
Serial.println("DISCONNECT");
|
||||
}
|
||||
|
||||
Serial.println("=========================");
|
||||
|
||||
Serial.print("BATTERY STATUS: ");
|
||||
|
||||
// You can use isBatteryConnect() to check whether the battery is connected properly
|
||||
if (axp.isBatteryConnect()) {
|
||||
|
||||
Serial.println("CONNECT");
|
||||
|
||||
// Get battery voltage
|
||||
Serial.print("BAT Volate:");
|
||||
Serial.print(axp.getBattVoltage());
|
||||
Serial.println(" mV");
|
||||
|
||||
// To display the charging status, you must first discharge the battery,
|
||||
// and it is impossible to read the full charge when it is fully charged
|
||||
if (axp.isChargeing()) {
|
||||
Serial.print("Charge:");
|
||||
Serial.print(axp.getBattChargeCurrent());
|
||||
Serial.println(" mA");
|
||||
} else {
|
||||
// Show current consumption
|
||||
Serial.print("Discharge:");
|
||||
Serial.print(axp.getBattDischargeCurrent());
|
||||
Serial.println(" mA");
|
||||
|
||||
/*getBattPercentage just only support axp202 */
|
||||
if (slave_address == AXP202_SLAVE_ADDRESS) {
|
||||
Serial.print("Per: ");
|
||||
Serial.print(axp.getBattPercentage());
|
||||
Serial.println(" %");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Serial.println("DISCONNECT");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
|
||||
void printPowerChannel()
|
||||
{
|
||||
Serial.print("DC2:");
|
||||
Serial.print(axp.isDCDC2Enable() ? String(axp.getDCDC2Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("DC3:");
|
||||
Serial.print(axp.isDCDC3Enable() ? String(axp.getDCDC3Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("LDO2:");
|
||||
Serial.print(axp.isLDO2Enable() ? String(axp.getLDO2Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("LDO3:");
|
||||
Serial.print(axp.isLDO3Enable() ? String(axp.getLDO3Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("LDO4:");
|
||||
Serial.print(axp.isLDO4Enable() ? "ENABLE" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("Exten:");
|
||||
Serial.print(axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
||||
Serial.print("\r\n");
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 lewis he
|
||||
|
||||
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.
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
AXP20X_Class axp;
|
||||
bool axpIrq = 0;
|
||||
|
||||
const uint8_t i2c_sda = 21;
|
||||
const uint8_t i2c_scl = 22;
|
||||
const uint8_t axp_irq_pin = 35;
|
||||
|
||||
void setFlag(void)
|
||||
{
|
||||
axpIrq = true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Wire.begin(i2c_sda, i2c_scl);
|
||||
|
||||
//! Use the Wire port
|
||||
int ret = axp.begin(Wire, AXP192_SLAVE_ADDRESS);
|
||||
// int ret = axp.begin(Wire);
|
||||
if (ret == AXP_FAIL) {
|
||||
Serial.println("AXP Power begin failed");
|
||||
while (1);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
axp.setVWarningLevel1(3450);
|
||||
axp.setVWarningLevel2(3400);
|
||||
uint16_t level1 = axp.getVWarningLevel1();
|
||||
uint16_t level2 = axp.getVWarningLevel2();
|
||||
Serial.printf("getVWarningLevel1:%u mV \n", level1 );
|
||||
Serial.printf("getVWarningLevel2:%u mV \n", level2);
|
||||
Serial.printf("getPowerDonwVoltage:%u mV \n", axp.getPowerDownVoltage());
|
||||
axp.setPowerDownVoltage(2600);
|
||||
Serial.printf("getPowerDonwVoltage:%u mV \n", axp.getPowerDownVoltage());
|
||||
Serial.println();
|
||||
|
||||
//! attachInterrupt to gpio 35
|
||||
pinMode(axp_irq_pin, INPUT_PULLUP);
|
||||
attachInterrupt(axp_irq_pin, setFlag, FALLING);
|
||||
axp.clearIRQ();
|
||||
|
||||
//! enable all irq channel
|
||||
axp.enableIRQ(AXP202_ALL_IRQ, true);
|
||||
|
||||
axp.setPowerOutPut(AXP202_DCDC3, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP202_EXTEN, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP202_LDO2, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP202_LDO4, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP202_DCDC2, AXP202_ON);
|
||||
axp.setLDO4Voltage(AXP202_LDO4_3300MV);
|
||||
axp.setLDO3Voltage(3500);
|
||||
axp.setPowerOutPut(AXP202_LDO3, AXP202_ON);
|
||||
|
||||
Serial.print("DC2:");
|
||||
Serial.print(axp.isDCDC2Enable() ? String(axp.getDCDC2Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("DC3:");
|
||||
Serial.print(axp.isDCDC3Enable() ? String(axp.getDCDC3Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("LDO2:");
|
||||
Serial.print(axp.isLDO2Enable() ? String(axp.getLDO2Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("LDO3:");
|
||||
Serial.print(axp.isLDO3Enable() ? String(axp.getLDO3Voltage()) + " mv" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("LDO4:");
|
||||
Serial.print(axp.isLDO4Enable() ? "ENABLE" : "DISABLE");
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print("Exten:");
|
||||
Serial.print(axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
||||
Serial.print("\r\n");
|
||||
|
||||
axp.setTimer(1);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (axpIrq) {
|
||||
axpIrq = 0;
|
||||
axp.readIRQ();
|
||||
Serial.println("axp20x irq enter!");
|
||||
if (axp.isAcinOverVoltageIRQ()) {
|
||||
Serial.printf("isAcinOverVoltageIRQ\n");
|
||||
}
|
||||
if (axp.isAcinPlugInIRQ()) {
|
||||
Serial.printf("isAcinPlugInIRQ\n");
|
||||
}
|
||||
if (axp.isAcinRemoveIRQ()) {
|
||||
Serial.printf("isAcinRemoveIRQ\n");
|
||||
}
|
||||
if (axp.isVbusOverVoltageIRQ()) {
|
||||
Serial.printf("isVbusOverVoltageIRQ\n");
|
||||
}
|
||||
if (axp.isVbusPlugInIRQ()) {
|
||||
Serial.printf("isVbusPlugInIRQ\n");
|
||||
}
|
||||
if (axp.isVbusRemoveIRQ()) {
|
||||
Serial.printf("isVbusRemoveIRQ\n");
|
||||
}
|
||||
if (axp.isVbusLowVHOLDIRQ()) {
|
||||
Serial.printf("isVbusLowVHOLDIRQ\n");
|
||||
}
|
||||
if (axp.isBattPlugInIRQ()) {
|
||||
Serial.printf("isBattPlugInIRQ\n");
|
||||
}
|
||||
if (axp.isBattRemoveIRQ()) {
|
||||
Serial.printf("isBattRemoveIRQ\n");
|
||||
}
|
||||
if (axp.isBattEnterActivateIRQ()) {
|
||||
Serial.printf("isBattEnterActivateIRQ\n");
|
||||
}
|
||||
if (axp.isBattExitActivateIRQ()) {
|
||||
Serial.printf("isBattExitActivateIRQ\n");
|
||||
}
|
||||
if (axp.isChargingIRQ()) {
|
||||
Serial.printf("isChargingIRQ\n");
|
||||
}
|
||||
if (axp.isChargingDoneIRQ()) {
|
||||
Serial.printf("isChargingDoneIRQ\n");
|
||||
}
|
||||
if (axp.isBattTempLowIRQ()) {
|
||||
Serial.printf("isBattTempLowIRQ\n");
|
||||
}
|
||||
if (axp.isBattTempHighIRQ()) {
|
||||
Serial.printf("isBattTempHighIRQ\n");
|
||||
}
|
||||
if (axp.isChipOvertemperatureIRQ()) {
|
||||
Serial.printf("isChipOvertemperatureIRQ\n");
|
||||
}
|
||||
if (axp.isChargingCurrentLessIRQ()) {
|
||||
Serial.printf("isChargingCurrentLessIRQ\n");
|
||||
}
|
||||
if (axp.isDC2VoltageLessIRQ()) {
|
||||
Serial.printf("isDC2VoltageLessIRQ\n");
|
||||
}
|
||||
if (axp.isDC3VoltageLessIRQ()) {
|
||||
Serial.printf("isDC3VoltageLessIRQ\n");
|
||||
}
|
||||
if (axp.isLDO3VoltageLessIRQ()) {
|
||||
Serial.printf("isLDO3VoltageLessIRQ\n");
|
||||
}
|
||||
if (axp.isPEKShortPressIRQ()) {
|
||||
Serial.printf("isPEKShortPressIRQ\n");
|
||||
}
|
||||
if (axp.isPEKLongtPressIRQ()) {
|
||||
Serial.printf("isPEKLongtPressIRQ\n");
|
||||
}
|
||||
if (axp.isNOEPowerOnIRQ()) {
|
||||
Serial.printf("isNOEPowerOnIRQ\n");
|
||||
}
|
||||
if (axp.isNOEPowerDownIRQ()) {
|
||||
Serial.printf("isNOEPowerDownIRQ\n");
|
||||
}
|
||||
if (axp.isVBUSEffectiveIRQ()) {
|
||||
Serial.printf("isVBUSEffectiveIRQ\n");
|
||||
}
|
||||
if (axp.isVBUSInvalidIRQ()) {
|
||||
Serial.printf("isVBUSInvalidIRQ\n");
|
||||
}
|
||||
if (axp.isVUBSSessionIRQ()) {
|
||||
Serial.printf("isVUBSSessionIRQ\n");
|
||||
}
|
||||
if (axp.isVUBSSessionEndIRQ()) {
|
||||
Serial.printf("isVUBSSessionEndIRQ\n");
|
||||
}
|
||||
if (axp.isLowVoltageLevel1IRQ()) {
|
||||
Serial.printf("isLowVoltageLevel1IRQ\n");
|
||||
}
|
||||
if (axp.isLowVoltageLevel2IRQ()) {
|
||||
Serial.printf("isLowVoltageLevel2IRQ\n");
|
||||
}
|
||||
if (axp.isTimerTimeoutIRQ()) {
|
||||
Serial.printf("isTimerTimeoutIRQ\n");
|
||||
axp.offTimer();
|
||||
axp.setChgLEDMode(AXP20X_LED_BLINK_1HZ);
|
||||
}
|
||||
if (axp.isPEKRisingEdgeIRQ()) {
|
||||
Serial.printf("isPEKRisingEdgeIRQ\n");
|
||||
}
|
||||
if (axp.isPEKFallingEdgeIRQ()) {
|
||||
Serial.printf("isPEKFallingEdgeIRQ\n");
|
||||
}
|
||||
if (axp.isGPIO3InputEdgeTriggerIRQ()) {
|
||||
Serial.printf("isGPIO3InputEdgeTriggerIRQ\n");
|
||||
}
|
||||
if (axp.isGPIO2InputEdgeTriggerIRQ()) {
|
||||
Serial.printf("isGPIO2InputEdgeTriggerIRQ\n");
|
||||
}
|
||||
if (axp.isGPIO1InputEdgeTriggerIRQ()) {
|
||||
Serial.printf("isGPIO1InputEdgeTriggerIRQ\n");
|
||||
}
|
||||
if (axp.isGPIO0InputEdgeTriggerIRQ()) {
|
||||
Serial.printf("isGPIO0InputEdgeTriggerIRQ\n");
|
||||
}
|
||||
axp.clearIRQ();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
#include <Wire.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
AXP20X_Class axp;
|
||||
|
||||
const uint8_t i2c_sda = 21;
|
||||
const uint8_t i2c_scl = 22;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
delay(3000);
|
||||
|
||||
Wire.begin(i2c_sda, i2c_scl);
|
||||
|
||||
int ret = axp.begin(Wire);
|
||||
if (ret == AXP_FAIL) {
|
||||
Serial.println("AXP Power begin failed");
|
||||
while (1);
|
||||
}
|
||||
int cur = axp.getChargeControlCur();
|
||||
Serial.printf("Current charge control current = %d mA \n", cur);
|
||||
|
||||
|
||||
//axp202 allows maximum charging current of 1800mA, minimum 300mA
|
||||
axp.setChargeControlCur(500);
|
||||
Serial.printf("Set charge control current 500 mA \n");
|
||||
|
||||
//When the chip is axp192 / 173, the allowed values are 0 ~ 15,
|
||||
//corresponding to the axp1xx_charge_current_t enumeration
|
||||
// axp.setChargeControlCur(AXP1XX_CHARGE_CUR_550MA);
|
||||
// Serial.printf("Set charge control current 550 mA \n");
|
||||
|
||||
cur = axp.getChargeControlCur();
|
||||
Serial.printf("Current charge control current = %d mA \n", cur);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
@ -0,0 +1,115 @@
|
||||
#include <Wire.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
AXP20X_Class axp;
|
||||
|
||||
const uint8_t i2c_sda = 21;
|
||||
const uint8_t i2c_scl = 22;
|
||||
const uint8_t irq_pin = 35;
|
||||
|
||||
bool pmu_irq = false;
|
||||
|
||||
|
||||
void sleepPMU()
|
||||
{
|
||||
int ret;
|
||||
// PEK or GPIO edge wake-up function enable setting in Sleep mode
|
||||
do {
|
||||
// In order to ensure that it is set correctly,
|
||||
// the loop waits for it to return the correct return value
|
||||
Serial.println("Set PMU in sleep mode");
|
||||
ret = axp.setSleep();
|
||||
delay(500);
|
||||
} while (ret != AXP_PASS) ;
|
||||
|
||||
// Turn off all power channels, only use PEK or AXP GPIO to wake up
|
||||
|
||||
// After setting AXP202/AXP192 to sleep,
|
||||
// it will start to record the status of the power channel that was turned off after setting,
|
||||
// it will restore the previously set state after PEK button or GPIO wake up
|
||||
|
||||
|
||||
// Turn off all AXP192 power channels
|
||||
ret = axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
||||
Serial.printf("Set Power AXP192_LDO2:%s\n", ret == AXP_PASS ? "OK" : "FAIL");
|
||||