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
#[derive(Debug)]
pub enum HalError {
InvalidConfig,
InvalidSpiMode,
NoPin,
#[cfg(feature = "hal-cp2130")]
Cp2130(driver_cp2130::Error),
#[cfg(feature = "hal-linux")]
Io(std::io::ErrorKind),
#[cfg(feature = "hal-linux")]
Sysfs(linux_embedded_hal::sysfs_gpio::Error),
}
impl HalError {
pub fn is_inner(&self) -> bool {
use HalError::*;
match self {
InvalidConfig | InvalidSpiMode | NoPin => false,
_ => true,
}
}
pub fn is_no_pin(&self) -> bool {
use HalError::*;
match self {
NoPin => true,
_ => false,
}
}
}
#[cfg(feature = "hal-cp2130")]
impl From<driver_cp2130::Error> for HalError {
fn from(e: driver_cp2130::Error) -> Self {
Self::Cp2130(e)
}
}
#[cfg(feature = "hal-linux")]
impl From<std::io::Error> for HalError {
fn from(e: std::io::Error) -> Self {
Self::Io(e.kind())
}
}
#[cfg(feature = "hal-linux")]
impl From<linux_embedded_hal::sysfs_gpio::Error> for HalError {
fn from(e: linux_embedded_hal::sysfs_gpio::Error) -> Self {
Self::Sysfs(e)
}
}