Rust bindings API review #51

Open
rafaelcaricio wants to merge 19 commits from api-review into master
rafaelcaricio commented 2021-06-04 20:35:34 +00:00 (Migrated from github.com)

This PR makes the Rust bindings usage more ergonomic and flexible.

This PR makes the Rust bindings usage more ergonomic and flexible.
rafaelcaricio (Migrated from github.com) reviewed 2021-06-04 20:36:28 +00:00
rafaelcaricio (Migrated from github.com) commented 2021-06-04 20:36:28 +00:00

This is used during development, to test the code generation options.

This is used during development, to test the code generation options.
rafaelcaricio (Migrated from github.com) reviewed 2021-06-04 20:37:20 +00:00
@ -74,2 +91,4 @@
use super::*;
use crate::mem::mem_info;
use crate::*;
use std::vec::Vec;
rafaelcaricio (Migrated from github.com) commented 2021-06-04 20:37:20 +00:00

Probably just need to make safe bindings for this simple function and add to the public API. It's useful for app debugging.

Probably just need to make safe bindings for this simple function and add to the public API. It's useful for app debugging.
rafaelcaricio (Migrated from github.com) reviewed 2021-06-04 20:38:52 +00:00
@ -10,6 +10,37 @@ impl Label {
}
}
rafaelcaricio (Migrated from github.com) commented 2021-06-04 20:38:52 +00:00

This is a test of what is possible with alloc feature enabled. In reality, the From trait implementation should use the TryFrom trait implementation and just call .unwrap() here. People will decide which guarantees they want to have.

This is a test of what is possible with `alloc` feature enabled. In reality, the `From` trait implementation should use the `TryFrom` trait implementation and just call `.unwrap()` here. People will decide which guarantees they want to have.
rafaelcaricio (Migrated from github.com) reviewed 2021-06-04 20:40:47 +00:00
rafaelcaricio (Migrated from github.com) commented 2021-06-04 20:40:47 +00:00

All tests run in the same LVGL "instance" so the tests might run out of memory at some point. :) Just to keep in mind.

All tests run in the same LVGL "instance" so the tests might run out of memory at some point. :) Just to keep in mind.
rafaelcaricio (Migrated from github.com) reviewed 2021-06-04 20:41:26 +00:00
rafaelcaricio (Migrated from github.com) commented 2021-06-04 20:41:26 +00:00

TODO: Remove this code duplication.

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

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 (Migrated from github.com) reviewed 2021-06-04 20:44:13 +00:00
@ -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)
rafaelcaricio (Migrated from github.com) commented 2021-06-04 20:44:13 +00:00

Extremely useful feature of bindgen. 💅🏽

Extremely useful feature of `bindgen`. 💅🏽
rafaelcaricio (Migrated from github.com) reviewed 2021-06-08 20:51:59 +00:00
@ -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();
rafaelcaricio (Migrated from github.com) commented 2021-06-08 20:51:59 +00:00

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).
rafaelcaricio (Migrated from github.com) reviewed 2021-06-08 20:52:46 +00:00
@ -0,0 +64,4 @@
pub struct DrawBuffer<const N: usize> {
initialized: RunOnce,
refresh_buffer: Mutex<RefCell<[MaybeUninit<lvgl_sys::lv_color_t>; N]>>,
rafaelcaricio (Migrated from github.com) commented 2021-06-08 20:52:46 +00:00

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.
rafaelcaricio (Migrated from github.com) reviewed 2021-06-08 20:53:27 +00:00
@ -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();
rafaelcaricio (Migrated from github.com) commented 2021-06-08 20:53:27 +00:00

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.
This pull request has changes conflicting with the target branch.
  • lvgl/Cargo.toml
  • lvgl/src/mem.rs
  • lvgl/src/ui.rs

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin api-review:api-review
git checkout api-review

Merge

Merge the changes and update on Forgejo.
git checkout master
git merge --no-ff api-review
git checkout master
git merge --ff-only api-review
git checkout api-review
git rebase master
git checkout master
git merge --no-ff api-review
git checkout master
git merge --squash api-review
git checkout master
git merge --ff-only api-review
git checkout master
git merge api-review
git push origin master
Sign in to join this conversation.
No description provided.