forked from jkroso/pico-button.c
-
Notifications
You must be signed in to change notification settings - Fork 1
/
button.h
50 lines (36 loc) · 930 Bytes
/
button.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* RP2040-Button
* Button debounce library for Raspberry Pi Pico
*
* Fork of https://github.com/jkroso/pico-button.c
* including https://github.com/jkroso/pico-gpio-interrupt.c,
* both by Jake Rosoman. MIT license.
*
* 2023-02-13: Adapted by Turi Scandurra
*/
#ifndef PICO_BUTTON_H
#define PICO_BUTTON_H
#include "pico/stdlib.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DEBOUNCE_US 200
typedef struct button_t {
uint8_t pin;
bool state;
void (*onchange)(struct button_t *button);
} button_t;
typedef void (*handler)(void *argument);
typedef struct {
void * argument;
handler fn;
} closure_t;
long long int handle_button_alarm(long int a, void *p);
void handle_button_interrupt(void *p);
void handle_interrupt(uint gpio, uint32_t events);
void listen(uint pin, int condition, handler fn, void *arg);
button_t * create_button(int pin, void (*onchange)(button_t *));
#ifdef __cplusplus
}
#endif
#endif