41
41
42
42
static gpio_irq_handler irq_handler ;
43
43
44
-
45
- //typedef struct {
46
- // uint32_t port[4];
47
- // uint32_t pin[16];
48
- // uint32_t ids;
49
- //} irq_channel;
50
-
51
44
static uint32_t channel_ids [4 ][16 ];
52
45
53
46
#ifdef __cplusplus
@@ -57,68 +50,40 @@ extern "C"{
57
50
58
51
void PORT0_Handler (void )
59
52
{
60
- int i = 0 ;
61
-
62
- for (i = 0 ; i < 16 ; i ++ )
63
- {
64
- if (GPIOA -> Interrupt .INTSTATUS & (1 << i ))
65
- {
66
- GPIOA -> Interrupt .INTCLEAR |= (1 << i );
67
- if (GPIOA -> INTPOLSET >> i ) //rising
68
- irq_handler (channel_ids [0 ][i ], IRQ_RISE );
69
- else //falling
70
- irq_handler (channel_ids [0 ][i ], IRQ_FALL );
71
- }
72
- }
53
+ port_generic_handler (GPIOA , 0 );
73
54
}
74
55
75
56
void PORT1_Handler (void )
76
57
{
77
- int i = 0 ;
78
-
79
- for (i = 0 ; i < 16 ; i ++ )
80
- {
81
- if (GPIOB -> Interrupt .INTSTATUS & (1 << i ))
82
- {
83
- GPIOB -> Interrupt .INTCLEAR |= (1 << i );
84
- if (GPIOB -> INTPOLSET >> i ) //rising
85
- irq_handler (channel_ids [0 ][i ], IRQ_RISE );
86
- else //falling
87
- irq_handler (channel_ids [0 ][i ], IRQ_FALL );
88
- }
89
- }
58
+ port_generic_handler (GPIOB , 1 );
90
59
}
91
60
92
61
void PORT2_Handler (void )
93
62
{
94
- int i = 0 ;
95
-
96
- for (i = 0 ; i < 16 ; i ++ )
97
- {
98
- if (GPIOC -> Interrupt .INTSTATUS & (1 << i ))
99
- {
100
- GPIOC -> Interrupt .INTCLEAR |= (1 << i );
101
- if (GPIOC -> INTPOLSET >> i ) //rising
102
- irq_handler (channel_ids [0 ][i ], IRQ_RISE );
103
- else //falling
104
- irq_handler (channel_ids [0 ][i ], IRQ_FALL );
105
- }
106
- }
63
+ port_generic_handler (GPIOC , 2 );
107
64
}
108
65
109
66
void PORT3_Handler (void )
110
67
{
111
- int i ;
68
+ port_generic_handler (GPIOD , 3 );
69
+ }
70
+
71
+ void port_generic_handler (GPIO_TypeDef * GPIOx , uint32_t port_num )
72
+ {
73
+ int i = 0 ;
74
+ int loop = 16 ;
75
+
76
+ if (GPIOx == GPIOD ) loop = 5 ;
112
77
113
- for (i = 0 ; i < 5 ; i ++ )
78
+ for (i = 0 ; i < loop ; i ++ )
114
79
{
115
- if (GPIOD -> Interrupt .INTSTATUS & (1 << i ))
80
+ if (GPIOx -> Interrupt .INTSTATUS & (1 << i ))
116
81
{
117
- GPIOD -> Interrupt .INTCLEAR |= (1 << i );
118
- if (GPIOD -> INTPOLSET >> i ) //rising
119
- irq_handler (channel_ids [0 ][i ], IRQ_RISE );
82
+ GPIOx -> Interrupt .INTCLEAR |= (1 << i );
83
+ if (GPIOx -> INTPOLSET >> i ) //rising
84
+ irq_handler (channel_ids [port_num ][i ], IRQ_RISE );
120
85
else //falling
121
- irq_handler (channel_ids [0 ][i ], IRQ_FALL );
86
+ irq_handler (channel_ids [port_num ][i ], IRQ_FALL );
122
87
}
123
88
}
124
89
}
0 commit comments