kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_Tracker
add T-Beam v1.2 AXP2101
rodzic
91319291b1
commit
b638d95153
|
@ -12,7 +12,7 @@ AlignOperands: Align
|
||||||
AlignTrailingComments: true
|
AlignTrailingComments: true
|
||||||
AllowAllArgumentsOnNextLine: true
|
AllowAllArgumentsOnNextLine: true
|
||||||
AllowAllConstructorInitializersOnNextLine: true
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
AllowAllParametersOfDeclarationOnNextLine: true
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortEnumsOnASingleLine: false
|
AllowShortEnumsOnASingleLine: false
|
||||||
AllowShortBlocksOnASingleLine: Never
|
AllowShortBlocksOnASingleLine: Never
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
@ -24,8 +24,8 @@ AlwaysBreakAfterDefinitionReturnType: None
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: false
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
AlwaysBreakTemplateDeclarations: MultiLine
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
BinPackArguments: true
|
BinPackArguments: false
|
||||||
BinPackParameters: true
|
BinPackParameters: false
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
AfterCaseLabel: false
|
AfterCaseLabel: false
|
||||||
AfterClass: false
|
AfterClass: false
|
||||||
|
@ -54,7 +54,7 @@ BreakConstructorInitializersBeforeComma: false
|
||||||
BreakConstructorInitializers: BeforeColon
|
BreakConstructorInitializers: BeforeColon
|
||||||
BreakAfterJavaFieldAnnotations: false
|
BreakAfterJavaFieldAnnotations: false
|
||||||
BreakStringLiterals: true
|
BreakStringLiterals: true
|
||||||
ColumnLimit: 500
|
ColumnLimit: 200
|
||||||
CommentPragmas: '^ IWYU pragma:'
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
|
|
@ -11,7 +11,7 @@ lib_deps =
|
||||||
adafruit/Adafruit GFX Library @ 1.11.5
|
adafruit/Adafruit GFX Library @ 1.11.5
|
||||||
adafruit/Adafruit SSD1306 @ 2.5.7
|
adafruit/Adafruit SSD1306 @ 2.5.7
|
||||||
bblanchon/ArduinoJson @ 6.21.2
|
bblanchon/ArduinoJson @ 6.21.2
|
||||||
lewisxhe/AXP202X_Library @ 1.1.3
|
lewisxhe/XPowersLib @ 0.1.8
|
||||||
sandeepmistry/LoRa @ 0.8.0
|
sandeepmistry/LoRa @ 0.8.0
|
||||||
peterus/APRS-Decoder-Lib @ 0.0.6
|
peterus/APRS-Decoder-Lib @ 0.0.6
|
||||||
mikalhart/TinyGPSPlus @ 1.0.3
|
mikalhart/TinyGPSPlus @ 1.0.3
|
||||||
|
@ -23,6 +23,10 @@ check_flags =
|
||||||
cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK
|
cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK
|
||||||
check_skip_packages = yes
|
check_skip_packages = yes
|
||||||
|
|
||||||
|
[env:ttgo-t-beam-AXP2101-v1_2]
|
||||||
|
board = ttgo-t-beam
|
||||||
|
build_flags = -Werror -Wall -DTTGO_T_Beam_V1_2
|
||||||
|
|
||||||
[env:ttgo-t-beam-v1]
|
[env:ttgo-t-beam-v1]
|
||||||
board = ttgo-t-beam
|
board = ttgo-t-beam
|
||||||
build_flags = -Werror -Wall -DTTGO_T_Beam_V1_0
|
build_flags = -Werror -Wall -DTTGO_T_Beam_V1_0
|
||||||
|
|
|
@ -13,15 +13,22 @@
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
#include "power_management.h"
|
#include "power_management.h"
|
||||||
|
|
||||||
#define VERSION "22.19.0"
|
#define VERSION "23.36.0"
|
||||||
|
|
||||||
logging::Logger logger;
|
logging::Logger logger;
|
||||||
|
|
||||||
Configuration Config;
|
Configuration Config;
|
||||||
BeaconManager BeaconMan;
|
BeaconManager BeaconMan;
|
||||||
|
|
||||||
PowerManagement powerManagement;
|
#ifdef TTGO_T_Beam_V1_0
|
||||||
OneButton userButton = OneButton(BUTTON_PIN, true, true);
|
AXP192 axp;
|
||||||
|
PowerManagement *powerManagement = &axp;
|
||||||
|
#endif
|
||||||
|
#ifdef TTGO_T_Beam_V1_2
|
||||||
|
AXP2101 axp;
|
||||||
|
PowerManagement *powerManagement = &axp;
|
||||||
|
#endif
|
||||||
|
OneButton userButton = OneButton(BUTTON_PIN, true, true);
|
||||||
|
|
||||||
HardwareSerial ss(1);
|
HardwareSerial ss(1);
|
||||||
TinyGPSPlus gps;
|
TinyGPSPlus gps;
|
||||||
|
@ -66,15 +73,27 @@ void setup() {
|
||||||
|
|
||||||
#ifdef TTGO_T_Beam_V1_0
|
#ifdef TTGO_T_Beam_V1_0
|
||||||
Wire.begin(SDA, SCL);
|
Wire.begin(SDA, SCL);
|
||||||
if (!powerManagement.begin(Wire)) {
|
if (powerManagement->begin(Wire)) {
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP192", "init done!");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP192", "init done!");
|
||||||
} else {
|
} else {
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP192", "init failed!");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP192", "init failed!");
|
||||||
}
|
}
|
||||||
powerManagement.activateLoRa();
|
powerManagement->activateLoRa();
|
||||||
powerManagement.activateOLED();
|
powerManagement->activateOLED();
|
||||||
powerManagement.activateGPS();
|
powerManagement->activateGPS();
|
||||||
powerManagement.activateMeasurement();
|
powerManagement->activateMeasurement();
|
||||||
|
#endif
|
||||||
|
#ifdef TTGO_T_Beam_V1_2
|
||||||
|
Wire.begin(SDA, SCL);
|
||||||
|
if (powerManagement->begin(Wire)) {
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP2101", "init done!");
|
||||||
|
} else {
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP2101", "init failed!");
|
||||||
|
}
|
||||||
|
powerManagement->activateLoRa();
|
||||||
|
powerManagement->activateOLED();
|
||||||
|
powerManagement->activateGPS();
|
||||||
|
powerManagement->activateMeasurement();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
|
@ -180,20 +199,15 @@ void loop() {
|
||||||
static String batteryChargeCurrent = "";
|
static String batteryChargeCurrent = "";
|
||||||
#ifdef TTGO_T_Beam_V1_0
|
#ifdef TTGO_T_Beam_V1_0
|
||||||
static unsigned int rate_limit_check_battery = 0;
|
static unsigned int rate_limit_check_battery = 0;
|
||||||
if (!(rate_limit_check_battery++ % 60))
|
if (!(rate_limit_check_battery++ % 60)) {
|
||||||
BatteryIsConnected = powerManagement.isBatteryConnect();
|
BatteryIsConnected = powerManagement->isBatteryConnect();
|
||||||
|
}
|
||||||
if (BatteryIsConnected) {
|
if (BatteryIsConnected) {
|
||||||
batteryVoltage = String(powerManagement.getBatteryVoltage(), 2);
|
batteryVoltage = String(powerManagement->getBatteryVoltage(), 2);
|
||||||
batteryChargeCurrent = String(powerManagement.getBatteryChargeDischargeCurrent(), 0);
|
batteryChargeCurrent = String(powerManagement->getBatteryChargeDischargeCurrent(), 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (powerManagement.isChargeing()) {
|
|
||||||
powerManagement.enableChgLed();
|
|
||||||
} else {
|
|
||||||
powerManagement.disableChgLed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!send_update && gps_loc_update && BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) {
|
if (!send_update && gps_loc_update && BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) {
|
||||||
uint32_t lastTx = millis() - lastTxTime;
|
uint32_t lastTx = millis() - lastTxTime;
|
||||||
currentHeading = gps.course.deg();
|
currentHeading = gps.course.deg();
|
||||||
|
@ -222,7 +236,8 @@ void loop() {
|
||||||
if (send_update && gps_loc_update) {
|
if (send_update && gps_loc_update) {
|
||||||
send_update = false;
|
send_update = false;
|
||||||
|
|
||||||
nextBeaconTimeStamp = now() + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate : (BeaconMan.getCurrentBeaconConfig()->timeout * SECS_PER_MIN));
|
nextBeaconTimeStamp =
|
||||||
|
now() + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate : (BeaconMan.getCurrentBeaconConfig()->timeout * SECS_PER_MIN));
|
||||||
|
|
||||||
APRSMessage msg;
|
APRSMessage msg;
|
||||||
String lat;
|
String lat;
|
||||||
|
@ -328,7 +343,20 @@ void loop() {
|
||||||
|
|
||||||
if (gps_time_update) {
|
if (gps_time_update) {
|
||||||
|
|
||||||
show_display(BeaconMan.getCurrentBeaconConfig()->callsign, createDateString(now()) + " " + createTimeString(now()), String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp), BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB", String("Smart Beacon: " + getSmartBeaconState()));
|
show_display(BeaconMan.getCurrentBeaconConfig()->callsign,
|
||||||
|
createDateString(now()) + " " + createTimeString(now()),
|
||||||
|
String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(),
|
||||||
|
String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp),
|
||||||
|
BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB",
|
||||||
|
String("Smart Beacon: " + getSmartBeaconState()));
|
||||||
|
|
||||||
|
Serial.println(BeaconMan.getCurrentBeaconConfig()->callsign);
|
||||||
|
Serial.println(createDateString(now()) + " " + createTimeString(now()));
|
||||||
|
Serial.println(String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop());
|
||||||
|
Serial.println(String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp));
|
||||||
|
Serial.println(BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB");
|
||||||
|
Serial.println(String("Smart Beacon: " + getSmartBeaconState()));
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) {
|
if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) {
|
||||||
// Change the Tx internal based on the current speed
|
// Change the Tx internal based on the current speed
|
||||||
|
@ -348,13 +376,16 @@ void loop() {
|
||||||
would lead to decrease of beacon rate in between 5 to 20 km/h. what
|
would lead to decrease of beacon rate in between 5 to 20 km/h. what
|
||||||
is even below the slow speed rate.
|
is even below the slow speed rate.
|
||||||
*/
|
*/
|
||||||
txInterval = min(BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate, BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed * BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate / curr_speed) * 1000;
|
txInterval = min(BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate,
|
||||||
|
BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed * BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate / curr_speed) *
|
||||||
|
1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) {
|
if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) {
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "GPS",
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR,
|
||||||
|
"GPS",
|
||||||
"No GPS frames detected! Try to reset the GPS Chip with this "
|
"No GPS frames detected! Try to reset the GPS Chip with this "
|
||||||
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
|
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
|
||||||
show_display("No GPS frames detected!", "Try to reset the GPS Chip", "https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset", 2000);
|
show_display("No GPS frames detected!", "Try to reset the GPS Chip", "https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset", 2000);
|
||||||
|
@ -366,11 +397,13 @@ void load_config() {
|
||||||
Config = confmg.readConfiguration();
|
Config = confmg.readConfiguration();
|
||||||
BeaconMan.loadConfig(Config.beacons);
|
BeaconMan.loadConfig(Config.beacons);
|
||||||
if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-7") {
|
if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-7") {
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Config",
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR,
|
||||||
|
"Config",
|
||||||
"You have to change your settings in 'data/tracker.json' and "
|
"You have to change your settings in 'data/tracker.json' and "
|
||||||
"upload it via \"Upload File System image\"!");
|
"upload it via \"Upload File System image\"!");
|
||||||
show_display("ERROR", "You have to change your settings in 'data/tracker.json' and "
|
show_display("ERROR",
|
||||||
"upload it via \"Upload File System image\"!");
|
"You have to change your settings in 'data/tracker.json' and "
|
||||||
|
"upload it via \"Upload File System image\"!");
|
||||||
while (true) {
|
while (true) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#define GPS_TX 12
|
#define GPS_TX 12
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TTGO_T_Beam_V1_0
|
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
|
||||||
#define GPS_RX 12
|
#define GPS_RX 12
|
||||||
#define GPS_TX 34
|
#define GPS_TX 34
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,86 +1,218 @@
|
||||||
|
#include <XPowersAXP192.tpp>
|
||||||
|
#include <XPowersAXP2101.tpp>
|
||||||
|
|
||||||
#include "power_management.h"
|
#include "power_management.h"
|
||||||
|
|
||||||
// cppcheck-suppress uninitMemberVar
|
AXP192::AXP192() {
|
||||||
PowerManagement::PowerManagement() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
bool PowerManagement::begin(TwoWire &port) {
|
bool AXP192::begin(TwoWire &port) {
|
||||||
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
_pmu = new XPowersAXP192(port);
|
||||||
if (!result) {
|
if (!_pmu->init()) {
|
||||||
axp.setDCDC1Voltage(3300);
|
delete _pmu;
|
||||||
|
_pmu = 0;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
// lora radio power channel
|
||||||
|
_pmu->setPowerChannelVoltage(XPOWERS_LDO2, 3300);
|
||||||
|
|
||||||
|
// oled module power channel,
|
||||||
|
// disable it will cause abnormal communication between boot and AXP power supply,
|
||||||
|
// do not turn it off
|
||||||
|
_pmu->setPowerChannelVoltage(XPOWERS_DCDC1, 3300);
|
||||||
|
|
||||||
|
// gnss module power channel - now turned on in setGpsPower
|
||||||
|
_pmu->setPowerChannelVoltage(XPOWERS_LDO3, 3300);
|
||||||
|
|
||||||
|
// protected oled power source
|
||||||
|
//_pmu->setProtectedChannel(XPOWERS_DCDC1);
|
||||||
|
// protected esp32 power source
|
||||||
|
_pmu->setProtectedChannel(XPOWERS_DCDC3);
|
||||||
|
|
||||||
|
// disable not use channel
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DCDC2);
|
||||||
|
|
||||||
|
// disable all axp chip interrupt
|
||||||
|
_pmu->disableIRQ(XPOWERS_AXP192_ALL_IRQ);
|
||||||
|
|
||||||
|
// Set constant current charging current
|
||||||
|
_pmu->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_780MA);
|
||||||
|
|
||||||
|
// Set up the charging voltage
|
||||||
|
_pmu->setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2);
|
||||||
|
|
||||||
|
_pmu->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateLoRa() {
|
void AXP192::activateLoRa() {
|
||||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
_pmu->enablePowerOutput(XPOWERS_LDO2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::deactivateLoRa() {
|
void AXP192::deactivateLoRa() {
|
||||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
_pmu->disablePowerOutput(XPOWERS_LDO2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateGPS() {
|
void AXP192::activateGPS() {
|
||||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
_pmu->enablePowerOutput(XPOWERS_LDO3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::deactivateGPS() {
|
void AXP192::deactivateGPS() {
|
||||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
_pmu->disablePowerOutput(XPOWERS_LDO3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateOLED() {
|
void AXP192::activateOLED() {
|
||||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
_pmu->enablePowerOutput(XPOWERS_DCDC1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::decativateOLED() {
|
void AXP192::deactivateOLED() {
|
||||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
_pmu->disablePowerOutput(XPOWERS_DCDC1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::disableChgLed() {
|
void AXP192::activateMeasurement() {
|
||||||
axp.setChgLEDMode(AXP20X_LED_OFF);
|
_pmu->enableBattVoltageMeasure();
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::enableChgLed() {
|
void AXP192::deactivateMeasurement() {
|
||||||
axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
|
_pmu->disableBattVoltageMeasure();
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::activateMeasurement() {
|
double AXP192::getBatteryVoltage() {
|
||||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
|
return _pmu->getBattVoltage() / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
void PowerManagement::deactivateMeasurement() {
|
double AXP192::getBatteryChargeDischargeCurrent() {
|
||||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
|
if (isCharging()) {
|
||||||
}
|
return ((XPowersAXP192 *)_pmu)->getBatteryChargeCurrent();
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
|
||||||
double PowerManagement::getBatteryVoltage() {
|
|
||||||
return axp.getBattVoltage() / 1000.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cppcheck-suppress unusedFunction
|
|
||||||
double PowerManagement::getBatteryChargeDischargeCurrent() {
|
|
||||||
if (axp.isChargeing()) {
|
|
||||||
return axp.getBattChargeCurrent();
|
|
||||||
}
|
}
|
||||||
return -1.0 * axp.getBattDischargeCurrent();
|
return -1.0 * ((XPowersAXP192 *)_pmu)->getBattDischargeCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerManagement::isBatteryConnect() {
|
bool AXP192::isBatteryConnect() {
|
||||||
return axp.isBatteryConnect();
|
return _pmu->isBatteryConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PowerManagement::isChargeing() {
|
bool AXP192::isCharging() {
|
||||||
return axp.isChargeing();
|
return _pmu->isCharging();
|
||||||
|
}
|
||||||
|
|
||||||
|
AXP2101::AXP2101() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
bool AXP2101::begin(TwoWire &port) {
|
||||||
|
_pmu = new XPowersAXP2101(port);
|
||||||
|
if (!_pmu->init()) {
|
||||||
|
delete _pmu;
|
||||||
|
_pmu = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unuse power channel
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DCDC2);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DCDC3);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DCDC4);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DCDC5);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_ALDO1);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_ALDO4);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_BLDO1);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_BLDO2);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DLDO1);
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DLDO2);
|
||||||
|
|
||||||
|
// GNSS RTC PowerVDD 3300mV
|
||||||
|
_pmu->setPowerChannelVoltage(XPOWERS_VBACKUP, 3300);
|
||||||
|
_pmu->enablePowerOutput(XPOWERS_VBACKUP);
|
||||||
|
|
||||||
|
// LoRa VDD 3300mV
|
||||||
|
_pmu->setPowerChannelVoltage(XPOWERS_ALDO2, 3300);
|
||||||
|
_pmu->enablePowerOutput(XPOWERS_ALDO2);
|
||||||
|
|
||||||
|
// GNSS VDD 3300mV
|
||||||
|
_pmu->setPowerChannelVoltage(XPOWERS_ALDO3, 3300);
|
||||||
|
_pmu->enablePowerOutput(XPOWERS_ALDO3);
|
||||||
|
|
||||||
|
// disable all axp chip interrupt
|
||||||
|
_pmu->disableIRQ(XPOWERS_AXP192_ALL_IRQ);
|
||||||
|
|
||||||
|
// Set constant current charging current
|
||||||
|
_pmu->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_780MA);
|
||||||
|
|
||||||
|
// Set up the charging voltage
|
||||||
|
_pmu->setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2);
|
||||||
|
|
||||||
|
_pmu->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::activateLoRa() {
|
||||||
|
_pmu->enablePowerOutput(XPOWERS_ALDO2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::deactivateLoRa() {
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_ALDO2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::activateGPS() {
|
||||||
|
_pmu->enablePowerOutput(XPOWERS_ALDO3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::deactivateGPS() {
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_ALDO3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::activateOLED() {
|
||||||
|
_pmu->enablePowerOutput(XPOWERS_DCDC1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::deactivateOLED() {
|
||||||
|
_pmu->disablePowerOutput(XPOWERS_DCDC1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::activateMeasurement() {
|
||||||
|
_pmu->enableBattVoltageMeasure();
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
void AXP2101::deactivateMeasurement() {
|
||||||
|
_pmu->disableBattVoltageMeasure();
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
double AXP2101::getBatteryVoltage() {
|
||||||
|
return _pmu->getBattVoltage() / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
double AXP2101::getBatteryChargeDischargeCurrent() {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AXP2101::isBatteryConnect() {
|
||||||
|
return _pmu->isBatteryConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AXP2101::isCharging() {
|
||||||
|
return _pmu->isCharging();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,43 @@
|
||||||
#ifndef POWER_MANAGEMENT_H_
|
#ifndef POWER_MANAGEMENT_H_
|
||||||
#define POWER_MANAGEMENT_H_
|
#define POWER_MANAGEMENT_H_
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Wire.h>
|
||||||
#include <axp20x.h>
|
#include <XPowersLibInterface.hpp>
|
||||||
|
|
||||||
class PowerManagement {
|
class PowerManagement {
|
||||||
public:
|
public:
|
||||||
PowerManagement();
|
~PowerManagement() {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool begin(TwoWire &port) = 0;
|
||||||
|
|
||||||
|
virtual void activateLoRa() = 0;
|
||||||
|
virtual void deactivateLoRa() = 0;
|
||||||
|
|
||||||
|
virtual void activateGPS() = 0;
|
||||||
|
virtual void deactivateGPS() = 0;
|
||||||
|
|
||||||
|
virtual void activateOLED() = 0;
|
||||||
|
virtual void deactivateOLED() = 0;
|
||||||
|
|
||||||
|
virtual void activateMeasurement() = 0;
|
||||||
|
virtual void deactivateMeasurement() = 0;
|
||||||
|
|
||||||
|
virtual double getBatteryVoltage() = 0;
|
||||||
|
|
||||||
|
virtual double getBatteryChargeDischargeCurrent() = 0;
|
||||||
|
|
||||||
|
virtual bool isBatteryConnect() = 0;
|
||||||
|
virtual bool isCharging() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
XPowersLibInterface *_pmu = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AXP192 : public PowerManagement {
|
||||||
|
public:
|
||||||
|
AXP192();
|
||||||
|
|
||||||
bool begin(TwoWire &port);
|
bool begin(TwoWire &port);
|
||||||
|
|
||||||
void activateLoRa();
|
void activateLoRa();
|
||||||
|
@ -16,7 +47,7 @@ public:
|
||||||
void deactivateGPS();
|
void deactivateGPS();
|
||||||
|
|
||||||
void activateOLED();
|
void activateOLED();
|
||||||
void decativateOLED();
|
void deactivateOLED();
|
||||||
|
|
||||||
void enableChgLed();
|
void enableChgLed();
|
||||||
void disableChgLed();
|
void disableChgLed();
|
||||||
|
@ -28,10 +59,35 @@ public:
|
||||||
double getBatteryChargeDischargeCurrent();
|
double getBatteryChargeDischargeCurrent();
|
||||||
|
|
||||||
bool isBatteryConnect();
|
bool isBatteryConnect();
|
||||||
bool isChargeing();
|
bool isCharging();
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
class AXP2101 : public PowerManagement {
|
||||||
AXP20X_Class axp;
|
public:
|
||||||
|
AXP2101();
|
||||||
|
|
||||||
|
bool begin(TwoWire &port);
|
||||||
|
|
||||||
|
void activateLoRa();
|
||||||
|
void deactivateLoRa();
|
||||||
|
|
||||||
|
void activateGPS();
|
||||||
|
void deactivateGPS();
|
||||||
|
|
||||||
|
void activateOLED();
|
||||||
|
void deactivateOLED();
|
||||||
|
|
||||||
|
void enableChgLed();
|
||||||
|
void disableChgLed();
|
||||||
|
|
||||||
|
void activateMeasurement();
|
||||||
|
void deactivateMeasurement();
|
||||||
|
|
||||||
|
double getBatteryVoltage();
|
||||||
|
double getBatteryChargeDischargeCurrent();
|
||||||
|
|
||||||
|
bool isBatteryConnect();
|
||||||
|
bool isCharging();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Ładowanie…
Reference in New Issue