HardFOC Core
API reference
Loading...
Searching...
No Matches
Pcal95555Handler.h
Go to the documentation of this file.
1
82#ifndef COMPONENT_HANDLER_PCAL95555_HANDLER_H_
83#define COMPONENT_HANDLER_PCAL95555_HANDLER_H_
84
85#include <atomic>
86#include <cstdint>
87#include <memory>
88#include <array>
89#include <functional>
90#include "base/BaseGpio.h"
91#include "base/BaseI2c.h"
92#include "core/hf-core-drivers/external/hf-pcal95555-driver/inc/pcal95555.hpp"
93#include "RtosMutex.h"
94
95// Forward declarations
97
103
126class HalI2cPcal95555Comm : public pcal95555::I2cInterface<HalI2cPcal95555Comm> {
127public:
133 explicit HalI2cPcal95555Comm(BaseI2c& i2c_device) noexcept;
134
138
151 bool Write(uint8_t addr, uint8_t reg, const uint8_t* data, size_t len) noexcept;
152
164 bool Read(uint8_t addr, uint8_t reg, uint8_t* data, size_t len) noexcept;
165
170 bool EnsureInitialized() noexcept;
171
182 bool RegisterInterruptHandler(std::function<void()> handler) noexcept;
183
185
190 const std::function<void()>& GetInterruptHandler() const noexcept { return interrupt_handler_; }
191
192private:
193 BaseI2c& i2c_device_;
194 mutable RtosMutex i2c_mutex_;
195 std::function<void()> interrupt_handler_;
196 uint8_t cmd_scratch_{0};
198 uint8_t tx_scratch_[4]{};
199 uint8_t rx_scratch_[2]{};
200};
201
203
209
230class Pcal95555GpioPin : public BaseGpio {
231public:
241 Pcal95555GpioPin(hf_pin_num_t pin,
242 Pcal95555Handler* parent_handler,
243 hf_gpio_direction_t direction = hf_gpio_direction_t::HF_GPIO_DIRECTION_INPUT,
244 hf_gpio_active_state_t active_state = hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH,
245 hf_gpio_output_mode_t output_mode = hf_gpio_output_mode_t::HF_GPIO_OUTPUT_MODE_PUSH_PULL,
246 hf_gpio_pull_mode_t pull_mode = hf_gpio_pull_mode_t::HF_GPIO_PULL_MODE_FLOATING,
247 bool configure_hardware = true) noexcept;
248
250 ~Pcal95555GpioPin() noexcept override = default;
251
254
256 bool Initialize() noexcept override;
257
259 bool Deinitialize() noexcept override;
260
262 bool IsPinAvailable() const noexcept override;
263
265 hf_u8_t GetMaxPins() const noexcept override { return 16; }
266
268 const char* GetDescription() const noexcept override;
269
277 hf_gpio_err_t SupportsInterrupts() const noexcept override;
278
290 hf_gpio_err_t ConfigureInterrupt(hf_gpio_interrupt_trigger_t trigger,
291 InterruptCallback callback = nullptr,
292 void* user_data = nullptr) noexcept override;
293
295
299
305 hf_gpio_err_t SetPolarityInversion(bool invert) noexcept;
306
312 hf_gpio_err_t SetInterruptMask(bool mask) noexcept;
313
315 using BaseGpio::GetInterruptStatus;
316
322 hf_gpio_err_t GetInterruptStatus(bool& status) noexcept;
323
325
326protected:
329
331 hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept override;
332
334 hf_gpio_err_t SetOutputModeImpl(hf_gpio_output_mode_t mode) noexcept override;
335
337 hf_gpio_err_t SetPullModeImpl(hf_gpio_pull_mode_t mode) noexcept override;
338
340 hf_gpio_pull_mode_t GetPullModeImpl() const noexcept override;
341
343 hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept override;
344
346 hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t& level) noexcept override;
347
349 hf_gpio_err_t GetDirectionImpl(hf_gpio_direction_t& direction) const noexcept override;
350
352 hf_gpio_err_t GetOutputModeImpl(hf_gpio_output_mode_t& mode) const noexcept override;
353
355
357 friend class Pcal95555Handler;
358
359private:
360 hf_pin_num_t pin_;
362 char description_[32] = {};
364
367 InterruptCallback interrupt_callback_ = nullptr;
368 void* interrupt_user_data_ = nullptr;
369 hf_gpio_interrupt_trigger_t interrupt_trigger_ =
370 hf_gpio_interrupt_trigger_t::HF_GPIO_INTERRUPT_TRIGGER_NONE;
371 bool interrupt_enabled_ = false;
373};
374
376
382
417public:
418 //==========================================================================
421 //==========================================================================
422
424 using Pcal95555Driver = pcal95555::PCAL95555<HalI2cPcal95555Comm>;
425
427
428 //==========================================================================
431 //==========================================================================
432
444 explicit Pcal95555Handler(BaseI2c& i2c_device, BaseGpio* interrupt_pin = nullptr) noexcept;
445
447 ~Pcal95555Handler() noexcept = default;
448
452 Pcal95555Handler& operator=(const Pcal95555Handler&) = delete;
453
457 Pcal95555Handler& operator=(Pcal95555Handler&&) = delete;
458
460
461 //==========================================================================
464 //==========================================================================
465
475 bool EnsureInitialized() noexcept;
476
485 bool EnsureDeinitialized() noexcept;
486
491 bool IsInitialized() const noexcept { return initialized_; }
492
494
495 //==========================================================================
499 //==========================================================================
500
507 hf_gpio_err_t SetDirection(uint8_t pin, hf_gpio_direction_t direction) noexcept;
508
515 hf_gpio_err_t SetOutput(uint8_t pin, bool active) noexcept;
516
527 hf_gpio_err_t ReadInput(uint8_t pin, bool& active) noexcept;
528
534 hf_gpio_err_t Toggle(uint8_t pin) noexcept;
535
550 hf_gpio_err_t SetPullMode(uint8_t pin, hf_gpio_pull_mode_t pull_mode) noexcept;
551
558 hf_gpio_err_t GetPullMode(uint8_t pin, hf_gpio_pull_mode_t& pull_mode) noexcept;
559
561
562 //==========================================================================
566 //==========================================================================
567
574 hf_gpio_err_t SetDirections(uint16_t pin_mask, hf_gpio_direction_t direction) noexcept;
575
582 hf_gpio_err_t SetOutputs(uint16_t pin_mask, bool active) noexcept;
583
594 hf_gpio_err_t SetOutputsVerified(uint16_t pin_mask, bool active) noexcept;
595
603 hf_gpio_err_t SetPullModes(uint16_t pin_mask, hf_gpio_pull_mode_t pull_mode) noexcept;
604
606
607 //==========================================================================
610 //==========================================================================
611
616 bool HasInterruptSupport() const noexcept { return interrupt_pin_ != nullptr; }
617
622 bool IsInterruptConfigured() const noexcept { return interrupt_configured_; }
623
633 bool DrainPendingInterrupts() noexcept;
634
641 hf_gpio_err_t GetAllInterruptMasks(uint16_t& mask) noexcept;
642
652 hf_gpio_err_t GetAllInterruptStatus(uint16_t& status) noexcept;
653
655
656 //==========================================================================
660 //==========================================================================
661
663 static constexpr uint8_t PinCount() noexcept { return 16; }
664
669 uint8_t GetI2cAddress() const noexcept;
670
680 bool AttachStaticPin(Pcal95555GpioPin& pin) noexcept;
681
693 std::shared_ptr<BaseGpio> CreateGpioPin(
694 hf_pin_num_t pin,
695 hf_gpio_direction_t direction = hf_gpio_direction_t::HF_GPIO_DIRECTION_INPUT,
696 hf_gpio_active_state_t active_state = hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH,
697 hf_gpio_output_mode_t output_mode = hf_gpio_output_mode_t::HF_GPIO_OUTPUT_MODE_PUSH_PULL,
698 hf_gpio_pull_mode_t pull_mode = hf_gpio_pull_mode_t::HF_GPIO_PULL_MODE_FLOATING,
699 bool allow_existing = true,
700 bool configure_hardware = true) noexcept;
701
706 std::shared_ptr<BaseGpio> GetGpioPin(hf_pin_num_t pin) noexcept;
707
711 Pcal95555GpioPin* GetGpioPinRaw(hf_pin_num_t pin) noexcept;
712
717 hf_gpio_err_t ReadAllInputLevels(uint16_t& levels) noexcept;
718
730 hf_gpio_err_t ProgramPortsAbsolute(uint16_t config, uint16_t output,
731 uint16_t out_check_mask) noexcept;
732
736 hf_gpio_err_t ReadConfigAndOutputPorts(uint16_t& config,
737 uint16_t& output) noexcept;
738
745 hf_gpio_err_t ReadOutputLatchFromWire(uint16_t& output) noexcept;
746
754 hf_gpio_err_t ReadStandardRegisterBank(uint16_t& input, uint16_t& output,
755 uint16_t& polarity,
756 uint16_t& config) noexcept;
757
769 hf_gpio_err_t VerifyOutputPinEffect(uint8_t pin, uint16_t& latch_high,
770 uint16_t& input_high, uint16_t& latch_low,
771 uint16_t& input_low) noexcept;
772
778 bool IsPinCreated(hf_pin_num_t pin) const noexcept;
779
784 uint16_t GetCreatedPinMask() const noexcept;
785
787
788 //==========================================================================
792 //==========================================================================
793
799 bool HasAgileIO() const noexcept;
800
805 pcal95555::ChipVariant GetChipVariant() const noexcept;
806
813 hf_gpio_err_t SetPolarityInversion(hf_pin_num_t pin, bool invert) noexcept;
814
821 hf_gpio_err_t SetMultiplePolarityInversion(uint16_t pin_mask, bool invert) noexcept;
822
830 hf_gpio_err_t SetInterruptMask(hf_pin_num_t pin, bool mask) noexcept;
831
839 hf_gpio_err_t GetInterruptStatus(hf_pin_num_t pin, bool& status) noexcept;
840
848 hf_gpio_err_t SetDriveStrength(hf_pin_num_t pin, pcal95555::DriveStrength level) noexcept;
849
857 hf_gpio_err_t EnableInputLatch(hf_pin_num_t pin, bool enable) noexcept;
858
866 hf_gpio_err_t SetOutputMode(bool port0_open_drain, bool port1_open_drain) noexcept;
867
872 hf_gpio_err_t ResetToDefault() noexcept;
873
875
876 //==========================================================================
879 //==========================================================================
880
885 uint16_t GetErrorFlags() const noexcept;
886
891 void ClearErrorFlags(uint16_t mask = 0xFFFF) noexcept;
892
894
895 //==========================================================================
898 //==========================================================================
899
906 void DumpDiagnostics() const noexcept;
907
909
911 friend class Pcal95555GpioPin;
912
913private:
914 //==========================================================================
915 // Private Methods
916 //==========================================================================
917
922 bool EnsureInitializedLocked() noexcept;
923
928 hf_gpio_err_t Initialize() noexcept;
929
934 hf_gpio_err_t Deinitialize() noexcept;
935
937 bool ValidatePin(uint8_t pin) const noexcept { return pin < 16; }
938
947 hf_gpio_err_t RegisterPinInterrupt(hf_pin_num_t pin,
948 hf_gpio_interrupt_trigger_t trigger,
949 InterruptCallback callback,
950 void* user_data) noexcept;
951
957 hf_gpio_err_t UnregisterPinInterrupt(hf_pin_num_t pin) noexcept;
958
963 hf_gpio_err_t ConfigureHardwareInterrupt() noexcept;
964
971 static void HardwareInterruptCallback(BaseGpio* gpio,
972 hf_gpio_interrupt_trigger_t trigger,
973 void* user_data) noexcept;
974
978 void ProcessInterrupts() noexcept;
979
980 //==========================================================================
983 //==========================================================================
984
989 [[nodiscard]] Pcal95555Driver* GetDriver() noexcept;
990 [[nodiscard]] const Pcal95555Driver* GetDriver() const noexcept;
991
993
994 //==========================================================================
995 // Private Members
996 //==========================================================================
997
1000 BaseI2c& i2c_device_;
1003 bool initialized_ = false;
1004 mutable RtosMutex handler_mutex_;
1006
1009 std::array<Pcal95555GpioPin*, 16> pin_registry_{};
1010 std::array<std::unique_ptr<Pcal95555GpioPin>, 16> owned_pins_{};
1012
1015 BaseGpio* interrupt_pin_;
1017 std::atomic<bool> interrupt_pending_{false};
1019
1023 std::array<hf_gpio_pull_mode_t, 16> pull_mode_cache_;
1025
1029 uint16_t prev_input_state_ = 0;
1031
1035 uint16_t output_shadow_{0xFFFFU};
1036 uint16_t config_shadow_{0xFFFFU};
1037 uint16_t polarity_shadow_{0};
1040};
1041
1043
1044#endif // COMPONENT_HANDLER_PCAL95555_HANDLER_H_
Concrete I2C communication adapter for PCAL95555 using BaseI2c.
Definition Pcal95555Handler.h:126
uint8_t cmd_scratch_
Register cmd byte for Read/Write framing.
Definition Pcal95555Handler.h:196
bool Read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) noexcept
Read data from a device register.
Definition Pcal95555Handler.cpp:87
bool Write(uint8_t addr, uint8_t reg, const uint8_t *data, size_t len) noexcept
Write data to a device register.
Definition Pcal95555Handler.cpp:60
std::function< void()> interrupt_handler_
Stored interrupt handler from driver.
Definition Pcal95555Handler.h:195
bool RegisterInterruptHandler(std::function< void()> handler) noexcept
Register an interrupt handler to be called when the INT pin fires.
Definition Pcal95555Handler.cpp:124
RtosMutex i2c_mutex_
Thread safety for I2C operations.
Definition Pcal95555Handler.h:194
uint8_t rx_scratch_[2]
Definition Pcal95555Handler.h:199
BaseI2c & i2c_device_
I2C device interface (not owned).
Definition Pcal95555Handler.h:193
bool EnsureInitialized() noexcept
Ensure the I2C bus is initialized and ready.
Definition Pcal95555Handler.cpp:120
uint8_t tx_scratch_[4]
Definition Pcal95555Handler.h:198
const std::function< void()> & GetInterruptHandler() const noexcept
Get the stored interrupt handler (if any).
Definition Pcal95555Handler.h:190
BaseGpio adapter for a single PCAL95555 GPIO expander pin.
Definition Pcal95555Handler.h:230
hf_gpio_err_t SetPullModeImpl(hf_gpio_pull_mode_t mode) noexcept override
Set pull mode (floating/up/down). PCAL9555A only.
Definition Pcal95555Handler.cpp:1534
bool configure_hardware_
If false, Initialize() skips I2C.
Definition Pcal95555Handler.h:363
hf_gpio_err_t SetPolarityInversion(bool invert) noexcept
Set input polarity inversion for this pin.
Definition Pcal95555Handler.cpp:1503
~Pcal95555GpioPin() noexcept override=default
Default destructor.
bool Deinitialize() noexcept override
Deinitialize (marks pin as uninitialized; expander state persists).
Definition Pcal95555Handler.cpp:1473
hf_gpio_err_t SetOutputModeImpl(hf_gpio_output_mode_t mode) noexcept override
Returns GPIO_ERR_UNSUPPORTED_OPERATION (use Pcal95555Handler::SetOutputMode for per-port control).
Definition Pcal95555Handler.cpp:1526
void * interrupt_user_data_
Definition Pcal95555Handler.h:368
hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept override
Write pin level via the PCAL95555 driver.
Definition Pcal95555Handler.cpp:1552
InterruptCallback interrupt_callback_
Definition Pcal95555Handler.h:367
bool IsPinAvailable() const noexcept override
Check if this pin number is valid (0-15).
Definition Pcal95555Handler.cpp:1478
bool Initialize() noexcept override
Initialize the pin (configures direction and pull mode on the expander).
Definition Pcal95555Handler.cpp:1440
hf_pin_num_t pin_
Pin number (0-15).
Definition Pcal95555Handler.h:360
hf_gpio_err_t SupportsInterrupts() const noexcept override
Check if this pin supports interrupt configuration.
Definition Pcal95555Handler.cpp:1482
char description_[32]
Human-readable description.
Definition Pcal95555Handler.h:362
hf_gpio_err_t GetInterruptStatus(bool &status) noexcept
Get the interrupt status for this pin.
Definition Pcal95555Handler.cpp:1513
hf_gpio_pull_mode_t GetPullModeImpl() const noexcept override
Get current pull mode (tracked internally).
Definition Pcal95555Handler.cpp:1540
bool interrupt_enabled_
Definition Pcal95555Handler.h:371
hf_gpio_err_t SetInterruptMask(bool mask) noexcept
Set the interrupt mask for this pin.
Definition Pcal95555Handler.cpp:1508
hf_gpio_err_t GetDirectionImpl(hf_gpio_direction_t &direction) const noexcept override
Get pin direction from the PCAL95555 driver.
Definition Pcal95555Handler.cpp:1571
Pcal95555Handler * parent_handler_
Owning handler (not owned).
Definition Pcal95555Handler.h:361
hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept override
Set pin direction via the PCAL95555 driver.
Definition Pcal95555Handler.cpp:1520
hf_gpio_err_t ConfigureInterrupt(hf_gpio_interrupt_trigger_t trigger, InterruptCallback callback=nullptr, void *user_data=nullptr) noexcept override
Configure interrupt for this pin.
Definition Pcal95555Handler.cpp:1493
const char * GetDescription() const noexcept override
Returns a description string like "PCAL95555_PIN_5".
Definition Pcal95555Handler.cpp:1489
hf_gpio_err_t GetOutputModeImpl(hf_gpio_output_mode_t &mode) const noexcept override
Get output mode (tracked internally).
Definition Pcal95555Handler.cpp:1578
hf_gpio_interrupt_trigger_t interrupt_trigger_
Definition Pcal95555Handler.h:369
hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t &level) noexcept override
Read pin level via the PCAL95555 driver.
Definition Pcal95555Handler.cpp:1559
hf_u8_t GetMaxPins() const noexcept override
Returns 16 (total pins on the expander).
Definition Pcal95555Handler.h:265
Unified, non-templated handler for a single PCA9555 / PCAL9555A device.
Definition Pcal95555Handler.h:416
hf_gpio_err_t ReadConfigAndOutputPorts(uint16_t &config, uint16_t &output) noexcept
Read CONFIG (1=input) and OUTPUT latch port pairs (PCA pin bits).
Definition Pcal95555Handler.cpp:1040
uint8_t GetI2cAddress() const noexcept
Get the I2C address of the underlying device.
Definition Pcal95555Handler.cpp:839
hf_gpio_err_t GetInterruptStatus(hf_pin_num_t pin, bool &status) noexcept
Get interrupt status for a single pin.
Definition Pcal95555Handler.cpp:1252
uint16_t output_shadow_
PCA POR default OUTPUT.
Definition Pcal95555Handler.h:1035
hf_gpio_err_t GetPullMode(uint8_t pin, hf_gpio_pull_mode_t &pull_mode) noexcept
Get the pull resistor mode for a single pin (tracked internally).
Definition Pcal95555Handler.cpp:478
hf_gpio_err_t ReadStandardRegisterBank(uint16_t &input, uint16_t &output, uint16_t &polarity, uint16_t &config) noexcept
Read the full standard PCA9555 bank (0x00..0x07) as four 16-bit ports.
Definition Pcal95555Handler.cpp:1063
std::unique_ptr< Pcal95555Driver > pcal95555_driver_
Typed driver (created in Initialize).
Definition Pcal95555Handler.h:1002
uint16_t GetCreatedPinMask() const noexcept
Get a bitmask of all created pin numbers.
Definition Pcal95555Handler.cpp:939
pcal95555::ChipVariant GetChipVariant() const noexcept
Get the detected chip variant.
Definition Pcal95555Handler.cpp:1198
hf_gpio_err_t Deinitialize() noexcept
Internal deinitialization.
Definition Pcal95555Handler.cpp:303
bool EnsureInitialized() noexcept
Ensure the handler is initialized (lazy initialization).
Definition Pcal95555Handler.cpp:149
bool AttachStaticPin(Pcal95555GpioPin &pin) noexcept
Register a caller-owned pin wrapper (no heap allocation).
Definition Pcal95555Handler.cpp:859
std::unique_ptr< HalI2cPcal95555Comm > i2c_adapter_
I2C adapter (created in Initialize).
Definition Pcal95555Handler.h:1001
bool IsPinCreated(hf_pin_num_t pin) const noexcept
Check if a pin wrapper has been created.
Definition Pcal95555Handler.cpp:933
bool DrainPendingInterrupts() noexcept
Drain any pending interrupt that was deferred from ISR context.
Definition Pcal95555Handler.cpp:757
hf_gpio_err_t ReadAllInputLevels(uint16_t &levels) noexcept
Read both INPUT_PORT registers in one dual-port transaction.
Definition Pcal95555Handler.cpp:950
bool EnsureDeinitialized() noexcept
Deinitialize the handler and release resources.
Definition Pcal95555Handler.cpp:157
hf_gpio_err_t SetMultiplePolarityInversion(uint16_t pin_mask, bool invert) noexcept
Batch-set input polarity inversion for a pin mask.
Definition Pcal95555Handler.cpp:1215
hf_gpio_err_t SetPolarityInversion(hf_pin_num_t pin, bool invert) noexcept
Set input polarity inversion for a pin.
Definition Pcal95555Handler.cpp:1204
hf_gpio_err_t ReadInput(uint8_t pin, bool &active) noexcept
Read the physical level of a pin.
Definition Pcal95555Handler.cpp:401
BaseI2c & i2c_device_
I2C device reference (not owned).
Definition Pcal95555Handler.h:1000
bool interrupt_configured_
Whether hardware interrupt is active.
Definition Pcal95555Handler.h:1016
uint16_t prev_input_state_
Last-read pin input levels (bitmask).
Definition Pcal95555Handler.h:1029
hf_gpio_err_t SetOutput(uint8_t pin, bool active) noexcept
Write a logical level to an output pin.
Definition Pcal95555Handler.cpp:348
hf_gpio_err_t EnableInputLatch(hf_pin_num_t pin, bool enable) noexcept
Enable or disable input latch for a pin.
Definition Pcal95555Handler.cpp:1273
hf_gpio_err_t UnregisterPinInterrupt(hf_pin_num_t pin) noexcept
Unregister a per-pin interrupt callback.
Definition Pcal95555Handler.cpp:704
uint16_t GetErrorFlags() const noexcept
Get the driver's error flags.
Definition Pcal95555Handler.cpp:1306
hf_gpio_err_t ReadOutputLatchFromWire(uint16_t &output) noexcept
Read OUTPUT_PORT_0/1 from the chip (never the CM4 shadow).
Definition Pcal95555Handler.cpp:1026
bool HasInterruptSupport() const noexcept
Check if hardware interrupt support is available.
Definition Pcal95555Handler.h:616
hf_gpio_err_t RegisterPinInterrupt(hf_pin_num_t pin, hf_gpio_interrupt_trigger_t trigger, InterruptCallback callback, void *user_data) noexcept
Register a per-pin interrupt callback (called by Pcal95555GpioPin).
Definition Pcal95555Handler.cpp:647
hf_gpio_err_t Initialize() noexcept
Internal initialization (called by EnsureInitialized under mutex).
Definition Pcal95555Handler.cpp:171
hf_gpio_err_t SetDirection(uint8_t pin, hf_gpio_direction_t direction) noexcept
Set the direction of a single pin.
Definition Pcal95555Handler.cpp:334
BaseGpio * interrupt_pin_
Hardware INT pin (optional, not owned).
Definition Pcal95555Handler.h:1015
hf_gpio_err_t GetAllInterruptMasks(uint16_t &mask) noexcept
Get the interrupt mask for all 16 pins.
Definition Pcal95555Handler.cpp:617
hf_gpio_err_t SetDirections(uint16_t pin_mask, hf_gpio_direction_t direction) noexcept
Set direction for multiple pins at once.
Definition Pcal95555Handler.cpp:492
bool port_shadow_valid_
Definition Pcal95555Handler.h:1038
Pcal95555Driver * GetDriver() noexcept
Get the underlying PCAL95555 driver for advanced register-level operations.
Definition Pcal95555Handler.cpp:824
bool IsInitialized() const noexcept
Check if the handler has been initialized.
Definition Pcal95555Handler.h:491
hf_gpio_err_t SetInterruptMask(hf_pin_num_t pin, bool mask) noexcept
Set the per-pin interrupt mask.
Definition Pcal95555Handler.cpp:1241
hf_gpio_err_t SetOutputs(uint16_t pin_mask, bool active) noexcept
Write output level for multiple pins at once.
Definition Pcal95555Handler.cpp:519
hf_gpio_err_t SetPullModes(uint16_t pin_mask, hf_gpio_pull_mode_t pull_mode) noexcept
Set pull mode for multiple pins at once.
Definition Pcal95555Handler.cpp:572
pcal95555::PCAL95555< HalI2cPcal95555Comm > Pcal95555Driver
Typed PCAL95555 driver using our I2C adapter.
Definition Pcal95555Handler.h:424
Pcal95555GpioPin * GetGpioPinRaw(hf_pin_num_t pin) noexcept
Raw pointer to a registered pin (no shared_ptr control block).
Definition Pcal95555Handler.cpp:927
void ProcessInterrupts() noexcept
Process pending interrupts by reading status and dispatching callbacks.
Definition Pcal95555Handler.cpp:767
hf_gpio_err_t VerifyOutputPinEffect(uint8_t pin, uint16_t &latch_high, uint16_t &input_high, uint16_t &latch_low, uint16_t &input_low) noexcept
Drive one pin and verify OUTPUT latch + INPUT pad follow.
Definition Pcal95555Handler.cpp:1102
bool EnsureInitializedLocked() noexcept
Check init state under already-held handler_mutex_.
Definition Pcal95555Handler.cpp:166
void DumpDiagnostics() const noexcept
Dump comprehensive diagnostics to the system log.
Definition Pcal95555Handler.cpp:1320
bool ValidatePin(uint8_t pin) const noexcept
Validate pin number is in range 0-15.
Definition Pcal95555Handler.h:937
static constexpr uint8_t PinCount() noexcept
Total number of GPIO pins on the expander.
Definition Pcal95555Handler.h:663
uint16_t config_shadow_
PCA POR default CONFIG (all input)
Definition Pcal95555Handler.h:1036
static void HardwareInterruptCallback(BaseGpio *gpio, hf_gpio_interrupt_trigger_t trigger, void *user_data) noexcept
Static ISR callback for the hardware interrupt pin.
Definition Pcal95555Handler.cpp:746
std::shared_ptr< BaseGpio > CreateGpioPin(hf_pin_num_t pin, hf_gpio_direction_t direction=hf_gpio_direction_t::HF_GPIO_DIRECTION_INPUT, hf_gpio_active_state_t active_state=hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH, hf_gpio_output_mode_t output_mode=hf_gpio_output_mode_t::HF_GPIO_OUTPUT_MODE_PUSH_PULL, hf_gpio_pull_mode_t pull_mode=hf_gpio_pull_mode_t::HF_GPIO_PULL_MODE_FLOATING, bool allow_existing=true, bool configure_hardware=true) noexcept
Create or retrieve an existing BaseGpio pin wrapper (heap).
Definition Pcal95555Handler.cpp:886
bool HasAgileIO() const noexcept
Check if the detected chip supports Agile I/O features.
Definition Pcal95555Handler.cpp:1194
std::atomic< bool > interrupt_pending_
Deferred interrupt flag (set in ISR, cleared in task context).
Definition Pcal95555Handler.h:1017
std::array< hf_gpio_pull_mode_t, 16 > pull_mode_cache_
Definition Pcal95555Handler.h:1023
hf_gpio_err_t SetOutputsVerified(uint16_t pin_mask, bool active) noexcept
Write output level for multiple pins in one transaction, then read the latch back and retry (up to 3×...
Definition Pcal95555Handler.cpp:544
hf_gpio_err_t SetPullMode(uint8_t pin, hf_gpio_pull_mode_t pull_mode) noexcept
Set the pull resistor mode for a single pin.
Definition Pcal95555Handler.cpp:439
hf_gpio_err_t SetOutputMode(bool port0_open_drain, bool port1_open_drain) noexcept
Configure per-port output mode (push-pull or open-drain).
Definition Pcal95555Handler.cpp:1283
hf_gpio_err_t ResetToDefault() noexcept
Reset all registers to power-on default state.
Definition Pcal95555Handler.cpp:1293
std::array< std::unique_ptr< Pcal95555GpioPin >, 16 > owned_pins_
Heap pins from CreateGpioPin.
Definition Pcal95555Handler.h:1010
RtosMutex handler_mutex_
Thread safety for handler operations.
Definition Pcal95555Handler.h:1004
hf_gpio_err_t Toggle(uint8_t pin) noexcept
Toggle the output state of a pin.
Definition Pcal95555Handler.cpp:429
bool IsInterruptConfigured() const noexcept
Check if hardware interrupt is configured and enabled.
Definition Pcal95555Handler.h:622
hf_gpio_err_t ConfigureHardwareInterrupt() noexcept
Configure the hardware interrupt pin (falling edge, active-low).
Definition Pcal95555Handler.cpp:731
hf_gpio_err_t ProgramPortsAbsolute(uint16_t config, uint16_t output, uint16_t out_check_mask) noexcept
Absolute program POL=0, OUTPUT latch, and CONFIG (no RMW).
Definition Pcal95555Handler.cpp:966
std::shared_ptr< BaseGpio > GetGpioPin(hf_pin_num_t pin) noexcept
Get an existing GPIO pin wrapper by number.
Definition Pcal95555Handler.cpp:923
uint16_t polarity_shadow_
POLARITY_INV.
Definition Pcal95555Handler.h:1037
std::array< Pcal95555GpioPin *, 16 > pin_registry_
Non-owning registry slots.
Definition Pcal95555Handler.h:1009
hf_gpio_err_t GetAllInterruptStatus(uint16_t &status) noexcept
Get the interrupt status for all 16 pins.
Definition Pcal95555Handler.cpp:634
hf_gpio_err_t SetDriveStrength(hf_pin_num_t pin, pcal95555::DriveStrength level) noexcept
Set output drive strength for a pin.
Definition Pcal95555Handler.cpp:1262
bool initialized_
Initialization state.
Definition Pcal95555Handler.h:1003
void ClearErrorFlags(uint16_t mask=0xFFFF) noexcept
Clear driver error flags.
Definition Pcal95555Handler.cpp:1310