hal_sim/dto/
gpio.rs

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
use core::fmt::Debug;

use serde::*;

pub type PinName = heapless::String<64>;
pub type PinCategory = heapless::String<64>;

#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum ButtonType {
    Toggle,
    Click,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum PinType {
    Input(ButtonType),
    Output,
    InputOutput(ButtonType),
    Analog(u16, u16),
}

impl PinType {
    pub fn is_click(&self) -> bool {
        matches!(
            self,
            Self::Input(ButtonType::Click) | Self::InputOutput(ButtonType::Click)
        )
    }
}

impl Default for PinType {
    fn default() -> Self {
        Self::Output
    }
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct PinMeta {
    pub name: PinName,
    pub category: PinCategory,
    pub pin_type: PinType,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum PinValue {
    Input(bool),
    Output(bool),
    InputOutput { input: bool, output: bool },
    Adc(u16),
}