# GPIOs API

This page aggregates all C++ GPIO-related public methods of the class CosmicAsyncSDK.

group CosmicSDK GPIO API

  Constants and APIs related to GPIO operations.

  Functions

  uint16_t gpioSetVoltage(uint16_t id, uint16_t voltage_mV, bool persist = false)

    Set the operating voltage of the GPIO pins.

    Warning

    On Supernova and Pulsar host adapters, the GPIO interface shares the same voltage domain as I2C, SPI and UART. As a result, calling this method to set the GPIOs voltage will also affect the voltage of I2C, SPI and UART interfaces. This must be taken into account when more than one interfaces are used simultaneously.

    Parameters:

      - id – uint16_t Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - voltage_mV – uint16_t Voltage in millivolts to set the GPIO pins to. The valid values are 0 mV, and any value in the range 1200 to 3300 mV. The value 0mV deactivates the VTARG pin and turn offs the downstream devices.

      - persist – bool If true, the voltage setting will be persistent across power cycles. This ensures that any DUT connected to the GPIO pins (e.g. via Pulsar or Supernova) will receive power immediately upon startup, without waiting for the host to issue the voltage set command. If false, the setting will only apply to the current session.

    Returns:

      uint16_t Result of the request.

  uint16_t gpioConfigurePin(uint16_t id, GpioPinNumber pinNumber, GpioFunctionality functionality, GpioLogicLevel initialOutputLogicLevel)

    Configures a GPIO pin with the specified functionality.

    Sends a request to configure a single GPIO pin as a digital input or output.

    Note

    - This function must be called before any other GPIO operation on the pin.

    - When `functionality` is `GPIO_DIGITAL_INPUT`, `initialOutputLogicLevel` is ignored.

    - The host adapter response may return `FW_INVALID_PARAMETER` if the pin number or functionality is invalid.

    - This function only reports whether the command was sent; check the response for the operation result.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - pinNumber – The GPIO pin number to configure. See GpioPinNumber.

      - functionality – The desired functionality for the GPIO pin. See GpioFunctionality.

      - initialOutputLogicLevel – Initial output logic level applied when configuring as a digital output. See GpioLogicLevel for valid values. This parameter is ignored when configuring as a digital input.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.

  uint16_t gpioDigitalWrite(uint16_t id, GpioPinNumber pinNumber, GpioLogicLevel logicLevel)

    Writes a digital logic level to a GPIO pin.

    Sends a request to write the provided logic level to a pin configured as a digital output.

    Note

    - The pin must be configured as `GPIO_DIGITAL_OUTPUT` using gpioConfigurePin.

    - If the pin is not configured, the host adapter response returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital input, the host adapter response returns `FW_GPIO_WRONG_CONFIGURATION`.

    - The host adapter response may return `FW_INVALID_PARAMETER` if the pin number is invalid.

    - This function only reports whether the command was sent; check the response for the operation result.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - pinNumber – The GPIO pin number to write to. See GpioPinNumber.

      - logicLevel – The logic level to write to the GPIO pin. See GpioLogicLevel.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.

  uint16_t gpioDigitalRead(uint16_t id, GpioPinNumber pinNumber)

    Reads the digital logic level from a GPIO pin.

    Sends a request to read the logic level from a pin configured as a digital input. The logic level is returned in the corresponding response payload.

    Note

    - The pin must be configured as `GPIO_DIGITAL_INPUT` using gpioConfigurePin.

    - If the pin is not configured, the host adapter response returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital output, the host adapter response returns `FW_GPIO_WRONG_CONFIGURATION`.

    - The host adapter response may return `FW_INVALID_PARAMETER` if the pin number is invalid.

    - This function only reports whether the command was sent; check the response for the operation result.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - pinNumber – The GPIO pin number to read from. See GpioPinNumber.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.

  uint16_t gpioConfigureInterrupt(uint16_t id, GpioPinNumber pinNumber, GpioTriggerType trigger)

    Configures and enables interrupts in a GPIO pin.

    Sends a request to configure the interrupt trigger for a GPIO pin and enable its callback.

    Note

    - The pin must be configured as `GPIO_DIGITAL_INPUT` using gpioConfigurePin.

    - If the pin is not configured, the host adapter response returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital output, the host adapter response returns `FW_GPIO_WRONG_CONFIGURATION`.

    - If the pin does not support interrupts, the host adapter response returns `FW_FEATURE_NOT_SUPPORTED_BY_HARDWARE`.

    - The host adapter response may return `FW_INVALID_PARAMETER` if the pin number or trigger is invalid.

    - This function only reports whether the command was sent; check the response for the operation result.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - pinNumber – The GPIO pin number to configure interrupts for. See GpioPinNumber.

      - trigger – The trigger type used for the interruption. See GpioTriggerType.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.

  uint16_t gpioDisableInterrupt(uint16_t id, GpioPinNumber pinNumber)

    Disables interruptions of a GPIO pin.

    Sends a request to disable interrupts for a GPIO pin configured as a digital input.

    Note

    - The pin must be configured as `GPIO_DIGITAL_INPUT` using gpioConfigurePin.

    - If the pin is not configured, the host adapter response returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital output, the host adapter response returns `FW_GPIO_WRONG_CONFIGURATION`.

    - The host adapter response may return `FW_INVALID_PARAMETER` if the pin number is invalid.

    - This function only reports whether the command was sent; check the response for the operation result.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - pinNumber – The GPIO pin number to which the interrupt will be disabled. See GpioPinNumber.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.