roo_control
API Documentation for roo_control
Loading...
Searching...
No Matches
roo_control::Pcf8574 Class Reference

PCF8574 I2C-controlled 8-bit port extender. More...

#include <pcf8574.h>

Data Structures

class  OutputPort
 Output-only port. More...
 
class  Port
 Quasi-bidirectional port usable as both input and output. More...
 

Public Member Functions

 Pcf8574 (TwoWire &wire, uint8_t addr)
 Creates the extender on the specified TwoWire bus and I2C address.
 
roo_time::Duration getReadCacheDuration () const
 Returns the maximum allowed staleness of cached reads.
 
void setReadCacheDuration (roo_time::Duration duration)
 Sets the maximum allowed staleness of cached reads.
 
bool read (uint8_t &data)
 Reads, caches, and returns levels of all ports.
 
bool write (uint8_t data)
 Writes the levels of all ports.
 
uint8_t last_read () const
 Returns the most recently read byte, or 0xFF if never read.
 
uint8_t last_written () const
 Returns the most recently written byte, or 0xFF if never written.
 
BinaryLogicalState readPort (uint8_t port)
 Reads the level of the specified port.
 
bool writePort (uint8_t port, BinaryLogicalState state)
 Writes the level of the specified port.
 

Detailed Description

PCF8574 I2C-controlled 8-bit port extender.

Datasheet: https://www.ti.com/lit/ds/symlink/pcf8574.pdf

Each port can be used as digital input, digital output, or quasi-bidirectional.

To use a given port as output, drive the corresponding bit from the extender, and read it from the slave. See the datasheet for details.

To use a given port as input, set the corresponding bit to HIGH (the initial value), and then use the slave to drive the line to VCC or GND.

Definition at line 21 of file pcf8574.h.

Constructor & Destructor Documentation

◆ Pcf8574()

roo_control::Pcf8574::Pcf8574 ( TwoWire wire,
uint8_t  addr 
)

Creates the extender on the specified TwoWire bus and I2C address.

Definition at line 34 of file pcf8574.cpp.

Member Function Documentation

◆ getReadCacheDuration()

roo_time::Duration roo_control::Pcf8574::getReadCacheDuration ( ) const
inline

Returns the maximum allowed staleness of cached reads.

Useful to reduce unnecessary repetitive I2C reads. Defaults to 20 ms.

Definition at line 61 of file pcf8574.h.

◆ last_read()

uint8_t roo_control::Pcf8574::last_read ( ) const
inline

Returns the most recently read byte, or 0xFF if never read.

Definition at line 83 of file pcf8574.h.

Referenced by readPort().

◆ last_written()

uint8_t roo_control::Pcf8574::last_written ( ) const
inline

Returns the most recently written byte, or 0xFF if never written.

Definition at line 86 of file pcf8574.h.

◆ read()

bool roo_control::Pcf8574::read ( uint8_t data)

Reads, caches, and returns levels of all ports.

If called within the read-cache interval, may return cached results. Returns false on a communication failure.

Definition at line 80 of file pcf8574.cpp.

Referenced by readPort().

◆ readPort()

BinaryLogicalState roo_control::Pcf8574::readPort ( uint8_t  port)

Reads the level of the specified port.

For output ports, the value generally reflects what was last written, but it is always read from the extender. On failure, returns the last known state.

Definition at line 53 of file pcf8574.cpp.

References roo_control::BINARY_STATE_HIGH, roo_control::BINARY_STATE_LOW, last_read(), and read().

◆ setReadCacheDuration()

void roo_control::Pcf8574::setReadCacheDuration ( roo_time::Duration  duration)
inline

Sets the maximum allowed staleness of cached reads.

Definition at line 66 of file pcf8574.h.

◆ write()

bool roo_control::Pcf8574::write ( uint8_t  data)

Writes the levels of all ports.

For input ports, the corresponding bits should be HIGH to allow the slave to keep driving the actual line level. Returns false on failure.

Definition at line 99 of file pcf8574.cpp.

Referenced by writePort().

◆ writePort()

bool roo_control::Pcf8574::writePort ( uint8_t  port,
BinaryLogicalState  state 
)

Writes the level of the specified port.

Returns false on a communication failure. For input ports, it is OK to write HIGH to allow the slave to keep driving the level seen by readPort. Writing LOW will force the LOW state.

Definition at line 62 of file pcf8574.cpp.

References roo_control::BINARY_STATE_HIGH, and write().

Referenced by roo_control::Pcf8574::Port::setState().


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