Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish powermon/powerstress #4230

Merged
merged 74 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
f33bf01
Turn off vscode cmake prompt - we don't use cmake on meshtastic
geeksville Jun 16, 2024
ce2047a
Add rak4631_dap variant for debugging with NanoDAP debug probe device.
geeksville Jun 16, 2024
22212b2
The rak device can also run freertos (which is underneath nrf52 arduino)
geeksville Jun 17, 2024
8d65e03
Add semihosting support for nrf52840 devices
geeksville Jun 17, 2024
03033ec
Merge remote-tracking branch 'root/master' into dev
geeksville Jun 18, 2024
f435851
powermon WIP (for https://github.com/meshtastic/firmware/issues/4136 )
geeksville Jun 18, 2024
8c46a7e
oops - mean't to mark the _dbg variant as an 'extra' board.
geeksville Jun 20, 2024
a8c265a
Merge remote-tracking branch 'root/master' into dev
geeksville Jun 20, 2024
dc5c5bf
powermon wip
geeksville Jun 20, 2024
2705fe6
Merge branch 'dev' into powermon
geeksville Jun 20, 2024
f872cf1
Make serial port on wio-sdk-wm1110 board work
geeksville Jun 20, 2024
33a929c
Instrument (radiolib only for now) lora for powermon
geeksville Jun 20, 2024
809e06b
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 21, 2024
b2a388b
powermon gps support
geeksville Jun 21, 2024
febe747
Add CPU deep and light sleep powermon states
geeksville Jun 21, 2024
c830942
Change the board/swversion bootstring so it is a new "structured" log…
geeksville Jun 21, 2024
c328e6a
powermon wip
geeksville Jun 21, 2024
0acfeae
add example script for getting esp S3 debugging working
geeksville Jun 21, 2024
039de45
Add PowerMon reporting for screen and bluetooth pwr.
geeksville Jun 21, 2024
c05f2e3
make power.powermon_enables config setting work.
geeksville Jun 21, 2024
948bc4b
update to latest protobufs
geeksville Jun 23, 2024
c67a9df
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 23, 2024
1eff321
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 25, 2024
232e9d9
fix bogus shellcheck warning
geeksville Jun 27, 2024
76c9fb3
Merge remote-tracking branch 'root/master' into powermon
geeksville Jun 27, 2024
d266484
make powermon optional (but default enabled because tiny and no runti…
geeksville Jun 27, 2024
6c753ce
tell vscode, if formatting, use whatever our trunk formatter wants
geeksville Jun 27, 2024
6929a14
Merge branch 'pr-trunkish' into powermon
geeksville Jun 27, 2024
669afac
add PowerStress module
geeksville Jun 27, 2024
b0de20f
nrf52 arduino is built upon freertos, so let platformio debug it
geeksville Jun 27, 2024
1382ac6
don't accidentally try to Segger ICE if we are using another ICE
geeksville Jun 27, 2024
1d65dae
clean up RedirectablePrint::log so it doesn't have three very differe…
geeksville Jun 27, 2024
5464310
remove NoopPrint - it is no longer needed
geeksville Jun 27, 2024
a94a5e6
when talking to API clients via serial, don't turn off log msgs inste…
geeksville Jun 27, 2024
c0482f5
fix the build - would loop forever if there were no files to send
geeksville Jun 28, 2024
5fd18a0
Merge branch 'master' into pr-fixbuild
geeksville Jun 28, 2024
c8a4b99
Merge branch 'pr-fixbuild' into pr-protolog
geeksville Jun 28, 2024
4301544
don't use Segger code if not talking to a Segger debugger
geeksville Jun 28, 2024
b69956e
when encapsulating logs, make sure the strings always has nul termina…
geeksville Jun 28, 2024
ca53564
nrf52 soft device will watchdog if you use ICE while BT on...
geeksville Jun 28, 2024
359fe6a
Merge branch 'pr-fixdebug2' into pr-protolog
geeksville Jun 28, 2024
f37bed4
Important to not print debug messages while writing to the toPhone sc…
geeksville Jun 28, 2024
d5bcfc6
don't include newlines if encapsulating log records as protobufs
geeksville Jun 28, 2024
fcb7f13
Merge remote-tracking branch 'root/master' into pr-protolog
geeksville Jun 28, 2024
a5a2a7d
Merge branch 'pr-protolog' into powermon
geeksville Jun 28, 2024
d885d59
update to latest protobufs (needed for powermon goo)
geeksville Jun 28, 2024
baa258c
PowerStress WIP
geeksville Jun 30, 2024
db68c88
for #4154 and #4136 add concept of dependent gpios...
geeksville Jun 30, 2024
95885a1
Merge remote-tracking branch 'root/master' into pr-protolog
geeksville Jun 30, 2024
7cd3c0c
Merge branch 'pr-protolog' into powermon
geeksville Jun 30, 2024
25ebf4c
Merge remote-tracking branch 'root/master' into powermon
geeksville Jul 3, 2024
c0a7796
fix linter warning
geeksville Jul 3, 2024
d9a094c
Merge remote-tracking branch 'root/master' into pr-gpiologic
geeksville Jul 3, 2024
bfe6a18
Merge branch 'pr-gpiologic' into pr-powermon2
geeksville Jul 3, 2024
16ff719
Transformer is a better name for the LED input > operation > output c…
geeksville Jul 3, 2024
588cee0
PMW led changes to work on esp32-s3
geeksville Jul 3, 2024
0baf0c5
Merge branch 'pr-gpiologic' into pr-powermon2
geeksville Jul 4, 2024
52b0b8a
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Jul 4, 2024
b5a35be
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Jul 5, 2024
0ddd329
power stress improvements
geeksville Jul 5, 2024
cebee58
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Jul 7, 2024
c316eb8
allow ble logrecords to be fetched either by NOTIFY or INDICATE ble t…
geeksville Jul 7, 2024
36eea30
Fix serious problem with nrf52 BLE logging.
geeksville Jul 7, 2024
177d19a
Merge branch 'pr-fixble' into pr-powermon2
geeksville Jul 7, 2024
781a06b
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Jul 24, 2024
e7067a9
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Jul 31, 2024
e66b3ec
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Jul 31, 2024
69d8446
Merge remote-tracking branch 'root/master' into pr-gpiologic
geeksville Aug 3, 2024
fedbb82
Merge branch 'master' into pr-powermon2
thebentern Aug 4, 2024
ec376a6
Merge branch 'pr-gpiologic' into pr-powermon2
geeksville Aug 4, 2024
a67e3fe
fix gpio transformer stuff to work correctly with LED_INVERTED
geeksville Aug 4, 2024
59eb2fa
Support driving multiple output gpios from one input.
geeksville Aug 4, 2024
2aa1b37
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Aug 4, 2024
5773b7c
Merge remote-tracking branch 'root/master' into pr-powermon2
geeksville Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/GpioLogic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "GpioLogic.h"
#include <assert.h>

void GpioVirtPin::set(bool value)
{
if (value != this->value) {
this->value = value ? PinState::On : PinState::Off;
if (dependentPin)
dependentPin->update();
}
}

GpioTransformer::GpioTransformer(GpioPin *outPin) : outPin(outPin) {}

void GpioTransformer::set(bool value)
{
outPin->set(value);
}

GpioNotTransformer::GpioNotTransformer(GpioVirtPin *inPin, GpioPin *outPin) : GpioTransformer(outPin), inPin(inPin)
{
assert(!inPin->dependentPin); // We only allow one dependent pin
inPin->dependentPin = this;
update();
}

void GpioNotTransformer::set(bool value)
{
outPin->set(value);
}

/**
* Update the output pin based on the current state of the input pin.
*/
void GpioNotTransformer::update()
{
auto p = inPin->get();
if (p == GpioVirtPin::PinState::Unset)
return; // Not yet fully initialized

set(!p);
}

GpioBinaryTransformer::GpioBinaryTransformer(GpioVirtPin *inPin1, GpioVirtPin *inPin2, GpioPin *outPin, Operation operation)
: GpioTransformer(outPin), inPin1(inPin1), inPin2(inPin2), operation(operation)
{
assert(!inPin1->dependentPin); // We only allow one dependent pin
inPin1->dependentPin = this;
assert(!inPin2->dependentPin); // We only allow one dependent pin
inPin2->dependentPin = this;
update();
}

void GpioBinaryTransformer::update()
{
auto p1 = inPin1->get(), p2 = inPin2->get();
GpioVirtPin::PinState newValue = GpioVirtPin::PinState::Unset;

if (p1 == GpioVirtPin::PinState::Unset)
newValue = p2; // Not yet fully initialized
else if (p2 == GpioVirtPin::PinState::Unset)
newValue = p1; // Not yet fully initialized

// If we've already found our value just use it, otherwise need to do the operation
if (newValue == GpioVirtPin::PinState::Unset) {
switch (operation) {
case And:
newValue = (GpioVirtPin::PinState)(p1 && p2);
break;
case Or:
newValue = (GpioVirtPin::PinState)(p1 || p2);
break;
case Xor:
newValue = (GpioVirtPin::PinState)(p1 != p2);
break;
default:
assert(false);
}
}
set(newValue);
}
126 changes: 126 additions & 0 deletions src/GpioLogic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#pragma once

#include "configuration.h"

/**This is a set of classes to mediate access to GPIOs in a structured way. Most usage of GPIOs do not
require these classes! But if your hardware has a GPIO that is 'shared' between multiple devices (i.e. a shared power enable)
then using these classes might be able to let you cleanly turn on that enable when either dependent device is needed.

Note: these classes are intended to be 99% inline for the common case so should have minimal impact on flash or RAM
requirements.
*/

/**
* A logical GPIO pin (not necessary raw hardware).
*/
class GpioPin
{
public:
virtual void set(bool value) = 0;
};

/**
* A physical GPIO hw pin.
*/
class GpioHwPin : public GpioPin
{
uint32_t num;

public:
explicit GpioHwPin(uint32_t num) : num(num) {}

void set(bool value) { digitalWrite(num, value); }
};

class GpioTransformer;
class GpioNotTransformer;
class GpioBinaryTransformer;

/**
* A virtual GPIO pin.
*/
class GpioVirtPin : public GpioPin
{
friend class GpioBinaryTransformer;
friend class GpioNotTransformer;

public:
enum PinState { On = true, Off = false, Unset = 2 };

void set(bool value);
PinState get() const { return value; }

private:
PinState value = PinState::Unset;
GpioTransformer *dependentPin = NULL;
};

#include <assert.h>

/**
* A 'smart' trigger that can depend in a fake GPIO and if that GPIO changes, drive some other downstream GPIO to change.
* notably: the set method is not public (because it always is calculated by a subclass)
*/
class GpioTransformer
{
public:
/**
* Update the output pin based on the current state of the input pin.
*/
virtual void update() = 0;

protected:
GpioTransformer(GpioPin *outPin);

void set(bool value);

private:
GpioPin *outPin;
};

/**
* A transformer that performs a unary NOT operation from an input.
*/
class GpioNotTransformer : public GpioTransformer
{
public:
GpioNotTransformer(GpioVirtPin *inPin, GpioPin *outPin);
void set(bool value);

protected:
friend class GpioVirtPin;

/**
* Update the output pin based on the current state of the input pin.
*/
void update();

private:
GpioVirtPin *inPin;
GpioPin *outPin;
};

/**
* A transformer that combines multiple virtual pins to drive an output pin
*/
class GpioBinaryTransformer : public GpioTransformer
{

public:
enum Operation { And, Or, Xor };

GpioBinaryTransformer(GpioVirtPin *inPin1, GpioVirtPin *inPin2, GpioPin *outPin, Operation operation);

protected:
friend class GpioVirtPin;

/**
* Update the output pin based on the current state of the input pins.
*/
void update();

private:
GpioVirtPin *inPin1;
GpioVirtPin *inPin2;
Operation operation;
};
61 changes: 61 additions & 0 deletions src/Led.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "Led.h"
#include "PowerMon.h"
#include "main.h"
#include "power.h"

GpioVirtPin ledForceOn, ledBlink;

#if defined(LED_PIN)

// Most boards have a GPIO for LED control
static GpioHwPin ledRawHwPin(LED_PIN);

#elif defined(HAS_PMU)

/**
* A GPIO controlled by the PMU
*/
class GpioPmuPin : public GpioPin
{
public:
void set(bool value)
{
if (pmu_found && PMU) {
// blink the axp led
PMU->setChargingLedMode(value ? XPOWERS_CHG_LED_ON : XPOWERS_CHG_LED_OFF);
}
}
} ledRawHwPin;

#else
static GpioVirtPin ledRawHwPin; // Dummy pin for no hardware
#endif

#if LED_INVERTED
static GpioVirtPin ledHwPin;
static GpioNotTransformer ledInverter(&ledHwPin, &ledRawHwPin);
#else
static GpioPin &ledHwPin = ledRawHwPin;
#endif

#ifdef USE_POWERMON
/**
* We monitor changes to the LED drive output because we use that as a sanity test in our power monitor stuff.
*/
class MonitoredLedPin : public GpioPin
{
public:
void set(bool value)
{
if (value)
powerMon->setState(meshtastic_PowerMon_State_LED_On);
else
powerMon->clearState(meshtastic_PowerMon_State_LED_On);
ledHwPin.set(value);
}
} monitoredLedPin;
#else
static GpioPin &monitoredLedPin = ledHwPin;
#endif

static GpioBinaryTransformer ledForcer(&ledForceOn, &ledBlink, &monitoredLedPin, GpioBinaryTransformer::Or);
7 changes: 7 additions & 0 deletions src/Led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "GpioLogic.h"
#include "configuration.h"

/**
* ledForceOn and ledForceOff both override the normal ledBlinker behavior (which is controlled by main)
*/
extern GpioVirtPin ledForceOn, ledBlink;
5 changes: 1 addition & 4 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ RAK9154Sensor rak9154Sensor;
#endif

#ifdef HAS_PMU
#include "XPowersAXP192.tpp"
#include "XPowersAXP2101.tpp"
#include "XPowersLibInterface.hpp"
XPowersLibInterface *PMU = NULL;
#else

Expand Down Expand Up @@ -1051,4 +1048,4 @@ bool Power::axpChipInit()
#else
return false;
#endif
}
}
Loading
Loading