NavHAL 0.1.0
NAVRobotec's architecture-agnostic HAL for embedded systems.
Loading...
Searching...
No Matches
gpio.c File Reference

HAL GPIO driver implementation for STM32F4 series. More...

Include dependency graph for gpio.c:

Functions

void hal_gpio_setmode (hal_gpio_pin pin, hal_gpio_mode mode, hal_gpio_pullup_pulldown pupd)
 Configure the mode and pull-up/pull-down for a GPIO pin.
hal_gpio_mode hal_gpio_getmode (hal_gpio_pin pin)
 Get the current mode of a GPIO pin.
void hal_gpio_digitalwrite (hal_gpio_pin pin, hal_gpio_state state)
 Write a digital value to a GPIO pin.
hal_gpio_state hal_gpio_digitalread (hal_gpio_pin pin)
 Read the digital value from a GPIO pin.
void hal_gpio_enable_rcc (hal_gpio_pin pin)
 Enable the RCC clock for the GPIO port of a given pin.
void hal_gpio_set_alternate_function (hal_gpio_pin pin, hal_gpio_alternate_function_t alt_fn)
 Configure the alternate function of a GPIO pin.
void hal_gpio_set_output_type (hal_gpio_pin pin, hal_gpio_output_type otyper)
 Set the output type for a GPIO pin.
void hal_gpio_set_output_speed (hal_gpio_pin pin, hal_gpio_output_speed speed)
 Set the output speed for a GPIO pin.

Detailed Description

HAL GPIO driver implementation for STM32F4 series.

This file contains the implementation of the high-level HAL functions declared in gpio.h for configuring and controlling GPIO pins.

The functions in this file handle:

  • Pin mode configuration
  • Pull-up/pull-down settings
  • Digital read/write operations
  • RCC clock enabling for GPIO ports
  • Alternate function selection

Function Documentation

◆ hal_gpio_digitalread()

hal_gpio_state hal_gpio_digitalread ( hal_gpio_pin pin)

Read the digital value from a GPIO pin.

Read the digital state from a GPIO pin.

Parameters
pinPin identifier.
Returns
Current pin state (high or low).

◆ hal_gpio_digitalwrite()

void hal_gpio_digitalwrite ( hal_gpio_pin pin,
hal_gpio_state state )

Write a digital value to a GPIO pin.

Write a digital state to a GPIO pin.

Parameters
pinPin identifier.
stateDesired pin state (high or low).
// Example: Set PA5 high
hal_gpio_digitalwrite(PA5, HAL_GPIO_HIGH);
void hal_gpio_digitalwrite(hal_gpio_pin pin, hal_gpio_state state)
Write a digital state to a GPIO pin.
Definition gpio.c:61

◆ hal_gpio_enable_rcc()

void hal_gpio_enable_rcc ( hal_gpio_pin pin)

Enable the RCC clock for the GPIO port of a given pin.

Enable the RCC clock for a specific GPIO pin's port.

Parameters
pinPin identifier.
Note
This function is usually called automatically by other GPIO functions, but can be called manually if required.

◆ hal_gpio_getmode()

hal_gpio_mode hal_gpio_getmode ( hal_gpio_pin pin)

Get the current mode of a GPIO pin.

Parameters
pinPin identifier.
Returns
The current GPIO mode of the pin.

◆ hal_gpio_set_alternate_function()

void hal_gpio_set_alternate_function ( hal_gpio_pin pin,
hal_gpio_alternate_function_t alt_fn )

Configure the alternate function of a GPIO pin.

Set the alternate function for a GPIO pin.

Parameters
pinPin identifier.
alt_fnAlternate function number/type.
Note
This function will internally set the pin mode to alternate function mode.
// Example: Set PA2 to USART2_TX alternate function
hal_gpio_set_alternate_function(PA2, HAL_GPIO_AF_USART2);
void hal_gpio_set_alternate_function(hal_gpio_pin pin, hal_gpio_alternate_function_t alt_fn)
Set the alternate function for a GPIO pin.
Definition gpio.c:98

◆ hal_gpio_set_output_speed()

void hal_gpio_set_output_speed ( hal_gpio_pin pin,
hal_gpio_output_speed speed )

Set the output speed for a GPIO pin.

Parameters
pinThe GPIO pin to configure.
speedThe output speed (low, medium, high, very high).

◆ hal_gpio_set_output_type()

void hal_gpio_set_output_type ( hal_gpio_pin pin,
hal_gpio_output_type otyper )

Set the output type for a GPIO pin.

Parameters
pinThe GPIO pin to configure.
otyperThe output type (push-pull or open-drain).

◆ hal_gpio_setmode()

void hal_gpio_setmode ( hal_gpio_pin pin,
hal_gpio_mode mode,
hal_gpio_pullup_pulldown pupd )

Configure the mode and pull-up/pull-down for a GPIO pin.

Set the mode of a GPIO pin.

Parameters
pinPin identifier.
modeGPIO mode (input, output, alternate function, analog).
pupdPull-up/pull-down configuration.
Note
This function automatically enables the RCC clock for the GPIO port.
// Example: Configure PA5 as output with no pull-up/pull-down
hal_gpio_setmode(PA5, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_NO_PULL);
void hal_gpio_setmode(hal_gpio_pin pin, hal_gpio_mode mode, hal_gpio_pullup_pulldown pupd)
Set the mode of a GPIO pin.
Definition gpio.c:31