DUDS
Distributed Update of Data from Something
DigitalPinConfig.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
11 
12 namespace duds { namespace hardware { namespace interface {
13 
49 
51  int chk = 0;
52  if (options & DirInput) ++chk;
53  if (options & DirOutput) ++chk;
54  if (options & DirImmaterial) ++chk;
55  if (chk > 1) {
57  }
58  chk = 0;
59  if (options & InputNoPull) ++chk;
60  if (options & InputPulldown) ++chk;
61  if (options & InputPullup) ++chk;
62  if (options & InputPullImmaterial) ++chk;
63  if (chk > 1) {
65  }
66  chk = 0;
67  if (options & EventNone) ++chk;
68  if (options & EventEdge) ++chk;
69  if (options & EventLevelLow) ++chk;
70  if (options & EventLevelHigh) ++chk;
71  if (options & EventImmaterial) ++chk;
72  if (chk > 1) {
74  }
75  chk = 0;
76  if (options & InterruptNone) ++chk;
77  if (options & InterruptOnEvent) ++chk;
78  if (options & InterruptImmaterial) ++chk;
79  if (chk > 1) {
81  }
82  chk = 0;
83  if (options & OutputPushPull) ++chk;
84  if (options & OutputHighImpedance) ++chk;
85  if (options & OutputImmaterial) ++chk;
86  if (chk > 1) {
88  }
89  if ((minOutputCurrent > 0) && (maxOutputCurrent > 0) &&
92  }
93 }
94 
96  // change all immaterial bits at once
97  options.setMasked(newCfg.options,
99  );
100  // pin direction options
101  if (!(newCfg.options & DirImmaterial) &&
102  ((newCfg.options & DirMask) != DirNoChange)) {
103  options.setMasked(newCfg.options, DirMask);
104  }
105  // input pull up/down options
106  if (!(newCfg.options & InputPullImmaterial) &&
107  ((newCfg.options & InputPullMask) != InputPullNoChange)) {
109  }
110  // event options
111  if (!(newCfg.options & InterruptImmaterial) &&
112  ((newCfg.options & InterruptMask) != InterruptNoChange)) {
114  }
115  // interrupt options
116  if (!(newCfg.options & EventImmaterial) &&
117  ((newCfg.options & EventMask) != EventNoChange)) {
119  }
120  // output options
121  if (!(newCfg.options & OutputImmaterial) &&
122  ((newCfg.options & OutputMask) != OutputNoChange)) {
124  }
125  // current requests
126  if (newCfg.minOutputCurrent) {
128  }
129  if (newCfg.maxOutputCurrent) {
131  }
132 }
133 
135  const DigitalPinConfig &oldCfg,
136  const DigitalPinConfig &newCfg
137 ) {
138  DigitalPinConfig res(oldCfg);
139  res.combine(newCfg);
140  return res;
141 }
142 
144  const DigitalPinCap &cap
145 ) const {
146  return cap.compatible(*this);
147 }
148 
149 } } }
Indicates that mutually exclusive option flags were set for pin interrupts.
static constexpr Flags DirMask
A bit mask for all direction flags.
static constexpr Flags DirInput
Configure the pin for input.
static constexpr Flags DirImmaterial
Do not care about the pin's direction.
static constexpr Flags InterruptMask
A bit mask for the interrupt configuration flags.
static constexpr Flags InterruptNone
Configure the pin to not trigger an interrupt.
Defines the configuration for a digital general purpose I/O pin.
static constexpr Flags EventNoChange
Do not change the pin's event configuration.
static constexpr Flags EventNone
Configure the pin to not flag an event when the input state changes.
static constexpr Flags EventLevelHigh
Configure the pin to flag an event on a high level input.
static constexpr Flags OutputHighImpedance
Configure the pin to have a high impedance or floating output.
static constexpr Flags InputPulldown
Configure the pin to have a pull-down resistor.
static constexpr Flags EventEdge
Configure the pin to flag an event on any edge.
static constexpr Flags InterruptImmaterial
Do not care about the pin's interrupt configuration.
static constexpr Flags OutputPushPull
Configure the pin to drive output both high and low.
Indicates that mutually exclusive option flags were set for pin events.
static constexpr Flags EventEdgeFalling
Configure the pin to flag an event on the falling edge.
Indicates that mutually exclusive option flags were set for pull ups or downs.
static constexpr Flags OutputImmaterial
Do not care about the pin's output configuration.
duds::general::BitFlags< struct DigitalPinConfigFlags, std::uint32_t > Flags
A container of flags that control the operation of a digital pin.
static constexpr Flags InputPullMask
A bit mask for the pull-up and pull-down resistor flags.
static constexpr Flags InputPullImmaterial
Do not care about the pin&#39;s use of a pull-up or pull-down resistor.
static constexpr Flags InterruptNoChange
Do not change the pin&#39;s interrupt configuration.
static constexpr Flags OutputDriveLow
Configure the pin to be able to drive the output low.
static constexpr Flags InputPullup
Configure the pin to have a pull-up resistor.
Indicates that mutually exclusive option flags were set for pin output drive.
static constexpr Flags OutputDriveHigh
Configure the pin to be able to drive the output high.
Indicates that mutually exclusive option flags were set for pin direction.
std::uint16_t maxOutputCurrent
The selected maximum output current in milliamps (?) for the pin, or zero for no change and immateria...
DigitalPinRejectedConfiguration::Reason compatible(const DigitalPinCap &cap) const
Returns a set of flags that indicate certain incompatible conditions in the given pin configuration i...
static constexpr Flags DirNoChange
Do not change the pin&#39;s direction.
A type-safe bit flag storage class.
Definition: BitFlags.hpp:101
void combine(const DigitalPinConfig &newCfg)
Combines this configuration with a newer configuration taking into account requests to not change cer...
static constexpr Flags OutputNoChange
Do not change the pin&#39;s output configuration.
std::uint16_t minOutputCurrent
The selected minimum output current in milliamps (?) for the pin, or zero for no change and immateria...
static constexpr Flags OutputMask
A bit mask for the output options.
static constexpr Flags EventLevelLow
Configure the pin to flag an event on a low level input.
static constexpr Flags InputNoPull
Configure the pin to not use a pull-up or pull-down resistor.
static constexpr Flags DirOutput
Configure the pin for output.
Indicates that both the maximum and minimum output current were specified, and the maximum is less th...
static constexpr Flags InterruptOnEvent
Configure the pin to trigger an interrupt when an event occurs.
Defines the capabilites of a digital general purpose I/O pin.
static constexpr Flags EventMask
A bit mask for the event configuration flags.
static constexpr Flags OperationNoChange
No change to any pin operation.
void checkValidity() const
Checks for the use of obviously invalid data, such as the use of mutually exclusive options...
Flags options
The control options requested for a digital pin.
static constexpr Flags OutputState
The set output state for the pin.
DigitalPinRejectedConfiguration::Reason compatible(const DigitalPinConfig &cfg) const
Returns a set of flags that indicate certain incompatible conditions in the given pin configuration i...
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Definition: Errors.hpp:48
static constexpr Flags EventEdgeRising
Configure the pin to flag an event on the rising edge.
static constexpr Flags InputPullNoChange
Do not change the use or non-use of a pull-up or pull-down resistor.
static constexpr Flags EventImmaterial
Do not care about the pin&#39;s event configuration.
static constexpr Flags InputState
The last known input state from the pin.
BitFlags setMasked(const BitFlags &bf, const BitFlags &mask)
Changes only the bits in a masked range.
Definition: BitFlags.hpp:278