1 /*
2 * Copyright 2021 MindMotion Microelectronics Co., Ltd.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include "hal_exti.h"
9
EXTI_EnableLineInterrupt(EXTI_Type * EXTIx,uint32_t lines,bool enable)10 void EXTI_EnableLineInterrupt(EXTI_Type * EXTIx, uint32_t lines, bool enable)
11 {
12 if (enable)
13 {
14 EXTIx->IMR |= lines;
15 }
16 else
17 {
18 EXTIx->IMR &= ~ lines;
19 }
20 }
21
EXTI_EnableLineEvent(EXTI_Type * EXTIx,uint32_t lines,bool enable)22 void EXTI_EnableLineEvent(EXTI_Type * EXTIx, uint32_t lines, bool enable)
23 {
24 if (enable)
25 {
26 EXTIx->EMR |= lines;
27 }
28 else
29 {
30 EXTIx->EMR &= ~ lines;
31 }
32 }
33
EXTI_SetTriggerIn(EXTI_Type * EXTIx,uint32_t lines,EXTI_TriggerIn_Type trgin)34 void EXTI_SetTriggerIn(EXTI_Type * EXTIx, uint32_t lines, EXTI_TriggerIn_Type trgin)
35 {
36 switch (trgin)
37 {
38 case EXTI_TriggerIn_Disable:
39 EXTIx->RTSR &= ~ lines;
40 EXTIx->FTSR &= ~ lines;
41 break;
42 case EXTI_TriggerIn_RisingEdge:
43 EXTI->RTSR |= lines;
44 EXTIx->FTSR &= ~ lines;
45 break;
46 case EXTI_TriggerIn_FallingEdge:
47 EXTI->RTSR &= ~ lines;
48 EXTI->FTSR |= lines;
49 break;
50 case EXTI_TriggerIn_BothEdges:
51 EXTI->RTSR |= lines;
52 EXTI->FTSR |= lines;
53 break;
54 default:
55 break;
56 }
57 }
58
EXTI_DoSwTrigger(EXTI_Type * EXTIx,uint32_t lines)59 void EXTI_DoSwTrigger(EXTI_Type * EXTIx, uint32_t lines)
60 {
61 EXTIx->SWIER = lines;
62 }
63
EXTI_GetLineStatus(EXTI_Type * EXTIx)64 uint32_t EXTI_GetLineStatus(EXTI_Type * EXTIx)
65 {
66 return EXTIx->PR;
67 }
68
EXTI_ClearLineStatus(EXTI_Type * EXTIx,uint32_t lines)69 void EXTI_ClearLineStatus(EXTI_Type * EXTIx, uint32_t lines)
70 {
71 EXTIx->PR |= lines;
72 }
73
74 /* EOF. */
75
76