mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 01:42:15 +00:00

Some checks are pending
CI / setup (check) (push) Waiting to run
CI / setup (esp32) (push) Waiting to run
CI / setup (esp32c3) (push) Waiting to run
CI / setup (esp32c6) (push) Waiting to run
CI / setup (esp32s3) (push) Waiting to run
CI / setup (nrf52840) (push) Waiting to run
CI / setup (rp2040) (push) Waiting to run
CI / setup (stm32) (push) Waiting to run
CI / check (push) Blocked by required conditions
CI / build-esp32 (push) Blocked by required conditions
CI / build-esp32-s3 (push) Blocked by required conditions
CI / build-esp32-c3 (push) Blocked by required conditions
CI / build-esp32-c6 (push) Blocked by required conditions
CI / build-nrf52 (push) Blocked by required conditions
CI / build-rpi2040 (push) Blocked by required conditions
CI / build-stm32 (push) Blocked by required conditions
CI / package-raspbian (push) Waiting to run
CI / package-raspbian-armv7l (push) Waiting to run
CI / package-native (push) Waiting to run
CI / after-checks (push) Blocked by required conditions
CI / gather-artifacts (esp32) (push) Blocked by required conditions
CI / gather-artifacts (esp32c3) (push) Blocked by required conditions
CI / gather-artifacts (esp32c6) (push) Blocked by required conditions
CI / gather-artifacts (esp32s3) (push) Blocked by required conditions
CI / gather-artifacts (nrf52840) (push) Blocked by required conditions
CI / gather-artifacts (rp2040) (push) Blocked by required conditions
CI / gather-artifacts (stm32) (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
CI / release-firmware (esp32) (push) Blocked by required conditions
CI / release-firmware (esp32c3) (push) Blocked by required conditions
CI / release-firmware (esp32c6) (push) Blocked by required conditions
CI / release-firmware (esp32s3) (push) Blocked by required conditions
CI / release-firmware (nrf52840) (push) Blocked by required conditions
CI / release-firmware (rp2040) (push) Blocked by required conditions
CI / release-firmware (stm32) (push) Blocked by required conditions
Flawfinder Scan / Flawfinder (push) Waiting to run
* Spelling Fixes * More Spelling Errors * More Spelling Checks * fixed wording * Undo mesh\generated changes * Missed one file on readd * missed second file
104 lines
3.1 KiB
C++
104 lines
3.1 KiB
C++
#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();
|
|
}
|
|
}
|
|
|
|
void GpioHwPin::set(bool value)
|
|
{
|
|
// if (num == 3) LOG_DEBUG("Setting pin %d to %d", num, value);
|
|
pinMode(num, OUTPUT);
|
|
digitalWrite(num, value);
|
|
}
|
|
|
|
GpioTransformer::GpioTransformer(GpioPin *outPin) : outPin(outPin) {}
|
|
|
|
void GpioTransformer::set(bool value)
|
|
{
|
|
outPin->set(value);
|
|
}
|
|
|
|
GpioUnaryTransformer::GpioUnaryTransformer(GpioVirtPin *inPin, GpioPin *outPin) : GpioTransformer(outPin), inPin(inPin)
|
|
{
|
|
assert(!inPin->dependentPin); // We only allow one dependent pin
|
|
inPin->dependentPin = this;
|
|
|
|
// Don't update at construction time, because various GpioPins might be global constructor based not yet initied because
|
|
// order of operations for global constructors is not defined.
|
|
// update();
|
|
}
|
|
|
|
/**
|
|
* Update the output pin based on the current state of the input pin.
|
|
*/
|
|
void GpioUnaryTransformer::update()
|
|
{
|
|
auto p = inPin->get();
|
|
if (p == GpioVirtPin::PinState::Unset)
|
|
return; // Not yet fully initialized
|
|
|
|
set(p);
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
|
|
// Don't update at construction time, because various GpioPins might be global constructor based not yet initiated because
|
|
// order of operations for global constructors is not defined.
|
|
// 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:
|
|
// LOG_DEBUG("Doing GPIO OR");
|
|
newValue = (GpioVirtPin::PinState)(p1 || p2);
|
|
break;
|
|
case Xor:
|
|
newValue = (GpioVirtPin::PinState)(p1 != p2);
|
|
break;
|
|
default:
|
|
assert(false);
|
|
}
|
|
}
|
|
set(newValue);
|
|
}
|
|
|
|
GpioSplitter::GpioSplitter(GpioPin *outPin1, GpioPin *outPin2) : outPin1(outPin1), outPin2(outPin2) {} |