2022-10-19 22:44:15 +08:00

132 lines
6.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************************************************************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>: SWM320_exti.c
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SWM320<32><30>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϹ<D0B6><CFB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>: http://www.synwit.com.cn/e/tool/gbook/?bid=1
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* <20><EFBFBD><E6B1BE><EFBFBD><EFBFBD>: V1.1.0 2017<31><37>10<31><30>25<32><35>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼:
*
*******************************************************************************************************************************************
* @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 "SWM320.h"
#include "SWM320_exti.h"
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: EXTI_Init()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϳ<D0B6>ʼ<EFBFBD><CABC>
* <20><> <20><>: GPIO_TypeDef * GPIOx ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49>˿ڣ<CBBF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>GPIOA<4F><41>GPIOB<4F><42>GPIOC<4F><43>GPIOM<4F><4D>GPION<4F><4E>GPIOP
* uint32_t n ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49><4F><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PIN0<4E><30>PIN1<4E><31>PIN2<4E><32>... ... PIN22<32><32>PIN23
* uint32_t mode <20><>Чֵ<D0A7><D6B5>EXTI_FALL_EDGE<47><45>EXTI_RISE_EDGE<47><45>EXTI_BOTH_EDGE<47><45>EXTI_LOW_LEVEL<45><4C>EXTI_HIGH_LEVEL
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD>GPIOA<4F><41>GPIOB<4F><42>GPIOC<4F><43>GPIOM<4F><4D>PIN0--7<><37><EFBFBD>ż<EFBFBD><C5BC><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>NVIC<49>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD>GPIOA0_IRQn<51><6E><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>NVIC<49><43><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6>GPIOA_IRQn<51><6E><EFBFBD><EFBFBD>
* <09><><EFBFBD>Բ<EFBFBD><D4B2>ڴ˺<DAB4><CBBA><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>NVIC_EnableIRQ()ʹ<><CAB9>NVIC<49>жϣ<D0B6><CFA3>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>NVIC_EnableIRQ(GPIOA0_IRQn)<29><>NVIC_EnableIRQ(GPIOA_IRQn)
******************************************************************************************************************************************/
void EXTI_Init(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t mode)
{
EXTI_Close(GPIOx, n); //<2F><><EFBFBD>ùؼ<C3B9><D8BC>Ĵ<EFBFBD><C4B4><EFBFBD>ǰ<EFBFBD>ȹر<C8B9>
if(mode & 0x10)
{
GPIOx->INTLVLTRG |= (0x01 << n); //<2F><>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
if(mode & 0x01)
GPIOx->INTRISEEN |= (0x01 << n); //<2F>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
else
GPIOx->INTRISEEN &= ~(0x01 << n); //<2F>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
}
else
{
GPIOx->INTLVLTRG &= ~(0x01 << n); //<2F><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
if(mode & 0x02)
{
GPIOx->INTBE |= (0x01 << n); //˫<><CBAB><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
}
else
{
GPIOx->INTBE &= ~(0x01 << n); //<2F><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
if(mode & 0x01)
GPIOx->INTRISEEN |= (0x01 << n); //<2F><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
else
GPIOx->INTRISEEN &= ~(0x01 << n); //<2F>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
}
}
GPIOx->INTCLR = (1 << n); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊģʽ<C4A3><CABD><EFBFBD>ÿ<EFBFBD><C3BF>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: EXTI_Open()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϴ򿪣<CFB4><F2BFAAA3><EFBFBD>ʹ<EFBFBD>ܣ<EFBFBD>
* <20><> <20><>: GPIO_TypeDef * GPIOx ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49>˿ڣ<CBBF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>GPIOA<4F><41>GPIOB<4F><42>GPIOC<4F><43>GPIOM<4F><4D>GPION<4F><4E>GPIOP
* uint32_t n ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49><4F><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PIN0<4E><30>PIN1<4E><31>PIN2<4E><32>... ... PIN22<32><32>PIN23
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void EXTI_Open(GPIO_TypeDef * GPIOx, uint32_t n)
{
GPIOx->INTEN |= (0x01 << n);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: EXTI_Close()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϹرգ<D8B1><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>
* <20><> <20><>: GPIO_TypeDef * GPIOx ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49>˿ڣ<CBBF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>GPIOA<4F><41>GPIOB<4F><42>GPIOC<4F><43>GPIOM<4F><4D>GPION<4F><4E>GPIOP
* uint32_t n ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49><4F><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PIN0<4E><30>PIN1<4E><31>PIN2<4E><32>... ... PIN22<32><32>PIN23
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void EXTI_Close(GPIO_TypeDef * GPIOx, uint32_t n)
{
GPIOx->INTEN &= ~(0x01 << n);
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: EXTI_State()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ񴥷<C7B7><F1B4A5B7><EFBFBD><EFBFBD>ж<EFBFBD>
* <20><> <20><>: GPIO_TypeDef * GPIOx ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49>˿ڣ<CBBF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>GPIOA<4F><41>GPIOB<4F><42>GPIOC<4F><43>GPIOM<4F><4D>GPION<4F><4E>GPIOP
* uint32_t n ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49><4F><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PIN0<4E><30>PIN1<4E><31>PIN2<4E><32>... ... PIN22<32><32>PIN23
* <20><> <20><>: uint32_t 1 <20><><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint32_t EXTI_State(GPIO_TypeDef * GPIOx, uint32_t n)
{
return (GPIOx->INTSTAT >> n) & 0x01;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: EXTI_RawState()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϹر<CFB9>ʱ<EFBFBD><CAB1>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ô˺<C3B4><CBBA><EFBFBD><EFBFBD>Բ<EFBFBD>ѯ<EFBFBD>ķ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><> <20><>: GPIO_TypeDef * GPIOx ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49>˿ڣ<CBBF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>GPIOA<4F><41>GPIOB<4F><42>GPIOC<4F><43>GPIOM<4F><4D>GPION<4F><4E>GPIOP
* uint32_t n ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49><4F><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PIN0<4E><30>PIN1<4E><31>PIN2<4E><32>... ... PIN22<32><32>PIN23
* <20><> <20><>: uint32_t 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint32_t EXTI_RawState(GPIO_TypeDef * GPIOx, uint32_t n)
{
return (GPIOx->INTRAWSTAT >> n) & 0x01;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: EXTI_Clear()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴν<D9B4><CEBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6>
* <20><> <20><>: GPIO_TypeDef * GPIOx ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49>˿ڣ<CBBF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>GPIOA<4F><41>GPIOB<4F><42>GPIOC<4F><43>GPIOM<4F><4D>GPION<4F><4E>GPIOP
* uint32_t n ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>жϵ<D0B6>GPIO<49><4F><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PIN0<4E><30>PIN1<4E><31>PIN2<4E><32>... ... PIN22<32><32>PIN23
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD>жϵı<CFB5>־<EFBFBD><D6BE><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>жϵı<CFB5>־<EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
******************************************************************************************************************************************/
void EXTI_Clear(GPIO_TypeDef * GPIOx, uint32_t n)
{
GPIOx->INTCLR = (0x01 << n);
}