]> git.scottworley.com Git - tattlekey/blame - client/button.c
client: xcalloc
[tattlekey] / client / button.c
CommitLineData
d1521eda
SW
1#include "button.h"
2#include "config.h"
3
4#include "hardware/gpio.h"
5
6#include "pico/stdlib.h"
7
8static callback_t button_callback = NULL;
9
10static void respond_to_gpio_interrupt(uint gpio, uint32_t event_mask) {
d7789e5b 11 if (gpio == config_button_pin && event_mask & GPIO_IRQ_EDGE_FALL &&
d1521eda
SW
12 button_callback) {
13 button_callback();
14 }
15}
16
17void begin_listening_for_button_press(callback_t callback) {
18 button_callback = callback;
19
d7789e5b 20 gpio_set_pulls(config_button_pin, 1, 0);
d1521eda
SW
21
22 /* Allow some time for the pull-up to take effect.
23 * I'm not sure if this is necessary.
24 * https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf says
25 * the internal GPIO pull-up resistors are 50k. */
26 sleep_ms(100);
27
d7789e5b 28 gpio_set_irq_enabled_with_callback(config_button_pin, GPIO_IRQ_EDGE_FALL, 1,
d1521eda
SW
29 respond_to_gpio_interrupt);
30}