17const gpio_val_t gpio_values[ACTIVE_NODE::gpioMax];
18const virt_val_t virt_values[ACTIVE_NODE::virtCount];
21void __set(
const GPIO &pin, T value) {
22 if (pin.pin >= VIRT_ID_OFFSET) {
23 virt_values[pin.pin - VIRT_ID_OFFSET] = value;
24 }
else if (pin.outOrIn) {
25 if (pin.pin < ACTIVE_NODE::gpioMax)
26 gpio_values[pin.pin] = value;
28 digitalWriteFast(pin.pin, value);
30 analogWrite(pin.pin, value);
34inline void checkSettee(
const SDBC::SIG *settee, T value) {
35 if (settee !=
nullptr) {
36 settee->msg->setSig(settee, value));
40template <
typename T = gpio_val_t>
41void set(
const GPIO &pin, T value) {
43 checkSettee<T>(pin.settee, value);
46template <
typename T = virt_val_t>
47void set(
const VIRT &pin, T value) {
48 checkSettee<T>(pin.settee, value);
51template <
typename T = gpio_val_t>
52void set(
const int pin, T value) {
53 auto iter = ACTIVE_NODE.__pinMap.find(pin);
54 if (iter != ACTIVE_NODE.__pinMap.end()) {
57 return set(*(
VIRT *)gpio, value);
58 return set<T>(*gpio, value);
60 if (pin < VIRT_ID_OFFSET) {
61 if (pin < ACTIVE_NODE::gpioMax)
62 gpio_values[pin.pin] = value;
66template <
typename T =
int>
67T __get(
const GPIO &pin) {
69 if (pin.pin >= VIRT_ID_OFFSET) {
70 return virt_values[pin.pin - VIRT_ID_OFFSET];
73 if (pin.pin >= ACTIVE_NODE::gpioMax) {
74 Log.
e(ID,
"Attempting to read a pin that is out of range", pin.pin);
79 return gpio_values[pin.pin];
83 return (gpio_values[pin.pin] = digitalReadFast(pin.pin, value));
86 return (gpio_values[pin.pin] = analogRead(pin.pin, value));
88template <
typename T = gpio_val_t>
89inline T get(
const GPIO &pin) {
92template <
typename T = virt_val_t>
93inline T get(
const VIRT &pin) {
99void incoming(
const uint32_t addr,
volatile uint8_t *buf) {
100 auto iter = MessageMap.find(addr);
101 if (iter == MessageMap.end())
104 auto msg = iter->second;
108 msg->value.raw = *(
volatile uint64_t *)buf;
110 if (!msg->hasValueSetter)
113 for (
size_t i = 0; i < msg->signalCount; i++) {
114 auto sig = msg->SIGNALS[i];
115 if (sig->setter ==
nullptr)
117 switch (sig->dataType) {
118#define X(dt_id, typ) \
120 Pins::__set<typ>(*sig->setter, msg->getSig<typ>(sig)); \
122 SDBC_TYPE_DEFINITIONS