1use super::Duration;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6pub struct ButtonConfig {
7 pub debounce: Duration,
9 pub double_click: Duration,
12 pub long_press: Duration,
14 pub mode: Mode,
16}
17
18impl ButtonConfig {
19 pub fn new(
21 debounce: Duration,
22 double_click: Duration,
23 long_press: Duration,
24 mode: Mode,
25 ) -> Self {
26 Self {
27 debounce,
28 double_click,
29 long_press,
30 mode,
31 }
32 }
33}
34
35impl Default for ButtonConfig {
36 fn default() -> Self {
37 Self {
38 debounce: Duration::from_millis(10),
39 double_click: Duration::from_millis(350),
40 long_press: Duration::from_millis(1000),
41 mode: Mode::default(),
42 }
43 }
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
48#[cfg_attr(feature = "defmt", derive(defmt::Format))]
49pub enum Mode {
50 #[default]
52 PullUp,
53 PullDown,
55}
56
57impl Mode {
58 pub const fn is_pullup(&self) -> bool {
60 matches!(self, Mode::PullUp)
61 }
62
63 pub const fn is_pulldown(&self) -> bool {
65 !self.is_pullup()
66 }
67}