|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Concrete driver for the PCA9570 4‑bit output‑only I2C GPIO expander. More...
#include <IoExpanderPCA9570.hpp>
Public Types | |
| enum | Port { PORT_ALL = 0x0F } |
Public Member Functions | |
| IoExpanderPCA9570 () | |
| Construct a new IoExpanderPCA9570 object. | |
| ~IoExpanderPCA9570 ()=default | |
| Destroy the IoExpanderPCA9570 object. | |
| void | digitalWritePort (uint16_t mask, uint16_t values) override |
| Write to multiple pins simultaneously using a mask. | |
| uint16_t | digitalReadPort () override |
| Read the current output register value. | |
Public Member Functions inherited from IoExpanderBase | |
| IoExpanderBase (uint8_t pinCount) | |
| Construct a new IoExpanderBase object. | |
| virtual | ~IoExpanderBase ()=default |
| Virtual destructor. | |
| virtual void | deinit () |
| Deinitialize the expander. | |
| void | configPins (uint16_t pinMask, uint8_t mode) |
| Configure multiple pins as input or output simultaneously. | |
| void | pinMode (uint8_t pin, uint8_t mode) |
| Set the direction of a GPIO pin. | |
| void | digitalWrite (uint8_t pin, bool value) |
| Write a digital value to an output pin. | |
| bool | digitalRead (uint8_t pin) |
| Read the digital value from an input pin. | |
| void | digitalToggle (uint8_t pin) |
| Toggle the state of an output pin. | |
| uint8_t | pinCount () const |
| Get the total number of pins provided by this expander. | |
| uint16_t | pinToMask (uint8_t pin) const |
| Convert a pin number to its corresponding bitmask. | |
Public Member Functions inherited from I2CDeviceNoHal | |
| bool | begin (SensorCommCustom::CustomCallback callback, uint8_t addr) |
| Initialize the sensor using custom callback interface. | |
Public Member Functions inherited from DeviceBeginCommon | |
| virtual | ~DeviceBeginCommon () |
| uint8_t | getAddress () const |
| uint8_t | getInterface () const |
Public Member Functions inherited from SensorCommWrapper | |
| SensorCommWrapper ()=default | |
| int | readReg (uint8_t reg) const |
| int | readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const |
| int | readBuff (uint8_t *buf, size_t len) const |
| int | writeReg (uint8_t reg, uint8_t val) |
| int | writeRegBuff (uint8_t reg, uint8_t *buf, size_t len) |
| int | writeBuff (uint8_t *buf, size_t len) |
| int | writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len) |
| bool | setRegBit (uint8_t reg, uint8_t bit) |
| bool | clrRegBit (uint8_t reg, uint8_t bit) |
| bool | getRegBit (uint8_t reg, uint8_t bit) |
| int | updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted) |
| void | setAddress (uint8_t address) |
| void | setAck (bool enable) |
Public Member Functions inherited from SensorCommInterface | |
| virtual | ~SensorCommInterface ()=default |
Protected Member Functions | |
| void | pinModeImpl (uint8_t pin, uint8_t mode) override |
| Set the direction of a single pin. | |
| void | configPinsImpl (uint16_t pinMask, uint8_t mode) override |
| Hardware‑specific implementation for configuring multiple pins simultaneously. | |
| void | digitalWriteImpl (uint8_t pin, bool value) override |
| Write a digital value to an output pin. | |
| bool | digitalReadImpl (uint8_t pin) override |
| Read the current output value of a pin. | |
| bool | initImpl (uint8_t param) override |
| Perform chip‑specific initialization. | |
Protected Member Functions inherited from DeviceBeginCommon | |
| DeviceBeginCommon ()=default | |
| virtual bool | ensureValid () const override |
| virtual SensorCommBase * | getComm () const override |
| virtual void | beforeBegin () |
| virtual void | afterCommReady () |
| virtual void | afterInitSuccess (uint8_t param) |
| virtual void | onBeginFail () |
| bool | fail () |
| void | clearCommState () |
| template<typename CreateComm > | |
| bool | beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm) |
Additional Inherited Members | |
Protected Attributes inherited from IoExpanderBase | |
| uint8_t | _pinCount |
| Number of GPIO pins. | |
| std::unique_ptr< uint8_t[]> | _pinModes |
| Cached pin modes (INPUT/OUTPUT) | |
| std::unique_ptr< bool[]> | _outputStates |
| Cached output states (true = HIGH) | |
Protected Attributes inherited from DeviceBeginCommon | |
| std::unique_ptr< SensorCommBase > | comm |
| std::unique_ptr< SensorHal > | hal |
| std::unique_ptr< SensorCommStatic > | staticComm |
| uint8_t | _addr = 0 |
| uint8_t | _iface = COMM_CUSTOM |
Concrete driver for the PCA9570 4‑bit output‑only I2C GPIO expander.
The PCA9570 provides 4 output‑only pins. All pins are configured as outputs by default; pinMode() will accept only OUTPUT. Reading a pin returns the last written value (output register).
Definition at line 49 of file IoExpanderPCA9570.hpp.
| Enumerator | |
|---|---|
| PORT_ALL | |
Definition at line 53 of file IoExpanderPCA9570.hpp.
|
inline |
Construct a new IoExpanderPCA9570 object.
Initializes the base class with the fixed pin count of 4.
Definition at line 62 of file IoExpanderPCA9570.hpp.
|
default |
Destroy the IoExpanderPCA9570 object.
|
inlineoverrideprotectedvirtual |
Hardware‑specific implementation for configuring multiple pins simultaneously.
The PCA9570 has fixed output‑only pins; therefore, this function does not perform any hardware configuration. It validates that the requested mode is OUTPUT (as INPUT is not supported) and updates the internal pin mode cache accordingly.
| pinMask | Bitmask of pins to configure (ignored, as all pins behave identically). |
| mode | Desired mode. Only OUTPUT is accepted; INPUT will log an error. |
Implements IoExpanderBase.
Definition at line 164 of file IoExpanderPCA9570.hpp.
References IoExpanderBase::_pinModes, i, and SENSORLIB_LOG_E.
|
inlineoverrideprotectedvirtual |
Read the current output value of a pin.
Since PCA9570 has no input capability, this returns the last written value (output register state).
| pin | Pin number (0‑3). |
Implements IoExpanderBase.
Definition at line 210 of file IoExpanderPCA9570.hpp.
References digitalReadPort().
|
inlineoverridevirtual |
Read the current output register value.
Reimplemented from IoExpanderBase.
Definition at line 119 of file IoExpanderPCA9570.hpp.
References SensorCommWrapper::readBuff(), and SENSORLIB_LOG_E.
Referenced by digitalReadImpl(), and digitalWriteImpl().
|
inlineoverrideprotectedvirtual |
Write a digital value to an output pin.
Reads the current output register, updates the specified bit, and writes the new value back.
| pin | Pin number (0‑3). |
| value | true for HIGH, false for LOW. |
Implements IoExpanderBase.
Definition at line 189 of file IoExpanderPCA9570.hpp.
References digitalReadPort(), and SensorCommWrapper::writeRegBuff().
|
inlineoverridevirtual |
Write to multiple pins simultaneously using a mask.
Reads the current output register, modifies only the bits specified by the mask, and writes the result back. The internal output state cache is also updated.
| mask | Bitmask where a 1 indicates the pin should be updated. |
| values | Bitmask of the new values for the selected pins. |
Reimplemented from IoExpanderBase.
Definition at line 79 of file IoExpanderPCA9570.hpp.
References IoExpanderBase::_outputStates, i, SensorCommWrapper::readBuff(), SENSORLIB_LOG_E, and SensorCommWrapper::writeRegBuff().
Referenced by loop().
|
inlineoverrideprotectedvirtual |
Perform chip‑specific initialization.
Reads the device ID registers to verify communication and logs the manufacturer ID, part ID, and revision.
| param | No use |
Implements IoExpanderBase.
Definition at line 226 of file IoExpanderPCA9570.hpp.
References SensorCommWrapper::readRegBuff(), SENSORLIB_LOG_D, and SENSORLIB_LOG_E.
|
inlineoverrideprotectedvirtual |
Set the direction of a single pin.
The PCA9570 only supports output mode; therefore, any request for INPUT mode is rejected with an error. No hardware configuration is performed because all pins are fixed as outputs.
| pin | Pin number (0‑3). (Not used, as all pins behave identically.) |
| mode | Desired mode. Only OUTPUT is accepted. |
Implements IoExpanderBase.
Definition at line 141 of file IoExpanderPCA9570.hpp.
References SENSORLIB_LOG_E.