DUDS
Distributed Update of Data from Something
DigitalPinSet.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 DIGITALPINSET_HPP
11 #define DIGITALPINSET_HPP
12 
15 
16 namespace duds { namespace hardware { namespace interface {
17 
22 class DigitalPinSet : public DigitalPinBase {
26  std::vector<unsigned int> pinvec;
27 public:
31  DigitalPinSet() = default;
45  const std::shared_ptr<DigitalPort> &port,
46  const std::vector<unsigned int> &pvec
47  );
63  const std::shared_ptr<DigitalPort> &port,
64  std::vector<unsigned int> &&pvec
65  );
70  std::unique_ptr<DigitalPinSetAccess> access() const {
71  return port()->access(pinvec);
72  }
79  void access(DigitalPinSetAccess &acc) const {
80  acc.retire();
81  port()->access(pinvec, acc);
82  }
86  const std::vector<unsigned int> &globalIds() const {
87  return pinvec;
88  }
93  std::vector<unsigned int> localIds() const {
94  return port()->localIds(pinvec);
95  }
99  bool havePins() const {
100  return (port() != nullptr) && !pinvec.empty();
101  }
107  bool exists(unsigned int pos) const {
108  return (pos < pinvec.size()) && (pinvec[pos] != -1);
109  }
114  unsigned int size() const {
115  return (unsigned int)pinvec.size();
116  }
122  unsigned int localId(unsigned int pos) const {
123  // check range using at()
124  return port()->localId(pinvec.at(pos));
125  }
131  unsigned int globalId(unsigned int pos) const {
132  // check range using at()
133  return pinvec.at(pos);
134  }
139  DigitalPinCap capabilities(unsigned int pos) const {
140  return port()->capabilities(pinvec.at(pos));
141  }
147  std::vector<DigitalPinCap> capabilities() const {
148  return port()->capabilities(pinvec);
149  }
163  DigitalPinConfig configuration(unsigned int pos) const {
164  return port()->configuration(pinvec.at(pos));
165  }
180  std::vector<DigitalPinConfig> configuration() const {
181  return port()->configuration(pinvec);
182  }
194  unsigned int pos,
195  DigitalPinConfig &conf
196  ) const {
197  return port()->proposeConfig(pinvec.at(pos), conf);
198  }
213  unsigned int pos,
214  DigitalPinConfig &proposed,
215  DigitalPinConfig &initial
216  ) const {
217  return port()->proposeConfig(pinvec.at(pos), proposed, initial);
218  }
237  std::vector<DigitalPinConfig> &propConf,
238  std::vector<DigitalPinConfig> &initConf,
239  std::function<void(DigitalPinRejectedConfiguration::Reason)> insertReason
240  = std::function<void(DigitalPinRejectedConfiguration::Reason)>()
241  ) {
242  return port()->proposeConfig(
243  pinvec,
244  propConf,
245  initConf,
246  insertReason
247  );
248  }
249 
250  // convenience functions -- may expand later
251 
257  bool simultaneousOperations() const {
258  return port()->simultaneousOperations();
259  }
264  bool independentConfig() const {
265  return port()->independentConfig();
266  }
271  bool canBeInput(unsigned int pos) const {
272  return capabilities(pos) & DigitalPinCap::Input;
273  }
278  bool canBeOutput(unsigned int pos) const {
280  }
286  bool canFloat(unsigned int pos) const {
288  }
289 };
290 
291 } } }
292 
293 #endif // #ifndef DIGITALPINSET_HPP
static constexpr Flags OutputDriveMask
A mask of all output flags that involve driving the line.
std::vector< unsigned int > localIds() const
Returns a vector of port-local pin IDs for the pins represented by this object.
unsigned int localId(unsigned int pos) const
Returns the local pin ID of the pin at the given position inside this set of pins.
static constexpr Flags Input
Input operation is supported.
Provides access to multiple pins on a DigitalPort.
std::vector< DigitalPinCap > capabilities() const
Returns the capabilities of all the pins in this set.
const std::vector< unsigned int > & globalIds() const
Provides access to the internal vector of global pin IDs.
Defines the configuration for a digital general purpose I/O pin.
DigitalPinRejectedConfiguration::Reason proposeConfig(unsigned int pos, DigitalPinConfig &proposed, DigitalPinConfig &initial) const
Propose a new configuration for the given pin using a hypothetical given initial configuration.
std::vector< DigitalPinConfig > configuration() const
Returns the current configuration all pins in this set.
std::vector< unsigned int > pinvec
The port global pin IDs this object will represent.
const std::shared_ptr< DigitalPort > & port() const
Returns the port that grants access to the pin(s) referenced by this object.
DigitalPinSet()=default
Constructs DigitalPinSet object with nothing to represent.
DigitalPinCap capabilities(unsigned int pos) const
Returns the capabilities of the specified pin.
void access(DigitalPinSetAccess &acc) const
Obtains an access object for all the pins in this set.
bool canBeInput(unsigned int pos) const
Returns true if the pin can operate as an input.
unsigned int size() const
Returns the number of pins in this object.
Represents a set of pins on a single DigitalPort.
bool exists(unsigned int pos) const
Returns true if the given position is for an existent pin rather than a gap or a position past the en...
std::unique_ptr< DigitalPinSetAccess > access() const
Obtains an access object for all the pins in this set.
bool havePins() const
Returns true if this object has been given any pins to represent.
bool independentConfig() const
Returns true if all pins on the port always have an independent configuration from all other pins...
bool canFloat(unsigned int pos) const
Returns true if the pin can provide a non-input high impedence state (or maybe allow input state...
bool simultaneousOperations() const
True if the port supports operating on multiple pins simultaneously.
A type-safe bit flag storage class.
Definition: BitFlags.hpp:101
static constexpr Flags OutputHighImpedance
The pin supports a high impedance state without input.
bool canBeOutput(unsigned int pos) const
Returns true if the pin can operate as an output.
Defines the capabilites of a digital general purpose I/O pin.
DigitalPinRejectedConfiguration::Reason proposeConfig(unsigned int pos, DigitalPinConfig &conf) const
Propose a new configuration for the given pin using the current configuration as the initial configur...
bool proposeConfig(std::vector< DigitalPinConfig > &propConf, std::vector< DigitalPinConfig > &initConf, std::function< void(DigitalPinRejectedConfiguration::Reason)> insertReason=std::function< void(DigitalPinRejectedConfiguration::Reason)>())
Propose a new configuration for the entire pin set using a hypothetical given initial configuration...
A base class for classes that represent one or more pins on a single DigitalPort, but do not provide ...
unsigned int globalId(unsigned int pos) const
Returns the global pin ID of the pin at the given position inside this set of pins.
DigitalPinConfig configuration(unsigned int pos) const
Returns the current configuration of the specified pin.