|
SensorLib 0.5.1
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Driver for the AW9523/AW9523B 16-channel GPIO and LED controller. More...
#include <IoExpanderAW9523.hpp>
Public Types | |
| enum | Port : uint16_t { PORT0 = 0x00FF , PORT1 = 0xFF00 , PORT_ALL = 0xFFFF } |
| enum class | LedCurrentRange : uint8_t { FULL = 0 , THREE_QUARTERS = 1 , HALF = 2 , QUARTER = 3 } |
| Global maximum LED current as a fraction of the typical 37 mA IMAX. More... | |
Public Member Functions | |
| IoExpanderAW9523 () | |
| ~IoExpanderAW9523 ()=default | |
| void | digitalWritePort (uint16_t mask, uint16_t values) override |
| Write selected GPIO outputs while preserving unselected pins. | |
| uint16_t | digitalReadPort () override |
| Read both GPIO input ports. | |
| bool | setPort0PushPull (bool pushPull) |
| Select the P0 GPIO output driver type. | |
| bool | setLedCurrentRange (LedCurrentRange range) |
| Set the global maximum current range for all LED channels. | |
| bool | setLedMode (uint8_t pin, bool enable=true) |
| Enable or disable constant-current LED mode on one pin. | |
| bool | setLedModes (uint16_t pinMask, bool enable=true) |
| Enable or disable constant-current LED mode on selected pins. | |
| bool | analogWrite (uint8_t pin, uint8_t value) |
| Set one constant-current LED channel's brightness. | |
| bool | enableInterrupt (uint8_t pin, bool enable=true) |
| Enable or disable input-change interrupt generation for one pin. | |
| bool | enableInterrupts (uint16_t pinMask, bool enable=true) |
| Enable or disable input-change interrupts for selected pins. | |
| bool | softwareReset () |
| Restore all registers to their hardware defaults over I2C. | |
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 |
| Hardware‑specific implementation of pinMode(). | |
| void | configPinsImpl (uint16_t pinMask, uint8_t mode) override |
| Hardware‑specific implementation of batch pin mode configuration. | |
| void | digitalWriteImpl (uint8_t pin, bool value) override |
| Hardware‑specific implementation of digitalWrite(). | |
| bool | digitalReadImpl (uint8_t pin) override |
| Hardware‑specific implementation of digitalRead(). | |
| bool | initImpl (uint8_t address) override |
| 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 |
Driver for the AW9523/AW9523B 16-channel GPIO and LED controller.
Pins 0-7 map to P0_0-P0_7 and pins 8-15 map to P1_0-P1_7. In addition to the IoExpanderBase GPIO API, this class supports input-change interrupts, P0 open-drain/push-pull selection, and 256-step constant-current LED output.
Definition at line 58 of file IoExpanderAW9523.hpp.
|
strong |
Global maximum LED current as a fraction of the typical 37 mA IMAX.
| Enumerator | |
|---|---|
| FULL | |
| THREE_QUARTERS | |
| HALF | |
| QUARTER | |
Definition at line 68 of file IoExpanderAW9523.hpp.
| enum IoExpanderAW9523::Port : uint16_t |
| Enumerator | |
|---|---|
| PORT0 | |
| PORT1 | |
| PORT_ALL | |
Definition at line 61 of file IoExpanderAW9523.hpp.
|
inline |
Definition at line 75 of file IoExpanderAW9523.hpp.
|
default |
|
inline |
Set one constant-current LED channel's brightness.
| pin | Pin number from 0 to 15. |
| value | Linear brightness/current value from 0 (off) to 255 (maximum). |
Definition at line 207 of file IoExpanderAW9523.hpp.
References SensorCommWrapper::writeReg().
|
inlineoverrideprotectedvirtual |
Hardware‑specific implementation of batch pin mode configuration.
| pinMask | Bitmask of pins to configure. |
| mode | Desired mode (INPUT or OUTPUT). |
Implements IoExpanderBase.
Definition at line 280 of file IoExpanderAW9523.hpp.
References SENSORLIB_LOG_E.
|
inlineoverrideprotectedvirtual |
Hardware‑specific implementation of digitalRead().
Called by digitalRead() after validating arguments.
| pin | Pin number. |
Implements IoExpanderBase.
Definition at line 308 of file IoExpanderAW9523.hpp.
References SensorCommWrapper::readReg(), and SENSORLIB_LOG_E.
|
inlineoverridevirtual |
Read both GPIO input ports.
Reimplemented from IoExpanderBase.
Definition at line 115 of file IoExpanderAW9523.hpp.
References SensorCommWrapper::readReg(), and SENSORLIB_LOG_E.
Referenced by scanKeyboard().
|
inlineoverrideprotectedvirtual |
Hardware‑specific implementation of digitalWrite().
Called by digitalWrite() after validating arguments and updating the cache.
| pin | Pin number. |
| value | true for HIGH, false for LOW. |
Implements IoExpanderBase.
Definition at line 299 of file IoExpanderAW9523.hpp.
References SENSORLIB_LOG_E.
|
inlineoverridevirtual |
Write selected GPIO outputs while preserving unselected pins.
| mask | Bits set to 1 select pins to update. |
| values | New output levels; bit 0 maps to P0_0 and bit 15 to P1_7. |
Reimplemented from IoExpanderBase.
Definition at line 83 of file IoExpanderAW9523.hpp.
References IoExpanderBase::_outputStates, and SENSORLIB_LOG_E.
Referenced by scanKeyboard(), and setup().
|
inline |
Enable or disable input-change interrupt generation for one pin.
| pin | Pin number from 0 to 15. |
| enable | true to enable interrupt generation. |
Definition at line 221 of file IoExpanderAW9523.hpp.
References enableInterrupts().
Referenced by setup().
|
inline |
Enable or disable input-change interrupts for selected pins.
| pinMask | Pins to modify. |
| enable | true to enable interrupt generation. |
Interrupt mask bits are active high in this API even though the AW9523 interrupt registers use 0 for enabled and 1 for disabled.
Definition at line 238 of file IoExpanderAW9523.hpp.
Referenced by enableInterrupt(), and setup().
|
inlineoverrideprotectedvirtual |
Chip‑specific initialization.
Called by all begin() overloads after the communication object is set up. Derived classes should perform any necessary hardware configuration (e.g., reset, verify device ID, set default registers).
| param | Opaque parameter passed from begin() (typically I2C address). |
Implements IoExpanderBase.
Definition at line 319 of file IoExpanderAW9523.hpp.
References DeviceBeginCommon::_addr, SensorCommWrapper::readReg(), SENSORLIB_LOG_D, SENSORLIB_LOG_E, and SensorCommWrapper::setAddress().
|
inlineoverrideprotectedvirtual |
Hardware‑specific implementation of pinMode().
Called by pinMode() after validating arguments and updating the cache.
| pin | Pin number. |
| mode | Desired mode (INPUT or OUTPUT). |
Implements IoExpanderBase.
Definition at line 264 of file IoExpanderAW9523.hpp.
References SENSORLIB_LOG_E.
|
inline |
Set the global maximum current range for all LED channels.
| range | Maximum current range relative to the typical 37 mA IMAX. |
Definition at line 147 of file IoExpanderAW9523.hpp.
References QUARTER, SensorCommWrapper::readReg(), SENSORLIB_LOG_E, and SensorCommWrapper::writeReg().
Referenced by setup().
|
inline |
Enable or disable constant-current LED mode on one pin.
| pin | Pin number from 0 to 15. |
| enable | true for LED mode, false for GPIO mode. |
Definition at line 169 of file IoExpanderAW9523.hpp.
References setLedModes().
Referenced by setup().
|
inline |
Enable or disable constant-current LED mode on selected pins.
| pinMask | Pins to modify. |
| enable | true for LED mode, false for GPIO mode. |
Definition at line 183 of file IoExpanderAW9523.hpp.
Referenced by setLedMode().
|
inline |
Select the P0 GPIO output driver type.
| pushPull | true for push-pull, false for open-drain. |
Definition at line 131 of file IoExpanderAW9523.hpp.
References SensorCommWrapper::readReg(), and SensorCommWrapper::writeReg().
Referenced by setup().
|
inline |
Restore all registers to their hardware defaults over I2C.
Definition at line 255 of file IoExpanderAW9523.hpp.
References SensorCommWrapper::writeReg().