rt-thread-official/bsp/swm341/libraries/SWM341_StdPeriph_Driver/SWM341_exti.c

131 lines
7.2 KiB
C
Raw Normal View History

/******************************************************************************************************************************************
* : SWM341_exti.c
* : SWM341单片机的外部中断功能驱动库
* : http://www.synwit.com.cn/e/tool/gbook/?bid=1
* :
* : V1.0.0 2016130
* :
*
*******************************************************************************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
* REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
* FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
* -ECTION WITH THEIR PRODUCTS.
*
* COPYRIGHT 2012 Synwit Technology
*******************************************************************************************************************************************/
#include "SWM341.h"
#include "SWM341_exti.h"
/******************************************************************************************************************************************
* : EXTI_Init()
* :
* : GPIO_TypeDef * GPIOx GPIO端口GPIOAGPIOBGPIOCGPIODGPIOEGPIOMGPION
* uint32_t n GPIO引脚PIN0PIN1PIN2... ... PIN14PIN15
* uint32_t mode EXTI_FALL_EDGEEXTI_RISE_EDGEEXTI_BOTH_EDGEEXTI_LOW_LEVELEXTI_HIGH_LEVEL
* :
* :
******************************************************************************************************************************************/
void EXTI_Init(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t mode)
{
EXTI_Close(GPIOx, n); //配置关键寄存器前先关闭
if(mode & 0x10)
{
GPIOx->INTLVLTRG |= (0x01 << n); //电平触发
if(mode & 0x01)
GPIOx->INTRISEEN |= (0x01 << n); //高电平触发
else
GPIOx->INTRISEEN &= ~(0x01 << n); //低电平触发
}
else
{
GPIOx->INTLVLTRG &= ~(0x01 << n); //边沿触发
if(mode & 0x02)
{
GPIOx->INTBE |= (0x01 << n); //双边沿触发
}
else
{
GPIOx->INTBE &= ~(0x01 << n); //单边沿触发
if(mode & 0x01)
GPIOx->INTRISEEN |= (0x01 << n); //上升沿触发
else
GPIOx->INTRISEEN &= ~(0x01 << n); //下降沿触发
}
}
GPIOx->INTCLR = (1 << n); //清除掉因为模式配置可能产生的中断
}
/******************************************************************************************************************************************
* : EXTI_Open()
* : 使
* : GPIO_TypeDef * GPIOx GPIO端口GPIOAGPIOBGPIOCGPIODGPIOEGPIOMGPION
* uint32_t n GPIO引脚PIN0PIN1PIN2... ... PIN14PIN15
* :
* :
******************************************************************************************************************************************/
void EXTI_Open(GPIO_TypeDef * GPIOx, uint32_t n)
{
GPIOx->INTEN |= (0x01 << n);
}
/******************************************************************************************************************************************
* : EXTI_Close()
* :
* : GPIO_TypeDef * GPIOx GPIO端口GPIOAGPIOBGPIOCGPIODGPIOEGPIOMGPION
* uint32_t n GPIO引脚PIN0PIN1PIN2... ... PIN14PIN15
* :
* :
******************************************************************************************************************************************/
void EXTI_Close(GPIO_TypeDef * GPIOx, uint32_t n)
{
GPIOx->INTEN &= ~(0x01 << n);
}
/******************************************************************************************************************************************
* : EXTI_State()
* :
* : GPIO_TypeDef * GPIOx GPIO端口GPIOAGPIOBGPIOCGPIODGPIOEGPIOMGPION
* uint32_t n GPIO引脚PIN0PIN1PIN2... ... PIN14PIN15
* : uint32_t 1 0
* :
******************************************************************************************************************************************/
uint32_t EXTI_State(GPIO_TypeDef * GPIOx, uint32_t n)
{
return (GPIOx->INTSTAT >> n) & 0x01;
}
/******************************************************************************************************************************************
* : EXTI_RawState()
* : //
* : GPIO_TypeDef * GPIOx GPIO端口GPIOAGPIOBGPIOCGPIODGPIOEGPIOMGPION
* uint32_t n GPIO引脚PIN0PIN1PIN2... ... PIN14PIN15
* : uint32_t 1 / 0 /
* :
******************************************************************************************************************************************/
uint32_t EXTI_RawState(GPIO_TypeDef * GPIOx, uint32_t n)
{
return (GPIOx->INTRAWSTAT >> n) & 0x01;
}
/******************************************************************************************************************************************
* : EXTI_Clear()
* :
* : GPIO_TypeDef * GPIOx GPIO端口GPIOAGPIOBGPIOCGPIODGPIOEGPIOMGPION
* uint32_t n GPIO引脚PIN0PIN1PIN2... ... PIN14PIN15
* :
* : 沿
******************************************************************************************************************************************/
void EXTI_Clear(GPIO_TypeDef * GPIOx, uint32_t n)
{
GPIOx->INTCLR = (0x01 << n);
}