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

Defines the configuration for a digital general purpose I/O pin. More...

#include <DigitalPinConfig.hpp>

Collaboration diagram for duds::hardware::interface::DigitalPinConfig:

Classes

struct  ClearAll
 Construction option for initializing all fields to defaul values. More...
 

Public Types

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

Public Member Functions

 DigitalPinConfig ()=default
 Construct uninitialized. More...
 
constexpr DigitalPinConfig (const Flags opt, const std::uint16_t minOut=0, const std::uint16_t maxOut=0)
 Construct with initial flags and current values. More...
 
constexpr DigitalPinConfig (const ClearAll)
 Construct with all values initialized to zero. More...
 
void checkValidity () const
 Checks for the use of obviously invalid data, such as the use of mutually exclusive options. More...
 
void combine (const DigitalPinConfig &newCfg)
 Combines this configuration with a newer configuration taking into account requests to not change certain options. More...
 
DigitalPinRejectedConfiguration::Reason compatible (const DigitalPinCap &cap) const
 Returns a set of flags that indicate certain incompatible conditions in the given pin configuration irrespective of any other pin. More...
 
void reverseCombine (const DigitalPinConfig &oldCfg)
 Combines an old (initial) configuration with a new configuration in this object and stores the result in this object. More...
 

Static Public Member Functions

static DigitalPinConfig combine (const DigitalPinConfig &oldCfg, const DigitalPinConfig &newCfg)
 Combines a configuration with a newer configuration taking into account requests to not change certain options, and produces a new configuration object. More...
 

Public Attributes

std::uint16_t maxOutputCurrent
 The selected maximum output current in milliamps (?) for the pin, or zero for no change and immaterial. More...
 
std::uint16_t minOutputCurrent
 The selected minimum output current in milliamps (?) for the pin, or zero for no change and immaterial. More...
 
Flags options
 The control options requested for a digital pin. More...
 

Static Public Attributes

static constexpr Flags DirImmaterial = Flags::Bit(2)
 Do not care about the pin's direction. More...
 
static constexpr Flags DirInput = Flags::Bit(0)
 Configure the pin for input. More...
 
static constexpr Flags DirMask
 A bit mask for all direction flags. More...
 
static constexpr Flags DirNoChange = Flags::Zero()
 Do not change the pin's direction. More...
 
static constexpr Flags DirOutput = Flags::Bit(1)
 Configure the pin for output. More...
 
static constexpr Flags EventEdge = EventEdgeFalling | EventEdgeRising
 Configure the pin to flag an event on any edge. More...
 
static constexpr Flags EventEdgeFalling = Flags::Bit(8)
 Configure the pin to flag an event on the falling edge. More...
 
static constexpr Flags EventEdgeRising = Flags::Bit(9)
 Configure the pin to flag an event on the rising edge. More...
 
static constexpr Flags EventImmaterial = Flags::Bit(12)
 Do not care about the pin's event configuration. More...
 
static constexpr Flags EventLevelHigh = Flags::Bit(11)
 Configure the pin to flag an event on a high level input. More...
 
static constexpr Flags EventLevelLow = Flags::Bit(10)
 Configure the pin to flag an event on a low level input. More...
 
static constexpr Flags EventMask
 A bit mask for the event configuration flags. More...
 
static constexpr Flags EventNoChange = Flags::Zero()
 Do not change the pin's event configuration. More...
 
static constexpr Flags EventNone = Flags::Bit(7)
 Configure the pin to not flag an event when the input state changes. More...
 
static constexpr Flags InputNoPull = Flags::Bit(3)
 Configure the pin to not use a pull-up or pull-down resistor. More...
 
static constexpr Flags InputPulldown = Flags::Bit(4)
 Configure the pin to have a pull-down resistor. More...
 
static constexpr Flags InputPullImmaterial = Flags::Bit(6)
 Do not care about the pin's use of a pull-up or pull-down resistor. More...
 
static constexpr Flags InputPullMask
 A bit mask for the pull-up and pull-down resistor flags. More...
 
static constexpr Flags InputPullNoChange = Flags::Zero()
 Do not change the use or non-use of a pull-up or pull-down resistor. More...
 
static constexpr Flags InputPullup = Flags::Bit(5)
 Configure the pin to have a pull-up resistor. More...
 
static constexpr Flags InputState = Flags::Bit(20)
 The last known input state from the pin. More...
 
static constexpr Flags InterruptImmaterial = Flags::Bit(15)
 Do not care about the pin's interrupt configuration. More...
 
static constexpr Flags InterruptMask = InterruptNone | InterruptOnEvent
 A bit mask for the interrupt configuration flags. More...
 
static constexpr Flags InterruptNoChange = Flags::Zero()
 Do not change the pin's interrupt configuration. More...
 
static constexpr Flags InterruptNone = Flags::Bit(13)
 Configure the pin to not trigger an interrupt. More...
 
static constexpr Flags InterruptOnEvent = Flags::Bit(14)
 Configure the pin to trigger an interrupt when an event occurs. More...
 
static constexpr Flags OperationNoChange = Flags::Zero()
 No change to any pin operation. More...
 
static constexpr Flags OutputDriveHigh = Flags::Bit(17)
 Configure the pin to be able to drive the output high. More...
 
static constexpr Flags OutputDriveLow = Flags::Bit(16)
 Configure the pin to be able to drive the output low. More...
 
static constexpr Flags OutputHighImpedance = Flags::Bit(18)
 Configure the pin to have a high impedance or floating output. More...
 
static constexpr Flags OutputImmaterial = Flags::Bit(19)
 Do not care about the pin's output configuration. More...
 
static constexpr Flags OutputMask
 A bit mask for the output options. More...
 
static constexpr Flags OutputNoChange = Flags::Zero()
 Do not change the pin's output configuration. More...
 
static constexpr Flags OutputPushPull = OutputDriveLow | OutputDriveHigh
 Configure the pin to drive output both high and low. More...
 
static constexpr Flags OutputState = Flags::Bit(21)
 The set output state for the pin. More...
 

Detailed Description

Defines the configuration for a digital general purpose I/O pin.

Author
Jeff Jackowski

Definition at line 22 of file DigitalPinConfig.hpp.

Member Typedef Documentation

◆ Flags

typedef duds::general::BitFlags<struct DigitalPinConfigFlags, std::uint32_t> duds::hardware::interface::DigitalPinConfig::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 29 of file DigitalPinConfig.hpp.

Constructor & Destructor Documentation

◆ DigitalPinConfig() [1/3]

duds::hardware::interface::DigitalPinConfig::DigitalPinConfig ( )
default

Construct uninitialized.

◆ DigitalPinConfig() [2/3]

constexpr duds::hardware::interface::DigitalPinConfig::DigitalPinConfig ( const Flags  opt,
const std::uint16_t  minOut = 0,
const std::uint16_t  maxOut = 0 
)
inline

Construct with initial flags and current values.

Parameters
optThe initial configuration flags.
minOutThe initial minimum output current. The default value 0 indicates that a minimum value is not set.
maxOutThe initial maximum output current. The default value 0 indicates that a maximum value is not set.

Definition at line 259 of file DigitalPinConfig.hpp.

◆ DigitalPinConfig() [3/3]

constexpr duds::hardware::interface::DigitalPinConfig::DigitalPinConfig ( const ClearAll  )
inline

Construct with all values initialized to zero.

Definition at line 275 of file DigitalPinConfig.hpp.

Member Function Documentation

◆ checkValidity()

void duds::hardware::interface::DigitalPinConfig::checkValidity ( ) const

Checks for the use of obviously invalid data, such as the use of mutually exclusive options.

This is intended as a debugging check. Any invalid data found is a programming error, so the error is reported as an exception.

Exceptions
DigitalPinConfigurationErrorAn exception indicating the first problem found. The actual object will be derived from this class.

Definition at line 50 of file DigitalPinConfig.cpp.

Referenced by duds::hardware::interface::DigitalPinCap::compatible(), and DigitalPinConfig().

◆ combine() [1/2]

void duds::hardware::interface::DigitalPinConfig::combine ( const DigitalPinConfig newCfg)

Combines this configuration with a newer configuration taking into account requests to not change certain options.

If an immaterial flag is set in newCfg, the corresponding configuration flags will be taken from this object and the immaterial flag will be set.

Postcondition
This configuration object is changed to the result of the combination.
Parameters
newCfgThe new configuration. Anything set to a value indicating no change will result in the current configuration (this object) being used for that option.

Definition at line 95 of file DigitalPinConfig.cpp.

Referenced by combine(), DigitalPinConfig(), duds::hardware::interface::DigitalPort::modifyConfig(), and reverseCombine().

◆ combine() [2/2]

DigitalPinConfig duds::hardware::interface::DigitalPinConfig::combine ( const DigitalPinConfig oldCfg,
const DigitalPinConfig newCfg 
)
static

Combines a configuration with a newer configuration taking into account requests to not change certain options, and produces a new configuration object.

If an immaterial flag is set in newCfg, the corresponding configuration flags will be taken from oldCfg and the immaterial flag will be set.

Parameters
oldCfgThe starting configuration.
newCfgThe new configuration. Anything set to a value indicating no change will result in the starting configuration, oldCfg, being used for that option.
Returns
The resulting configuration.

Definition at line 134 of file DigitalPinConfig.cpp.

◆ compatible()

DigitalPinRejectedConfiguration::Reason duds::hardware::interface::DigitalPinConfig::compatible ( const DigitalPinCap cap) 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
capThe capabilities to check against.
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 143 of file DigitalPinConfig.cpp.

Referenced by reverseCombine().

◆ reverseCombine()

void duds::hardware::interface::DigitalPinConfig::reverseCombine ( const DigitalPinConfig oldCfg)
inline

Combines an old (initial) configuration with a new configuration in this object and stores the result in this object.

Todo:
Finish this comment.

Definition at line 324 of file DigitalPinConfig.hpp.

Referenced by duds::hardware::interface::DigitalPortIndependentPins::proposeConfigImpl(), and duds::hardware::interface::DigitalPortDependentPins::proposeConfigImpl().

Member Data Documentation

◆ DirImmaterial

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::DirImmaterial = Flags::Bit(2)
static

Do not care about the pin's direction.

This allows the direction to be changed if a request to alter the configuration of several pins must change this pin's direction to succeed with the given hardware. If the request can be honored without changing the pin's direction, then the direction will not change.

Definition at line 55 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and combine().

◆ DirInput

◆ DirMask

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::DirMask
static

◆ DirNoChange

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::DirNoChange = Flags::Zero()
static

Do not change the pin's direction.

Definition at line 59 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ DirOutput

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::DirOutput = Flags::Bit(1)
static

◆ EventEdge

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventEdge = EventEdgeFalling | EventEdgeRising
static

Configure the pin to flag an event on any edge.

Definition at line 112 of file DigitalPinConfig.hpp.

Referenced by checkValidity().

◆ EventEdgeFalling

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventEdgeFalling = Flags::Bit(8)
static

Configure the pin to flag an event on the falling edge.

Definition at line 104 of file DigitalPinConfig.hpp.

Referenced by duds::hardware::interface::DigitalPinCap::compatible().

◆ EventEdgeRising

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventEdgeRising = Flags::Bit(9)
static

Configure the pin to flag an event on the rising edge.

Definition at line 108 of file DigitalPinConfig.hpp.

Referenced by duds::hardware::interface::DigitalPinCap::compatible().

◆ EventImmaterial

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventImmaterial = Flags::Bit(12)
static

Do not care about the pin's event configuration.

This allows the event configuration to be changed if a request to alter the configuration of several pins must change this pin's event configuration to succeed with the given hardware. If the request can be honored without making such a change, then the event configuration will not be changed.

Definition at line 129 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and combine().

◆ EventLevelHigh

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventLevelHigh = Flags::Bit(11)
static

Configure the pin to flag an event on a high level input.

Definition at line 120 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and duds::hardware::interface::DigitalPinCap::compatible().

◆ EventLevelLow

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventLevelLow = Flags::Bit(10)
static

Configure the pin to flag an event on a low level input.

Definition at line 116 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and duds::hardware::interface::DigitalPinCap::compatible().

◆ EventMask

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventMask
static
Initial value:

A bit mask for the event configuration flags.

Definition at line 137 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ EventNoChange

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventNoChange = Flags::Zero()
static

Do not change the pin's event configuration.

Definition at line 133 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ EventNone

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::EventNone = Flags::Bit(7)
static

Configure the pin to not flag an event when the input state changes.

Definition at line 100 of file DigitalPinConfig.hpp.

Referenced by checkValidity().

◆ InputNoPull

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InputNoPull = Flags::Bit(3)
static

Configure the pin to not use a pull-up or pull-down resistor.

Definition at line 69 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and duds::hardware::interface::DigitalPinCap::compatible().

◆ InputPulldown

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InputPulldown = Flags::Bit(4)
static

Configure the pin to have a pull-down resistor.

Definition at line 73 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and duds::hardware::interface::DigitalPinCap::compatible().

◆ InputPullImmaterial

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InputPullImmaterial = Flags::Bit(6)
static

Do not care about the pin's use of a pull-up or pull-down resistor.

This allows the pull-up or pull-down to be changed if a request to alter the configuration of several pins must change this pin's pull-up or pull-down resistor useage to succeed with the given hardware. If the request can be honored without making such a change, then it will not be changed.

Definition at line 86 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and combine().

◆ InputPullMask

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InputPullMask
static
Initial value:

A bit mask for the pull-up and pull-down resistor flags.

Definition at line 94 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ InputPullNoChange

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InputPullNoChange = Flags::Zero()
static

Do not change the use or non-use of a pull-up or pull-down resistor.

Definition at line 90 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ InputPullup

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InputPullup = Flags::Bit(5)
static

Configure the pin to have a pull-up resistor.

Definition at line 77 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and duds::hardware::interface::DigitalPinCap::compatible().

◆ InputState

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InputState = Flags::Bit(20)
static

The last known input state from the pin.

This flag is updated on any single pin read operation for the pin. It is handled independently of the output state.

Todo:
This is not yet implemented in DigitalPort.

Definition at line 220 of file DigitalPinConfig.hpp.

Referenced by duds::hardware::interface::test::VirtualPort::inputImpl(), and duds::hardware::interface::linux::GpioDevPort::inputImpl().

◆ InterruptImmaterial

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InterruptImmaterial = Flags::Bit(15)
static

Do not care about the pin's interrupt configuration.

This allows the interrupt configuration to be changed if a request to alter the configuration of several pins must change this pin's interrupt configuration to succeed with the given hardware. If the request can be honored without making such a change, then the interrupt configuration will not be changed.

Definition at line 157 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and combine().

◆ InterruptMask

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InterruptMask = InterruptNone | InterruptOnEvent
static

A bit mask for the interrupt configuration flags.

Definition at line 165 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ InterruptNoChange

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InterruptNoChange = Flags::Zero()
static

Do not change the pin's interrupt configuration.

Definition at line 161 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ InterruptNone

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::InterruptNone = Flags::Bit(13)
static

Configure the pin to not trigger an interrupt.

Definition at line 144 of file DigitalPinConfig.hpp.

Referenced by checkValidity().

◆ InterruptOnEvent

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

Configure the pin to trigger an interrupt when an event occurs.

Definition at line 148 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and duds::hardware::interface::DigitalPinCap::compatible().

◆ maxOutputCurrent

std::uint16_t duds::hardware::interface::DigitalPinConfig::maxOutputCurrent

The selected maximum output current in milliamps (?) for the pin, or zero for no change and immaterial.

This will have no effect for inputs. If the pin capabilities ommits an output current limit, this value will not be used.

Todo:
Rethink usage; may be useless; not currently used.

Definition at line 246 of file DigitalPinConfig.hpp.

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

◆ minOutputCurrent

std::uint16_t duds::hardware::interface::DigitalPinConfig::minOutputCurrent

The selected minimum output current in milliamps (?) for the pin, or zero for no change and immaterial.

This will have no effect for inputs. If the pin capabilities ommits an output current limit, this value will not be used.

Definition at line 238 of file DigitalPinConfig.hpp.

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

◆ OperationNoChange

◆ options

◆ OutputDriveHigh

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::OutputDriveHigh = Flags::Bit(17)
static

Configure the pin to be able to drive the output high.

If not configured to also drive the output low, then operation like an open emitter is requested, and may be emulated by configuring the pin as an input when the output state is changed to low. Emulation using input will only be done if no other pin can be affected.

Definition at line 182 of file DigitalPinConfig.hpp.

Referenced by duds::hardware::interface::DigitalPinCap::compatible(), duds::hardware::interface::DigitalPinCap::firstOutputDriveConfigFlags(), duds::hardware::interface::linux::GpioDevPort::initPin(), and duds::hardware::interface::ChipBinarySelectManager::setSelectPin().

◆ OutputDriveLow

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::OutputDriveLow = Flags::Bit(16)
static

Configure the pin to be able to drive the output low.

If not configured to also drive the output high, then operation like an open collector or open drain output is requested, and may be emulated by configuring the pin as an input when the output state is changed to high. Emulation using input will only be done if no other pin can be affected.

Definition at line 174 of file DigitalPinConfig.hpp.

Referenced by duds::hardware::interface::DigitalPinCap::compatible(), duds::hardware::interface::DigitalPinCap::firstOutputDriveConfigFlags(), duds::hardware::interface::linux::GpioDevPort::initPin(), and duds::hardware::interface::ChipBinarySelectManager::setSelectPin().

◆ OutputHighImpedance

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::OutputHighImpedance = Flags::Bit(18)
static

Configure the pin to have a high impedance or floating output.

Definition at line 190 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and duds::hardware::interface::DigitalPinCap::compatible().

◆ OutputImmaterial

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::OutputImmaterial = Flags::Bit(19)
static

Do not care about the pin's output configuration.

This allows the output configuration to be changed if a request to alter the configuration of several pins must change this pin's output configuration to succeed with the given hardware. If the request can be honored without making such a change, then the output configuration will not be changed.

Definition at line 199 of file DigitalPinConfig.hpp.

Referenced by checkValidity(), and combine().

◆ OutputMask

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::OutputMask
static
Initial value:

A bit mask for the output options.

Definition at line 207 of file DigitalPinConfig.hpp.

Referenced by combine().

◆ OutputNoChange

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::OutputNoChange = Flags::Zero()
static

Do not change the pin's output configuration.

Definition at line 203 of file DigitalPinConfig.hpp.

Referenced by combine(), and duds::hardware::interface::DigitalPinCap::firstOutputDriveConfigFlags().

◆ OutputPushPull

◆ OutputState

constexpr DigitalPinConfig::Flags duds::hardware::interface::DigitalPinConfig::OutputState = Flags::Bit(21)
static

The set output state for the pin.

This flag is updated on any single pin write operation for the pin. It is handled independently of the input state.

Todo:
This is not yet implemented in DigitalPort.

Definition at line 227 of file DigitalPinConfig.hpp.

Referenced by duds::hardware::interface::linux::GpioDevPort::configurePort(), duds::hardware::interface::linux::GpioDevPort::madeAccess(), duds::hardware::interface::test::VirtualPort::outputImpl(), and duds::hardware::interface::linux::GpioDevPort::outputImpl().


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