-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhal_button.hpp
90 lines (75 loc) · 2.1 KB
/
hal_button.hpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* hal_button.hpp
*
* Created on: 5 paź 2021
* Author: kwarc
*/
#ifndef HAL_BUTTON_HPP_
#define HAL_BUTTON_HPP_
#include <hal/hal_interface.hpp>
#include <drivers/button_gpio.hpp>
namespace hal
{
//---------------------------------------------------------------------------
class button
{
public:
button(hal::interface::button *interface);
virtual ~button() {};
virtual void debounce(void);
bool is_pressed(void);
bool was_pressed(void);
bool was_released(void);
protected:
hal::interface::button *interface;
private:
bool pressed, released;
uint32_t debounce_state;
};
//-----------------------------------------------------------------------------
namespace buttons
{
class center_btn : public button
{
public:
center_btn(void) : button {&drv} {}
private:
const drivers::gpio::io io = { drivers::gpio::port::porta, drivers::gpio::pin::pin0 };
drivers::button_gpio drv {io};
};
class up_btn : public button
{
public:
up_btn(void) : button {&drv} {}
private:
const drivers::gpio::io io = { drivers::gpio::port::porta, drivers::gpio::pin::pin3 };
drivers::button_gpio drv {io};
};
class down_btn : public button
{
public:
down_btn(void) : button {&drv} {}
private:
const drivers::gpio::io io = { drivers::gpio::port::porta, drivers::gpio::pin::pin5 };
drivers::button_gpio drv {io};
};
class left_btn : public button
{
public:
left_btn(void) : button {&drv} {}
private:
const drivers::gpio::io io = { drivers::gpio::port::porta, drivers::gpio::pin::pin1 };
drivers::button_gpio drv {io};
};
class right_btn : public button
{
public:
right_btn(void) : button {&drv} {}
private:
const drivers::gpio::io io = { drivers::gpio::port::porta, drivers::gpio::pin::pin2 };
drivers::button_gpio drv {io};
};
}
//---------------------------------------------------------------------------
}
#endif /* HAL_BUTTON_HPP_ */