Skip to content

Commit 051574f

Browse files
authored
Fix GPIO debounce for GG11 (#2780)
***NO_CI***
1 parent f7d963e commit 051574f

File tree

1 file changed

+27
-27
lines changed
  • targets/AzureRTOS/SiliconLabs/_nanoCLR/System.Device.Gpio

1 file changed

+27
-27
lines changed

targets/AzureRTOS/SiliconLabs/_nanoCLR/System.Device.Gpio/cpu_gpio.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ gpio_input_state *GetGpioWithInterrupt(uint16_t gpioPin)
117117
return NULL;
118118
}
119119

120-
static void DebounceTimerCallback(uint32_t id)
120+
static void DebounceTimerCallback(ULONG pinState)
121121
{
122-
gpio_input_state *pState = (gpio_input_state *)id;
122+
gpio_input_state *pState = (gpio_input_state *)pinState;
123123

124124
GPIO_Port_TypeDef port;
125125
uint32_t portPin;
@@ -130,24 +130,23 @@ static void DebounceTimerCallback(uint32_t id)
130130

131131
if (actual == pState->expected)
132132
{
133+
// call ISR
133134
pState->isrPtr(pState->pinNumber, actual, pState->param);
134-
if (pState->mode == GPIO_INT_EDGE_BOTH)
135-
{
136-
// both edges
137-
// update expected state
138-
pState->expected ^= 1;
139-
}
140135
}
141136

137+
// reset flag
142138
pState->waitingDebounce = false;
143139
}
144140

145141
static void GpioEventCallback(uint32_t intFlags)
146142
{
147-
// TX_DISABLE
148143
uint32_t irqIdx;
149144
gpio_input_state *pGpio;
150145

146+
NATIVE_INTERRUPT_START
147+
148+
TX_DISABLE
149+
151150
// check for all flags set in IF register
152151
while (intFlags != 0U)
153152
{
@@ -160,39 +159,40 @@ static void GpioEventCallback(uint32_t intFlags)
160159

161160
if (pGpio != NULL)
162161
{
163-
// Ignore any pin changes during debounce
164-
if (!pGpio->waitingDebounce)
162+
if (pGpio->waitingDebounce)
163+
{
164+
// Ignore any pin changes during debounce
165+
continue;
166+
}
167+
else
165168
{
166169
// check if there is a debounce time set
167170
if (pGpio->debounceMs > 0)
168171
{
172+
// stop timer, just in case
173+
tx_timer_deactivate(&pGpio->debounceTimer);
174+
169175
// Set flag we are waiting for debounce on this pin
170176
pGpio->waitingDebounce = true;
171177

178+
// expecting same state as current one
179+
pGpio->expected = CPU_GPIO_GetPinState(pGpio->pinNumber);
180+
172181
// setup timer
173-
tx_timer_deactivate(&pGpio->debounceTimer);
174-
tx_timer_change(&pGpio->debounceTimer, 0, pGpio->debounceMs / 10);
182+
tx_timer_change(&pGpio->debounceTimer, TX_TICKS_PER_MILLISEC(pGpio->debounceMs), 0);
175183
tx_timer_activate(&pGpio->debounceTimer);
176184
}
177185
else
178186
{
179-
GPIO_Port_TypeDef port;
180-
uint32_t portPin;
181-
GetIoLine(pGpio->pinNumber, &port, &portPin);
182-
183-
TX_RESTORE
184-
185-
pGpio->isrPtr(pGpio->pinNumber, GPIO_PinInGet(port, portPin), pGpio->param);
186-
187-
TX_DISABLE
187+
pGpio->isrPtr(pGpio->pinNumber, CPU_GPIO_GetPinState(pGpio->pinNumber), pGpio->param);
188188
}
189189
}
190190
}
191+
}
191192

192-
TX_RESTORE
193+
TX_RESTORE
193194

194-
NATIVE_INTERRUPT_END
195-
}
195+
NATIVE_INTERRUPT_END
196196
}
197197

198198
// Get pointer to gpio_input_state for GPIO pin
@@ -234,9 +234,9 @@ gpio_input_state *AllocateGpioInputState(GPIO_PIN pinNumber)
234234
&ptr->debounceTimer,
235235
(char *)"GPIO debounce timer",
236236
DebounceTimerCallback,
237-
0,
238-
0,
237+
(ULONG)ptr,
239238
1,
239+
0,
240240
TX_NO_ACTIVATE);
241241

242242
gpioInputList.LinkAtBack(ptr);

0 commit comments

Comments
 (0)