mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-01 11:25:44 +00:00
Add tbeam esp32s3 version support, replace AXP202X_Library with XPowersLIb
This commit is contained in:
parent
f767fd5075
commit
5621719eef
48
boards/tbeam-s3-core.json
Normal file
48
boards/tbeam-s3-core.json
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"arduino":{
|
||||||
|
"ldscript": "esp32s3_out.ld"
|
||||||
|
},
|
||||||
|
"core": "esp32",
|
||||||
|
"extra_flags": [
|
||||||
|
"-DBOARD_HAS_PSRAM",
|
||||||
|
"-DLILYGO_TBEAM_S3_CORE",
|
||||||
|
"-DARDUINO_USB_CDC_ON_BOOT=1",
|
||||||
|
"-DARDUINO_USB_DFU_ON_BOOT=1",
|
||||||
|
"-DARDUINO_USB_MSC_ON_BOOT=1",
|
||||||
|
"-DARDUINO_USB_MODE=1",
|
||||||
|
"-DARDUINO_RUNNING_CORE=1",
|
||||||
|
"-DARDUINO_EVENT_RUNNING_CORE=1"
|
||||||
|
],
|
||||||
|
"f_cpu": "240000000L",
|
||||||
|
"f_flash": "80000000L",
|
||||||
|
"flash_mode": "dio",
|
||||||
|
"hwids": [
|
||||||
|
[
|
||||||
|
"0X303A",
|
||||||
|
"0x1001"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"mcu": "esp32s3",
|
||||||
|
"variant": "tbeam-s3-core"
|
||||||
|
},
|
||||||
|
"connectivity": [
|
||||||
|
"wifi"
|
||||||
|
],
|
||||||
|
"debug": {
|
||||||
|
"openocd_target": "esp32s3.cfg"
|
||||||
|
},
|
||||||
|
"frameworks": [
|
||||||
|
"arduino"
|
||||||
|
],
|
||||||
|
"name": "LilyGo TBeam-S3-Core",
|
||||||
|
"upload": {
|
||||||
|
"flash_size": "8MB",
|
||||||
|
"maximum_ram_size": 327680,
|
||||||
|
"maximum_size": 8388608,
|
||||||
|
"require_upload_port": true,
|
||||||
|
"speed": 921600
|
||||||
|
},
|
||||||
|
"url": "http://www.lilygo.cn/",
|
||||||
|
"vendor": "LilyGo"
|
||||||
|
}
|
@ -2,8 +2,8 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
; default_envs = tbeam
|
default_envs = tbeam
|
||||||
default_envs = tbeam-s3
|
;default_envs = tbeam-s3-core
|
||||||
;default_envs = tbeam0.7
|
;default_envs = tbeam0.7
|
||||||
;default_envs = heltec-v1
|
;default_envs = heltec-v1
|
||||||
;default_envs = heltec-v2.0
|
;default_envs = heltec-v2.0
|
||||||
@ -14,7 +14,7 @@ default_envs = tbeam-s3
|
|||||||
;default_envs = tlora-v2
|
;default_envs = tlora-v2
|
||||||
;default_envs = tlora-v2-1-1.6
|
;default_envs = tlora-v2-1-1.6
|
||||||
;default_envs = lora-relay-v1 # nrf board
|
;default_envs = lora-relay-v1 # nrf board
|
||||||
;default_envs = t-echo
|
; default_envs = t-echo
|
||||||
;default_envs = nrf52840dk-geeksville
|
;default_envs = nrf52840dk-geeksville
|
||||||
;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here
|
;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here
|
||||||
;default_envs = nano-g1
|
;default_envs = nano-g1
|
||||||
@ -111,8 +111,8 @@ lib_deps =
|
|||||||
h2zero/NimBLE-Arduino@1.4.0
|
h2zero/NimBLE-Arduino@1.4.0
|
||||||
arduino-libraries/NTPClient@^3.1.0
|
arduino-libraries/NTPClient@^3.1.0
|
||||||
lorol/LittleFS_esp32@^1.0.6
|
lorol/LittleFS_esp32@^1.0.6
|
||||||
https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460
|
https://github.com/lewisxhe/XPowersLib.git
|
||||||
|
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
segger_rtt
|
segger_rtt
|
||||||
ESP32 BLE Arduino
|
ESP32 BLE Arduino
|
||||||
@ -212,7 +212,8 @@ extends = arduino_base
|
|||||||
platform = espressif32
|
platform = espressif32
|
||||||
build_src_filter =
|
build_src_filter =
|
||||||
${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/stm32wl> -<platform/rp2040>
|
${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/stm32wl> -<platform/rp2040>
|
||||||
upload_speed = 115200
|
upload_speed = 961200
|
||||||
|
monitor_speed = 115200
|
||||||
debug_init_break = tbreak setup
|
debug_init_break = tbreak setup
|
||||||
|
|
||||||
# Remove -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL for low level BLE logging.
|
# Remove -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL for low level BLE logging.
|
||||||
@ -223,7 +224,7 @@ build_flags =
|
|||||||
-Wall
|
-Wall
|
||||||
-Wextra
|
-Wextra
|
||||||
-Isrc/platform/esp32
|
-Isrc/platform/esp32
|
||||||
-lnimble -std=c++11
|
-std=c++11
|
||||||
-DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG
|
-DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||||
-DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL
|
-DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL
|
||||||
@ -236,14 +237,21 @@ lib_deps =
|
|||||||
${arduino_base.lib_deps}
|
${arduino_base.lib_deps}
|
||||||
${networking_base.lib_deps}
|
${networking_base.lib_deps}
|
||||||
${environmental_base.lib_deps}
|
${environmental_base.lib_deps}
|
||||||
https://github.com/meshtastic/esp32_https_server.git
|
; https://github.com/meshtastic/esp32_https_server.git
|
||||||
|
; PR has been submitted and can be deleted after merging ,https://github.com/meshtastic/esp32_https_server/pull/1
|
||||||
|
https://github.com/lewisxhe/esp32_https_server.git
|
||||||
h2zero/NimBLE-Arduino@1.4.0
|
h2zero/NimBLE-Arduino@1.4.0
|
||||||
arduino-libraries/NTPClient@^3.1.0
|
arduino-libraries/NTPClient@^3.1.0
|
||||||
lorol/LittleFS_esp32@^1.0.6
|
https://github.com/lewisxhe/XPowersLib.git
|
||||||
; https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460
|
|
||||||
|
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
segger_rtt
|
segger_rtt
|
||||||
ESP32 BLE Arduino
|
ESP32 BLE Arduino
|
||||||
platform_packages =
|
platform_packages =
|
||||||
framework-arduinoespressif32 @ 3.20004.220825
|
framework-arduinoespressif32@ 3.20004.220825
|
||||||
|
|
||||||
|
; customize the partition table
|
||||||
|
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
|
||||||
|
board_build.partitions = partition-table.csv
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class ButtonThread : public concurrency::OSThread
|
|||||||
#endif
|
#endif
|
||||||
// If user button is held down for 5 seconds, shutdown the device.
|
// If user button is held down for 5 seconds, shutdown the device.
|
||||||
if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0)) {
|
if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0)) {
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
if (axp192_found == true) {
|
if (axp192_found == true) {
|
||||||
setLed(false);
|
setLed(false);
|
||||||
power->shutdown();
|
power->shutdown();
|
||||||
|
@ -23,9 +23,16 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARCH_ESP32)
|
#if defined(ARCH_ESP32)
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
#include <LittleFS.h> //esp32s3 uses the framework's built-in LittleFS
|
||||||
|
#define FSCom LittleFS
|
||||||
|
#else
|
||||||
// ESP32 version
|
// ESP32 version
|
||||||
#include "LITTLEFS.h"
|
#include "LITTLEFS.h"
|
||||||
#define FSCom LITTLEFS
|
#define FSCom LITTLEFS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define FSBegin() FSCom.begin(true)
|
#define FSBegin() FSCom.begin(true)
|
||||||
#define FILE_O_WRITE "w"
|
#define FILE_O_WRITE "w"
|
||||||
#define FILE_O_READ "r"
|
#define FILE_O_READ "r"
|
||||||
|
425
src/Power.cpp
425
src/Power.cpp
@ -7,10 +7,11 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "buzz/buzz.h"
|
#include "buzz/buzz.h"
|
||||||
|
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
#include "axp20x.h"
|
#include "XPowersLibInterface.hpp"
|
||||||
|
#include "XPowersAXP2101.tpp"
|
||||||
AXP20X_Class axp;
|
#include "XPowersAXP192.tpp"
|
||||||
|
XPowersLibInterface *PMU = NULL;
|
||||||
#else
|
#else
|
||||||
// Copy of the base class defined in axp20x.h.
|
// Copy of the base class defined in axp20x.h.
|
||||||
// I'd rather not inlude axp20x.h as it brings Wire dependency.
|
// I'd rather not inlude axp20x.h as it brings Wire dependency.
|
||||||
@ -20,20 +21,20 @@ class HasBatteryLevel
|
|||||||
/**
|
/**
|
||||||
* Battery state of charge, from 0 to 100 or -1 for unknown
|
* Battery state of charge, from 0 to 100 or -1 for unknown
|
||||||
*/
|
*/
|
||||||
virtual int getBattPercentage() { return -1; }
|
virtual int getBatteryPercent() { return -1; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw voltage of the battery or NAN if unknown
|
* The raw voltage of the battery or NAN if unknown
|
||||||
*/
|
*/
|
||||||
virtual float getBattVoltage() { return NAN; }
|
virtual uint16_t getBattVoltage() { return 0; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return true if there is a battery installed in this unit
|
* return true if there is a battery installed in this unit
|
||||||
*/
|
*/
|
||||||
virtual bool isBatteryConnect() { return false; }
|
virtual bool isBatteryConnect() { return false; }
|
||||||
|
|
||||||
virtual bool isVBUSPlug() { return false; }
|
virtual bool isVbusIn() { return false; }
|
||||||
virtual bool isChargeing() { return false; }
|
virtual bool isCharging() { return false; }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
*
|
*
|
||||||
* FIXME - use a lipo lookup table, the current % full is super wrong
|
* FIXME - use a lipo lookup table, the current % full is super wrong
|
||||||
*/
|
*/
|
||||||
virtual int getBattPercentage() override
|
virtual int getBatteryPercent() override
|
||||||
{
|
{
|
||||||
float v = getBattVoltage();
|
float v = getBattVoltage();
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
/**
|
/**
|
||||||
* The raw voltage of the batteryin millivolts or NAN if unknown
|
* The raw voltage of the batteryin millivolts or NAN if unknown
|
||||||
*/
|
*/
|
||||||
virtual float getBattVoltage() override
|
virtual uint16_t getBattVoltage() override
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifndef ADC_MULTIPLIER
|
#ifndef ADC_MULTIPLIER
|
||||||
@ -130,27 +131,27 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
#endif
|
#endif
|
||||||
// DEBUG_MSG("battery gpio %d raw val=%u scaled=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled));
|
// DEBUG_MSG("battery gpio %d raw val=%u scaled=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled));
|
||||||
last_read_value = scaled;
|
last_read_value = scaled;
|
||||||
return scaled;
|
return scaled * 1000;
|
||||||
} else {
|
} else {
|
||||||
return last_read_value;
|
return last_read_value;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return NAN;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return true if there is a battery installed in this unit
|
* return true if there is a battery installed in this unit
|
||||||
*/
|
*/
|
||||||
virtual bool isBatteryConnect() override { return getBattPercentage() != -1; }
|
virtual bool isBatteryConnect() override { return getBatteryPercent() != -1; }
|
||||||
|
|
||||||
/// If we see a battery voltage higher than physics allows - assume charger is pumping
|
/// If we see a battery voltage higher than physics allows - assume charger is pumping
|
||||||
/// in power
|
/// in power
|
||||||
virtual bool isVBUSPlug() override { return getBattVoltage() > chargingVolt; }
|
virtual bool isVbusIn() override { return getBattVoltage() > chargingVolt; }
|
||||||
|
|
||||||
/// Assume charging if we have a battery and external power is connected.
|
/// Assume charging if we have a battery and external power is connected.
|
||||||
/// we can't be smart enough to say 'full'?
|
/// we can't be smart enough to say 'full'?
|
||||||
virtual bool isChargeing() override { return isBatteryConnect() && isVBUSPlug(); }
|
virtual bool isCharging() override { return isBatteryConnect() && isVbusIn(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// If we see a battery voltage higher than physics allows - assume charger is pumping
|
/// If we see a battery voltage higher than physics allows - assume charger is pumping
|
||||||
@ -219,7 +220,7 @@ bool Power::analogInit()
|
|||||||
|
|
||||||
bool Power::setup()
|
bool Power::setup()
|
||||||
{
|
{
|
||||||
bool found = axp192Init();
|
bool found = axpChipInit();
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
found = analogInit();
|
found = analogInit();
|
||||||
@ -232,10 +233,14 @@ bool Power::setup()
|
|||||||
|
|
||||||
void Power::shutdown()
|
void Power::shutdown()
|
||||||
{
|
{
|
||||||
#ifdef HAS_AXP192
|
|
||||||
|
|
||||||
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
DEBUG_MSG("Shutting down\n");
|
DEBUG_MSG("Shutting down\n");
|
||||||
axp.setChgLEDMode(AXP20X_LED_OFF);
|
if(PMU){
|
||||||
axp.shutdown();
|
PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF);
|
||||||
|
PMU->shutdown();
|
||||||
|
}
|
||||||
#elif defined(ARCH_NRF52)
|
#elif defined(ARCH_NRF52)
|
||||||
playBeep();
|
playBeep();
|
||||||
ledOff(PIN_LED1);
|
ledOff(PIN_LED1);
|
||||||
@ -256,8 +261,8 @@ void Power::readPowerStatus()
|
|||||||
if (hasBattery) {
|
if (hasBattery) {
|
||||||
batteryVoltageMv = batteryLevel->getBattVoltage();
|
batteryVoltageMv = batteryLevel->getBattVoltage();
|
||||||
// If the AXP192 returns a valid battery percentage, use it
|
// If the AXP192 returns a valid battery percentage, use it
|
||||||
if (batteryLevel->getBattPercentage() >= 0) {
|
if (batteryLevel->getBatteryPercent() >= 0) {
|
||||||
batteryChargePercent = batteryLevel->getBattPercentage();
|
batteryChargePercent = batteryLevel->getBatteryPercent();
|
||||||
} else {
|
} else {
|
||||||
// If the AXP192 returns a percentage less than 0, the feature is either not supported or there is an error
|
// If the AXP192 returns a percentage less than 0, the feature is either not supported or there is an error
|
||||||
// In that case, we compute an estimate of the charge percent based on maximum and minimum voltages defined in
|
// In that case, we compute an estimate of the charge percent based on maximum and minimum voltages defined in
|
||||||
@ -270,8 +275,8 @@ void Power::readPowerStatus()
|
|||||||
|
|
||||||
// Notify any status instances that are observing us
|
// Notify any status instances that are observing us
|
||||||
const PowerStatus powerStatus2 =
|
const PowerStatus powerStatus2 =
|
||||||
PowerStatus(hasBattery ? OptTrue : OptFalse, batteryLevel->isVBUSPlug() ? OptTrue : OptFalse,
|
PowerStatus(hasBattery ? OptTrue : OptFalse, batteryLevel->isVbusIn() ? OptTrue : OptFalse,
|
||||||
batteryLevel->isChargeing() ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent);
|
batteryLevel->isCharging() ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent);
|
||||||
DEBUG_MSG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d\n", powerStatus2.getHasUSB(),
|
DEBUG_MSG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d\n", powerStatus2.getHasUSB(),
|
||||||
powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent());
|
powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent());
|
||||||
newStatus.notifyObservers(&powerStatus2);
|
newStatus.notifyObservers(&powerStatus2);
|
||||||
@ -304,41 +309,46 @@ int32_t Power::runOnce()
|
|||||||
{
|
{
|
||||||
readPowerStatus();
|
readPowerStatus();
|
||||||
|
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
// WE no longer use the IRQ line to wake the CPU (due to false wakes from sleep), but we do poll
|
// WE no longer use the IRQ line to wake the CPU (due to false wakes from sleep), but we do poll
|
||||||
// the IRQ status by reading the registers over I2C
|
// the IRQ status by reading the registers over I2C
|
||||||
axp.readIRQ();
|
if(PMU){
|
||||||
|
|
||||||
if (axp.isVbusRemoveIRQ()) {
|
PMU->getIrqStatus();
|
||||||
DEBUG_MSG("USB unplugged\n");
|
|
||||||
powerFSM.trigger(EVENT_POWER_DISCONNECTED);
|
|
||||||
}
|
|
||||||
if (axp.isVbusPlugInIRQ()) {
|
|
||||||
DEBUG_MSG("USB plugged In\n");
|
|
||||||
powerFSM.trigger(EVENT_POWER_CONNECTED);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Other things we could check if we cared...
|
|
||||||
|
|
||||||
if (axp.isChargingIRQ()) {
|
if(PMU->isVbusRemoveIrq()){
|
||||||
DEBUG_MSG("Battery start charging\n");
|
DEBUG_MSG("USB unplugged\n");
|
||||||
|
powerFSM.trigger(EVENT_POWER_DISCONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PMU->isVbusInsertIrq()) {
|
||||||
|
DEBUG_MSG("USB plugged In\n");
|
||||||
|
powerFSM.trigger(EVENT_POWER_CONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Other things we could check if we cared...
|
||||||
|
|
||||||
|
if (PMU->isBatChagerStartIrq()) {
|
||||||
|
DEBUG_MSG("Battery start charging\n");
|
||||||
|
}
|
||||||
|
if (PMU->isBatChagerDoneIrq()) {
|
||||||
|
DEBUG_MSG("Battery fully charged\n");
|
||||||
|
}
|
||||||
|
if (PMU->isBatInsertIrq()) {
|
||||||
|
DEBUG_MSG("Battery inserted\n");
|
||||||
|
}
|
||||||
|
if (PMU->isBatRemoveIrq()) {
|
||||||
|
DEBUG_MSG("Battery removed\n");
|
||||||
|
}
|
||||||
|
if (PMU->isPekeyShortPressIrq()) {
|
||||||
|
DEBUG_MSG("PEK short button press\n");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
PMU->clearIrqStatus();
|
||||||
}
|
}
|
||||||
if (axp.isChargingDoneIRQ()) {
|
|
||||||
DEBUG_MSG("Battery fully charged\n");
|
|
||||||
}
|
|
||||||
if (axp.isBattPlugInIRQ()) {
|
|
||||||
DEBUG_MSG("Battery inserted\n");
|
|
||||||
}
|
|
||||||
if (axp.isBattRemoveIRQ()) {
|
|
||||||
DEBUG_MSG("Battery removed\n");
|
|
||||||
}
|
|
||||||
if (axp.isPEKShortPressIRQ()) {
|
|
||||||
DEBUG_MSG("PEK short button press\n");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
axp.clearIRQ();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Only read once every 20 seconds once the power status for the app has been initialized
|
// Only read once every 20 seconds once the power status for the app has been initialized
|
||||||
return (statusHandler && statusHandler->isInitialized()) ? (1000 * 20) : RUN_SAME;
|
return (statusHandler && statusHandler->isInitialized()) ? (1000 * 20) : RUN_SAME;
|
||||||
}
|
}
|
||||||
@ -351,128 +361,213 @@ int32_t Power::runOnce()
|
|||||||
share the same i2c bus, instead use ssd1306 sleep mode DCDC2 -> unused DCDC3 0.7-3.5V @ 700mA max -> ESP32 (keep this on!) LDO1
|
share the same i2c bus, instead use ssd1306 sleep mode DCDC2 -> unused DCDC3 0.7-3.5V @ 700mA max -> ESP32 (keep this on!) LDO1
|
||||||
30mA -> charges GPS backup battery // charges the tiny J13 battery by the GPS to power the GPS ram (for a couple of days), can
|
30mA -> charges GPS backup battery // charges the tiny J13 battery by the GPS to power the GPS ram (for a couple of days), can
|
||||||
not be turned off LDO2 200mA -> LORA LDO3 200mA -> GPS
|
not be turned off LDO2 200mA -> LORA LDO3 200mA -> GPS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
bool Power::axp192Init()
|
bool Power::axpChipInit()
|
||||||
{
|
{
|
||||||
#ifdef HAS_AXP192
|
|
||||||
if (axp192_found) {
|
|
||||||
if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) {
|
|
||||||
batteryLevel = &axp;
|
|
||||||
|
|
||||||
DEBUG_MSG("AXP192 Begin PASS\n");
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
|
|
||||||
// axp.setChgLEDMode(LED_BLINK_4HZ);
|
if (!PMU) {
|
||||||
DEBUG_MSG("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE");
|
PMU = new XPowersAXP2101(Wire, I2C_SDA, I2C_SCL);
|
||||||
DEBUG_MSG("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE");
|
if (!PMU->init()) {
|
||||||
DEBUG_MSG("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE");
|
DEBUG_MSG("Warning: Failed to find AXP2101 power management\n");
|
||||||
DEBUG_MSG("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE");
|
delete PMU;
|
||||||
DEBUG_MSG("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE");
|
PMU = NULL;
|
||||||
DEBUG_MSG("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
|
||||||
DEBUG_MSG("----------------------------------------\n");
|
|
||||||
|
|
||||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA radio
|
|
||||||
// axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS main power - now turned on in setGpsPower
|
|
||||||
axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
|
|
||||||
axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
|
|
||||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
|
||||||
axp.setDCDC1Voltage(3300); // for the OLED power
|
|
||||||
|
|
||||||
DEBUG_MSG("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE");
|
|
||||||
DEBUG_MSG("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE");
|
|
||||||
DEBUG_MSG("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE");
|
|
||||||
DEBUG_MSG("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE");
|
|
||||||
DEBUG_MSG("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE");
|
|
||||||
DEBUG_MSG("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
|
||||||
|
|
||||||
switch (config.power.charge_current) {
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MAUnset:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_450MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA100:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_100MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA190:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_190MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA280:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_280MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA360:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_360MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA450:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_450MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA550:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_550MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA630:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_630MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA700:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_700MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA780:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_780MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA880:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_880MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA960:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_960MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA1000:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_1000MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA1080:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_1080MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA1160:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_1160MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA1240:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_1240MA);
|
|
||||||
break;
|
|
||||||
case Config_PowerConfig_ChargeCurrent_MA1320:
|
|
||||||
axp.setChargeControlCur(AXP1XX_CHARGE_CUR_1320MA);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
// Not connected
|
|
||||||
//val = 0xfc;
|
|
||||||
//axp._writeByte(AXP202_VHTF_CHGSET, 1, &val); // Set temperature protection
|
|
||||||
|
|
||||||
//not used
|
|
||||||
//val = 0x46;
|
|
||||||
//axp._writeByte(AXP202_OFF_CTL, 1, &val); // enable bat detection
|
|
||||||
#endif
|
|
||||||
axp.debugCharging();
|
|
||||||
|
|
||||||
#ifdef PMU_IRQ
|
|
||||||
pinMode(PMU_IRQ, INPUT);
|
|
||||||
attachInterrupt(
|
|
||||||
PMU_IRQ, [] { pmu_irq = true; }, FALLING);
|
|
||||||
|
|
||||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
|
||||||
// we do not look for AXP202_CHARGING_FINISHED_IRQ & AXP202_CHARGING_IRQ because it occurs repeatedly while there is
|
|
||||||
// no battery also it could cause inadvertent waking from light sleep just because the battery filled
|
|
||||||
// we don't look for AXP202_BATT_REMOVED_IRQ because it occurs repeatedly while no battery installed
|
|
||||||
// we don't look at AXP202_VBUS_REMOVED_IRQ because we don't have anything hooked to vbus
|
|
||||||
axp.enableIRQ(AXP202_BATT_CONNECT_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_PEK_SHORTPRESS_IRQ, 1);
|
|
||||||
|
|
||||||
axp.clearIRQ();
|
|
||||||
#endif
|
|
||||||
readPowerStatus();
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG_MSG("AXP192 Begin FAIL\n");
|
DEBUG_MSG("AXP2101 PMU init succeeded, using AXP2101 PMU\n");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
DEBUG_MSG("AXP192 not found\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!PMU) {
|
||||||
|
PMU = new XPowersAXP192(Wire, I2C_SDA, I2C_SCL);
|
||||||
|
if (!PMU->init()) {
|
||||||
|
DEBUG_MSG("Warning: Failed to find AXP192 power management\n");
|
||||||
|
delete PMU;
|
||||||
|
PMU = NULL;
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("AXP192 PMU init succeeded, using AXP192 PMU\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PMU) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
batteryLevel = PMU;
|
||||||
|
|
||||||
|
if (PMU->getChipModel() == XPOWERS_AXP192) {
|
||||||
|
|
||||||
|
// lora radio power channel
|
||||||
|
PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300);
|
||||||
|
PMU->enablePowerOutput(XPOWERS_LDO2);
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
// enable oled power
|
||||||
|
PMU->enablePowerOutput(XPOWERS_DCDC1);
|
||||||
|
|
||||||
|
|
||||||
|
// gnss module power channel - now turned on in setGpsPower
|
||||||
|
PMU->setPowerChannelVoltage(XPOWERS_LDO3, 3300);
|
||||||
|
// PMU->enablePowerOutput(XPOWERS_LDO3);
|
||||||
|
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
/*
|
||||||
|
PMU->enableIRQ(XPOWERS_AXP192_VBUS_REMOVE_IRQ |
|
||||||
|
XPOWERS_AXP192_VBUS_INSERT_IRQ |
|
||||||
|
XPOWERS_AXP192_BAT_CHG_DONE_IRQ |
|
||||||
|
XPOWERS_AXP192_BAT_CHG_START_IRQ |
|
||||||
|
XPOWERS_AXP192_BAT_REMOVE_IRQ |
|
||||||
|
XPOWERS_AXP192_BAT_INSERT_IRQ |
|
||||||
|
XPOWERS_AXP192_PKEY_SHORT_IRQ
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(config.power.charge_current == Config_PowerConfig_ChargeCurrent_MAUnset){
|
||||||
|
config.power.charge_current = Config_PowerConfig_ChargeCurrent_MA450;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set constant current charging current
|
||||||
|
PMU->setChargerConstantCurr(config.power.charge_current - 1);
|
||||||
|
|
||||||
|
|
||||||
|
} else if (PMU->getChipModel() == XPOWERS_AXP2101) {
|
||||||
|
|
||||||
|
// t-beam s3 core
|
||||||
|
|
||||||
|
// gnss module power channel - now turned on in setGpsPower
|
||||||
|
// PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300);
|
||||||
|
// PMU->enablePowerOutput(XPOWERS_ALDO4);
|
||||||
|
|
||||||
|
// lora radio power channel
|
||||||
|
PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300);
|
||||||
|
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||||
|
|
||||||
|
// m.2 interface
|
||||||
|
PMU->setPowerChannelVoltage(XPOWERS_DCDC3, 3300);
|
||||||
|
PMU->enablePowerOutput(XPOWERS_DCDC3);
|
||||||
|
|
||||||
|
// PMU->setPowerChannelVoltage(XPOWERS_DCDC4, 3300);
|
||||||
|
// PMU->enablePowerOutput(XPOWERS_DCDC4);
|
||||||
|
|
||||||
|
//not use channel
|
||||||
|
PMU->disablePowerOutput(XPOWERS_DCDC2); //not elicited
|
||||||
|
PMU->disablePowerOutput(XPOWERS_DCDC5); //not elicited
|
||||||
|
PMU->disablePowerOutput(XPOWERS_DLDO1); //Invalid power channel, it does not exist
|
||||||
|
PMU->disablePowerOutput(XPOWERS_DLDO2); //Invalid power channel, it does not exist
|
||||||
|
PMU->disablePowerOutput(XPOWERS_VBACKUP);
|
||||||
|
|
||||||
|
//disable all axp chip interrupt
|
||||||
|
PMU->disableIRQ(XPOWERS_AXP2101_ALL_IRQ);
|
||||||
|
|
||||||
|
//Set the constant current charging current of AXP2101, temporarily use 500mA by default
|
||||||
|
PMU->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_500MA);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PMU->clearIrqStatus();
|
||||||
|
|
||||||
|
// TBeam1.1 /T-Beam S3-Core has no external TS detection,
|
||||||
|
// it needs to be disabled, otherwise it will cause abnormal charging
|
||||||
|
PMU->disableTSPinMeasure();
|
||||||
|
|
||||||
|
// PMU->enableSystemVoltageMeasure();
|
||||||
|
PMU->enableVbusVoltageMeasure();
|
||||||
|
PMU->enableBattVoltageMeasure();
|
||||||
|
|
||||||
|
DEBUG_MSG("=======================================================================\n");
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_DCDC1)) {
|
||||||
|
DEBUG_MSG("DC1 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC1));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_DCDC2)) {
|
||||||
|
DEBUG_MSG("DC2 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC2));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_DCDC3)) {
|
||||||
|
DEBUG_MSG("DC3 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC3));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_DCDC4)) {
|
||||||
|
DEBUG_MSG("DC4 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC4) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC4));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_LDO2)) {
|
||||||
|
DEBUG_MSG("LDO2 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO2));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_LDO3)) {
|
||||||
|
DEBUG_MSG("LDO3 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO3));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_ALDO1)) {
|
||||||
|
DEBUG_MSG("ALDO1: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO1));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_ALDO2)) {
|
||||||
|
DEBUG_MSG("ALDO2: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO2));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_ALDO3)) {
|
||||||
|
DEBUG_MSG("ALDO3: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO3));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_ALDO4)) {
|
||||||
|
DEBUG_MSG("ALDO4: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO4) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO4));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_BLDO1)) {
|
||||||
|
DEBUG_MSG("BLDO1: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_BLDO1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_BLDO1));
|
||||||
|
}
|
||||||
|
if (PMU->isChannelAvailable(XPOWERS_BLDO2)) {
|
||||||
|
DEBUG_MSG("BLDO2: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_BLDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_BLDO2));
|
||||||
|
}
|
||||||
|
DEBUG_MSG("=======================================================================\n");
|
||||||
|
|
||||||
|
|
||||||
|
//Set up the charging voltage, AXP2101/AXP192 4.2V gear is the same
|
||||||
|
// XPOWERS_AXP192_CHG_VOL_4V2 = XPOWERS_AXP2101_CHG_VOL_4V2
|
||||||
|
PMU->setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2);
|
||||||
|
|
||||||
|
// Set PMU shutdown voltage at 2.6V to maximize battery utilization
|
||||||
|
PMU->setSysPowerDownVoltage(2600);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PMU_IRQ
|
||||||
|
uint64_t pmuIrqMask = 0;
|
||||||
|
|
||||||
|
if (PMU->getChipModel() == XPOWERS_AXP192) {
|
||||||
|
pmuIrqMask = XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_PKEY_SHORT_IRQ;
|
||||||
|
} else if (PMU->getChipModel() == XPOWERS_AXP2101) {
|
||||||
|
pmuIrqMask = XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_PKEY_SHORT_IRQ;
|
||||||
|
}
|
||||||
|
|
||||||
|
pinMode(PMU_IRQ, INPUT);
|
||||||
|
attachInterrupt(
|
||||||
|
PMU_IRQ, [] { pmu_irq = true; }, FALLING);
|
||||||
|
|
||||||
|
// we do not look for AXPXXX_CHARGING_FINISHED_IRQ & AXPXXX_CHARGING_IRQ because it occurs repeatedly while there is
|
||||||
|
// no battery also it could cause inadvertent waking from light sleep just because the battery filled
|
||||||
|
// we don't look for AXPXXX_BATT_REMOVED_IRQ because it occurs repeatedly while no battery installed
|
||||||
|
// we don't look at AXPXXX_VBUS_REMOVED_IRQ because we don't have anything hooked to vbus
|
||||||
|
PMU->enableIRQ(pmuIrqMask);
|
||||||
|
|
||||||
|
PMU->clearIrqStatus();
|
||||||
|
#endif /*PMU_IRQ*/
|
||||||
|
|
||||||
|
readPowerStatus();
|
||||||
|
|
||||||
|
axp192_found = true;
|
||||||
|
|
||||||
return axp192_found;
|
return axp192_found;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
static bool isPowered()
|
static bool isPowered()
|
||||||
{
|
{
|
||||||
// Circumvent the battery sensing logic and assumes constant power if no battery pin or power mgmt IC
|
// Circumvent the battery sensing logic and assumes constant power if no battery pin or power mgmt IC
|
||||||
#if !defined(BATTERY_PIN) && !defined(HAS_AXP192)
|
#if !defined(BATTERY_PIN) && !defined(HAS_AXP192) && !defined(HAS_AXP2101)
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include "mesh/generated/telemetry.pb.h"
|
#include "mesh/generated/telemetry.pb.h"
|
||||||
|
|
||||||
#ifdef HAS_AXP192
|
|
||||||
#include "axp20x.h"
|
#ifndef XPOWERS_AXP192_AXP2101_ADDRESS
|
||||||
|
#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_WIRE
|
#if HAS_WIRE
|
||||||
@ -114,10 +115,10 @@ void scanI2Cdevice(void)
|
|||||||
screen_found = addr;
|
screen_found = addr;
|
||||||
DEBUG_MSG("st7567 display found\n");
|
DEBUG_MSG("st7567 display found\n");
|
||||||
}
|
}
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
if (addr == AXP192_SLAVE_ADDRESS) {
|
if (addr == XPOWERS_AXP192_AXP2101_ADDRESS) {
|
||||||
axp192_found = true;
|
axp192_found = true;
|
||||||
DEBUG_MSG("axp192 PMU found\n");
|
DEBUG_MSG("axp192/axp2101 PMU found\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (addr == BME_ADDR || addr == BME_ADDR_ALTERNATE) {
|
if (addr == BME_ADDR || addr == BME_ADDR_ALTERNATE) {
|
||||||
|
@ -64,16 +64,23 @@ bool GPS::setupGPS()
|
|||||||
if (_serial_gps && !didSerialInit) {
|
if (_serial_gps && !didSerialInit) {
|
||||||
didSerialInit = true;
|
didSerialInit = true;
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
// In esp32s3 framework, setRxBufferSize needs to be initialized before Serial
|
||||||
|
_serial_gps->setRxBufferSize(2048); // the default is 256
|
||||||
|
#endif
|
||||||
|
|
||||||
// ESP32 has a special set of parameters vs other arduino ports
|
// ESP32 has a special set of parameters vs other arduino ports
|
||||||
#if defined(GPS_RX_PIN) && defined(ARCH_ESP32)
|
#if defined(GPS_RX_PIN) && defined(ARCH_ESP32)
|
||||||
_serial_gps->begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
_serial_gps->begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
||||||
#else
|
#else
|
||||||
_serial_gps->begin(GPS_BAUDRATE);
|
_serial_gps->begin(GPS_BAUDRATE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARCH_ESP32
|
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
_serial_gps->setRxBufferSize(2048); // the default is 256
|
_serial_gps->setRxBufferSize(2048); // the default is 256
|
||||||
#endif
|
#endif
|
||||||
#ifdef TTGO_T_ECHO
|
|
||||||
|
#if defined(TTGO_T_ECHO) || defined(LILYGO_TBEAM_S3_CORE)
|
||||||
// Switch to 9600 baud, then close and reopen port
|
// Switch to 9600 baud, then close and reopen port
|
||||||
_serial_gps->end();
|
_serial_gps->end();
|
||||||
delay(250);
|
delay(250);
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
|
extern uint8_t cardkb_found;
|
||||||
|
|
||||||
KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
|
KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
|
||||||
{
|
{
|
||||||
this->_originName = name;
|
this->_originName = name;
|
||||||
@ -9,6 +11,11 @@ KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
|
|||||||
|
|
||||||
int32_t KbI2cBase::runOnce()
|
int32_t KbI2cBase::runOnce()
|
||||||
{
|
{
|
||||||
|
if (cardkb_found != CARDKB_ADDR){
|
||||||
|
// Input device is not detected.
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
|
||||||
InputEvent e;
|
InputEvent e;
|
||||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||||
e.source = this->_originName;
|
e.source = this->_originName;
|
||||||
|
@ -301,7 +301,7 @@ void setup()
|
|||||||
setupModules();
|
setupModules();
|
||||||
|
|
||||||
// Do this after service.init (because that clears error_code)
|
// Do this after service.init (because that clears error_code)
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
if (!axp192_found)
|
if (!axp192_found)
|
||||||
RECORD_CRITICALERROR(CriticalErrorCode_NoAXP192); // Record a hardware fault for missing hardware
|
RECORD_CRITICALERROR(CriticalErrorCode_NoAXP192); // Record a hardware fault for missing hardware
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,7 +74,7 @@ typedef enum _HardwareModel {
|
|||||||
/* B&Q Consulting Station Edition G1: https://uniteng.com/wiki/doku.php?id=meshtastic:station */
|
/* B&Q Consulting Station Edition G1: https://uniteng.com/wiki/doku.php?id=meshtastic:station */
|
||||||
HardwareModel_STATION_G1 = 45,
|
HardwareModel_STATION_G1 = 45,
|
||||||
/* TODO: REPLACE */
|
/* TODO: REPLACE */
|
||||||
HardwareModel_TBEAM_S3_M2 = 46,
|
HardwareModel_LILYGO_TBEAM_S3_CORE = 46,
|
||||||
/* Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. */
|
/* Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. */
|
||||||
HardwareModel_PRIVATE_HW = 255
|
HardwareModel_PRIVATE_HW = 255
|
||||||
} HardwareModel;
|
} HardwareModel;
|
||||||
|
@ -44,8 +44,8 @@
|
|||||||
#define HW_VENDOR HardwareModel_TBEAM
|
#define HW_VENDOR HardwareModel_TBEAM
|
||||||
#elif defined(TBEAM_V07)
|
#elif defined(TBEAM_V07)
|
||||||
#define HW_VENDOR HardwareModel_TBEAM0p7
|
#define HW_VENDOR HardwareModel_TBEAM0p7
|
||||||
#elif defined(TBEAM_S3_M2)
|
#elif defined(LILYGO_TBEAM_S3_CORE)
|
||||||
#define HW_VENDOR HardwareModel_TBEAM_S3_M2
|
#define HW_VENDOR HardwareModel_LILYGO_TBEAM_S3_CORE
|
||||||
#elif defined(DIY_V1)
|
#elif defined(DIY_V1)
|
||||||
#define HW_VENDOR HardwareModel_DIY_V1
|
#define HW_VENDOR HardwareModel_DIY_V1
|
||||||
#elif defined(RAK_11200)
|
#elif defined(RAK_11200)
|
||||||
|
@ -32,8 +32,8 @@ class Power : private concurrency::OSThread
|
|||||||
protected:
|
protected:
|
||||||
meshtastic::PowerStatus *statusHandler;
|
meshtastic::PowerStatus *statusHandler;
|
||||||
|
|
||||||
/// Setup a axp192, return true if found
|
/// Setup a xpowers chip axp192/axp2101, return true if found
|
||||||
bool axp192Init();
|
bool axpChipInit();
|
||||||
|
|
||||||
/// Setup a simple ADC input based battery sensor
|
/// Setup a simple ADC input based battery sensor
|
||||||
bool analogInit();
|
bool analogInit();
|
||||||
|
@ -35,7 +35,7 @@ void powerCommandsCheck()
|
|||||||
|
|
||||||
if (shutdownAtMsec && millis() > shutdownAtMsec) {
|
if (shutdownAtMsec && millis() > shutdownAtMsec) {
|
||||||
DEBUG_MSG("Shutting down from admin command\n");
|
DEBUG_MSG("Shutting down from admin command\n");
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
if (axp192_found == true) {
|
if (axp192_found == true) {
|
||||||
playShutdownMelody();
|
playShutdownMelody();
|
||||||
power->shutdown();
|
power->shutdown();
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
esp_sleep_source_t wakeCause; // the reason we booted this time
|
esp_sleep_source_t wakeCause; // the reason we booted this time
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
#include "axp20x.h"
|
#include "XPowersLibInterface.hpp"
|
||||||
extern AXP20X_Class axp;
|
extern XPowersLibInterface *PMU;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Called to ask any observers if they want to veto sleep. Return 1 to veto or 0 to allow sleep to happen
|
/// Called to ask any observers if they want to veto sleep. Return 1 to veto or 0 to allow sleep to happen
|
||||||
@ -78,10 +78,10 @@ void setLed(bool ledOn)
|
|||||||
digitalWrite(LED_PIN, ledOn ^ LED_INVERTED);
|
digitalWrite(LED_PIN, ledOn ^ LED_INVERTED);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
if (axp192_found) {
|
if (axp192_found) {
|
||||||
// blink the axp led
|
// blink the axp led
|
||||||
axp.setChgLEDMode(ledOn ? AXP20X_LED_LOW_LEVEL : AXP20X_LED_OFF);
|
PMU->setChargingLedMode(ledOn ? XPOWERS_CHG_LED_ON : XPOWERS_CHG_LED_OFF);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -90,9 +90,14 @@ void setGPSPower(bool on)
|
|||||||
{
|
{
|
||||||
DEBUG_MSG("Setting GPS power=%d\n", on);
|
DEBUG_MSG("Setting GPS power=%d\n", on);
|
||||||
|
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
if (axp192_found)
|
if (axp192_found){
|
||||||
axp.setPowerOutPut(AXP192_LDO3, on ? AXP202_ON : AXP202_OFF); // GPS main power
|
#ifdef LILYGO_TBEAM_S3_CORE
|
||||||
|
on ? PMU->enablePowerOutput(XPOWERS_ALDO4) : PMU->disablePowerOutput(XPOWERS_ALDO4);
|
||||||
|
#else
|
||||||
|
on ? PMU->enablePowerOutput(XPOWERS_LDO3) : PMU->disablePowerOutput(XPOWERS_LDO3);
|
||||||
|
#endif /*LILYGO_TBEAM_S3_CORE*/
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +190,7 @@ void doDeepSleep(uint64_t msecToWake)
|
|||||||
digitalWrite(VEXT_ENABLE, 1); // turn off the display power
|
digitalWrite(VEXT_ENABLE, 1); // turn off the display power
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_AXP192
|
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
|
||||||
if (axp192_found) {
|
if (axp192_found) {
|
||||||
// Obsolete comment: from back when we we used to receive lora packets while CPU was in deep sleep.
|
// Obsolete comment: from back when we we used to receive lora packets while CPU was in deep sleep.
|
||||||
// We no longer do that, because our light-sleep current draws are low enough and it provides fast start/low cost
|
// We no longer do that, because our light-sleep current draws are low enough and it provides fast start/low cost
|
||||||
@ -198,7 +203,11 @@ void doDeepSleep(uint64_t msecToWake)
|
|||||||
// in its sequencer (true?) so the average power draw should be much lower even if we were listinging for packets
|
// in its sequencer (true?) so the average power draw should be much lower even if we were listinging for packets
|
||||||
// all the time.
|
// all the time.
|
||||||
|
|
||||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF); // LORA radio
|
#ifdef LILYGO_TBEAM_S3_CORE
|
||||||
|
PMU->disablePowerOutput(XPOWERS_ALDO3); // lora radio power channel
|
||||||
|
#else
|
||||||
|
PMU->disablePowerOutput(XPOWERS_LDO2); // lora radio power channel
|
||||||
|
#endif /*LILYGO_TBEAM_S3_CORE*/
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
29
variants/tbeam-s3-core/pins_arduino.h
Normal file
29
variants/tbeam-s3-core/pins_arduino.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef Pins_Arduino_h
|
||||||
|
#define Pins_Arduino_h
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define USB_VID 0x303a
|
||||||
|
#define USB_PID 0x1001
|
||||||
|
|
||||||
|
#define EXTERNAL_NUM_INTERRUPTS 46
|
||||||
|
#define NUM_DIGITAL_PINS 48
|
||||||
|
#define NUM_ANALOG_INPUTS 20
|
||||||
|
|
||||||
|
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
|
||||||
|
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
|
||||||
|
#define digitalPinHasPWM(p) (p < 46)
|
||||||
|
|
||||||
|
static const uint8_t TX = 43;
|
||||||
|
static const uint8_t RX = 44;
|
||||||
|
|
||||||
|
static const uint8_t SDA = 42;
|
||||||
|
static const uint8_t SCL = 41;
|
||||||
|
|
||||||
|
static const uint8_t SS = 10;
|
||||||
|
static const uint8_t MOSI = 11;
|
||||||
|
static const uint8_t MISO = 13;
|
||||||
|
static const uint8_t SCK = 12;
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* Pins_Arduino_h */
|
11
variants/tbeam-s3-core/platformio.ini
Normal file
11
variants/tbeam-s3-core/platformio.ini
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
; The 1.0 release of the LilyGo TBEAM-S3-Core board
|
||||||
|
[env:tbeam-s3-core]
|
||||||
|
extends = esp32s3_base
|
||||||
|
board = tbeam-s3-core
|
||||||
|
|
||||||
|
lib_deps =
|
||||||
|
${esp32s3_base.lib_deps}
|
||||||
|
build_flags =
|
||||||
|
${esp32s3_base.build_flags}
|
||||||
|
-Ivariants/tbeam-s3-core
|
||||||
|
|
49
variants/tbeam-s3-core/variant.h
Normal file
49
variants/tbeam-s3-core/variant.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep
|
||||||
|
|
||||||
|
#define I2C_SDA 42
|
||||||
|
#define I2C_SCL 41
|
||||||
|
|
||||||
|
#define BUTTON_PIN 0 // The middle button GPIO on the T-Beam S3
|
||||||
|
//#define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented anywhere.
|
||||||
|
// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module.
|
||||||
|
|
||||||
|
#define LED_INVERTED 1
|
||||||
|
// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4
|
||||||
|
|
||||||
|
// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if
|
||||||
|
// not found then probe for SX1262
|
||||||
|
#define USE_SX1262
|
||||||
|
#define USE_SX1268
|
||||||
|
|
||||||
|
#define LORA_DIO0 -1 // a No connect on the SX1262 module
|
||||||
|
#define LORA_RESET 5
|
||||||
|
#define LORA_DIO1 1 // SX1262 IRQ
|
||||||
|
#define LORA_DIO2 4 // SX1262 BUSY
|
||||||
|
#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled
|
||||||
|
|
||||||
|
#ifdef USE_SX1262
|
||||||
|
#define SX126X_CS 10 // FIXME - we really should define LORA_CS instead
|
||||||
|
#define SX126X_DIO1 LORA_DIO1
|
||||||
|
#define SX126X_BUSY LORA_DIO2
|
||||||
|
#define SX126X_RESET LORA_RESET
|
||||||
|
#define SX126X_E22 // Not really an E22 but TTGO seems to be trying to clone that
|
||||||
|
// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface
|
||||||
|
// code)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts
|
||||||
|
// and waking from light sleep
|
||||||
|
// #define PMU_IRQ 40
|
||||||
|
#define HAS_AXP2101
|
||||||
|
|
||||||
|
#define RF95_SCK 12
|
||||||
|
#define RF95_MISO 13
|
||||||
|
#define RF95_MOSI 11
|
||||||
|
#define RF95_NSS 10
|
||||||
|
|
||||||
|
#define GPS_RX_PIN 9
|
||||||
|
#define GPS_TX_PIN 8
|
||||||
|
#define GPS_WAKEUP_PIN 7
|
||||||
|
#define GPS_1PPS_PIN 6
|
||||||
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
|||||||
; The 1.0 release of the TBEAM board
|
|
||||||
[env:tbeam-s3]
|
|
||||||
extends = esp32s3_base
|
|
||||||
board = esp32-s3-devkitc-1
|
|
||||||
lib_deps =
|
|
||||||
${esp32s3_base.lib_deps}
|
|
||||||
lewisxhe/XPowersLib @ ^0.1.3
|
|
||||||
build_flags =
|
|
||||||
${esp32s3_base.build_flags}
|
|
||||||
-D TBEAM_S3_M2
|
|
||||||
-DMBEDTLS_USE_PSA_CRYPTO
|
|
||||||
-I variants/tbeam-s3
|
|
||||||
-DBOARD_HAS_PSRAM
|
|
||||||
-DARDUINO_USB_MODE=1
|
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
|
||||||
-DARDUINO_USB_DFU_ON_BOOT=1
|
|
||||||
-DARDUINO_USB_MSC_ON_BOOT=1
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
|||||||
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep
|
|
||||||
|
|
||||||
#define I2C_SDA 42
|
|
||||||
#define I2C_SCL 41
|
|
||||||
|
|
||||||
#define BUTTON_PIN 43 // The middle button GPIO on the T-Beam
|
|
||||||
//#define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented anywhere.
|
|
||||||
// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module.
|
|
||||||
|
|
||||||
#define LED_INVERTED 1
|
|
||||||
// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4
|
|
||||||
|
|
||||||
// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if
|
|
||||||
// not found then probe for SX1262
|
|
||||||
#define USE_SX1262
|
|
||||||
#define USE_SX1268
|
|
||||||
|
|
||||||
#define LORA_DIO0 -1 // a No connect on the SX1262 module
|
|
||||||
#define LORA_RESET 5
|
|
||||||
#define LORA_DIO1 1 // SX1262 IRQ
|
|
||||||
#define LORA_DIO2 4 // SX1262 BUSY
|
|
||||||
#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled
|
|
||||||
|
|
||||||
#ifdef USE_SX1262
|
|
||||||
#define SX126X_CS 10 // FIXME - we really should define LORA_CS instead
|
|
||||||
#define SX126X_DIO1 LORA_DIO1
|
|
||||||
#define SX126X_BUSY LORA_DIO2
|
|
||||||
#define SX126X_RESET LORA_RESET
|
|
||||||
#define SX126X_E22 // Not really an E22 but TTGO seems to be trying to clone that
|
|
||||||
// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface
|
|
||||||
// code)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts
|
|
||||||
// and waking from light sleep
|
|
||||||
#define PMU_IRQ 40
|
|
||||||
#define HAS_AXP2101
|
|
Loading…
Reference in New Issue
Block a user