Skip to content

Commit

Permalink
Make framebuffer an optional feature
Browse files Browse the repository at this point in the history
Some users of libremarkable might want to use it only for its input
handling, but not for its framebuffer functionality. By disabling the
framebuffer feature, users can also avoid lots of dependencies (73
instead of 151 dependencies to install), some of which (e.g., zstd) even
need a C compiler.

The default features will build everything as before, so this will not
cause any compatibility issues.
  • Loading branch information
lluchs committed Jan 16, 2021
1 parent 340bc9a commit 7ab5005
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 33 deletions.
40 changes: 27 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,39 @@ edition = "2018"
[dependencies]
log = "0.4.8"
env_logger = "0.7.1"
ioctl-gen = "0.1.1"
lazy_static = "1.4.0"
atomic = "0.5.0"
cgmath = "0.17.0"
libc = "0.2.69"
mmap = "0.1.1"
rusttype = "0.8.2"

# input
evdev = "0.10.2"
epoll = "4.1.0"
image = "0.21.3"
line_drawing = "0.8.0"
hlua = "0.4.1"
aabb-quadtree = "0.1.0"
zstd = "0.5.1"
stopwatch = "0.0.7"
atomic = { version = "0.5.0" }
cgmath = "0.17.0"
fxhash = "0.2.1"
lazy_static = "1.4.0"

# framebuffer
rusttype = { version = "0.8.2", optional = true }
mmap = { version = "0.1.1", optional = true }
image = { version = "0.21.3", optional = true }
ioctl-gen = { version = "0.1.1", optional = true }
line_drawing = { version = "0.8.0", optional = true }
zstd = { version = "0.5.1", optional = true }

# appctx
aabb-quadtree = { version = "0.1.0", optional = true }
hlua = { version = "0.4.1", optional = true }

# runtime benchmarking
stopwatch = { version = "0.0.7", optional = true }


[features]
enable-runtime-benchmarking = []
default = ["framebuffer", "appctx"]

framebuffer = ["rusttype", "mmap", "image", "ioctl-gen", "line_drawing", "zstd"]
appctx = ["aabb-quadtree", "hlua"]

enable-runtime-benchmarking = ["stopwatch"]

[profile.release]
debug = true
Expand Down
16 changes: 16 additions & 0 deletions src/dimensions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::input::scan::SCANNED;

pub const DISPLAYWIDTH: u16 = 1404;
pub const DISPLAYHEIGHT: u16 = 1872;

lazy_static! {
/// Will be 767 rM1 and 1403 on the rM2
pub static ref MTWIDTH: u16 = SCANNED.mt_width;
/// Will be 1023 the rM1 and 1871 on the rM2
pub static ref MTHEIGHT: u16 = SCANNED.mt_height;

/// Will be 15725 on both the rM1 and rM2
pub static ref WACOMWIDTH: u16 = SCANNED.wacom_width;
/// Will be 20967 on the rM1 and 20966 on the rM2
pub static ref WACOMHEIGHT: u16 = SCANNED.wacom_height;
}
19 changes: 3 additions & 16 deletions src/framebuffer/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(non_camel_case_types)]
use crate::framebuffer::cgmath;
use crate::framebuffer::mxcfb::*;
use crate::input::scan::SCANNED;

// Compatibility re-exports
pub use crate::dimensions::{DISPLAYWIDTH, DISPLAYHEIGHT, MTWIDTH, MTHEIGHT, WACOMWIDTH, WACOMHEIGHT};

/// This is to allow tests to run on systems with 64bit pointer types.
/// It doesn't make a difference since we will be mocking the ioctl calls.
Expand All @@ -12,21 +14,6 @@ pub type NativeWidthType = i32;
#[cfg(all(target_pointer_width = "32", target_env = "gnu"))]
pub type NativeWidthType = u32;

pub const DISPLAYWIDTH: u16 = 1404;
pub const DISPLAYHEIGHT: u16 = 1872;

lazy_static! {
/// Will be 767 rM1 and 1403 on the rM2
pub static ref MTWIDTH: u16 = SCANNED.mt_width;
/// Will be 1023 the rM1 and 1871 on the rM2
pub static ref MTHEIGHT: u16 = SCANNED.mt_height;

/// Will be 15725 on both the rM1 and rM2
pub static ref WACOMWIDTH: u16 = SCANNED.wacom_width;
/// Will be 20967 on the rM1 and 20966 on the rM2
pub static ref WACOMHEIGHT: u16 = SCANNED.wacom_height;
}

pub const MXCFB_SET_AUTO_UPDATE_MODE: NativeWidthType =
iow!(b'F', 0x2D, std::mem::size_of::<u32>()) as NativeWidthType;
pub const MXCFB_SET_UPDATE_SCHEME: NativeWidthType =
Expand Down
4 changes: 2 additions & 2 deletions src/input/multitouch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::ecodes;
use crate::device::CURRENT_DEVICE;
use crate::framebuffer::cgmath;
use crate::framebuffer::common::{DISPLAYHEIGHT, DISPLAYWIDTH, MTHEIGHT, MTWIDTH};
use crate::cgmath;
use crate::dimensions::{DISPLAYHEIGHT, DISPLAYWIDTH, MTHEIGHT, MTWIDTH};
use crate::input::rotate::CoordinatePart;
use crate::input::scan::SCANNED;
use crate::input::{InputDeviceState, InputEvent};
Expand Down
4 changes: 2 additions & 2 deletions src/input/wacom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use evdev::raw::input_event;
use log::debug;
use std::sync::atomic::{AtomicU16, Ordering};

use crate::framebuffer::cgmath;
use crate::framebuffer::common::{DISPLAYHEIGHT, DISPLAYWIDTH, WACOMHEIGHT, WACOMWIDTH};
use crate::cgmath;
use crate::dimensions::{DISPLAYHEIGHT, DISPLAYWIDTH, WACOMHEIGHT, WACOMWIDTH};

lazy_static! {
static ref WACOM_HSCALAR: f32 = (DISPLAYWIDTH as f32) / (*WACOMWIDTH as f32);
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ macro_rules! end_bench {
};
}

#[cfg(feature = "framebuffer")]
#[macro_use]
extern crate ioctl_gen;
#[macro_use]
Expand All @@ -39,16 +40,23 @@ extern crate lazy_static;
pub use cgmath;
pub use epoll;
pub use evdev;
#[cfg(feature = "framebuffer")]
pub use image;
#[cfg(feature = "framebuffer")]
pub use line_drawing;
#[cfg(feature = "enable-runtime-benchmarking")]
pub use stopwatch;

/// One of the core components, allowing output and refresh of the EInk display
#[cfg(feature = "framebuffer")]
pub mod framebuffer;

/// The other core component, allowing decoding of the three input devices present on the tablet
pub mod input;

/// Device dimensions.
pub mod dimensions;

/// Simple battery and charging status provider
pub mod battery;

Expand All @@ -60,5 +68,7 @@ pub mod device;
/// to a scene after wrapping them in `UIElementWrapper`. None of these are mandatory to be used.
/// You can choose to entirely ignore the `ApplicationContext` and `ui_extensions` and interact
/// with the `framebuffer` and `input` devices directly.
#[cfg(all(feature = "framebuffer", feature = "appctx"))]
pub mod appctx;
#[cfg(all(feature = "framebuffer", feature = "appctx"))]
pub mod ui_extensions;

0 comments on commit 7ab5005

Please sign in to comment.