Rust bindings API review #51

Open
rafaelcaricio wants to merge 19 commits from api-review into master
5 changed files with 55 additions and 51 deletions
Showing only changes of commit de568593ef - Show all commits

View file

@ -5,10 +5,9 @@ use embedded_graphics_simulator::{
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
}; };
use lvgl; use lvgl;
use lvgl::display::{DefaultDisplay, Display, DrawBuffer};
use lvgl::style::Style; use lvgl::style::Style;
use lvgl::widgets::{Label, LabelAlign}; use lvgl::widgets::{Label, LabelAlign};
use lvgl::{Align, Color, LvError, Part, State, Widget, UI}; use lvgl::{Align, Color, DefaultDisplay, Display, DrawBuffer, LvError, Part, State, Widget};
use lvgl_sys; use lvgl_sys;
use parking_lot::Mutex; use parking_lot::Mutex;
use std::sync::Arc as SyncArc; use std::sync::Arc as SyncArc;
@ -16,25 +15,32 @@ use std::thread;
use std::thread::sleep; use std::thread::sleep;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
static DRAW_BUFFER: DrawBuffer = DrawBuffer::new();
fn main() -> Result<(), LvError> { fn main() -> Result<(), LvError> {
lvgl::init();
let embedded_graphics_display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new( let embedded_graphics_display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
lvgl_sys::LV_HOR_RES_MAX, lvgl::DISP_HOR_RES as u32,
lvgl_sys::LV_VER_RES_MAX, lvgl::DISP_VER_RES as u32,
)); ));
let output_settings = OutputSettingsBuilder::new().scale(1).build(); let output_settings = OutputSettingsBuilder::new().scale(1).build();
let mut window = Window::new("PineTime", &output_settings); let mut window = Window::new("PineTime", &output_settings);
// Implement and register your display:
let shared_native_display = SyncArc::new(Mutex::new(embedded_graphics_display)); let shared_native_display = SyncArc::new(Mutex::new(embedded_graphics_display));
let _display = Display::register_shared(&DRAW_BUFFER, &shared_native_display)?;
// LVGL-rs usage starts here
lvgl::init();
// LVGL will render the graphics here first, and seed the rendered image to the
// display. The buffer size can be set freely but 1/10 screen size is a good starting point.
const REFRESH_BUFFER_SIZE: usize = lvgl::DISP_HOR_RES * lvgl::DISP_VER_RES / 10;
static DRAW_BUFFER: DrawBuffer<REFRESH_BUFFER_SIZE> = DrawBuffer::new();
// Register your native display with LVGL. We use the `Display::register_shared()` method here,
// but that's because the Simulator needs a mutable reference to the display so it can draw
// updates. On your embedded device code, you will use `Display::register()`.
let display = Display::register_shared(&DRAW_BUFFER, &shared_native_display)?;
// Create screen and widgets // Create screen and widgets
let mut screen = DefaultDisplay::get_scr_act()?; let mut screen = display.get_scr_act()?;
println!("Before all widgets: {:?}", mem_info()); println!("Before all widgets: {:?}", mem_info());

View file

@ -80,7 +80,7 @@ typedef int16_t lv_coord_t;
#define LV_MEM_CUSTOM 0 #define LV_MEM_CUSTOM 0
#if LV_MEM_CUSTOM == 0 #if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ /* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (1048576U) // 1Mb # define LV_MEM_SIZE (14U * 1024U)
/* Compiler prefix for a big array declaration */ /* Compiler prefix for a big array declaration */
# define LV_MEM_ATTR # define LV_MEM_ATTR

View file

@ -18,7 +18,6 @@ embedded-graphics = "0.6.2"
cstr_core = "0.2.3" cstr_core = "0.2.3"
bitflags = "1.2.1" bitflags = "1.2.1"
parking_lot = "0.11.1" parking_lot = "0.11.1"
lazy_static = "1.4.0"
heapless = "0.7.1" heapless = "0.7.1"
[features] [features]

View file

@ -1,12 +1,11 @@
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
use crate::functions::CoreError; use crate::functions::CoreError;
use crate::Box;
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
use crate::{disp_drv_register, disp_get_default, get_str_act}; use crate::{disp_drv_register, disp_get_default, get_str_act};
use crate::{Box, RunOnce};
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
use crate::{Color, Obj}; use crate::{Color, Obj};
use core::cell::{Cell, RefCell}; use core::cell::RefCell;
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
use core::marker::PhantomData; use core::marker::PhantomData;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use core::ptr::NonNull; use core::ptr::NonNull;
use core::sync::atomic::{AtomicBool, Ordering};
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
use core::{ptr, result}; use core::{ptr, result};
use embedded_graphics::drawable; use embedded_graphics::drawable;
use embedded_graphics::prelude::*; use embedded_graphics::prelude::*;
@ -16,10 +15,8 @@ use parking_lot::Mutex;
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::sync::Arc; use alloc::sync::Arc;
// TODO: Make this an external configuration pub const DISP_HOR_RES: usize = lvgl_sys::LV_HOR_RES_MAX as usize;
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
const REFRESH_BUFFER_LEN: usize = 2; pub const DISP_VER_RES: usize = lvgl_sys::LV_VER_RES_MAX as usize;
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
// Declare a buffer for the refresh rate
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
const BUF_SIZE: usize = lvgl_sys::LV_HOR_RES_MAX as usize * REFRESH_BUFFER_LEN;
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum DisplayError { pub enum DisplayError {
@ -42,7 +39,10 @@ impl Display {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
Self { disp } Self { disp }
} }
pub fn register<T, C>(draw_buffer: &'static DrawBuffer, native_display: T) -> Result<Self> pub fn register<T, C, const N: usize>(
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
draw_buffer: &'static DrawBuffer<N>,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
native_display: T,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
) -> Result<Self>
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
where where
T: DrawTarget<C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
@ -52,8 +52,8 @@ impl Display {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
} }
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub fn register_shared<T, C>( pub fn register_shared<T, C, const N: usize>(
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
draw_buffer: &'static DrawBuffer, draw_buffer: &'static DrawBuffer<N>,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
shared_native_display: &SharedNativeDisplay<T>, shared_native_display: &SharedNativeDisplay<T>,
) -> Result<Self> ) -> Result<Self>
where where
@ -65,7 +65,7 @@ impl Display {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
Ok(disp_drv_register(&mut display_diver)?) Ok(disp_drv_register(&mut display_diver)?)
} }
rafaelcaricio commented 2021-06-08 20:52:46 +00:00 (Migrated from github.com)
Review

I'm using a Mutex here just to make this Sync, not sure if there is a way to remove it but still keep the memory statically allocated.

I'm using a Mutex here just to make this `Sync`, not sure if there is a way to remove it but still keep the memory statically allocated.
pub fn get_str_act(&self) -> Result<Obj> { pub fn get_scr_act(&self) -> Result<Obj> {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
Ok(get_str_act(Some(&self))?) Ok(get_str_act(Some(&self))?)
} }
} }
@ -86,33 +86,29 @@ impl DefaultDisplay {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
} }
} }
pub struct DrawBuffer { pub struct DrawBuffer<const N: usize> {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
initialized: AtomicBool, initialized: RunOnce,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
refresh_buffer: Mutex<RefCell<heapless::Vec<lvgl_sys::lv_color_t, BUF_SIZE>>>, refresh_buffer: Mutex<RefCell<heapless::Vec<lvgl_sys::lv_color_t, N>>>,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
} }
impl DrawBuffer { impl<const N: usize> DrawBuffer<N> {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
initialized: AtomicBool::new(false), initialized: RunOnce::new(),
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
refresh_buffer: const_mutex(RefCell::new(heapless::Vec::new())), refresh_buffer: const_mutex(RefCell::new(heapless::Vec::new())),
} }
} }
fn get_ptr(&self) -> Option<Box<lvgl_sys::lv_disp_buf_t>> { fn get_ptr(&self) -> Option<Box<lvgl_sys::lv_disp_buf_t>> {
if self if self.initialized.swap_and_check() {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
.initialized
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
.is_ok()
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
{
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
let mut inner: MaybeUninit<lvgl_sys::lv_disp_buf_t> = MaybeUninit::uninit(); let mut inner: MaybeUninit<lvgl_sys::lv_disp_buf_t> = MaybeUninit::uninit();
let refresh_buffer_guard = self.refresh_buffer.lock(); let primary_buffer_guard = self.refresh_buffer.lock();
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
let draw_buf = unsafe { let draw_buf = unsafe {
lvgl_sys::lv_disp_buf_init( lvgl_sys::lv_disp_buf_init(
inner.as_mut_ptr(), inner.as_mut_ptr(),
refresh_buffer_guard.borrow_mut().as_mut_ptr() as *mut _ as *mut cty::c_void, primary_buffer_guard.borrow_mut().as_mut_ptr() as *mut _ as *mut cty::c_void,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
ptr::null_mut(), ptr::null_mut(),
lvgl_sys::LV_HOR_RES_MAX * REFRESH_BUFFER_LEN as u32, N as u32,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
); );
inner.assume_init() inner.assume_init()
}; };
@ -138,7 +134,10 @@ where
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
T: DrawTarget<C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
{ {
pub fn new(draw_buffer: &'static DrawBuffer, native_display: T) -> Result<Self> { pub fn new<const N: usize>(
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
draw_buffer: &'static DrawBuffer<N>,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
native_display: T,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
) -> Result<Self> {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
let mut disp_drv = unsafe { let mut disp_drv = unsafe {
let mut inner = MaybeUninit::uninit(); let mut inner = MaybeUninit::uninit();
lvgl_sys::lv_disp_drv_init(inner.as_mut_ptr()); lvgl_sys::lv_disp_drv_init(inner.as_mut_ptr());
@ -171,8 +170,8 @@ where
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
} }
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub fn new_shared( pub fn new_shared<const N: usize>(
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
draw_buffer: &'static DrawBuffer, draw_buffer: &'static DrawBuffer<N>,
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
shared_native_display: SharedNativeDisplay<T>, shared_native_display: SharedNativeDisplay<T>,
) -> Result<Self> { ) -> Result<Self> {
let mut disp_drv = unsafe { let mut disp_drv = unsafe {
@ -339,7 +338,7 @@ mod tests {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
let display = Display::default(); let display = Display::default();
let _screen_direct = display let _screen_direct = display
.get_str_act() .get_scr_act()
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
.expect("Return screen directly from the display instance"); .expect("Return screen directly from the display instance");
let _screen_default = let _screen_default =
@ -352,7 +351,7 @@ mod tests {
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
let display = Display::default(); let display = Display::default();
let _screen = display let _screen = display
.get_str_act() .get_scr_act()
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
.expect("Return screen directly from the display instance"); .expect("Return screen directly from the display instance");
Ok(()) Ok(())

rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.
rafaelcaricio commented 2021-06-04 20:41:26 +00:00 (Migrated from github.com)
Review

TODO: Remove this code duplication.

TODO: Remove this code duplication.
rafaelcaricio commented 2021-06-04 20:43:14 +00:00 (Migrated from github.com)
Review

I use a Mutex here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

I use a `Mutex` here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.

View file

@ -17,9 +17,6 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
#[macro_use]
extern crate lazy_static;
#[macro_use] #[macro_use]
mod lv_core; mod lv_core;
@ -47,7 +44,8 @@ pub(crate) mod mem;
#[cfg(not(feature = "lvgl_alloc"))] #[cfg(not(feature = "lvgl_alloc"))]
use crate::mem::Box; use crate::mem::Box;
pub mod display; mod display;
pub use display::*;
mod functions; mod functions;
mod support; mod support;
mod ui; mod ui;
@ -65,7 +63,7 @@ impl RunOnce {
Self(AtomicBool::new(false)) Self(AtomicBool::new(false))
} }
fn swap_and_get(&self) -> bool { fn swap_and_check(&self) -> bool {
self.0 self.0
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
.is_ok() .is_ok()
@ -75,7 +73,7 @@ impl RunOnce {
static LVGL_INITIALIZED: RunOnce = RunOnce::new(); static LVGL_INITIALIZED: RunOnce = RunOnce::new();
pub fn init() { pub fn init() {
if LVGL_INITIALIZED.swap_and_get() { if LVGL_INITIALIZED.swap_and_check() {
unsafe { unsafe {
lvgl_sys::lv_init(); lvgl_sys::lv_init();
} }
@ -92,11 +90,13 @@ pub(crate) mod tests {
pub(crate) fn initialize_test() { pub(crate) fn initialize_test() {
init(); init();
static DRAW_BUFFER: DrawBuffer = DrawBuffer::new(); let embedded_graphics_display: MockDisplay<Rgb565> = Default::default();
const REFRESH_BUFFER_SIZE: usize = 64 * 64 / 10;
static DRAW_BUFFER: DrawBuffer<REFRESH_BUFFER_SIZE> = DrawBuffer::new();
static ONCE_INIT: RunOnce = RunOnce::new(); static ONCE_INIT: RunOnce = RunOnce::new();
if ONCE_INIT.swap_and_get() { if ONCE_INIT.swap_and_check() {
let embedded_graphics_display: MockDisplay<Rgb565> = Default::default();
let _ = Display::register(&DRAW_BUFFER, embedded_graphics_display).unwrap(); let _ = Display::register(&DRAW_BUFFER, embedded_graphics_display).unwrap();
} }
} }