Skip to main content

pinenote_service/
lib.rs

1/// Driver support
2pub mod drivers {
3    pub mod drm {
4        pub mod rockchip_ebc;
5    }
6
7    pub use drm::rockchip_ebc;
8}
9
10pub mod ioctls {
11    use nix::libc;
12    use std::{fs::OpenOptions, os::unix::fs::OpenOptionsExt, path::Path};
13    use thiserror::Error;
14
15    pub mod drm {
16        pub const IOCTL_MAGIC: u8 = b'd';
17        pub const COMMAND_BASE: u8 = 0x40;
18
19        /// DRM UAPI 2D rectangle.
20        pub struct Rect {
21            /// Starting horizontal coordinate(inclusive)
22            pub x1: i32,
23            /// Starting vertical coordinate(inclusive)
24            pub y1: i32,
25            /// Ending horizontal coordinate(exclusive)
26            pub x2: i32,
27            /// Ending vertical coordinate(exclusive)
28            pub y2: i32,
29        }
30
31        pub mod rockchip_ebc;
32    }
33
34    pub use drm::rockchip_ebc;
35
36    #[derive(Error, Debug)]
37    #[error("Could not open device at '{path}'")]
38    pub struct OpenError {
39        path: String,
40        source: std::io::Error,
41    }
42
43    pub fn open_device(path: impl AsRef<Path>) -> Result<std::fs::File, OpenError> {
44        OpenOptions::new()
45            .read(true)
46            .write(true)
47            .custom_flags(libc::O_NONBLOCK)
48            .open(&path)
49            .map_err(|source| {
50                let path = path.as_ref().to_string_lossy().to_string();
51                OpenError { path, source }
52            })
53    }
54}
55
56pub mod types {
57    pub mod rect;
58    pub mod rockchip_ebc;
59    pub use rect::Rect;
60
61    pub mod ztree;
62}
63
64pub mod sysfs {
65    pub mod attribute;
66}
67
68pub mod pixel_manager;