Skip to content

Commit 7b8a9ba

Browse files
author
Bogdan Marinescu
committed
Merge branch 'patch-3' of git://github.com/cfb95/mbed into cfb95-patch-3
2 parents ffe6a9b + bf59715 commit 7b8a9ba

File tree

1 file changed

+69
-38
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB

1 file changed

+69
-38
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB/gpio_irq_api.c

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,49 @@
3939
#define EDGE_FALL (2)
4040
#define EDGE_BOTH (3)
4141

42-
#define CHANNEL_NUM (4)
42+
#define CHANNEL_NUM (16)
4343

44-
static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0};
45-
static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0};
46-
static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0};
44+
static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
45+
static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
46+
static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
4747

4848
static gpio_irq_handler irq_handler;
4949

5050
static void handle_interrupt_in(uint32_t irq_index) {
51-
// Retrieve the gpio and pin that generate the irq
52-
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
53-
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
54-
55-
// Clear interrupt flag
56-
if (EXTI_GetITStatus(pin) != RESET)
57-
{
58-
EXTI_ClearITPendingBit(pin);
59-
}
60-
61-
if (channel_ids[irq_index] == 0) return;
62-
63-
// Check which edge has generated the irq
64-
if ((gpio->IDR & pin) == 0) {
65-
irq_handler(channel_ids[irq_index], IRQ_FALL);
66-
}
67-
else {
68-
irq_handler(channel_ids[irq_index], IRQ_RISE);
69-
}
51+
//if irq_index==5 loop exti 5 to 9
52+
//if irq_index==10 loop exti 10 to 15
53+
//else exti loop one irq_index
54+
uint32_t to_irq_index=(irq_index==5)?9:((irq_index==10)?15:irq_index);
55+
GPIO_TypeDef *gpio;
56+
uint32_t pin;
57+
do{
58+
// Retrieve the gpio and pin that generate the irq
59+
gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
60+
pin = (uint32_t)(1 << channel_pin[irq_index]);
61+
// Clear interrupt flag
62+
if (EXTI_GetITStatus(pin) != RESET)
63+
{
64+
EXTI_ClearITPendingBit(pin);
65+
if (channel_ids[irq_index] == 0) return;
66+
// Check which edge has generated the irq
67+
if ((gpio->IDR & pin) == 0) {
68+
irq_handler(channel_ids[irq_index], IRQ_FALL);
69+
} else {
70+
irq_handler(channel_ids[irq_index], IRQ_RISE);
71+
}
72+
}
73+
}while(irq_index++ < to_irq_index);
7074
}
7175

76+
7277
// The irq_index is passed to the function
73-
static void gpio_irq0(void) {handle_interrupt_in(0);}
74-
static void gpio_irq1(void) {handle_interrupt_in(1);}
75-
static void gpio_irq2(void) {handle_interrupt_in(2);}
76-
static void gpio_irq3(void) {handle_interrupt_in(3);}
78+
static void gpio_irq0(void) {handle_interrupt_in(0);} // EXTI line 0
79+
static void gpio_irq1(void) {handle_interrupt_in(1);} // EXTI line 1
80+
static void gpio_irq2(void) {handle_interrupt_in(2);} // EXTI line 2
81+
static void gpio_irq3(void) {handle_interrupt_in(3);} // EXTI line 3
82+
static void gpio_irq4(void) {handle_interrupt_in(4);} // EXTI line 4
83+
static void gpio_irq5(void) {handle_interrupt_in(5);} // EXTI lines 5 to 9
84+
static void gpio_irq6(void) {handle_interrupt_in(10);} // EXTI lines 10 to 15
7785

7886
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
7987

@@ -88,32 +96,55 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
8896
uint32_t pin_index = STM_PIN(pin);
8997

9098
// Select irq number and interrupt routine
91-
switch (pin) {
92-
case PC_13: // User button
93-
irq_n = EXTI15_10_IRQn;
99+
switch (pin_index) {
100+
case 0:
101+
irq_n = EXTI0_IRQn;
94102
vector = (uint32_t)&gpio_irq0;
95103
irq_index = 0;
96104
break;
97-
case PB_3:
98-
irq_n = EXTI3_IRQn;
105+
case 1:
106+
irq_n = EXTI1_IRQn;
99107
vector = (uint32_t)&gpio_irq1;
100108
irq_index = 1;
101109
break;
102-
case PB_4:
103-
irq_n = EXTI4_IRQn;
110+
case 2:
111+
irq_n = EXTI2_IRQn;
104112
vector = (uint32_t)&gpio_irq2;
105113
irq_index = 2;
106114
break;
107-
case PB_5:
108-
irq_n = EXTI9_5_IRQn;
115+
case 3:
116+
irq_n = EXTI3_IRQn;
109117
vector = (uint32_t)&gpio_irq3;
110118
irq_index = 3;
111119
break;
120+
case 4:
121+
irq_n = EXTI4_IRQn;
122+
vector = (uint32_t)&gpio_irq4;
123+
irq_index = 4;
124+
break;
125+
case 5:
126+
case 6:
127+
case 7:
128+
case 8:
129+
case 9:
130+
irq_n = EXTI9_5_IRQn;
131+
vector = (uint32_t)&gpio_irq5;
132+
irq_index = pin_index;
133+
break;
134+
case 10:
135+
case 11:
136+
case 12:
137+
case 13:
138+
case 14:
139+
case 15:
140+
irq_n = EXTI15_10_IRQn;
141+
vector = (uint32_t)&gpio_irq6;
142+
irq_index = pin_index;
143+
break;
112144
default:
113-
error("This pin is not supported with InterruptIn.");
145+
error("InterruptIn error: pin not supported.\n");
114146
return -1;
115147
}
116-
117148
// Enable GPIO clock
118149
uint32_t gpio_add = Set_GPIO_Clock(port_index);
119150

0 commit comments

Comments
 (0)