-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.h
More file actions
41 lines (30 loc) · 796 Bytes
/
Copy pathbutton.h
File metadata and controls
41 lines (30 loc) · 796 Bytes
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
#pragma once
//=========================================================
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
//=========================================================
struct Button
{
uint32_t GPIOx;
uint8_t pin;
uint32_t saturation;
bool is_pressed;
};
enum Button_error
{
BTN_INV_PTR = -1,
BTN_INV_GPIO = -2,
BTN_INV_PIN = -3
};
//=========================================================
// Setup button on GPIOx:pin
int button_setup(struct Button* button, uint32_t GPIOx, uint8_t pin);
// Read from input and update state of button
int button_update(struct Button* button);
static inline bool button_is_pressed(struct Button* button)
{
if (button == NULL)
return BTN_INV_PTR;
return button->is_pressed;
}