Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
pw::digital_io::DigitalInOutMockImpl Class Reference
Inheritance diagram for pw::digital_io::DigitalInOutMockImpl:
pw::digital_io::DigitalInOut pw::digital_io::DigitalIoOptional pw::digital_io::DigitalInOutMock< kCapacity >

Classes

struct  Event
 

Public Types

using State = ::pw::digital_io::State
 
using Clock = ::pw::chrono::VirtualSystemClock
 

Public Member Functions

pw::InlineDeque< Event > & events ()
 
- Public Member Functions inherited from pw::digital_io::DigitalInOut
Result< State > GetState ()
 
Result< bool > IsStateActive ()
 
Status SetState (State state)
 
Status SetStateActive ()
 
Status SetStateInactive ()
 
- Public Member Functions inherited from pw::digital_io::DigitalIoOptional
constexpr bool provides_input () const
 
constexpr bool provides_output () const
 
constexpr bool provides_interrupt () const
 
Result< State > GetState ()
 
Status SetState (State state)
 
Result< bool > IsStateActive ()
 
Status SetStateActive ()
 
Status SetStateInactive ()
 
Status SetInterruptHandler (InterruptTrigger trigger, InterruptHandler &&handler)
 
Status ClearInterruptHandler ()
 
Status EnableInterruptHandler ()
 
Status DisableInterruptHandler ()
 
Status Enable ()
 
Status Disable ()
 

Protected Member Functions

 DigitalInOutMockImpl (Clock &clock, pw::InlineDeque< Event > &events)
 

Private Member Functions

pw::Status DoEnable (bool) override
 
pw::Result< State > DoGetState () override
 
pw::Status DoSetState (State state) override
 

Detailed Description

Mock implementation of DigitalInOut for testing.

Records the times at which the state is changed using a provided clock. This class cannot be instantiated directly. Instead, use DigitalInOutMock<kCapacity>.

Member Function Documentation

◆ DoEnable()

pw::Status pw::digital_io::DigitalInOutMockImpl::DoEnable ( bool  enable)
inlineoverrideprivatevirtual

Enables the line to initialize it into the default state as determined by the backend or disables the line to power down any pull-up/down resistors and disconnect from any voltage sources.

This may enable pull-up/down resistors, drive the line high/low, etc. The line must be enabled before getting/setting the state or enabling interrupts. Callers are responsible for waiting for the voltage level to settle after this call returns.

Calling DoEnable(true) on an already-enabled line should be a no-op, it shouldn't reset the line back to the "default state".

Calling DoEnable(false) should force the line into the disabled state, If the line was not initialized at object construction time.

Precondition
This method cannot be used in interrupt contexts.
When disabling, the interrupt handler must already be disabled.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The line is enabled and ready for use.
* 
*  Returns other status codes as defined by the backend.
* 
*  

Implements pw::digital_io::DigitalIoOptional.

◆ DoGetState()

pw::Result< State > pw::digital_io::DigitalInOutMockImpl::DoGetState ( )
overrideprivatevirtual

Gets the state of the line.

Precondition
This method cannot be used in interrupt contexts.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: An active or inactive state.
* 
*     FAILED_PRECONDITION: The line has not been enabled.
* 
*  Returns other status codes as defined by the backend.
* 
*  

Implements pw::digital_io::DigitalIoOptional.

◆ DoSetState()

pw::Status pw::digital_io::DigitalInOutMockImpl::DoSetState ( State  level)
overrideprivatevirtual

Sets the state of the line.

Callers are responsible to wait for the voltage level to settle after this call returns.

Precondition
This method cannot be used in interrupt contexts.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The state has been set.
* 
*     FAILED_PRECONDITION: The line has not been enabled.
* 
*  Returns other status codes as defined by the backend.
* 
*  

Implements pw::digital_io::DigitalIoOptional.


The documentation for this class was generated from the following file: