|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Concrete driver for the XL9555 16‑bit I2C GPIO expander. More...
#include <IoExpanderXL9555.hpp>
Public Types | |
| enum | Port { PORT0 = 0x00FF , PORT1 = 0xFF00 , PORT_ALL = 0xFFFF } |
| enum | IoExpanderGPIO { __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) , __attribute__ =((deprecated("Use integer pin numbers (0-15) directly instead."))) } |
Public Member Functions | |
| IoExpanderXL9555 () | |
| Construct a new IoExpanderXL9555 object. | |
| ~IoExpanderXL9555 ()=default | |
| Destroy the IoExpanderXL9555 object. | |
| void | digitalWritePort (uint16_t mask, uint16_t values) override |
| Write to multiple pins simultaneously using a mask. | |
| uint16_t | digitalReadPort () override |
| Read the values of all 16 input pins as a single 16-bit word. | |
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 digital value from an input 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 XL9555 16‑bit I2C GPIO expander.
The XL9555 provides 16 bidirectional I/O pins, organized as two 8‑bit ports. This class implements the hardware‑specific operations required by the IoExpanderBase interface using I2C communication.
Definition at line 97 of file expander/IoExpanderXL9555.hpp.
Definition at line 106 of file expander/IoExpanderXL9555.hpp.
| Enumerator | |
|---|---|
| PORT0 | |
| PORT1 | |
| PORT_ALL | |
Definition at line 100 of file expander/IoExpanderXL9555.hpp.
|
inline |
Construct a new IoExpanderXL9555 object.
Initializes the base class with the fixed pin count of 16.
Definition at line 130 of file expander/IoExpanderXL9555.hpp.
|
default |
Destroy the IoExpanderXL9555 object.
|
inlineoverrideprotectedvirtual |
Hardware‑specific implementation for configuring multiple pins simultaneously.
This function modifies the configuration registers (CFG0/CFG1) of the XL9555. It reads the current register values, updates only the bits specified in pinMask, and writes the new values back. This ensures that the direction of pins not listed in the mask remains unchanged.
After updating the hardware, the internal pin mode cache (_pinModes) is also updated for consistency, so that subsequent individual pin operations see the correct cached state.
| pinMask | Bitmask of pins to configure. Bits 0‑7 correspond to Port 0 (pins 0‑7), bits 8‑15 correspond to Port 1 (pins 8‑15). |
| mode | Desired mode: INPUT or OUTPUT. |
Implements IoExpanderBase.
Definition at line 232 of file expander/IoExpanderXL9555.hpp.
References IoExpanderBase::_pinModes, i, SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().
|
inlineoverrideprotectedvirtual |
Read the digital value from an input pin.
Reads the input register (INP0 for pins 0‑7, INP1 for pins 8‑15).
| pin | Pin number (0‑15). |
Implements IoExpanderBase.
Definition at line 310 of file expander/IoExpanderXL9555.hpp.
References DeviceBeginCommon::ensureValid(), SensorCommWrapper::readReg(), and SENSORLIB_LOG_E.
|
inlineoverridevirtual |
Read the values of all 16 input pins as a single 16-bit word.
Reads both input registers (INP0 and INP1) and combines them into a 16-bit value where the lower 8 bits correspond to Port 0 (pins 0‑7) and the upper 8 bits correspond to Port 1 (pins 8‑15).
Reimplemented from IoExpanderBase.
Definition at line 177 of file expander/IoExpanderXL9555.hpp.
References SensorCommWrapper::readReg().
Referenced by loop().
|
inlineoverrideprotectedvirtual |
Write a digital value to an output pin.
Updates the output register (OUTP0 for pins 0‑7, OUTP1 for pins 8‑15) accordingly.
| pin | Pin number (0‑15). |
| value | true for HIGH, false for LOW. |
Implements IoExpanderBase.
Definition at line 286 of file expander/IoExpanderXL9555.hpp.
References SensorCommWrapper::clrRegBit(), SENSORLIB_LOG_E, and SensorCommWrapper::setRegBit().
|
inlineoverridevirtual |
Write to multiple pins simultaneously using a mask.
This override writes whole output registers when the mask covers an entire port, and updates the internal output state cache.
| 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 146 of file expander/IoExpanderXL9555.hpp.
References IoExpanderBase::_outputStates, i, SENSORLIB_LOG_E, and SensorCommWrapper::writeReg().
Referenced by loop().
|
inlineoverrideprotectedvirtual |
Perform chip‑specific initialization.
If the provided address is XL9555_UNKNOWN_ADDRESS, this function attempts to auto‑discover the device by scanning the standard XL9555 I2C addresses (0x20‑0x27). Otherwise, it verifies communication by reading the input port 0 register.
| param | I2C device address, or XL9555_UNKNOWN_ADDRESS for auto‑discovery. |
Implements IoExpanderBase.
Definition at line 337 of file expander/IoExpanderXL9555.hpp.
References SensorCommWrapper::readReg(), SENSORLIB_LOG_D, SENSORLIB_LOG_E, and SensorCommWrapper::setAddress().
|
inlineoverrideprotectedvirtual |
Set the direction of a single pin.
This function configures the corresponding bit in the configuration register (CFG0 for pins 0‑7, CFG1 for pins 8‑15). A 0 in the configuration register means output, a 1 means input.
| pin | Pin number (0‑15). |
| mode | Desired mode: OUTPUT (0) or INPUT (1). |
Implements IoExpanderBase.
Definition at line 197 of file expander/IoExpanderXL9555.hpp.
References SensorCommWrapper::clrRegBit(), SENSORLIB_LOG_E, and SensorCommWrapper::setRegBit().