S32K144使用SDK2.0实现GPIO中断设置的函数分享
/***********************************************************************************************
Function: void GPIO_SetPinInt(Gpio_Port_t Portx, Gpio_Pin_t GPIO_Pin,port_interrupt_config_t intConfig,isr_t isr_hand)
Description: I/O外部中断设置
Input: @ Gpio_Port_t 端口
@ Gpio_Pin_t 引脚
@ port_interrupt_config_t 中断触发配置
@isr_t 中断回调函数,无参
Output:
Return:
Others:
************************************************************************************************/
void GPIO_SetPinInt(Gpio_Port_t Portx, Gpio_Pin_t GPIO_Pin,port_interrupt_config_t intConfig,isr_t isr_hand)
{
// 4.关闭全局中断
INT_SYS_DisableIRQGlobal();
if(intConfig == PORT_INT_RISING_EDGE)
{
GPIO_Init(Portx,GPIO_Pin,GPIO_Mode_IN_FLOATING);
}
else if(intConfig == PORT_INT_FALLING_EDGE)
{
GPIO_Init(Portx,GPIO_Pin,GPIO_Mode_IN_FLOATING);
}
else
{
GPIO_Init(Portx,GPIO_Pin,GPIO_Mode_IN_FLOATING);
}
// 设置触发模式
// DEV_ASSERT(Gpio_Pin_t < PORT_PCR_COUNT);
uint32 regValue = Port_list[Portx]->PCR[GPIO_Pin];
regValue &= ~(PORT_PCR_IRQC_MASK);
regValue |= PORT_PCR_IRQC(intConfig);
Port_list[Portx]->PCR[GPIO_Pin] = regValue;
// 8.清除中断标记
// PORT_HAL_ClearPinIntFlagCmd(port, pin);
PINS_DRV_ClearPortIntFlagCmd(Port_list[Portx]);
/* Install hander for Button ISR */
INT_SYS_InstallHandler((IRQn_Type)(PORTA_IRQn+Portx), isr_hand, (isr_t *)0);
/* Enable button port IRQ */
INT_SYS_EnableIRQ((IRQn_Type)(PORTA_IRQn+Portx));
// 9.使能全局中断
INT_SYS_EnableIRQGlobal();
}