10 #ifndef DIGITALPINSETACCESS_HPP 11 #define DIGITALPINSETACCESS_HPP 16 namespace duds {
namespace hardware {
namespace interface {
73 void retire(
unsigned int pos);
84 const std::vector<unsigned int> &
localIds()
const {
98 return (
port() !=
nullptr) && !pinvec.empty();
106 return (pos < pinvec.size()) && (pinvec[pos] != -1);
113 return (
unsigned int)pinvec.size();
120 unsigned int localId(
unsigned int pos)
const {
122 return pinvec.at(pos);
174 std::vector<unsigned int>
subset(
const std::vector<unsigned int> &pos)
const;
229 std::vector<DigitalPinConfig> &propConf,
230 std::vector<DigitalPinConfig> &initConf,
305 const std::vector<unsigned int> &pos,
306 std::vector<DigitalPinConfig> &conf
315 bool input(
unsigned int pos)
const {
333 std::vector<bool>
input(
const std::vector<unsigned int> &pos)
const {
343 void output(
unsigned int pos,
bool state)
const {
354 void output(
const std::vector<bool> &state)
const {
365 void output(
bool state)
const;
378 const std::vector<unsigned int> &pos,
379 const std::vector<bool> &state
455 template <
typename Int>
456 void write(Int val,
int bits)
const {
458 if ((bits < 1) || (bits > pinvec.size())) {
463 if (val >= (1 << bits)) {
469 std::vector<bool> out;
472 for (; bits; --bits) {
473 out.push_back(val & 1);
477 if (out.size() == pinvec.size()) {
482 std::vector<unsigned int> pins(
484 pinvec.begin() + out.size()
498 template <
typename Int>
500 write(val, pinvec.size());
508 #endif // #ifndef DIGITALPINSETACCESS_HPP bool input(unsigned int pos) const
Samples the input state of a pin.
An attempt was made to output a number in binary on a set of pins that was too small to represent the...
virtual bool simultaneousOperations() const =0
True if the implementation supports operating on multiple pins simultaneously.
std::vector< bool > input() const
Samples the input state of all the pins.
boost::error_info< struct Info_DigitalPinNumericBits, int > DigitalPinNumericBits
The number of bits available for a numeric output.
static constexpr Flags Input
Input operation is supported.
Provides access to multiple pins on a DigitalPort.
bool input(unsigned int gid, DigitalPinAccessBase::PortData *pdata)
Does error checking in advance of calling inputImpl(unsigned int) to read the input of the given pin...
bool canBeOutput(unsigned int pos) const
Returns true if the pin can operate as an output.
DigitalPort * port() const
Returns a pointer to the port that controls the pin(s) that are operated through this object...
bool canBeInput(unsigned int pos) const
Returns true if the pin can operate as an input.
void write(Int val, int bits) const
Writes out a number in binary to the pins.
static constexpr Flags OutputDriveLow
The output is or can be an open collector or open drain type.
static constexpr Flags DirInput
Configure the pin for input.
Defines the configuration for a digital general purpose I/O pin.
bool isInput(unsigned int pos) const
Returns true if the pin is configured as an input.
The operation has too few or much data to work on the pins, which can alternately be stated as having...
std::vector< unsigned int > subset(const std::vector< unsigned int > &pos) const
Produces a vector with port local pin IDs that are a subset of the pins in this access object...
boost::error_info< struct Info_DigitalPinNumericOutput, std::int64_t > DigitalPinNumericOutput
The requested number to output; seen with DigitalPinNumericRangeError exceptions. ...
DigitalPinConfig modifyConfig(unsigned int globalPinId, const DigitalPinConfig &cfg, DigitalPinAccessBase::PortData *pdata)
Modifies the configuration of a single pin with an independent configuration.
static constexpr Flags OutputDriveHigh
The output is or can be an open emitter type.
bool isOutput(unsigned int pos) const
Returns true if the pin is configured as an output.
~DigitalPinSetAccess()
Relinquish access on destruction.
std::vector< DigitalPinConfig > configuration() const
Returns the current configuration all pins in this set.
DigitalPinSetAccess()=default
Constructs an access object with nothing to access.
void modifyConfig(const std::vector< unsigned int > &pos, std::vector< DigitalPinConfig > &conf) const
Sets the configuration for a subset of the pins.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
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...
Represents an interface to a group of hardware related digital GPIO lines.
unsigned int globalId(unsigned int localId) const
Returns the global ID for a pin given the local ID.
DigitalPinConfig modifyConfig(unsigned int pos, const DigitalPinConfig &conf) const
Modifies the configuration of a pin.
DigitalPinSetAccess & operator=(DigitalPinSetAccess &&old) noexcept
A move assignment.
bool independentConfig() const
Returns true if all pins on the port always have an independent configuration from all other pins...
std::vector< DigitalPinCap > capabilities(const std::vector< unsigned int > &pvec, bool global) const
void output(const std::vector< bool > &state) const
Changes the output state of all the 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...
PortData portdata
Port specific information.
std::vector< DigitalPinConfig > configurationLocalIds(const std::vector< unsigned int > &pvec) const
Returns the configuration of all the pins requested by local ID.
bool simultaneousOperations() const
True if the port supports operating on multiple pins simultaneously.
The base class for the digital pin access classes.
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 proposeConfigLocalIds(const std::vector< unsigned int > &localPinIds, std::vector< DigitalPinConfig > &propConf, std::vector< DigitalPinConfig > &initConf, std::function< void(DigitalPinRejectedConfiguration::Reason)> insertReason=std::function< void(DigitalPinRejectedConfiguration::Reason)>()) const
DigitalPinCap capabilities(unsigned int pos) const
Returns the capabilities of the specified pin.
void output(const std::vector< unsigned int > &pos, const std::vector< bool > &state) const
Changes the output state of a subset of the pins.
DigitalPinConfig configuration(unsigned int pos) const
Returns the current configuration of the specified pin.
void reserveAdditional(unsigned int len)
Reserves additional space in pins so that upcoming pushes onto the vector will not cause multiple mem...
DigitalPinSetAccess(DigitalPort *port, std::vector< unsigned int > &&pids)
Used by DigitalPort.
void modifyConfig(std::vector< DigitalPinConfig > &conf) const
Sets the configuration for all the pins.
std::vector< unsigned int > globalIds(const std::vector< unsigned int > &localIds) const
Converts the provided local pin IDs to global pin IDs.
A type-safe bit flag storage class.
bool havePins() const
Returns true if this object has been given any pins to access.
std::vector< DigitalPinCap > capabilitiesLocalIds(const std::vector< unsigned int > &pvec) const
Returns the capabilities of all the pins requested by local ID.
void output(unsigned int pos, bool state) const
Changes the output state of a pin.
void output(unsigned int gid, bool state, DigitalPinAccessBase::PortData *pdata)
Does error checking in advance of calling outputImpl(unsigned int, bool) to change the output of the ...
virtual bool independentConfig(unsigned int gid, const DigitalPinConfig &newcfg, const DigitalPinConfig &initcfg) const =0
Returns true if the given configuration for the given pin does not affect any other pins in the port...
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.
static constexpr Flags DirOutput
Configure the pin for output.
DigitalPinRejectedConfiguration::Reason proposeConfig(unsigned int gid, DigitalPinConfig &pconf, DigitalPinConfig &iconf) const
Proposes a configuration change for a single pin.
Defines the capabilites of a digital general purpose I/O pin.
unsigned int globalId(unsigned int pos) const
Returns the global pin ID of the pin at the given position inside this set of pins.
void write(Int val) const
Writes out a number in binary to the pins.
std::vector< bool > input(const std::vector< unsigned int > &pos) const
Samples the input state of a subset of the pins.
const std::vector< unsigned int > & localIds() const
Provides access to the internal vector of local pin IDs.
unsigned int localId(unsigned int pos) const
Returns the local pin ID of the pin at the given position inside this set of pins.
std::vector< unsigned int > pinvec
The port local pin IDs this object may use.
std::vector< DigitalPinCap > capabilities() const
Returns the capabilities of all the pins in this set.
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...
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
unsigned int size() const
Returns the number of pins in this access object.
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< unsigned int > globalIds() const
Returns a vector of global pin IDs for the pins accessed by this object.
void retire() noexcept
Relinquish access.
std::vector< DigitalPinConfig > configuration(const std::vector< unsigned int > &pvec, bool global) const