power.cpp added, i2cscan adapted
This commit is contained in:
parent
738543b529
commit
a1b7c102d0
@ -2,11 +2,15 @@
|
||||
#define _I2CSCAN_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef HAS_PMU
|
||||
#include "axp20x.h"
|
||||
#endif
|
||||
|
||||
#define SSD1306_PRIMARY_ADDRESS (0x3D)
|
||||
#define SSD1306_SECONDARY_ADDRESS (0x3C)
|
||||
#define BME_PRIMARY_ADDRESS (0x77)
|
||||
#define BME_SECONDARY_ADDRESS (0x76)
|
||||
#define AXP192_PRIMARY_ADDRESS (0x34)
|
||||
#define MCP_24AA02E64_PRIMARY_ADDRESS (0x50)
|
||||
#define QUECTEL_GPS_PRIMARY_ADDRESS (0x10)
|
||||
|
||||
int i2c_scan(void);
|
||||
void AXP192_init(void);
|
||||
|
||||
#endif
|
@ -7,6 +7,7 @@
|
||||
#include <esp_coexist.h> // needed for showing coex sw version
|
||||
|
||||
#include "globals.h"
|
||||
#include "power.h"
|
||||
#include "i2cscan.h"
|
||||
#include "blescan.h"
|
||||
#include "wifiscan.h"
|
||||
|
13
include/power.h
Normal file
13
include/power.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef _POWER_H
|
||||
#define _POWER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "i2cscan.h"
|
||||
|
||||
#ifdef HAS_PMU
|
||||
#include <axp20x.h>
|
||||
#endif
|
||||
|
||||
void AXP192_init(void);
|
||||
|
||||
#endif
|
@ -5,14 +5,6 @@
|
||||
// Local logging tag
|
||||
static const char TAG[] = __FILE__;
|
||||
|
||||
#define SSD1306_PRIMARY_ADDRESS (0x3D)
|
||||
#define SSD1306_SECONDARY_ADDRESS (0x3C)
|
||||
#define BME_PRIMARY_ADDRESS (0x77)
|
||||
#define BME_SECONDARY_ADDRESS (0x76)
|
||||
#define AXP192_PRIMARY_ADDRESS (0x34)
|
||||
#define MCP_24AA02E64_PRIMARY_ADDRESS (0x50)
|
||||
#define QUECTEL_GPS_PRIMARY_ADDRESS (0x10)
|
||||
|
||||
int i2c_scan(void) {
|
||||
|
||||
int i2c_ret, addr;
|
||||
@ -49,9 +41,6 @@ int i2c_scan(void) {
|
||||
|
||||
case AXP192_PRIMARY_ADDRESS:
|
||||
ESP_LOGI(TAG, "0x%X: AXP192 power management", addr);
|
||||
#ifdef HAS_PMU
|
||||
AXP192_init();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case QUECTEL_GPS_PRIMARY_ADDRESS:
|
||||
@ -73,42 +62,3 @@ int i2c_scan(void) {
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
#ifdef HAS_PMU
|
||||
|
||||
void AXP192_init(void) {
|
||||
|
||||
AXP20X_Class axp;
|
||||
|
||||
if (axp.begin(Wire, AXP192_PRIMARY_ADDRESS))
|
||||
ESP_LOGI(TAG, "AXP192 PMU initialization failed");
|
||||
else {
|
||||
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
axp.setDCDC1Voltage(3300);
|
||||
axp.setChgLEDMode(AXP20X_LED_BLINK_1HZ);
|
||||
// axp.setChgLEDMode(AXP20X_LED_OFF);
|
||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
||||
|
||||
#ifdef PMU_INT
|
||||
pinMode(PMU_INT, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(PMU_INT),
|
||||
[] {
|
||||
ESP_LOGI(TAG, "Power source changed");
|
||||
/* put your code here */
|
||||
},
|
||||
FALLING);
|
||||
axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ |
|
||||
AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ,
|
||||
1);
|
||||
axp.clearIRQ();
|
||||
#endif // PMU_INT
|
||||
|
||||
ESP_LOGI(TAG, "AXP192 PMU initialized.");
|
||||
}
|
||||
}
|
||||
#endif // HAS_PMU
|
18
src/main.cpp
18
src/main.cpp
@ -169,6 +169,17 @@ void setup() {
|
||||
ESP_LOGI(TAG, "TinyGPS+ version %s", TinyGPSPlus::libraryVersion());
|
||||
#endif
|
||||
|
||||
// setup power on boards with power management logic
|
||||
#ifdef EXT_POWER_SW
|
||||
pinMode(EXT_POWER_SW, OUTPUT);
|
||||
digitalWrite(EXT_POWER_SW, EXT_POWER_ON);
|
||||
strcat_P(features, " VEXT");
|
||||
#endif
|
||||
#ifdef HAS_PMU
|
||||
AXP192_init();
|
||||
strcat_P(features, " PMU");
|
||||
#endif
|
||||
|
||||
i2c_scan();
|
||||
|
||||
#endif // verbose
|
||||
@ -189,13 +200,6 @@ void setup() {
|
||||
strcat_P(features, " PSRAM");
|
||||
#endif
|
||||
|
||||
// set external power mode
|
||||
#ifdef EXT_POWER_SW
|
||||
pinMode(EXT_POWER_SW, OUTPUT);
|
||||
digitalWrite(EXT_POWER_SW, EXT_POWER_ON);
|
||||
strcat_P(features, " VEXT");
|
||||
#endif
|
||||
|
||||
#ifdef BAT_MEASURE_EN
|
||||
pinMode(BAT_MEASURE_EN, OUTPUT);
|
||||
#endif
|
||||
|
42
src/power.cpp
Normal file
42
src/power.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// Basic config
|
||||
#include "globals.h"
|
||||
#include "power.h"
|
||||
|
||||
#ifdef HAS_PMU
|
||||
|
||||
void AXP192_init(void) {
|
||||
|
||||
AXP20X_Class axp;
|
||||
|
||||
if (axp.begin(Wire, AXP192_PRIMARY_ADDRESS))
|
||||
ESP_LOGI(TAG, "AXP192 PMU initialization failed");
|
||||
else {
|
||||
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
axp.setDCDC1Voltage(3300);
|
||||
axp.setChgLEDMode(AXP20X_LED_BLINK_1HZ);
|
||||
// axp.setChgLEDMode(AXP20X_LED_OFF);
|
||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
||||
|
||||
#ifdef PMU_INT
|
||||
pinMode(PMU_INT, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(PMU_INT),
|
||||
[] {
|
||||
ESP_LOGI(TAG, "Power source changed");
|
||||
/* put your code here */
|
||||
},
|
||||
FALLING);
|
||||
axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ |
|
||||
AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ,
|
||||
1);
|
||||
axp.clearIRQ();
|
||||
#endif // PMU_INT
|
||||
|
||||
ESP_LOGI(TAG, "AXP192 PMU initialized.");
|
||||
}
|
||||
}
|
||||
#endif // HAS_PMU
|
Loading…
Reference in New Issue
Block a user