In this example one single interrupt will call two different callback functions, the application somehow configure the Pin 5 to respond to two different events, on a falling edge and a rising edge, both will cause the interrupt to trigger the interrupt in the same vector.
#include "bsp.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStruct; /*gpios initial structure*/
HAL_Init(); /*Init HAL library*/
__HAL_RCC_GPIOA_CLK_ENABLE(); /*Enable clock on port A*/
GPIO_InitStruct.Pin = GPIO_PIN_5; /*pins to set as inputs*/
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; /*input mode with interrupts enable on falling and rising edges*/
GPIO_InitStruct.Pull = GPIO_NOPULL; /*no pull-up niether pull-down*/
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; /*pin speed*/
/*use the previous parameters to set configuration on pin C0*/
HAL_GPIO_Init( GPIOA, &GPIO_InitStruct );
/*Enable interrupt vector EXTI4_15_IRQ where the CPU will jump if a input change
happens on pins 4 to 15*/
HAL_NVIC_SetPriority( EXTI4_15_IRQn, 2, 0 );
HAL_NVIC_EnableIRQ( EXTI4_15_IRQn );
while (1)
{
}
}
/* when the pin changes from high to low this function will be called by HAL_GPIO_EXTI_IRQHandler
which is in turn called from the EXTI4_15_IRQHandler interrupt vector*/
void HAL_GPIO_EXTI_Falling_Callback( uint16_t GPIO_Pin )
{
/*do something while still in the ISR*/
}
/* when the pin changes from low to high this function will be called by HAL_GPIO_EXTI_IRQHandler
which is in turn called from the EXTI4_15_IRQHandler interrupt vector*/
void HAL_GPIO_EXTI_Rising_Callback( uint16_t GPIO_Pin )
{
/*do something while still in the ISR*/
}
ints.c
/*Declare interrupt service rutine as it is declare in startup_stm32g0b1xx.s file
Function HAL_GPIO_EXTI_IRQHandler will determine which event cause the interrupt
and then call the proper callback function.*/
void EXTI4_15_IRQHandler( void )
{
/*HAL library fucntions that attend interrupt on inputs*/
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_5 );
}