supla-device
Loading...
Searching...
No Matches
io_group.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_IO_IO_GROUP_H_
5#define SRC_SUPLA_IO_IO_GROUP_H_
6
7#include <supla/io.h>
8
9namespace Supla {
10namespace Io {
11
12// One virtual output backed by several physical pins. Digital writes use each
13// member's active/inactive level; digital reads return the first member's
14// active state. PWM values stay unchanged; group/member inversions are XORed
15// during configuration. PWM ranges/frequencies must be compatible.
16//
17// The caller owns the array and backends; they must outlive this group and
18// remain unchanged while it is in use. No allocation or value cache is used.
19// Set mode and pull-up on the virtual IoPin returned by getPin(). Its polarity
20// can invert the whole group in addition to each member's own polarity.
21// Member mode/pull-up flags are ignored. Writes are sequential, not atomic.
22// Use distinct, set pins, with no cyclic group references.
23class IoGroup : public Base {
24 public:
25 IoGroup(const IoPin *pins, uint8_t count);
26
27 // All pin numbers on this backend refer to the same group. Use one handle
28 // (pin 0) consistently so existing IoPin equality checks keep working.
29 IoPin getPin();
30
31 bool isReady() const override;
32 void customPinMode(int channelNumber, uint8_t pin, uint8_t mode) override;
33 void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) override;
34 void customAnalogWrite(int channelNumber, uint8_t pin, int val) override;
35 void customConfigureAnalogOutput(int channelNumber,
36 uint8_t pin,
37 bool outputInvert = false) override;
38 void customSetPwmResolutionBits(uint8_t pin, uint8_t bits) override;
39 void customSetPwmFrequency(uint16_t frequency) override;
40
41 int customDigitalRead(int channelNumber, uint8_t pin) override;
42 int customAnalogRead(int channelNumber, uint8_t pin) override;
43 unsigned int customPulseIn(int channelNumber,
44 uint8_t pin,
45 uint8_t value,
46 uint64_t timeoutMicro) override;
47 uint8_t customDefaultPwmResolutionBits(uint8_t pin) const override;
48 bool customCanSetPwmResolutionBits(uint8_t pin) const override;
49 uint8_t customPwmResolutionBits(uint8_t pin) const override;
50 uint32_t customPwmMaxValue(uint8_t pin) const override;
51 uint16_t customPwmFrequency() const override;
52
53 // Interrupts observe the first member, just like reads.
54 void customAttachInterrupt(uint8_t pin,
55 void (*func)(void),
56 int mode) override;
57 void customDetachInterrupt(uint8_t pin) override;
58 uint8_t customPinToInterrupt(uint8_t pin) override;
59
60 private:
61 const IoPin *pins;
62 uint8_t count;
63};
64
65} // namespace Io
66} // namespace Supla
67
68#endif // SRC_SUPLA_IO_IO_GROUP_H_
Definition io.h:23
Definition io_group.h:23
Definition io_pin.h:14