Files
OpenParcelBox/docs/firmware/gpio_expander.md
T

1.6 KiB

GPIO Expander

Purpose

This module provides a hardware abstraction layer (HAL) for the external GPIO expander.

The current implementation targets the PCF8574 connected over the I²C bus. Other GPIO expanders (PCF8575, MCP23017, etc.) can later be supported by modifying only this module.

Higher-level modules connected to the PCF8574 use this API instead of directly accessing the I²C bus. Direct XIAO GPIO peripherals such as lock control do not pass through the expander.


Development Hardware

  • Seeed Studio XIAO nRF52840
  • PCF8574
  • I²C address: 0x20

Public API

int gpio_expander_init(void);

int gpio_expander_read_port(uint8_t *value);

int gpio_expander_write_port(uint8_t value);

bool gpio_expander_read_pin(uint8_t pin);

int gpio_expander_write_pin(uint8_t pin, bool state);

int gpio_expander_update_port(uint8_t mask, uint8_t value);

Design Goals

  • Hide the hardware implementation.
  • Avoid direct I²C access from application modules.
  • Allow replacing the GPIO expander without modifying the rest of the firmware.

Current Implementation

  • PCF8574
  • 8 GPIO
  • Quasi-bidirectional outputs
  • I²C communication

Future Improvements

Possible future implementations:

  • PCF8575
  • MCP23008
  • MCP23017

Only gpio_expander.c should require modifications.


Used By

  • Keypad
  • Future peripherals connected through an external GPIO expander

Notes

The PCF8574 uses quasi-bidirectional GPIOs.

A pin must be written HIGH before it can be used as an input.

This behavior is fully handled by this module and should remain transparent to higher-level drivers.