Skip to content

Commit 22ae1d1

Browse files
authored
Merge pull request #147 from tmobile/pushbutton-defect-fix
Fix pushbutton defect
2 parents 8aa3f03 + 412faff commit 22ae1d1

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

samples/push_button_sample/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
source "Kconfig.zephyr"
6+
7+
mainmenu "Gecko Pushbutton"
8+
9+
config PUSHBUTTON_ADDITIONAL_PULL_UP
10+
bool "Pushbutton additional pull-up resistor"
11+
default true
12+
help
13+
The additional conductance afforded by the Gecko GPIO pull-up resistor
14+
reduces the RC time constant of the pushbutton debounce filter circuit,
15+
making switch bounce more likely.

samples/push_button_sample/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ CONFIG_GPIO=y
99

1010
# Stack sizes
1111
CONFIG_MAIN_STACK_SIZE=4096
12+
13+
# Pull-up circuit - additional conductance
14+
CONFIG_PUSHBUTTON_ADDITIONAL_PULL_UP=n

samples/push_button_sample/src/main.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void user_push_button_intr_callback(const struct device *port, struct gpio_callb
5858
push_button_isr_count++;
5959
if (print_edges) {
6060
printk("\r%s interrupt (%d): %s edge%s\n", port->name, push_button_isr_count,
61-
button_state.current ? " rising" : "falling",
61+
button_state.current ? "falling" : "rising",
6262
button_state.current == button_state.previous ? " (bounce detected)" : "");
6363
}
6464
button_state.previous = button_state.current;
@@ -89,7 +89,11 @@ static void setup(void)
8989
return;
9090
}
9191

92-
ret = gpio_pin_configure_dt(&button, GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_EDGE_BOTH);
92+
ret = gpio_pin_configure_dt(&button, GPIO_INPUT
93+
#if defined(CONFIG_PUSHBUTTON_ADDITIONAL_PULL_UP) && (CONFIG_PUSHBUTTON_ADDITIONAL_PULL_UP)
94+
| GPIO_PULL_UP
95+
#endif
96+
);
9397
if (ret != 0) {
9498
printk("Error %d: failed to configure %s pin %d\n", ret, button.port->name,
9599
button.pin);
@@ -165,12 +169,11 @@ static void phase2()
165169
/* Enable the interrupt edge printing mechanism */
166170
print_edges = true;
167171

168-
/* Enable Energy Mode 2 (EM2) -- Deep Sleep Mode */
169-
pm_state_force(0u, &(struct pm_state_info){PM_STATE_SUSPEND_TO_IDLE, 0, 0});
170-
171172
/* Maintain sleep */
172173
while (true) {
173174
puts("Entering EM2 sleep...\n");
175+
/* Enable Energy Mode 2 (EM2) -- Deep Sleep Mode */
176+
pm_state_force(0u, &(struct pm_state_info){PM_STATE_SUSPEND_TO_IDLE, 0, 0});
174177
k_msleep(1);
175178
puts("Awake from EM2 sleep...");
176179
}

0 commit comments

Comments
 (0)