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
use crate::Error;
use downcast_rs::Downcast;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(feature = "hidapi")]
pub use self::hid::AccessHid;
#[cfg(feature = "hidapi")]
mod hid;
#[cfg(any(
feature = "redox_hwio",
all(feature = "std", target_os = "linux")
))]
pub use self::lpc::*;
#[cfg(any(
feature = "redox_hwio",
all(feature = "std", target_os = "linux")
))]
mod lpc;
pub trait Access: Downcast + Send + 'static {
unsafe fn command(&mut self, cmd: u8, data: &mut [u8]) -> Result<u8, Error>;
fn data_size(&self) -> usize;
unsafe fn read_debug(&mut self, _addr: u8) -> Result<u8, Error> {
Err(Error::NotSupported)
}
}
impl Access for Box<dyn Access> {
unsafe fn command(&mut self, cmd: u8, data: &mut [u8]) -> Result<u8, Error> {
(**self).command(cmd, data)
}
fn data_size(&self) -> usize {
(**self).data_size()
}
unsafe fn read_debug(&mut self, addr: u8) -> Result<u8, Error> {
(**self).read_debug(addr)
}
}
downcast_rs::impl_downcast!(Access);