DUDS
Distributed Update of Data from Something
duds::hardware::interface::DigitalPinCap Struct Reference

Defines the capabilites of a digital general purpose I/O pin. More...

#include <DigitalPinCap.hpp>

Collaboration diagram for duds::hardware::interface::DigitalPinCap:

Public Types

typedef duds::general::BitFlags< struct DigitalPinFlags, std::uint16_t > Flags
 A container of flags that control the operation of a digital pin. More...
 

Public Member Functions

 DigitalPinCap ()=default
 Construct uninitialized. More...
 
constexpr DigitalPinCap (const Flags cap, std::uint16_t cur=0)
 Construct fully initiallized. More...
 
constexpr bool canOutput () const
 Returns true if the port is capable of output. More...
 
DigitalPinRejectedConfiguration::Reason compatible (const DigitalPinConfig &cfg) const
 Returns a set of flags that indicate certain incompatible conditions in the given pin configuration irrespective of any other pin. More...
 
constexpr bool exists () const
 Returns true if the pin exists and is usable by this process. More...
 
DigitalPinConfig::Flags firstOutputDriveConfigFlags () const
 Returns the output configuration flags that corresponds to the result of firstOutputDriveFlag(). More...
 
Flags firstOutputDriveFlag () const
 Checks the flags in OutputDriveMask, starting with OutputPushPull, and returns the first match found in capabilities. More...
 

Public Attributes

Flags capabilities
 The capabilities of a digital pin. More...
 
std::uint16_t maxOutputCurrent
 The maximum output current in milliamps (?) the pin can manage, or zero if unspecified or not applicable. More...
 

Static Public Attributes

static constexpr Flags ControllablePulldown = Flags::Bit(6)
 The use of the pin's pull-down resistor can be controlled by software. More...
 
static constexpr Flags ControllablePullup = Flags::Bit(8)
 The use of the pin's pull-up resistor can be controlled by software. More...
 
static constexpr Flags EventEdgeChange = Flags::Bit(11)
 The pin supports setting an event flag on an edge change. More...
 
static constexpr Flags EventEdgeFalling = Flags::Bit(9)
 The pin supports setting an event flag on the falling edge. More...
 
static constexpr Flags EventEdgeRising = Flags::Bit(10)
 The pin supports setting an event flag on the rising edge. More...
 
static constexpr Flags EventLevelHigh = Flags::Bit(13)
 The pin supports setting an event flag on a high level. More...
 
static constexpr Flags EventLevelLow = Flags::Bit(12)
 The pin supports setting an event flag on a low level. More...
 
static constexpr Flags HasPulldown = Flags::Bit(5)
 The pin has a pull-down resistor. More...
 
static constexpr Flags HasPullup = Flags::Bit(7)
 The pin has a pull-up resistor. More...
 
static constexpr Flags Input = Flags::Bit(0)
 Input operation is supported. More...
 
static constexpr Flags InterruptOnEvent = Flags::Bit(14)
 The pin supports triggering an interrupt when an event occurs. More...
 
static constexpr Flags OutputDriveHigh = Flags::Bit(3)
 The output is or can be an open emitter type. More...
 
static constexpr Flags OutputDriveLow = Flags::Bit(2)
 The output is or can be an open collector or open drain type. More...
 
static constexpr Flags OutputDriveMask
 A mask of all output flags that involve driving the line. More...
 
static constexpr Flags OutputHighImpedance = Flags::Bit(4)
 The pin supports a high impedance state without input. More...
 
static constexpr Flags OutputPushPull = Flags::Bit(1)
 The output can drive the line either low or high. More...
 

Detailed Description

Defines the capabilites of a digital general purpose I/O pin.

The reported capabilities do not consider emulating any behaviors because emulation can lead to bad behavior under certain conditions. For instance, configuring a pin as an input to get open collector or high impedance behavior allows the possibility that the input will change its state rapidly wich can cause the input buffer to draw enough current to damage itself. This may not be a problem depending upon the circuit. The application software must have correct information about the capabilities so that if it is a problem it can report an error.

DigitalPort implementations may emulate behaviors not directly supported by the hardware.

Author
Jeff Jackowski

Definition at line 31 of file DigitalPinCap.hpp.

Member Typedef Documentation

◆ Flags

typedef duds::general::BitFlags<struct DigitalPinFlags, std::uint16_t> duds::hardware::interface::DigitalPinCap::Flags

A container of flags that control the operation of a digital pin.

The flags are intended to cover a wide range of hardware, so not all options may be available on specific hardware.

Definition at line 38 of file DigitalPinCap.hpp.

Constructor & Destructor Documentation

◆ DigitalPinCap() [1/2]

duds::hardware::interface::DigitalPinCap::DigitalPinCap ( )
default

Construct uninitialized.

◆ DigitalPinCap() [2/2]

constexpr duds::hardware::interface::DigitalPinCap::DigitalPinCap ( const Flags  cap,
std::uint16_t  cur = 0 
)
inline

Construct fully initiallized.

Parameters
capThe capability flags.
curThe maximum output current.

Definition at line 141 of file DigitalPinCap.hpp.

Member Function Documentation

◆ canOutput()

constexpr bool duds::hardware::interface::DigitalPinCap::canOutput ( ) const
inline

Returns true if the port is capable of output.

This does not imply a specific high impedence state.

Definition at line 161 of file DigitalPinCap.hpp.

Referenced by duds::hardware::interface::DigitalPinAccess::canBeOutput().

◆ compatible()

DigitalPinRejectedConfiguration::Reason duds::hardware::interface::DigitalPinCap::compatible ( const DigitalPinConfig cfg) const

Returns a set of flags that indicate certain incompatible conditions in the given pin configuration irrespective of any other pin.

The only condition currently checked is whether or not the configuration is supported by the hardware.

Parameters
cfgThe configuration to check.
Exceptions
DigitalPinConfigurationErrorThe configuration disagrees with itself from either having mutually exclusive flags set, or a minimum greater than a maximum. This is a programming mistake that has nothing to do with the pin capabilities.
Returns
Flags that are set for incompatible conditions. If all flags are clear, the given configuration is compatible.

Definition at line 56 of file DigitalPinCap.cpp.

Referenced by canOutput(), duds::hardware::interface::DigitalPinConfig::compatible(), and duds::hardware::interface::DigitalPortDependentPins::proposeConfigImpl().

◆ exists()

constexpr bool duds::hardware::interface::DigitalPinCap::exists ( ) const
inline

Returns true if the pin exists and is usable by this process.

If false, the pin may or may not actually exist, but the difference will be immaterial to this process. The result does not mean that the pin is not currently in use.

Definition at line 151 of file DigitalPinCap.hpp.

Referenced by duds::hardware::interface::DigitalPort::PinEntry::operator bool().

◆ firstOutputDriveConfigFlags()

DigitalPinConfig::Flags duds::hardware::interface::DigitalPinCap::firstOutputDriveConfigFlags ( ) const

Returns the output configuration flags that corresponds to the result of firstOutputDriveFlag().

If no driving output is available, the result is DigitalPinConfig::OutputNoChange. Otherwise, the flag DigitalPinConfig::DirOutput is included along with the flags to specify driving low and/or high.

Definition at line 44 of file DigitalPinCap.cpp.

Referenced by canOutput().

◆ firstOutputDriveFlag()

DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::firstOutputDriveFlag ( ) const

Checks the flags in OutputDriveMask, starting with OutputPushPull, and returns the first match found in capabilities.

If no match is found, returns Flags::Zero().

Definition at line 31 of file DigitalPinCap.cpp.

Referenced by canOutput().

Member Data Documentation

◆ capabilities

◆ ControllablePulldown

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::ControllablePulldown = Flags::Bit(6)
static

The use of the pin's pull-down resistor can be controlled by software.

Todo:
Support this.

Definition at line 80 of file DigitalPinCap.hpp.

◆ ControllablePullup

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::ControllablePullup = Flags::Bit(8)
static

The use of the pin's pull-up resistor can be controlled by software.

Todo:
Support this.

Definition at line 89 of file DigitalPinCap.hpp.

◆ EventEdgeChange

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::EventEdgeChange = Flags::Bit(11)
static

The pin supports setting an event flag on an edge change.

Definition at line 101 of file DigitalPinCap.hpp.

◆ EventEdgeFalling

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::EventEdgeFalling = Flags::Bit(9)
static

The pin supports setting an event flag on the falling edge.

Definition at line 93 of file DigitalPinCap.hpp.

◆ EventEdgeRising

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::EventEdgeRising = Flags::Bit(10)
static

The pin supports setting an event flag on the rising edge.

Definition at line 97 of file DigitalPinCap.hpp.

◆ EventLevelHigh

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::EventLevelHigh = Flags::Bit(13)
static

The pin supports setting an event flag on a high level.

Definition at line 109 of file DigitalPinCap.hpp.

◆ EventLevelLow

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::EventLevelLow = Flags::Bit(12)
static

The pin supports setting an event flag on a low level.

Definition at line 105 of file DigitalPinCap.hpp.

◆ HasPulldown

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::HasPulldown = Flags::Bit(5)
static

The pin has a pull-down resistor.

Definition at line 75 of file DigitalPinCap.hpp.

◆ HasPullup

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::HasPullup = Flags::Bit(7)
static

The pin has a pull-up resistor.

Definition at line 84 of file DigitalPinCap.hpp.

◆ Input

◆ InterruptOnEvent

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::InterruptOnEvent = Flags::Bit(14)
static

The pin supports triggering an interrupt when an event occurs.

If set, at least one of the event flags must also be set:

  • EventEdgeFalling
  • EventEdgeRising
  • EventEdgeChange
  • EventLevelLow
  • EventLevelHigh This flag may be false even when the hardware supports the interrupt if the driver works directly with the hardware even though an operating system is in use that normally operates and limits access to the hardware.

Definition at line 122 of file DigitalPinCap.hpp.

◆ maxOutputCurrent

std::uint16_t duds::hardware::interface::DigitalPinCap::maxOutputCurrent

The maximum output current in milliamps (?) the pin can manage, or zero if unspecified or not applicable.

Definition at line 131 of file DigitalPinCap.hpp.

Referenced by compatible(), and duds::hardware::interface::operator<<().

◆ OutputDriveHigh

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::OutputDriveHigh = Flags::Bit(3)
static

The output is or can be an open emitter type.

This type drives the line high, but not low.

Definition at line 62 of file DigitalPinCap.hpp.

Referenced by duds::hardware::interface::DigitalPin::canBeOutput(), duds::hardware::interface::DigitalPinSetAccess::canBeOutput(), compatible(), and firstOutputDriveConfigFlags().

◆ OutputDriveLow

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::OutputDriveLow = Flags::Bit(2)
static

The output is or can be an open collector or open drain type.

This type drives the line low, but not high.

Note
There is a difference in the electronics of open collector and open drain outputs, but so far as I know there is no difference to how software would use them, so I used the same flag for both.

Definition at line 57 of file DigitalPinCap.hpp.

Referenced by duds::hardware::interface::DigitalPin::canBeOutput(), duds::hardware::interface::DigitalPinSetAccess::canBeOutput(), compatible(), firstOutputDriveConfigFlags(), and duds::hardware::interface::ChipBinarySelectManager::setSelectPin().

◆ OutputDriveMask

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::OutputDriveMask
static
Initial value:

A mask of all output flags that involve driving the line.

Definition at line 66 of file DigitalPinCap.hpp.

Referenced by duds::hardware::interface::DigitalPinSet::canBeOutput().

◆ OutputHighImpedance

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::OutputHighImpedance = Flags::Bit(4)
static

◆ OutputPushPull

constexpr DigitalPinCap::Flags duds::hardware::interface::DigitalPinCap::OutputPushPull = Flags::Bit(1)
static

The output can drive the line either low or high.

This is distinct from the combination of the OutputDriveLow and OutputDriveHigh flags since many outputs are a push-pull type and not an open collector, drain, or emitter.

Definition at line 49 of file DigitalPinCap.hpp.

Referenced by duds::hardware::interface::DigitalPin::canBeOutput(), duds::hardware::interface::DigitalPinSetAccess::canBeOutput(), compatible(), firstOutputDriveConfigFlags(), firstOutputDriveFlag(), duds::hardware::interface::test::VirtualPort::initPin(), duds::hardware::interface::linux::GpioDevPort::initPin(), duds::hardware::interface::linux::SysFsPort::FsPin::open(), and duds::hardware::interface::ChipBinarySelectManager::setSelectPin().


The documentation for this struct was generated from the following files: