Enhanced General-Purpose Input/Output (EGPIO) Usage Scenarios#
You can use the general-purpose input/output (GPIO) interfaces on SiWx917 devices to implement a wide range of input and output behaviors, including polling, interrupt-driven events, wake-up triggers, and sensor interfacing.
This section presents common usage patterns and explains when to apply each technique in your application.
Typical Use Case 1: Polling (Blocking Mode)#
When to Use Polling#
Polling is appropriate when:
GPIO activity is infrequent and timing is not critical.
Power consumption is not a primary concern.
CPU cycles are available to check pin states periodically.
Polling is typically used only in the high-performance (HP) domain because it keeps the processor active.
Implementation Example#
#include "sl_si91x_driver_gpio.h"
#include "rsi_debug.h"
// HP GPIO polling and toggling example
static sl_si91x_gpio_pin_config_t led_pin_config = {
{ SL_SI91X_GPIO_10_PORT, GPIO_PIN_NUMBER10 },
GPIO_OUTPUT
};
void app_gpio_polling_example(void)
{
sl_status_t status = sl_gpio_driver_init();
if (status != SL_STATUS_OK) {
DEBUGOUT("GPIO driver init failed: %lu\r\n", status);
return;
}
status = sl_gpio_set_configuration(led_pin_config);
if (status != SL_STATUS_OK) {
DEBUGOUT("Pin configuration failed: %lu\r\n", status);
return;
}
while (1) {
sl_gpio_driver_toggle_pin(&led_pin_config.port_pin);
DEBUGOUT("LED toggled\r\n");
sl_si91x_delay_ms(1000); // 1-second delay
}
}Recommendation:
Use polling for low-frequency input monitoring or output toggling when CPU blocking does not impact overall system performance.
Typical Use Case 2: Interrupt-Driven (Callback-Based)#
When to Use Interrupts#
Use interrupts when you need:
Immediate response to changes on an input pin.
Event-driven wake-up from sleep modes in the high-performance (HP), ultra-low-power (ULP), or ultra-ultra-low-power (UULP) domains.
Minimal CPU activity during idle periods.
Interrupt-driven GPIOs allow the CPU to sleep and wake only when required, improving energy efficiency.
Implementation Example#
#include "sl_si91x_driver_gpio.h"
#include "rsi_debug.h"
// HP GPIO interrupt example
static sl_si91x_gpio_pin_config_t input_pin_config = {
{ SL_SI91X_GPIO_11_PORT, GPIO_PIN_NUMBER11 },
GPIO_INPUT
};
void gpio_pin_interrupt_callback(uint32_t pin_intr)
{
if (pin_intr == PIN_INTR_0) {
DEBUGOUT("Button press detected!\r\n");
}
}
void app_gpio_interrupt_example(void)
{
sl_status_t status = sl_gpio_driver_init();
if (status != SL_STATUS_OK) {
DEBUGOUT("GPIO driver init failed: %lu\r\n", status);
return;
}
status = sl_gpio_set_configuration(input_pin_config);
if (status != SL_STATUS_OK) {
DEBUGOUT("Pin configuration failed: %lu\r\n", status);
return;
}
status = sl_gpio_driver_configure_interrupt(&input_pin_config.port_pin,
0, // Interrupt channel
SL_GPIO_INTERRUPT_RISE_EDGE,
gpio_pin_interrupt_callback,
0);
if (status != SL_STATUS_OK) {
DEBUGOUT("Interrupt configuration failed: %lu\r\n", status);
}
}Recommendation:
Use interrupt-driven mode for event-triggered wake-ups, button presses, or real-time signal detection to achieve fast response and reduced power consumption.
For more example implementations, see WiSeConnect SDK GPIO Examples
Real-Time GPIO Application Scenarios#
GPIOs enable SiWx917 applications to detect external events, provide user feedback, and interface with sensors. The following scenarios illustrate common embedded workflows.
Scenario 1. Button Input with Debounce
Read mechanical button input through GPIO inputs.
Apply a short software delay or implement a debounce state machine.
Example: User interface navigation on a smart thermostat.
Scenario 2. LED Status Indication#
Drive LEDs on HP GPIOs to indicate device status.
Typical states include power on, network activity, and fault conditions.
Example: Wearable device showing charging state.
Scenario 3. Sensor Event Detection#
Connect motion, magnetic, or proximity sensors to GPIO pins.
Use ULP or UULP GPIO interrupts to wake the device.
Example: Battery-powered door sensor that wakes only when opened.
Scenario 4. Low-Power Wake-Up Events#
Configure ULP or UULP GPIOs for wake triggers in PS2 or PS3 states.
Ideal for always-on applications requiring minimal standby current.
Example: Remote node activated by threshold triggers.
Scenario 5. Software-Based Communication (Bit-Banging)#
Implement custom serial protocols using GPIOs when hardware peripherals are unavailable.
Example: RGB LED strip control using GPIO timing.
Scenario 6. Device Configuration Inputs#
Read DIP switches or jumper wires to determine device behavior.
Example: Selecting operating modes or network profiles at boot.
Scenario 7. Group Interrupt-Based Monitoring#
Monitor multiple GPIO inputs simultaneously using group interrupts.
Example: Home automation controller detecting multiple sensor lines.
Scenario 8. Safety and Fault Alerts#
Capture fault signals reported by external integrated circuits (ICs).
Example: Power-stage overtemperature detection in industrial systems.
Summary#
GPIOs on SiWx917 devices provide flexible mechanisms for interacting with external components. You can choose polling, interrupt-driven operation, or low-power wake-up behavior based on system requirements. By selecting the appropriate GPIO domain (HP, ULP, or UULP), you can balance response speed with overall power consumption.