From 16e34212b550818938d53644b84e586c92052705 Mon Sep 17 00:00:00 2001 From: Nia Espera Date: Thu, 30 Mar 2023 00:29:18 +0200 Subject: [PATCH] fmt, partially remedy #31 --- examples/rust_timer.rs | 4 +++- lvgl-sys/build.rs | 9 +++++++-- lvgl/Cargo.toml | 2 +- lvgl/src/drivers/lv_drv_input.rs | 16 ++++++++++------ lvgl/src/drivers/mod.rs | 6 +++--- lvgl/src/input_device/generic.rs | 2 +- lvgl/src/input_device/mod.rs | 6 +++--- lvgl/src/input_device/pointer.rs | 6 +++--- lvgl/src/lv_core/style.rs | 6 +++--- lvgl/src/timer.rs | 26 ++++++++++++-------------- 10 files changed, 46 insertions(+), 37 deletions(-) diff --git a/examples/rust_timer.rs b/examples/rust_timer.rs index 36847fe8..be8fc9f4 100644 --- a/examples/rust_timer.rs +++ b/examples/rust_timer.rs @@ -21,7 +21,9 @@ struct Clock { impl Default for Clock { fn default() -> Self { - Self { start: Instant::now() } + Self { + start: Instant::now(), + } } } diff --git a/lvgl-sys/build.rs b/lvgl-sys/build.rs index d8307b0b..561bbbbd 100644 --- a/lvgl-sys/build.rs +++ b/lvgl-sys/build.rs @@ -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()); @@ -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", @@ -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")] diff --git a/lvgl/Cargo.toml b/lvgl/Cargo.toml index 1306e32d..b09ac13e 100644 --- a/lvgl/Cargo.toml +++ b/lvgl/Cargo.toml @@ -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"] diff --git a/lvgl/src/drivers/lv_drv_input.rs b/lvgl/src/drivers/lv_drv_input.rs index 14325988..d162917b 100644 --- a/lvgl/src/drivers/lv_drv_input.rs +++ b/lvgl/src/drivers/lv_drv_input.rs @@ -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, ) } }; @@ -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, ) } }; @@ -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, ) } }; @@ -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, ) } }; @@ -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, ) } }; @@ -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, + ) } }; } diff --git a/lvgl/src/drivers/mod.rs b/lvgl/src/drivers/mod.rs index afededda..85d423fe 100644 --- a/lvgl/src/drivers/mod.rs +++ b/lvgl/src/drivers/mod.rs @@ -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 @@ -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; diff --git a/lvgl/src/input_device/generic.rs b/lvgl/src/input_device/generic.rs index 51d3f942..cb4f0ac1 100644 --- a/lvgl/src/input_device/generic.rs +++ b/lvgl/src/input_device/generic.rs @@ -46,7 +46,7 @@ pub trait InputDriver { unsafe extern "C" fn(*mut lvgl_sys::_lv_indev_drv_t, *mut lvgl_sys::lv_indev_data_t), >, feedback_cb: Option, - display: &crate::Display + display: &crate::Display, ) -> LvResult; unsafe fn set_descriptor(&mut self, descriptor: *mut lvgl_sys::lv_indev_t) -> LvResult<()>; diff --git a/lvgl/src/input_device/mod.rs b/lvgl/src/input_device/mod.rs index f37b8931..41813bf1 100644 --- a/lvgl/src/input_device/mod.rs +++ b/lvgl/src/input_device/mod.rs @@ -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 @@ -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! //! // ... diff --git a/lvgl/src/input_device/pointer.rs b/lvgl/src/input_device/pointer.rs index 50633c3a..d23cb452 100644 --- a/lvgl/src/input_device/pointer.rs +++ b/lvgl/src/input_device/pointer.rs @@ -50,7 +50,7 @@ impl InputDriver for Pointer { match crate::indev_drv_register(&mut dev) { Ok(()) => Ok(dev), - Err(e) => Err(e) + Err(e) => Err(e), } } @@ -63,7 +63,7 @@ impl InputDriver for Pointer { unsafe extern "C" fn(*mut lvgl_sys::_lv_indev_drv_t, *mut lvgl_sys::lv_indev_data_t), >, feedback_cb: Option, - _: &crate::Display + _: &crate::Display, ) -> LvResult { let driver = unsafe { let mut indev_drv = MaybeUninit::uninit(); @@ -74,7 +74,7 @@ impl InputDriver for Pointer { indev_drv.feedback_cb = feedback_cb; indev_drv }; - + let mut dev = Self { driver, descriptor: None, diff --git a/lvgl/src/lv_core/style.rs b/lvgl/src/lv_core/style.rs index 48b341c5..b19455e4 100644 --- a/lvgl/src/lv_core/style.rs +++ b/lvgl/src/lv_core/style.rs @@ -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(); //! // ... //! } diff --git a/lvgl/src/timer.rs b/lvgl/src/timer.rs index 7fed0e63..863216d2 100644 --- a/lvgl/src/timer.rs +++ b/lvgl/src/timer.rs @@ -1,28 +1,28 @@ //! 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 `` //! 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 { @@ -30,13 +30,13 @@ //! } //! } //! } -//! +//! //! impl LvClock for Clock { //! fn since_init(&self) -> Duration { //! Instant::now().duration_since(self.start) //! } //! } -//! +//! //! fn main() { //! // Initialize displays, etc. //! let clock = Clock::default(); @@ -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; @@ -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(()) }