DUDS
Distributed Update of Data from Something
DigitalPinCap.hpp
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 
31 struct DigitalPinCap {
42  static constexpr Flags Input = Flags::Bit(0);
49  static constexpr Flags OutputPushPull = Flags::Bit(1);
57  static constexpr Flags OutputDriveLow = Flags::Bit(2);
62  static constexpr Flags OutputDriveHigh = Flags::Bit(3);
66  static constexpr Flags OutputDriveMask =
67  OutputPushPull | OutputDriveLow | OutputDriveHigh;
71  static constexpr Flags OutputHighImpedance = Flags::Bit(4);
75  static constexpr Flags HasPulldown = Flags::Bit(5);
80  static constexpr Flags ControllablePulldown = Flags::Bit(6);
84  static constexpr Flags HasPullup = Flags::Bit(7);
89  static constexpr Flags ControllablePullup = Flags::Bit(8);
93  static constexpr Flags EventEdgeFalling = Flags::Bit(9);
97  static constexpr Flags EventEdgeRising = Flags::Bit(10);
101  static constexpr Flags EventEdgeChange = Flags::Bit(11);
105  static constexpr Flags EventLevelLow = Flags::Bit(12);
109  static constexpr Flags EventLevelHigh = Flags::Bit(13);
122  static constexpr Flags InterruptOnEvent = Flags::Bit(14);
131  std::uint16_t maxOutputCurrent;
135  DigitalPinCap() = default;
141  constexpr DigitalPinCap(const Flags cap, std::uint16_t cur = 0) :
142  capabilities(cap),
143  maxOutputCurrent(cur)
144  { }
151  constexpr bool exists() const {
152  return (capabilities & (
153  Input | OutputPushPull | OutputDriveHigh | OutputDriveLow |
154  ControllablePulldown | ControllablePullup | InterruptOnEvent
155  )) != Flags::Zero();
156  }
161  constexpr bool canOutput() const {
162  return (capabilities & OutputDriveMask) != Flags::Zero();
163  }
169  Flags firstOutputDriveFlag() const;
194  const DigitalPinConfig &cfg
195  ) const;
196 };
197 
204 
205 
206 typedef boost::error_info<
207  struct Info_DigitalPinCap, DigitalPinCap
209 
210 inline std::ostream &operator<<(std::ostream &os, const DigitalPinCap &c) {
211  return os << '(' << c.capabilities.flags() << ',' <<
212  c.maxOutputCurrent << ')';
213 }
214 
216  const DigitalPinCap &cap,
217  const DigitalPinCap::Flags &flg
218 ) {
219  return cap.capabilities & flg;
220 }
221 
223  const DigitalPinCap::Flags &flg,
224  const DigitalPinCap &cap
225 ) {
226  return flg & cap.capabilities;
227 }
228 
230  const DigitalPinCap &cap,
231  const DigitalPinCap::Flags &flg
232 ) {
233  return cap.capabilities | flg;
234 }
235 
237  const DigitalPinCap::Flags &flg,
238  const DigitalPinCap &cap
239 ) {
240  return flg | cap.capabilities;
241 }
242 
244  const DigitalPinCap &cap,
245  const DigitalPinCap::Flags &flg
246 ) {
247  return cap.capabilities ^ flg;
248 }
249 
251  const DigitalPinCap::Flags &flg,
252  const DigitalPinCap &cap
253 ) {
254  return flg ^ cap.capabilities;
255 }
256 
257 constexpr bool operator == (
258  const DigitalPinCap &cap,
259  const DigitalPinCap::Flags &flg
260 ) {
261  return cap.capabilities == flg;
262 }
263 
264 constexpr bool operator == (
265  const DigitalPinCap::Flags &flg,
266  const DigitalPinCap &cap
267 ) {
268  return flg == cap.capabilities;
269 }
270 
271 constexpr bool operator != (
272  const DigitalPinCap &cap,
273  const DigitalPinCap::Flags &flg
274 ) {
275  return cap.capabilities != flg;
276 }
277 
278 constexpr bool operator != (
279  const DigitalPinCap::Flags &flg,
280  const DigitalPinCap &cap
281 ) {
282  return flg != cap.capabilities;
283 }
284 
285 } } }
static constexpr Flags OutputDriveMask
A mask of all output flags that involve driving the line.
static constexpr Flags Input
Input operation is supported.
static constexpr Flags EventEdgeRising
The pin supports setting an event flag on the rising edge.
constexpr DigitalPinCap(const Flags cap, std::uint16_t cur=0)
Construct fully initiallized.
constexpr bool operator==(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
static constexpr Flags OutputDriveLow
The output is or can be an open collector or open drain type.
Defines the configuration for a digital general purpose I/O pin.
constexpr DigitalPinCap NonexistentDigitalPin
The capabilities of a non-existent pin.
constexpr bool canOutput() const
Returns true if the port is capable of output.
boost::error_info< struct Info_DigitalPinCap, DigitalPinCap > DigitalPinCapInfo
static constexpr Flags OutputDriveHigh
The output is or can be an open emitter type.
static constexpr Flags EventEdgeChange
The pin supports setting an event flag on an edge change.
static constexpr BitFlags Zero()
Makes a bit flags container with all flags cleared.
Definition: BitFlags.hpp:133
static constexpr Flags EventLevelHigh
The pin supports setting an event flag on a high level.
constexpr DigitalPinCap::Flags operator|(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
static constexpr BitFlags Bit(std::uint16_t b)
Makes a bit flags container with a single bit set that is specified by digit number rather than value...
Definition: BitFlags.hpp:141
std::uint16_t maxOutputCurrent
The maximum output current in milliamps (?) the pin can manage, or zero if unspecified or not applica...
static constexpr Flags ControllablePullup
The use of the pin&#39;s pull-up resistor can be controlled by software.
Flags capabilities
The capabilities of a digital pin.
constexpr DigitalPinCap::Flags operator&(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
constexpr bool operator!=(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
DigitalPinConfig::Flags firstOutputDriveConfigFlags() const
Returns the output configuration flags that corresponds to the result of firstOutputDriveFlag().
static constexpr Flags EventLevelLow
The pin supports setting an event flag on a low level.
duds::general::BitFlags< struct DigitalPinFlags, std::uint16_t > Flags
A container of flags that control the operation of a digital pin.
constexpr bool exists() const
Returns true if the pin exists and is usable by this process.
ConversationVector & operator<<(ConversationVector &cv, const Int &i)
Insertion operator to add an integer to a ConversationVector object.
static constexpr Flags OutputPushPull
The output can drive the line either low or high.
static constexpr Flags OutputHighImpedance
The pin supports a high impedance state without input.
constexpr BitsType flags() const
Returns the value stored in the object.
Definition: BitFlags.hpp:147
DigitalPinCap()=default
Construct uninitialized.
Defines the capabilites of a digital general purpose I/O pin.
static constexpr Flags InterruptOnEvent
The pin supports triggering an interrupt when an event occurs.
Flags firstOutputDriveFlag() const
Checks the flags in OutputDriveMask, starting with OutputPushPull, and returns the first match found ...
static constexpr Flags HasPulldown
The pin has a pull-down resistor.
DigitalPinRejectedConfiguration::Reason compatible(const DigitalPinConfig &cfg) const
Returns a set of flags that indicate certain incompatible conditions in the given pin configuration i...
static constexpr Flags ControllablePulldown
The use of the pin&#39;s pull-down resistor can be controlled by software.
constexpr DigitalPinCap::Flags operator^(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
static constexpr Flags EventEdgeFalling
The pin supports setting an event flag on the falling edge.
static constexpr Flags HasPullup
The pin has a pull-up resistor.