]> git.scottworley.com Git - tattlekey/blame_incremental - client/button.c
client: Exponential backoff resend intervals
[tattlekey] / client / button.c
... / ...
CommitLineData
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) {
11 if (gpio == config_button_pin && event_mask & GPIO_IRQ_EDGE_FALL &&
12 button_callback) {
13 button_callback();
14 }
15}
16
17void begin_listening_for_button_press(callback_t callback) {
18 button_callback = callback;
19
20 gpio_set_pulls(config_button_pin, 1, 0);
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
28 gpio_set_irq_enabled_with_callback(config_button_pin, GPIO_IRQ_EDGE_FALL, 1,
29 respond_to_gpio_interrupt);
30}