4 #include "hardware/gpio.h"
6 #include "pico/stdlib.h"
8 static callback_t button_callback
= NULL
;
10 static void respond_to_gpio_interrupt(uint gpio
, uint32_t event_mask
) {
11 if (gpio
== config_button_pin
&& event_mask
& GPIO_IRQ_EDGE_FALL
&&
17 void begin_listening_for_button_press(callback_t callback
) {
18 button_callback
= callback
;
20 gpio_set_pulls(config_button_pin
, 1, 0);
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. */
28 gpio_set_irq_enabled_with_callback(config_button_pin
, GPIO_IRQ_EDGE_FALL
, 1,
29 respond_to_gpio_interrupt
);