Rust bindings API review #51
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: rafaelcaricio/lvgl-rs#51
Loading…
Reference in a new issue
No description provided.
Delete branch "api-review"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR makes the Rust bindings usage more ergonomic and flexible.
This is used during development, to test the code generation options.
@ -74,2 +91,4 @@
use super::*;
use crate::mem::mem_info;
use crate::*;
use std::vec::Vec;
Probably just need to make safe bindings for this simple function and add to the public API. It's useful for app debugging.
@ -10,6 +10,37 @@ impl Label {
}
}
This is a test of what is possible with
alloc
feature enabled. In reality, theFrom
trait implementation should use theTryFrom
trait implementation and just call.unwrap()
here. People will decide which guarantees they want to have.All tests run in the same LVGL "instance" so the tests might run out of memory at some point. :) Just to keep in mind.
TODO: Remove this code duplication.
I use a
Mutex
here, to satisfy the Rust guarantees. But maybe it is not necessary... some food for thought.@ -114,6 +114,7 @@ fn main() {
let bindings = bindgen::Builder::default()
.header(shims_dir.join("lvgl_sys.h").to_str().unwrap())
.generate_comments(false)
.derive_default(true)
Extremely useful feature of
bindgen
. 💅🏽@ -0,0 +80,4 @@
// TODO: needs to be 'static somehow
// Cannot be in the DrawBuffer struct because the type `lv_disp_buf_t` contains a raw
// pointer and raw pointers are not Send and consequently cannot be in `static` variables.
let mut inner: MaybeUninit<lvgl_sys::lv_disp_buf_t> = MaybeUninit::uninit();
I would like to find a way to make this memory statically allocated. This seems to be a requirement for LVGL v8.
@ -0,0 +64,4 @@
pub struct DrawBuffer<const N: usize> {
initialized: RunOnce,
refresh_buffer: Mutex<RefCell<[MaybeUninit<lvgl_sys::lv_color_t>; N]>>,
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.@ -0,0 +25,4 @@
lvgl::init();
const REFRESH_BUFFER_SIZE: usize = lvgl::DISP_HOR_RES * lvgl::DISP_VER_RES / 10;
static DRAW_BUFFER: DrawBuffer<REFRESH_BUFFER_SIZE> = DrawBuffer::new();
Making this statically allocated will avoid dropping this memory address by mistake in an app code.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.