@@ -38,6 +38,8 @@ struct gpio_input_state : public HAL_DblLinkedNode<gpio_input_state>
3838 void *param;
3939 // Expected state for debounce handler
4040 GPIO_PinState expected;
41+ // Current pin state
42+ GPIO_PinState current;
4143 // True if waiting for debounce timer to complete
4244 bool waitingDebounce;
4345};
@@ -76,14 +78,15 @@ static void DebounceTimerCallback(uint32_t id)
7678 // get current pin state
7779 bool actual = HAL_GPIO_ReadPin (port, GPIO_PIN (pState->pinNumber ));
7880
79- if (actual == pState->expected )
81+ if (actual == pState->current )
8082 {
8183 pState->isrPtr (pState->pinNumber , actual, pState->param );
84+
8285 if (pState->mode == GPIO_INT_EDGE_BOTH)
8386 {
8487 // both edges
85- // update expected state
86- pState->expected = (GPIO_PinState)(pState->expected ^ GPIO_PIN_SET);
88+ // update current state
89+ pState->current = (GPIO_PinState)(pState->current ^ GPIO_PIN_SET);
8790 }
8891 }
8992
@@ -123,10 +126,14 @@ void HAL_GPIO_EXTI_Callback(uint16_t gpioPin)
123126 {
124127 TX_RESTORE
125128
126- pGpio->isrPtr (
127- pGpio->pinNumber ,
128- HAL_GPIO_ReadPin (GPIO_PORT (pGpio->pinNumber ), GPIO_PIN (pGpio->pinNumber )),
129- pGpio->param );
129+ bool level = HAL_GPIO_ReadPin (GPIO_PORT (pGpio->pinNumber ), GPIO_PIN (pGpio->pinNumber ));
130+
131+ if (level != pGpio->current )
132+ {
133+ pGpio->current = level;
134+
135+ pGpio->isrPtr (pGpio->pinNumber , level, pGpio->param );
136+ }
130137
131138 TX_DISABLE
132139 }
@@ -167,6 +174,7 @@ gpio_input_state *AllocateGpioInputState(GPIO_PIN pinNumber)
167174 {
168175 memset (ptr, 0 , sizeof (gpio_input_state));
169176 ptr->pinNumber = pinNumber;
177+ ptr->current = HAL_GPIO_ReadPin (GPIO_PORT (pGpio->pinNumber ), GPIO_PIN (pGpio->pinNumber ));
170178
171179 tx_timer_create (
172180 &ptr->debounceTimer ,
@@ -490,7 +498,7 @@ void CPU_GPIO_DisablePin(GPIO_PIN pinNumber, GpioPinDriveMode driveMode, uint32_
490498
491499 GPIO_TypeDef *port = GPIO_PORT (pinNumber);
492500 uint32_t pin = GPIO_PIN (pinNumber);
493-
501+
494502 GPIO_InitTypeDef gpio_init_structure;
495503 gpio_init_structure.Pin = pin;
496504
0 commit comments