1 /* tattlekey: A one-key UDP keyboard
2 * Copyright (C) 2023 Scott Worley <scottworley@scottworley.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 #include "hardware/gpio.h"
23 #include "pico/stdlib.h"
25 static callback_t button_callback
= NULL
;
27 static void respond_to_gpio_interrupt(uint gpio
, uint32_t event_mask
) {
28 if (gpio
== config_button_pin
&& event_mask
& GPIO_IRQ_EDGE_FALL
&&
34 void begin_listening_for_button_press(callback_t callback
) {
35 button_callback
= callback
;
37 gpio_set_pulls(config_button_pin
, 1, 0);
39 /* Allow some time for the pull-up to take effect.
40 * I'm not sure if this is necessary.
41 * https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf says
42 * the internal GPIO pull-up resistors are 50k. */
45 gpio_set_irq_enabled_with_callback(config_button_pin
, GPIO_IRQ_EDGE_FALL
, 1,
46 respond_to_gpio_interrupt
);