DUDS
Distributed Update of Data from Something
DigitalPin.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  */
10 #ifndef DIGITALPIN_HPP
11 #define DIGITALPIN_HPP
12 
15 
16 namespace duds { namespace hardware { namespace interface {
17 
22 class DigitalPin : public DigitalPinBase {
26  unsigned int gid;
27 public:
32  DigitalPin() = default;
41  DigitalPin(const std::shared_ptr<DigitalPort> &port, unsigned int pin);
46  std::unique_ptr<DigitalPinAccess> access() const {
47  return port()->access(gid);
48  }
56  void access(DigitalPinAccess *acc) const {
57  port()->access(&gid, 1, acc);
58  }
62  bool havePin() const {
63  return (bool)port();
64  }
68  unsigned int localId() const {
69  return port()->localId(gid);
70  }
74  unsigned int globalId() const {
75  return gid;
76  }
80  operator unsigned int () const {
81  return gid;
82  }
87  return port()->capabilities(gid);
88  }
102  return port()->configuration(gid);
103  }
114  DigitalPinConfig &conf
115  ) const {
116  return port()->proposeConfig(gid, conf);
117  }
131  DigitalPinConfig &proposed,
132  DigitalPinConfig &initial
133  ) const {
134  return port()->proposeConfig(gid, proposed, initial);
135  }
136 
137  // convenience functions -- may expand later
138 
142  bool canBeInput() const {
144  }
148  bool canBeOutput() const {
149  return capabilities() & (
153  );
154  }
159  bool canFloat() const {
161  }
162 };
163 
164 } } } // namespaces
165 
166 #endif // #ifndef DIGITALPIN_HPP
Represents a single pin on a DigitalPort.
Definition: DigitalPin.hpp:22
static constexpr Flags Input
Input operation is supported.
static constexpr Flags OutputDriveLow
The output is or can be an open collector or open drain type.
DigitalPinConfig configuration() const
Returns the current configuration of the represented pin.
Definition: DigitalPin.hpp:101
Defines the configuration for a digital general purpose I/O pin.
unsigned int globalId() const
Returns the global pin ID of the represented pin.
Definition: DigitalPin.hpp:74
static constexpr Flags OutputDriveHigh
The output is or can be an open emitter type.
DigitalPin()=default
Constructs a DigitalPin object without a port or pin.
DigitalPinRejectedConfiguration::Reason proposeConfig(DigitalPinConfig &proposed, DigitalPinConfig &initial) const
Propose a new configuration for the represented pin using a hypothetical given initial configuration...
Definition: DigitalPin.hpp:130
const std::shared_ptr< DigitalPort > & port() const
Returns the port that grants access to the pin(s) referenced by this object.
bool canBeOutput() const
Returns true if the pin can operate as an output.
Definition: DigitalPin.hpp:148
std::unique_ptr< DigitalPinAccess > access() const
Obtains an access object to the pin.
Definition: DigitalPin.hpp:46
DigitalPinCap capabilities() const
Returns the capabilities of the represented pin.
Definition: DigitalPin.hpp:86
bool havePin() const
Returns true if this object has been given a pin to represent.
Definition: DigitalPin.hpp:62
void access(DigitalPinAccess *acc) const
Obtains an access object to the pin.
Definition: DigitalPin.hpp:56
DigitalPinRejectedConfiguration::Reason proposeConfig(DigitalPinConfig &conf) const
Propose a new configuration for the represented pin using the current configuration as the initial co...
Definition: DigitalPin.hpp:113
Provides access to a single pin on a DigitalPort.
bool canBeInput() const
Returns true if the pin can operate as an input.
Definition: DigitalPin.hpp:142
A type-safe bit flag storage class.
Definition: BitFlags.hpp:101
static constexpr Flags OutputPushPull
The output can drive the line either low or high.
unsigned int localId() const
Returns the local pin ID of the represented pin.
Definition: DigitalPin.hpp:68
bool canFloat() const
Returns true if the pin can provide a non-input high impedence state (or maybe allow input state...
Definition: DigitalPin.hpp:159
static constexpr Flags OutputHighImpedance
The pin supports a high impedance state without input.
unsigned int gid
Global pin ID.
Definition: DigitalPin.hpp:26
Defines the capabilites of a digital general purpose I/O pin.
A base class for classes that represent one or more pins on a single DigitalPort, but do not provide ...