# GPIO Examples (Blocking API)

## Overview

The blocking GPIO examples are available for both C and C++:

- C: `examples/blocking_api/gpio/c/`

- C++: `examples/blocking_api/gpio/cpp/`

These examples are intended for both Supernova and Pulsar USB host adapters.

## Hardware Setup

Required hardware:

1. One Binho Supernova or Pulsar

2. One Binho Breakout Board

Required wiring:

- Short GPIO 1 and GPIO 3 together on the breakout board.

- This loopback connection is required for digital readback and interrupt validation.

## What The GPIO Examples Do

The C and C++ examples implement the same workflow:

1. Connect to the adapter and read device information.

2. Configure multiple GPIO pins as input/output and validate interrupt configuration behavior.

3. Verify digital write/read by driving `GPIO 3` and reading `GPIO 1`.

4. Set GPIO target voltage to `1800 mV`.

5. Register a GPIO notification callback.

6. Enable `GPIO 1` interrupt on both edges.

7. Toggle `GPIO 3` and verify interrupts are received on `GPIO 1`.

## Notification Callback Requirement

GPIO interrupt events are consumed through notifications. For this reason, the client must register a callback before starting the interrupt test:

- C API: `CosmicSDK_onNotification` and `CosmicSDK_notificationAsGpio`.

- C++ API: `CosmicSDK::onNotification` and `notification.gpio()`.

## Build and Run (GPIO C/C++)

GPIO example directories build binaries with the following names:

- C (`examples/blocking_api/gpio/c/`):

    - `example_c_dynamic`

    - `example_c_static`

- C++ (`examples/blocking_api/gpio/cpp/`):

    - `example_cpp_dynamic`

    - `example_cpp_static`

See also:

- C API GPIO reference: GPIOs API

- C++ blocking GPIO reference: GPIOs API