Skip to content

Commit

Permalink
fmt, partially remedy #31
Browse files Browse the repository at this point in the history
  • Loading branch information
nia-e committed Apr 1, 2023
1 parent 36d7d7c commit 16e3421
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
4 changes: 3 additions & 1 deletion examples/rust_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ struct Clock {

impl Default for Clock {
fn default() -> Self {
Self { start: Instant::now() }
Self {
start: Instant::now(),
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions lvgl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fn main() {
// Some basic defaults; SDL2 is the only driver enabled in the provided
// driver config by default
#[cfg(feature = "drivers")]
let incl_extra = env::var("LVGL_INCLUDE").unwrap_or("/usr/include,/usr/local/include".to_string());
let incl_extra =
env::var("LVGL_INCLUDE").unwrap_or("/usr/include,/usr/local/include".to_string());
#[cfg(feature = "drivers")]
let link_extra = env::var("LVGL_LINK").unwrap_or("SDL2".to_string());

Expand Down Expand Up @@ -169,7 +170,9 @@ fn main() {

let mut additional_args = Vec::new();
if target.ends_with("emscripten") {
if let Ok(em_path) = env::var("EMSDK") {
match env::var("EMSDK") {
Ok(em_path) =>
{
additional_args.push("-I".to_string());
additional_args.push(format!(
"{}/upstream/emscripten/system/include/libc",
Expand All @@ -186,6 +189,8 @@ fn main() {
em_path
));
}
Err(_) => panic!("The EMSDK environment variable is not set. Has emscripten been properly initialized?")
}
}

#[cfg(feature = "drivers")]
Expand Down
2 changes: 1 addition & 1 deletion lvgl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ required-features = ["alloc", "drivers"]

[[example]]
name = "rust_timer"
path = "../examples/rust_timer.h"
path = "../examples/rust_timer.rs"
required-features = ["alloc", "embedded_graphics", "rust_timer"]
16 changes: 10 additions & 6 deletions lvgl/src/drivers/lv_drv_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ macro_rules! lv_drv_input_pointer_evdev {
$crate::input_device::pointer::Pointer::new_raw(
Some(lvgl_sys::evdev_read),
None,
&$disp
&$disp,
)
}
};
Expand All @@ -19,7 +19,7 @@ macro_rules! lv_drv_input_pointer_gtk {
$crate::input_device::pointer::Pointer::new_raw(
Some(lvgl_sys::gtkdrv_mouse_read_cb),
None,
&$disp
&$disp,
)
}
};
Expand All @@ -32,7 +32,7 @@ macro_rules! lv_drv_input_pointer_sdl {
$crate::input_device::pointer::Pointer::new_raw(
Some(lvgl_sys::sdl_mouse_read),
None,
&$disp
&$disp,
)
}
};
Expand All @@ -46,7 +46,7 @@ macro_rules! lv_drv_input_ad_touch {
$crate::input_device::pointer::Pointer::new_raw(
Some(lvgl_sys::ad_touch_read),
None,
&$disp
&$disp,
)
}
};
Expand All @@ -60,7 +60,7 @@ macro_rules! lv_drv_input_ft5406ee8 {
$crate::input_device::pointer::Pointer::new_raw(
Some(lvgl_sys::ft5406ee8_read),
None,
&$disp
&$disp,
)
}
};
Expand All @@ -71,7 +71,11 @@ macro_rules! lv_drv_input_xpt2046 {
($disp:ident) => {
unsafe {
lvgl_sys::xpt2046_init();
$crate::input_device::pointer::Pointer::new_raw(Some(lvgl_sys::xpt2046_read), None, &$disp)
$crate::input_device::pointer::Pointer::new_raw(
Some(lvgl_sys::xpt2046_read),
None,
&$disp,
)
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions lvgl/src/drivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//!
//! The `sdl` example shows how to use both input and display drivers to port
//! the `button_click` example.
//!
//!
//! # Building
//! To compile in support for drivers, ensure the `drivers` feature is enabled
//! (this feature is enabled by default). Also ensure that the C configuration
//! for the drivers is located at the same path as the configuration for LVGL
//! itsel (i.e. the directory pointed to by `DEP_LV_CONFIG_PATH` contains both
//! `lv_conf.h` and `lv_drv_conf.h`).
//!
//!
//! Depending on desired drivers, certain environment variables need to be set.
//! `LVGL_INCLUDE` lists directories to be searched for headers during
//! compilation, and `LVGL_LINK` lists libraries that will be linked in. By
Expand All @@ -32,7 +32,7 @@
//! ```no_run
//! use lvgl::DrawBuffer;
//! use lvgl::lv_drv_disp_sdl;
//!
//!
//! fn main() {
//! const HOR_RES: u32 = 240;
//! const VER_RES: u32 = 240;
Expand Down
2 changes: 1 addition & 1 deletion lvgl/src/input_device/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait InputDriver<D> {
unsafe extern "C" fn(*mut lvgl_sys::_lv_indev_drv_t, *mut lvgl_sys::lv_indev_data_t),
>,
feedback_cb: Option<unsafe extern "C" fn(*mut lvgl_sys::_lv_indev_drv_t, u8)>,
display: &crate::Display
display: &crate::Display,
) -> LvResult<D>;

unsafe fn set_descriptor(&mut self, descriptor: *mut lvgl_sys::lv_indev_t) -> LvResult<()>;
Expand Down
6 changes: 3 additions & 3 deletions lvgl/src/input_device/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Input driver logic and handling
//!
//!
//! LVGL supports 4 types of input device. The current status as to support in
//! this library is:
//! - Pointer: Fully supported
//! - Keyboard: Unsupported
//! - Button: Unsupported
//! - Encoder: Unsupported
//!
//!
//! The general order of operations when creating an input device is
//! initializing an instance of the desired device, setting a callback function
//! (and any other parameters and functions, depending on type), and
Expand All @@ -16,7 +16,7 @@
//! use lvgl::input_device::InputDriver;
//! use lvgl::input_device::pointer::{Pointer, PointerInputData};
//! use embedded_graphics::prelude::*;
//!
//!
//! fn main() {
//! // IMPORTANT: Initialize a display driver first!
//! // ...
Expand Down
6 changes: 3 additions & 3 deletions lvgl/src/input_device/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl InputDriver<Pointer> for Pointer {

match crate::indev_drv_register(&mut dev) {
Ok(()) => Ok(dev),
Err(e) => Err(e)
Err(e) => Err(e),
}
}

Expand All @@ -63,7 +63,7 @@ impl InputDriver<Pointer> for Pointer {
unsafe extern "C" fn(*mut lvgl_sys::_lv_indev_drv_t, *mut lvgl_sys::lv_indev_data_t),
>,
feedback_cb: Option<unsafe extern "C" fn(*mut lvgl_sys::_lv_indev_drv_t, u8)>,
_: &crate::Display
_: &crate::Display,
) -> LvResult<Self> {
let driver = unsafe {
let mut indev_drv = MaybeUninit::uninit();
Expand All @@ -74,7 +74,7 @@ impl InputDriver<Pointer> for Pointer {
indev_drv.feedback_cb = feedback_cb;
indev_drv
};

let mut dev = Self {
driver,
descriptor: None,
Expand Down
6 changes: 3 additions & 3 deletions lvgl/src/lv_core/style.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Styling for LVGL objects and widgets
//!
//!
//! Objects in LVGL can have associated styling information. After a `Style` is
//! created and configured, it can be added to any object or widget:
//! ```
//! use lvgl::{Color, Widget};
//! use lvgl::style::Style;
//!
//!
//! fn main() {
//! let mut my_style = Style::default();
//! my_style.set_text_color(Color::from_rgb((0, 0, 0)));
//!
//!
//! //my_widget.add_style(Part::Main, &mut my_style).unwrap();
//! // ...
//! }
Expand Down
26 changes: 12 additions & 14 deletions lvgl/src/timer.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
//! Rust timer handling logic
//!
//!
//! LVGL allows for an external timer function to be used. This feature enables
//! a generic `LvClock` interface that can be used to build Rust-native timers.
//!
//!
//! # Building
//!
//! Set `LV_TICK_CUSTOM` to `1` and `LV_TICK_CUSTOM_INCLUDE` to `<rs_timer.h>`
//! in `lv_conf.h`, and enable the `rust_timer` feature on the `lvgl` crate to
//! enable this functionality.
//!
//!
//! # Usage
//!
//!
//! Implement the `lvgl::timer::LvClock` trait on a type and initialize it on
//! the first frame. The `since_init()` function should return a `Duration`
//! representing time elapsed since the beginning of the first frame of the
//! program.
//!
//!
//! ```no_run
//! use lvgl::timer::LvClock;
//!
//!
//! struct Clock {
//! start: Instant,
//! }
//!
//!
//! impl Default for Clock {
//! fn default() -> Self {
//! Self {
//! start: Instant::now(),
//! }
//! }
//! }
//!
//!
//! impl LvClock for Clock {
//! fn since_init(&self) -> Duration {
//! Instant::now().duration_since(self.start)
//! }
//! }
//!
//!
//! fn main() {
//! // Initialize displays, etc.
//! let clock = Clock::default();
Expand All @@ -46,13 +46,13 @@
//! }
//! }
//! ```
//!
//!
//! For a full example implementation similar to the above, see the
//! `rust_timer` example. When running, make sure to modify the config in
//! `examples/include/lv_conf.h` (or your own) as above first.
use core::time::Duration;
use core::num::TryFromIntError;
use core::time::Duration;

static mut RET_VAL: u32 = 0;

Expand All @@ -64,9 +64,7 @@ pub trait LvClock {

/// Synchronize the clock with LVGL. FIXME: When to call
pub fn update_clock(clock: &impl LvClock) -> Result<(), TryFromIntError> {
unsafe {
RET_VAL = clock.since_init().as_millis().try_into()?
}
unsafe { RET_VAL = clock.since_init().as_millis().try_into()? }
Ok(())
}

Expand Down

0 comments on commit 16e3421

Please sign in to comment.