Skip to content

A GPIO, or General Purpose Input/Output, is a pin on a microcontroller or processor that can be programmed to function either as an input or an output. As an input, it can read the state of an external electrical signal, such as a switch or a sensor. As an output, it can send an electrical signal, such as a high or low logic level, to an external component, such as an LED.

Initialization sequence

Note

1. Configure the pin in output mode.
2. Set the pin.

1. Configure the pin in output mode.
2. Reset the pin

1. Configure the pin in input mode.
2. Read the pin input.

Example

spin.gpio.configurePin(9, OUTPUT);
spin.gpio.setPin(9);

spin.gpio.configurePin(9, OUTPUT);
spin.gpio.resetPin(9);

spin.gpio.configurePin(9, INPUT);
uint8_t return_gpio = spin.gpio.readPin(9);

API Reference

Class GpioHAL

ClassList > GpioHAL

Public Functions

Type Name
void configurePin (uint8_t pin, gpio_flags_t flags)
Configure an I/O pin. This must be done prior to accessing any other function from this API on the pin.
uint8_t readPin (uint8_t pin)
Get the current value of a pin configured as input.
void resetPin (uint8_t pin)
Reset the value of a pin configured as output to 0.
void setPin (uint8_t pin)
Set the value of a pin configured as output to 1.
void togglePin (uint8_t pin)
Toggle the value of a pin configured as output:
void writePin (uint8_t pin, uint8_t value)
Set the value of a pin configured as output to a given value.

Public Functions Documentation

function configurePin

Configure an I/O pin. This must be done prior to accessing any other function from this API on the pin.

void GpioHAL::configurePin (
    uint8_t pin,
    gpio_flags_t flags
) 

Parameters:

  • pin Number of the Spin pin OR STM32-style name of the pin, e.g. PA1, PB10, etc. See pin_t type for the full list of available STM32-style pins on Spin board.
  • flags Pin configuration flags. Authorized values:
  • INPUT
  • INPUT_PULLUP
  • OUTPUT

function readPin

Get the current value of a pin configured as input.

uint8_t GpioHAL::readPin (
    uint8_t pin
) 

Parameters:

  • pin Number of the Spin pin OR STM32-style name of the pin, e.g. PA1, PB10, etc. See pin_t type for the full list of available STM32-style pins on Spin board.

Returns:

Current value (0 or 1) of the pin.


function resetPin

Reset the value of a pin configured as output to 0.

void GpioHAL::resetPin (
    uint8_t pin
) 

Parameters:

  • pin Number of the Spin pin OR STM32-style name of the pin, e.g. PA1, PB10, etc. See pin_t type for the full list of available STM32-style pins on Spin board.

function setPin

Set the value of a pin configured as output to 1.

void GpioHAL::setPin (
    uint8_t pin
) 

Parameters:

  • pin Number of the Spin pin OR STM32-style name of the pin, e.g. PA1, PB10, etc. See pin_t type for the full list of available STM32-style pins on Spin board.

function togglePin

Toggle the value of a pin configured as output:

void GpioHAL::togglePin (
    uint8_t pin
) 

  • if pin value is 1, it will be set to 0
  • if pin value is 0, it will be set to 1.

Parameters:

  • pin Number of the Spin pin OR STM32-style name of the pin, e.g. PA1, PB10, etc. See pin_t type for the full list of available STM32-style pins on Spin board.

function writePin

Set the value of a pin configured as output to a given value.

void GpioHAL::writePin (
    uint8_t pin,
    uint8_t value
) 

Parameters:

  • pin Number of the Spin pin OR STM32-style name of the pin, e.g. PA1, PB10, etc. See pin_t type for the full list of available STM32-style pins on Spin board.
  • value Value (0 or 1) to assign to the pin.


The documentation for this class was generated from the following file docs/core/zephyr/modules/owntech_spin_api/zephyr/src/GpioHAL.h