Rust bindings API review #51

Open
rafaelcaricio wants to merge 19 commits from api-review into master
3 changed files with 75 additions and 38 deletions
Showing only changes of commit e6d231cafa - Show all commits

View file

@ -3,6 +3,10 @@ use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
use lvgl;
use lvgl::display::Display;
use lvgl::widgets::Label;
use parking_lot::Mutex;
use std::cell::RefCell;
use std::sync::Arc;
type ColorSpace = Rgb565;
@ -15,7 +19,15 @@ fn main() {
let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("App Example", &output_settings);
let mut shared_native_display = Arc::new(Mutex::new(embedded_graphics_display));
// LVGL usage
lvgl::init();
Display::register(embedded_graphics_display).unwrap();
let display = Display::register_shared(&shared_native_display).unwrap();
let label = Label::new().unwrap();
rafaelcaricio commented 2021-06-08 20:53:27 +00:00 (Migrated from github.com)
Review

Making this statically allocated will avoid dropping this memory address by mistake in an app code.

Making this statically allocated will avoid dropping this memory address by mistake in an app code.
{
let mut val = shared_native_display.lock();
val.draw_pixel(Pixel::default()).unwrap();
}
}

View file

@ -3,12 +3,17 @@ 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.
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::{Color, Obj};
use core::marker::PhantomData;
use core::mem::MaybeUninit;
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::NonNull;
use core::{ptr, result};
use embedded_graphics::drawable;
use embedded_graphics::prelude::*;
#[cfg(feature = "alloc")]
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 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")]
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 alloc::sync::Arc;
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.
// TODO: Make this an external configuration
const REFRESH_BUFFER_LEN: usize = 2;
// Declare a buffer for the refresh rate
@ -23,7 +28,9 @@ pub enum DisplayError {
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.
type Result<T> = result::Result<T, DisplayError>;
#[derive(Copy, Clone)]
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")]
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 type SharedNativeDisplay<T> = Arc<Mutex<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.
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 Display {
pub(crate) disp: NonNull<lvgl_sys::lv_disp_t>,
}
@ -33,11 +40,23 @@ 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 }
}
pub fn register<C>(embedded_graphics_display: impl DrawTarget<C>) -> 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.
// pub fn register<T, C>(native_display: T) -> 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
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>,
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.
// C: PixelColor + From<Color>,
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 display_diver = DisplayDriver::new(DisplayBuffer::new(), native_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.
// Ok(disp_drv_register(&mut display_diver)?)
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.
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")]
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 fn register_shared<T, C>(shared_native_display: &SharedNativeDisplay<T>) -> 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
T: DrawTarget<C>,
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.
C: PixelColor + From<Color>,
{
let mut display_diver = DisplayDriver::new(DisplayBuffer::new(), embedded_graphics_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.
let mut display_diver =
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.
DisplayDriver::new_shared(DisplayBuffer::new(), Arc::clone(shared_native_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.
Ok(disp_drv_register(&mut display_diver)?)
}
@ -62,37 +81,36 @@ 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.
}
}
rafaelcaricio commented 2021-06-08 20:51:59 +00:00 (Migrated from github.com)
Review

I would like to find a way to make this memory statically allocated. This seems to be a requirement for LVGL v8.

I would like to find a way to make this memory statically allocated. This seems to be [a requirement for LVGL v8](https://docs.lvgl.io/8.0/get-started/quick-overview.html#add-lvgl-into-your-project).
#[derive(Copy, Clone)]
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 DisplayBuffer {
disp_buf: lvgl_sys::lv_disp_buf_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.
disp_buf: Box<lvgl_sys::lv_disp_buf_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.
}
impl DisplayBuffer {
pub fn new() -> Self {
let disp_buf = unsafe {
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_buf = MaybeUninit::uninit();
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 disp_buf = {
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_buf = Box::new(lvgl_sys::lv_disp_buf_t::default());
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 refresh_buffer = Box::new([lvgl_sys::lv_color_t::default(); BUF_SIZE]);
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.
lvgl_sys::lv_disp_buf_init(
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.
disp_buf.as_mut_ptr(),
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.
Box::into_raw(refresh_buffer) 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.
ptr::null_mut(),
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.
lvgl_sys::LV_HOR_RES_MAX * REFRESH_BUFFER_LEN 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.
disp_buf.assume_init()
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.
unsafe {
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.
lvgl_sys::lv_disp_buf_init(
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.
disp_buf.as_mut() as *mut _,
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.
Box::into_raw(refresh_buffer) 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.
ptr::null_mut(),
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.
lvgl_sys::LV_HOR_RES_MAX * REFRESH_BUFFER_LEN 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.
}
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.
disp_buf
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_buf }
}
}
#[derive(Copy, Clone)]
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 DisplayDriver<T, C>
where
T: DrawTarget<C>,
C: PixelColor + From<Color>,
{
pub(crate) disp_drv: lvgl_sys::lv_disp_drv_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.
pub(crate) disp_drv: Box<lvgl_sys::lv_disp_drv_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.
phantom_display: PhantomData<T>,
phantom_color: PhantomData<C>,
}
@ -102,25 +120,29 @@ 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>,
C: PixelColor + From<Color>,
{
pub fn new(display_buffer: DisplayBuffer, native_display: T) -> 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 {
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 = MaybeUninit::uninit();
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.
lvgl_sys::lv_disp_drv_init(disp_drv.as_mut_ptr());
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.
disp_drv.assume_init()
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")]
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 fn new_shared(
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.
display_buffer: DisplayBuffer,
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>,
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 {
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 = Box::new(lvgl_sys::lv_disp_drv_t::default());
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.
unsafe {
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.
lvgl_sys::lv_disp_drv_init(disp_drv.as_mut() as *mut _);
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.
// We need to add to a `Box`, so it's copied to a memory location in the "heap" (LVGL statically allocated heap).
let disp_buf = Box::new(display_buffer.disp_buf);
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.
disp_drv.buffer = Box::into_raw(disp_buf) as *mut lvgl_sys::lv_disp_buf_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.
disp_drv.buffer = Box::into_raw(display_buffer.disp_buf) as *mut lvgl_sys::lv_disp_buf_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.
let native_display = Box::new(DisplayUserData {
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.
display: native_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.
let native_display = Box::new(SharedDisplayUserData {
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.
display: shared_native_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.
phantom: PhantomData,
});
disp_drv.user_data =
Box::into_raw(native_display) as *mut _ as lvgl_sys::lv_disp_drv_user_data_t;
disp_drv.flush_cb = Some(disp_flush_trampoline::<T, C>);
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.
// Sets trampoline pointer to the function implementation using the types (T, C) that
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.
// are used in this instance of `DisplayDriver`.
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.
disp_drv.flush_cb = Some(shared_disp_flush_trampoline::<T, C>);
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.
// We do not store any memory that can be accidentally deallocated by on the Rust side.
Self {
@ -131,16 +153,18 @@ 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.
}
}
pub(crate) struct DisplayUserData<T, C>
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")]
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(crate) struct SharedDisplayUserData<T, C>
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
T: DrawTarget<C>,
C: PixelColor + From<Color>,
{
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.
display: SharedNativeDisplay<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.
phantom: PhantomData<C>,
}
unsafe extern "C" fn disp_flush_trampoline<T, C>(
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")]
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.
unsafe extern "C" fn shared_disp_flush_trampoline<T, C>(
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.
disp_drv: *mut lvgl_sys::lv_disp_drv_t,
area: *const lvgl_sys::lv_area_t,
color_p: *mut lvgl_sys::lv_color_t,
@ -150,7 +174,7 @@ unsafe extern "C" fn disp_flush_trampoline<T, C>(
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_driver = *disp_drv;
if !display_driver.user_data.is_null() {
let user_data = &mut *(display_driver.user_data as *mut DisplayUserData<T, C>);
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 user_data = &mut *(display_driver.user_data as *mut SharedDisplayUserData<T, C>);
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 x1 = (*area).x1;
let x2 = (*area).x2;
let y1 = (*area).y1;
@ -174,7 +198,10 @@ unsafe extern "C" fn disp_flush_trampoline<T, C>(
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.
})
.flatten();
let _ = user_data.display.draw_iter(pixels);
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 _ = user_data
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.
.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.
.try_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.
.map(move |mut display| display.draw_iter(pixels));
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.
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

@ -16,9 +16,7 @@ type Result<T> = result::Result<T, CoreError>;
pub fn disp_drv_register<C: PixelColor + From<Color>, T: DrawTarget<C>>(
disp_drv: &mut DisplayDriver<T, C>,
) -> Result<Display> {
let disp_ptr = unsafe {
lvgl_sys::lv_disp_drv_register(&mut disp_drv.disp_drv as *mut lvgl_sys::lv_disp_drv_t)
};
let disp_ptr = unsafe { lvgl_sys::lv_disp_drv_register(disp_drv.disp_drv.as_mut() as *mut _) };
Ok(Display::from_raw(
NonNull::new(disp_ptr).ok_or(CoreError::OperationFailed)?,
))