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
#include <GpioHAL.h>
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. |
Detailed Description
Class definition
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.
Parameters:
-
pin
Number of pin. Format allowed: -
the Spin pin number from 1 to 58
- STM32-style pin name from
PA1
toPA15
,PB1
toPB15
,PC1
toPC15
andPD1
toPD3
Parameters:
flags
Pin configuration flags. Authorized values:INPUT
,INPUT_PULLUP
,OUTPUT
function readPin
Get the current value of a pin configured as input.
Parameters:
-
pin
Number of pin. Format allowed: -
the Spin pin number from 1 to 58
- STM32-style pin name from
PA1
toPA15
,PB1
toPB15
,PC1
toPC15
andPD1
toPD3
Returns:
Current value (0 or 1) of the pin.
function resetPin
Reset the value of a pin configured as output to 0.
Parameters:
-
pin
Number of pin. Format allowed: -
the Spin pin number from 1 to 58
- STM32-style pin name from
PA1
toPA15
,PB1
toPB15
,PC1
toPC15
andPD1
toPD3
function setPin
Set the value of a pin configured as output to 1.
Parameters:
-
pin
Number of pin. Format allowed: -
the Spin pin number from 1 to 58
- STM32-style pin name from
PA1
toPA15
,PB1
toPB15
,PC1
toPC15
andPD1
toPD3
function togglePin
Toggle the value of a pin configured as output:
Parameters:
-
pin
Number of pin. Format allowed: -
the Spin pin number from 1 to 58
- STM32-style pin name from
PA1
toPA15
,PB1
toPB15
,PC1
toPC15
andPD1
toPD3
function writePin
Set the value of a pin configured as output to a given value.
Parameters:
-
pin
Number of pin. Format allowed: -
the Spin pin number from 1 to 58
- STM32-style pin name from
PA1
toPA15
,PB1
toPB15
,PC1
toPC15
andPD1
toPD3
Parameters:
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