# GPIOs API

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

group CosmicSDK GPIO API

  Constants and APIs related to GPIO operations.

  Functions

  uint16_t gpioSetVoltage(uint16_t voltage_mV, bool persist = false)

    Sets the GPIO pins voltage.

    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:

      - voltage_mV – 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:

      The status code of the operation

  uint16_t gpioConfigurePin(GpioPinNumber pinNumber, GpioFunctionality functionality, GpioLogicLevel initialOutputLogicLevel = GpioLogicLevel::GPIO_LOW)

    Configures a GPIO pin with the specified functionality.

    This function configures a single GPIO pin as a digital input or output. It may be invoked at any point to modify the pin functionality.

    Note

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

    - Calling any GPIO method before configuration will return `FW_GPIO_NOT_CONFIGURED`.

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

    Parameters:

      - 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 – GPIO pin was successfully configured.

      - FW_INVALID_PARAMETER – The pin number or functionality is invalid or unsupported.

      - SDK_ERROR_TIMEOUT – The operation timed out.

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

  uint16_t gpioDigitalWrite(GpioPinNumber pinNumber, GpioLogicLevel logicLevel)

    Writes a digital logic level to a GPIO pin.

    Writes 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, this function returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital input, this function returns `FW_GPIO_WRONG_CONFIGURATION`.

    Parameters:

      - 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 – Logic level was successfully written.

      - FW_GPIO_NOT_CONFIGURED – The GPIO pin has not been configured.

      - FW_GPIO_WRONG_CONFIGURATION – The GPIO pin is not configured as a digital output.

      - FW_INVALID_PARAMETER – The pin number is invalid or unsupported.

      - SDK_ERROR_TIMEOUT – The operation timed out.

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

  uint16_t gpioDigitalRead(GpioPinNumber pinNumber, GpioLogicLevel &logicLevel)

    Reads the digital logic level from a GPIO pin.

    Reads the logic level from a pin configured as a digital input.

    Note

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

    - If the pin is not configured, this function returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital output, this function returns `FW_GPIO_WRONG_CONFIGURATION`.

    Parameters:

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

      - logicLevel – On success, receives the logic level of the GPIO pin. See GpioLogicLevel.

    Return values:

      - SUCCESS – Logic level was successfully read.

      - FW_GPIO_NOT_CONFIGURED – The GPIO pin has not been configured.

      - FW_GPIO_WRONG_CONFIGURATION – The GPIO pin is not configured as a digital input.

      - FW_INVALID_PARAMETER – The pin number is invalid or unsupported.

      - SDK_ERROR_TIMEOUT – The operation timed out.

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

  uint16_t gpioConfigureInterrupt(GpioPinNumber pinNumber, GpioTriggerType trigger)

    Configures and enables interrupts in a GPIO pin.

    Configures the interrupt trigger for a GPIO pin and enables its callback.

    Note

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

    - If the pin is not configured, this function returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital output, this function returns `FW_GPIO_WRONG_CONFIGURATION`.

    - If the pin does not support interrupts, this function returns `FW_FEATURE_NOT_SUPPORTED_BY_HARDWARE`.

    Parameters:

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

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

    Return values:

      - SUCCESS – GPIO interrupt was successfully configured and enabled.

      - FW_FEATURE_NOT_SUPPORTED_BY_HARDWARE – The selected GPIO pin does not support interrupts.

      - FW_GPIO_NOT_CONFIGURED – The GPIO pin has not been configured.

      - FW_GPIO_WRONG_CONFIGURATION – The GPIO pin is not configured as a digital input.

      - FW_INVALID_PARAMETER – The pin number or trigger type is invalid or unsupported.

      - SDK_ERROR_TIMEOUT – The operation timed out.

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

  uint16_t gpioDisableInterrupt(GpioPinNumber pinNumber)

    Disables interrupts in a GPIO pin.

    Disables 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, this function returns `FW_GPIO_NOT_CONFIGURED`.

    - If the pin is configured as a digital output, this function returns `FW_GPIO_WRONG_CONFIGURATION`.

    Parameters:

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

    Return values:

      - SUCCESS – GPIO interrupt was successfully disabled.

      - FW_GPIO_NOT_CONFIGURED – The GPIO pin has not been configured.

      - FW_GPIO_WRONG_CONFIGURATION – The GPIO pin is not configured as a digital input.

      - FW_INVALID_PARAMETER – The pin number is invalid or unsupported.

      - SDK_ERROR_TIMEOUT – The operation timed out.

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