DUDS
Distributed Update of Data from Something
duds::hardware::interface::ChipSelect Class Reference

An object to wrap together a ChipSelectManager and chip ID to simplify code that needs to repeatedly select the same chip. More...

#include <ChipSelect.hpp>

Public Member Functions

 ChipSelect () noexcept
 Initializes the object to a non-configured state. More...
 
 ChipSelect (const std::shared_ptr< ChipSelectManager > &csm, int chipId)
 Makes a ChipSelect to select chipId from csm. More...
 
 ChipSelect (std::shared_ptr< ChipSelectManager > &&csm, int chipId)
 Makes a ChipSelect to select chipId from csm. More...
 
std::unique_ptr< ChipAccessaccess ()
 Obtains a ChipAccess object. More...
 
void access (ChipAccess &acc)
 Modifies a ChipAccess object to use the manager and chip specified within this object. More...
 
int chipId () const
 Returns the chip ID of the chip this object will select. More...
 
bool configured () const
 Returns true if this object was configured with a chip to select. More...
 
bool haveManager () const
 Returns true if this object has an associated manager. More...
 
const std::shared_ptr< ChipSelectManager > & manager () const
 Returns the associated manager object. More...
 
void modify (const std::shared_ptr< ChipSelectManager > &csm, int chipId)
 Changes the manager and chip to select. More...
 
void modify (std::shared_ptr< ChipSelectManager > &&csm, int chipId)
 Changes the manager and chip to select. More...
 
 operator bool () const
 This object evaluates to true if this object appears to be in a usable state. More...
 
void reset () noexcept
 Returns the object to the default constructed state of not having a manager or a valid chip ID. More...
 
std::unique_ptr< ChipAccessselect ()
 Obtains an access object and selects the chip. More...
 
void select (ChipAccess &acc)
 Modifies a ChipAccess object to use the manager and chip specified within this object, and selects the chip. More...
 

Private Attributes

int cid
 The chip to select. More...
 
std::shared_ptr< ChipSelectManagermgr
 The manager that will handle the selection. More...
 

Detailed Description

An object to wrap together a ChipSelectManager and chip ID to simplify code that needs to repeatedly select the same chip.

Author
Jeff Jackowski
Examples:
bppmenu.cpp, clockLCD.cpp, rendertext.cpp, st7920.cpp, and textdisplay.cpp.

Definition at line 24 of file ChipSelect.hpp.

Constructor & Destructor Documentation

◆ ChipSelect() [1/3]

duds::hardware::interface::ChipSelect::ChipSelect ( )
noexcept

Initializes the object to a non-configured state.

Postcondition
isConfigured() will return false.

Definition at line 16 of file ChipSelect.cpp.

◆ ChipSelect() [2/3]

duds::hardware::interface::ChipSelect::ChipSelect ( const std::shared_ptr< ChipSelectManager > &  csm,
int  chipId 
)

Makes a ChipSelect to select chipId from csm.

Parameters
csmA shared_ptr to the manager. It should be empty to be non-configured.
chipIdA non-negative chip ID, or negative to be non-configured.
Exceptions
ChipSelectInvalidChipThe manager reports that the given chip ID is invalid.

Definition at line 18 of file ChipSelect.cpp.

◆ ChipSelect() [3/3]

duds::hardware::interface::ChipSelect::ChipSelect ( std::shared_ptr< ChipSelectManager > &&  csm,
int  chipId 
)

Makes a ChipSelect to select chipId from csm.

Parameters
csmA shared_ptr to the manager. It will be moved into this object.
chipIdA non-negative chip ID, or negative to be non-configured.
Exceptions
ChipSelectInvalidChipThe manager reports that the given chip ID is invalid. csm will be unchanged.

Definition at line 25 of file ChipSelect.cpp.

Member Function Documentation

◆ access() [1/2]

std::unique_ptr< ChipAccess > duds::hardware::interface::ChipSelect::access ( )

Obtains a ChipAccess object.

Postcondition
The chip is not selected, but the resource is acquired.
Returns
The access object for selecting the chip.
Exceptions
ChipSelectBadManagerThe ChipSelectManager, manager, is not set. This is normal when the default constructor is used.

Definition at line 32 of file ChipSelect.cpp.

Referenced by duds::hardware::interface::DigitalPinMasterSyncSerial::open(), duds::hardware::devices::displays::ST7920::preparePins(), and duds::hardware::devices::displays::HD44780::preparePins().

◆ access() [2/2]

void duds::hardware::interface::ChipSelect::access ( ChipAccess acc)

Modifies a ChipAccess object to use the manager and chip specified within this object.

Precondition
acc is not providing access for chip selection.
Postcondition
The chip is not selected, but the resource is acquired.
Parameters
accThe access object that will allow chip selection.
Exceptions
ChipSelectBadManagerThe ChipSelectManager, manager, is not set. This is normal when the default constructor is used.

Definition at line 40 of file ChipSelect.cpp.

◆ chipId()

int duds::hardware::interface::ChipSelect::chipId ( ) const
inline

Returns the chip ID of the chip this object will select.

Definition at line 125 of file ChipSelect.hpp.

Referenced by modify(), and duds::hardware::interface::DigitalPinMasterSyncSerial::setChipSelect().

◆ configured()

bool duds::hardware::interface::ChipSelect::configured ( ) const
inline

Returns true if this object was configured with a chip to select.

Definition at line 112 of file ChipSelect.hpp.

Referenced by operator bool(), and duds::hardware::interface::DigitalPinMasterSyncSerial::setChipSelect().

◆ haveManager()

bool duds::hardware::interface::ChipSelect::haveManager ( ) const
inline

Returns true if this object has an associated manager.

Definition at line 100 of file ChipSelect.hpp.

Referenced by duds::hardware::interface::DigitalPinMasterSyncSerial::setChipSelect().

◆ manager()

const std::shared_ptr<ChipSelectManager>& duds::hardware::interface::ChipSelect::manager ( ) const
inline

Returns the associated manager object.

Definition at line 106 of file ChipSelect.hpp.

◆ modify() [1/2]

void duds::hardware::interface::ChipSelect::modify ( const std::shared_ptr< ChipSelectManager > &  csm,
int  chipId 
)

Changes the manager and chip to select.

Parameters
csmA shared_ptr to the manager. It should be empty to be non-configured.
chipIdA non-negative chip ID, or negative to be non-configured.
Exceptions
ChipSelectInvalidChipThe manager reports that the given chip ID is invalid.

Definition at line 64 of file ChipSelect.cpp.

Referenced by duds::hardware::interface::PinConfiguration::attachPort(), chipId(), and ChipSelect().

◆ modify() [2/2]

void duds::hardware::interface::ChipSelect::modify ( std::shared_ptr< ChipSelectManager > &&  csm,
int  chipId 
)

Changes the manager and chip to select.

Parameters
csmA shared_ptr to the manager. It will be moved into this object.
chipIdA non-negative chip ID, or negative to be non-configured.
Exceptions
ChipSelectInvalidChipThe manager reports that the given chip ID is invalid. csm will be unchanged.

Definition at line 78 of file ChipSelect.cpp.

◆ operator bool()

duds::hardware::interface::ChipSelect::operator bool ( ) const
inline

This object evaluates to true if this object appears to be in a usable state.

Definition at line 119 of file ChipSelect.hpp.

◆ reset()

void duds::hardware::interface::ChipSelect::reset ( )
noexcept

Returns the object to the default constructed state of not having a manager or a valid chip ID.

Definition at line 92 of file ChipSelect.cpp.

Referenced by chipId(), duds::hardware::interface::PinConfiguration::getPinSetAndSelect(), and modify().

◆ select() [1/2]

std::unique_ptr< ChipAccess > duds::hardware::interface::ChipSelect::select ( )

Obtains an access object and selects the chip.

Postcondition
The chip is selected.
Returns
The access object for selecting the chip.
Exceptions
ChipSelectBadManagerThe ChipSelectManager, manager, is not set. This is normal when the default constructor is used.

Definition at line 48 of file ChipSelect.cpp.

◆ select() [2/2]

void duds::hardware::interface::ChipSelect::select ( ChipAccess acc)

Modifies a ChipAccess object to use the manager and chip specified within this object, and selects the chip.

Precondition
acc is not providing access for chip selection.
Postcondition
The chip is selected.
Parameters
accThe access object that will allow chip selection.
Exceptions
ChipSelectBadManagerThe ChipSelectManager, manager, is not set. This is normal when the default constructor is used.

Definition at line 56 of file ChipSelect.cpp.

Member Data Documentation

◆ cid

int duds::hardware::interface::ChipSelect::cid
private

The chip to select.

Definition at line 32 of file ChipSelect.hpp.

Referenced by access(), chipId(), modify(), reset(), and select().

◆ mgr

std::shared_ptr<ChipSelectManager> duds::hardware::interface::ChipSelect::mgr
private

The manager that will handle the selection.

Definition at line 28 of file ChipSelect.hpp.

Referenced by access(), haveManager(), manager(), modify(), reset(), and select().


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