-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust bindings API review #51
Conversation
// let mut parent = crate::display::DefaultDisplay::get_scr_act()?; | ||
// Ok(Self::create_at(&mut parent)?) | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used during development, to test the code generation options.
@@ -69,14 +69,33 @@ impl<T> AsMut<T> for Box<T> { | |||
} | |||
} | |||
|
|||
fn mem_info() -> lvgl_sys::lv_mem_monitor_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just need to make safe bindings for this simple function and add to the public API. It's useful for app debugging.
lvgl/src/widgets/label.rs
Outdated
#[cfg(feature = "alloc")] | ||
impl<S: AsRef<str>> From<S> for Label { | ||
fn from(text: S) -> Self { | ||
let text_cstr = CString::new(text.as_ref()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
use embedded_graphics::pixelcolor::Rgb565; | ||
|
||
pub(crate) fn initialize_test() { | ||
init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All tests run in the same LVGL "instance" so the tests might run out of memory at some point. :) Just to keep in mind.
lvgl/src/display.rs
Outdated
|
||
pub struct DrawBuffer<const N: usize> { | ||
initialized: RunOnce, | ||
refresh_buffer: Mutex<RefCell<heapless::Vec<lvgl_sys::lv_color_t, N>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extremely useful feature of bindgen
. 💅🏽
// 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 Sync and consequently cannot be in `static` variables. | ||
let mut inner: MaybeUninit<lvgl_sys::lv_disp_buf_t> = MaybeUninit::uninit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to find a way to make this memory statically allocated. This seems to be a requirement for LVGL v8.
lvgl/src/display.rs
Outdated
|
||
pub struct DrawBuffer<const N: usize> { | ||
initialized: RunOnce, | ||
refresh_buffer: Mutex<RefCell<[MaybeUninit<lvgl_sys::lv_color_t>; N]>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
examples/app.rs
Outdated
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this statically allocated will avoid dropping this memory address by mistake in an app code.
What's the status on this PR? I was considering attempting to upgrade LVGL to 8.x and it seems like this is necessary. I can rebase on current master and flesh out any missing features if that would be desirable. |
@nia-e As described in the README of this project. I've moved on from it, since I couldn't find anyone to help me with the development. That means this PR is in its "final" state, as I don't plan to work further on it. I'm pleased that you seem to have interest in this project, and if you think this can or should be merged, please go ahead! I think this PR has some things that need a second opinion. I've added some comments to things I wanted to highlight. The public API changes here, and we remove explicit dependency on There is a part of this PR that I stopped working on before making use of it, which is in the code generation crate. I think we could do much better there. Just keep in mind that I've started this project to help me "learn Rust", so take with a grain of salt the things this library does. If you see something that seems wrong to you, it is because it is probably wrong indeed. 👀 |
To my utter surprise, a rebase and minimal fixes later, this compiles. I'd rather test more things before I do anything but it seems like my job is easier than expected. Should I open a new PR or push to this branch? I squashed all commits. |
@nia-e Awesome, Rust is great. lol You can commit to this branch and continue this PR. |
fbfd868
to
14054a3
Compare
What were the plans for |
Also; further digging on the |
@nia-e The idea with the LVGL is not thread-safe itself, so making this crate non-thread-safe shouldn't be a bid deal? 👀 For us to make this crate "thread-safe" we would need to (have and) lock a global |
Perfect, okay. I'll drop the |
Revising the public API for better flexibility Use old approach, write directly to DrawTarget Simplified API for display initialization Possibility to register a shared native display Fix shared display Update demo app to use new api Use ref Add basic API functions Add required features Update examples Make disp buffer and driver statically allocated Allow to create statically allocated DrawBuffer Make DrawBuffer customizable using const generics Update default features to empty Allow users to define a display refresh callback closure Make use of embedded_graphics optional Update app example Remove dependency on heapless Wrap alloc extension in its own module
|
Okay, now it's ready. Give this a look when you have some time @rafaelcaricio. Also this hopefully beings to close #42 |
get rid of warnings
LGTM. I cannot approve as I originally opened the PR. Feel free to merge ;) |
This PR makes the Rust bindings usage more ergonomic and flexible.