From c360bc2bddc6b153336fef0cef9e2fc82b9305cd Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Sun, 30 Jun 2024 22:57:03 -0400 Subject: [PATCH 1/6] Remove LVGL examples in Graphics --- Modules/Graphics/include/lv_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Graphics/include/lv_conf.h b/Modules/Graphics/include/lv_conf.h index 3bd6824..a5e8bbc 100644 --- a/Modules/Graphics/include/lv_conf.h +++ b/Modules/Graphics/include/lv_conf.h @@ -720,7 +720,7 @@ *==================*/ /*Enable the examples to be built with the library*/ -#define LV_BUILD_EXAMPLES 1 +#define LV_BUILD_EXAMPLES 0 /*=================== * DEMO USAGE From 0ab5fb2d41228f59bb421b0e96b00a3082473ba8 Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Sun, 30 Jun 2024 23:08:00 -0400 Subject: [PATCH 2/6] Add hooks setup script --- Setup_git_hooks.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Setup_git_hooks.sh diff --git a/Setup_git_hooks.sh b/Setup_git_hooks.sh new file mode 100644 index 0000000..cb9e012 --- /dev/null +++ b/Setup_git_hooks.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +Hooks_dir=".git/hooks" +Pre_commit_file=$Hooks_dir/pre-commit +Pre_commit_hook="\ +#!/bin/sh\n\ +cargo fmt -- --check\ +" + +if [ ! -d "$Hooks_dir" ]; then + echo "The \".git/hooks\" directory does not exist. Are you in the root of a git repository?" + exit 1 +fi + +rm -f $Pre_commit_file +echo $Pre_commit_hook > $Hooks_dir/pre-commit +chmod +x $Pre_commit_file + +echo "Git hooks setup successfully!" \ No newline at end of file From 159abeb2775cd664ea1e2a49532413fa119953a9 Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Sun, 30 Jun 2024 23:11:16 -0400 Subject: [PATCH 3/6] Update git hooks setup script --- Setup_git_hooks.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Setup_git_hooks.sh b/Setup_git_hooks.sh index cb9e012..dab78d3 100644 --- a/Setup_git_hooks.sh +++ b/Setup_git_hooks.sh @@ -4,11 +4,14 @@ Hooks_dir=".git/hooks" Pre_commit_file=$Hooks_dir/pre-commit Pre_commit_hook="\ #!/bin/sh\n\ -cargo fmt -- --check\ +if ! cargo fmt -- --check; then\n\ + echo \"Please run 'cargo fmt' to format your code before making a commit.\"\n\ + exit 1\n\ +fi\n\ " if [ ! -d "$Hooks_dir" ]; then - echo "The \".git/hooks\" directory does not exist. Are you in the root of a git repository?" + echo "The '.git/hooks' directory does not exist. Are you in the root of a git repository?" exit 1 fi From 974ba39c806b76e2f142e73b43dc9fa97078f926 Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Sun, 30 Jun 2024 23:13:54 -0400 Subject: [PATCH 4/6] Update hooks setup script --- Setup_git_hooks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup_git_hooks.sh b/Setup_git_hooks.sh index dab78d3..16d1f72 100644 --- a/Setup_git_hooks.sh +++ b/Setup_git_hooks.sh @@ -4,7 +4,7 @@ Hooks_dir=".git/hooks" Pre_commit_file=$Hooks_dir/pre-commit Pre_commit_hook="\ #!/bin/sh\n\ -if ! cargo fmt -- --check; then\n\ +if ! cargo fmt -- --check > /dev/null 2>&1; then\n\ echo \"Please run 'cargo fmt' to format your code before making a commit.\"\n\ exit 1\n\ fi\n\ From 1a16f590df8aef8c5f6a3489727619a18492ed41 Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Sun, 30 Jun 2024 23:29:17 -0400 Subject: [PATCH 5/6] Use Draw_buffer_type and fix some clippy warnings --- Modules/Graphics/src/Display.rs | 6 ++++-- Modules/Graphics/src/Input.rs | 8 +++----- Modules/Graphics/src/Window.rs | 9 +++------ Modules/Graphics/src/lib.rs | 18 +++++++++++++++--- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Modules/Graphics/src/Display.rs b/Modules/Graphics/src/Display.rs index c51fe2e..a41a686 100644 --- a/Modules/Graphics/src/Display.rs +++ b/Modules/Graphics/src/Display.rs @@ -1,11 +1,13 @@ use Screen::Prelude::{Area_type, Color_type, Point_type, Refresh_area_type, Screen_traits}; +use crate::Draw_buffer_type; + pub struct Display_type(lvgl::Display); impl Display_type { pub fn New, const Buffer_size: usize>( Screen: &mut Screen_type, - Draw_buffer: lvgl::DrawBuffer, + Draw_buffer: Draw_buffer_type, ) -> Result { let Resolution = match Screen.Get_resolution() { Ok(Resolution) => Resolution, @@ -41,7 +43,7 @@ impl Display_type { }; let LVGL_display = match lvgl::Display::register( - Draw_buffer, + Draw_buffer.into(), Resolution.X as u32, Resolution.Y as u32, Binding_function, diff --git a/Modules/Graphics/src/Input.rs b/Modules/Graphics/src/Input.rs index b97044e..6df0f80 100644 --- a/Modules/Graphics/src/Input.rs +++ b/Modules/Graphics/src/Input.rs @@ -20,11 +20,7 @@ impl Input_type { Touch_type::Released => Input_data.released(), }; - // if Changed { Input_data.once() - // } else { - // Input_data.and_continued() - // } }; match pointer::Pointer::register(Binding_function, Display.Get_lvgl_display()) { @@ -36,6 +32,8 @@ impl Input_type { #[cfg(test)] mod tests { + use crate::Draw_buffer_type; + use super::*; use lvgl::Widget; use std::{ @@ -58,7 +56,7 @@ mod tests { assert!(Touchscreen.is_ok()); let (mut Screen, mut Pointer) = Touchscreen.unwrap(); - let Buffer = lvgl::DrawBuffer::::default(); + let Buffer = Draw_buffer_type::::default(); let Display = Display_type::New(&mut Screen, Buffer); assert!(Display.is_ok()); diff --git a/Modules/Graphics/src/Window.rs b/Modules/Graphics/src/Window.rs index c7e6eb9..8e87295 100644 --- a/Modules/Graphics/src/Window.rs +++ b/Modules/Graphics/src/Window.rs @@ -2,9 +2,8 @@ use cstr_core::CString; use lvgl::{ style::{FlexFlow, Style}, widgets::Label, - LvError, NativeObject, Obj, Widget, + LvError, NativeObject, Obj, }; -use Task::Task_identifier_type; pub type Windows_indentifier_type = u16; @@ -13,11 +12,9 @@ struct Window_type<'a> { } impl<'a> Window_type<'a> { - pub fn New<'b>(Parent: &'a mut impl NativeObject, Title_string: &str) -> Result { + pub fn New(Parent: &'a mut impl NativeObject, Title_string: &str) -> Result { let mut Window = Obj::create(Parent)?; - let Style = Style::default().set_flex_flow(FlexFlow::COLUMN); - let mut Header = Obj::create(&mut Window)?; let mut Title = Label::create(&mut Header)?; @@ -28,7 +25,7 @@ impl<'a> Window_type<'a> { // TODO : Wait for lv_binding_rust to implement correct drop and lifetime management - let mut Window = Self { Window }; + let Window = Self { Window }; Ok(Window) } diff --git a/Modules/Graphics/src/lib.rs b/Modules/Graphics/src/lib.rs index 6da37be..e0d1c7c 100644 --- a/Modules/Graphics/src/lib.rs +++ b/Modules/Graphics/src/lib.rs @@ -4,12 +4,16 @@ mod Display; mod Input; -mod Window; +//mod Window; -pub use lvgl; +pub use Display::*; +pub use Input::*; +//pub use Window::*; -use Screen::Prelude::*; +pub use lvgl; +pub use lvgl::sys; +#[repr(transparent)] pub struct Draw_buffer_type(lvgl::DrawBuffer); impl Default for Draw_buffer_type { @@ -17,3 +21,11 @@ impl Default for Draw_buffer_type { Draw_buffer_type(lvgl::DrawBuffer::::default()) } } + +impl From> + for lvgl::DrawBuffer +{ + fn from(Draw_buffer: Draw_buffer_type) -> Self { + Draw_buffer.0 + } +} From ee395744006b9f0492cf11810d30933f8d0f6d16 Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Sun, 30 Jun 2024 23:31:21 -0400 Subject: [PATCH 6/6] Start to write Graphics bindings --- Modules/Bindings/Build.rs | 1 + Modules/Bindings/Cargo.toml | 9 ++- Modules/Bindings/Tests/Graphics.rs | 72 +++++++++++++++++++ Modules/Bindings/Tests/WASM_test/Cargo.toml | 2 +- .../Bindings/Tests/WASM_test/src/Graphics.rs | 31 ++++++++ Modules/Bindings/Tests/WASM_test/src/main.rs | 2 + Modules/Bindings/src/Graphics/Object.rs | 53 ++++++++++++++ Modules/Bindings/src/Graphics/mod.rs | 2 + Modules/Bindings/src/lib.rs | 3 + 9 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 Modules/Bindings/Tests/Graphics.rs create mode 100644 Modules/Bindings/Tests/WASM_test/src/Graphics.rs create mode 100644 Modules/Bindings/src/Graphics/Object.rs create mode 100644 Modules/Bindings/src/Graphics/mod.rs diff --git a/Modules/Bindings/Build.rs b/Modules/Bindings/Build.rs index 93a3cd5..f96a8c6 100644 --- a/Modules/Bindings/Build.rs +++ b/Modules/Bindings/Build.rs @@ -5,6 +5,7 @@ fn main() -> Result<(), ()> { println!("cargo:rerun-if-changed=Tests/WASM_test/src/main.rs"); println!("cargo:rerun-if-changed=Tests/WASM_test/src/File_system.rs"); println!("cargo:rerun-if-changed=Tests/WASM_test/src/Task.rs"); + println!("cargo:rerun-if-changed=Tests/WASM_test/src/Graphics.rs"); println!("cargo:rerun-if-changed=Tests/WASM_test/Cargo.toml"); // TODO : Add a check for test mode diff --git a/Modules/Bindings/Cargo.toml b/Modules/Bindings/Cargo.toml index d11357f..de07b61 100644 --- a/Modules/Bindings/Cargo.toml +++ b/Modules/Bindings/Cargo.toml @@ -11,11 +11,18 @@ Binding_tool = { path = "../../../Binding_tool", features = ["Native"] } Shared = { path = "../Shared" } Users = { path = "../Users" } Task = { path = "../Task" } +Graphics = { path = "../Graphics" } +Screen = { path = "../Screen" } [[test]] name = "File_system_bindings_tests" path = "Tests/File_system.rs" [[test]] -name = "Task_tests" +name = "Task_bindings_tests" path = "Tests/Task.rs" + +[[test]] +name = "Graphics_bindings_tests" +path = "Tests/Graphics.rs" + diff --git a/Modules/Bindings/Tests/Graphics.rs b/Modules/Bindings/Tests/Graphics.rs new file mode 100644 index 0000000..4e25e06 --- /dev/null +++ b/Modules/Bindings/Tests/Graphics.rs @@ -0,0 +1,72 @@ +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] + +use std::{ + thread::{self, sleep}, + time::{Duration, Instant}, +}; + +use Bindings::{File_system_bindings, Graphics_bindings, Task_bindings}; +use File_system::{ + Drivers::Native::File_system_type, + Prelude::{Path_type, Virtual_file_system_type}, +}; +use Graphics::{lvgl, Display_type, Draw_buffer_type, Input_type}; +use Screen::{Drivers::SDL2::New_touchscreen, Prelude::Point_type}; +use Virtual_machine::{Data_type, Instantiate_test_environment, WasmValue}; + +#[test] +fn Integration_test() { + let Binary_buffer = include_bytes!( + "../../../target/wasm32-unknown-unknown/release/File_system_bindings_WASM_test.wasm" + ); + + const Horizontal_resolution: u32 = 800; + const Vertical_resolution: u32 = 480; + const Buffer_size: usize = (Horizontal_resolution * Vertical_resolution / 2) as usize; + + let Touchscreen = New_touchscreen(Point_type::New( + Horizontal_resolution as i16, + Vertical_resolution as i16, + )); + assert!(Touchscreen.is_ok()); + let (mut Screen, mut Pointer) = Touchscreen.unwrap(); + + let Buffer = Draw_buffer_type::::default(); + + let Display = Display_type::New(&mut Screen, Buffer); + assert!(Display.is_ok()); + let Display = Display.unwrap(); + + let _Input = Input_type::New(&Pointer, &Display); + assert!(_Input.is_ok()); + let mut _Input = _Input.unwrap(); + + let Display_object = Display.Get_object(); + assert!(Display_object.is_ok()); + let mut Display_object = Display_object.unwrap(); + + thread::spawn(|| { + let (_Runtime, _Module, Instance) = Instantiate_test_environment( + Binary_buffer, + Graphics_bindings::New(), + &Data_type::New(), + ); + + assert_eq!( + Instance + .Call_export_function("Test_graphics", &vec![]) + .unwrap(), + WasmValue::I32(42) + ) + }); + + loop { + let Start = Instant::now(); + lvgl::task_handler(); + sleep(Duration::from_millis(5)); + lvgl::tick_inc(Instant::now().duration_since(Start)); + Pointer.Update(); + } +} diff --git a/Modules/Bindings/Tests/WASM_test/Cargo.toml b/Modules/Bindings/Tests/WASM_test/Cargo.toml index 8805a58..a2eb90d 100644 --- a/Modules/Bindings/Tests/WASM_test/Cargo.toml +++ b/Modules/Bindings/Tests/WASM_test/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -Binding_tool = { path = "../../../../../Binding_tool", features = ["WASM"] } \ No newline at end of file +Binding_tool = { path = "../../../../../Binding_tool", features = ["WASM"] } diff --git a/Modules/Bindings/Tests/WASM_test/src/Graphics.rs b/Modules/Bindings/Tests/WASM_test/src/Graphics.rs new file mode 100644 index 0000000..988ec93 --- /dev/null +++ b/Modules/Bindings/Tests/WASM_test/src/Graphics.rs @@ -0,0 +1,31 @@ +use std::thread::sleep; + +use Binding_tool::Bind_function_WASM; + +#[repr(transparent)] +pub struct Object_type([u8; 64]); + +impl Default for Object_type { + fn default() -> Self { + Self([0; 64]) + } +} + +#[Bind_function_WASM] +fn Create_calendar(Result: &mut Object_type) {} + +#[Bind_function_WASM] +fn Delete_object(Object: &mut Object_type) {} + +#[no_mangle] +fn Test_graphics() -> u32 { + let mut Object = Object_type::default(); + + Create_calendar(&mut Object); + + // sleep(std::time::Duration::from_secs(1)); + + // Delete_object(&mut Object); + + 42 +} diff --git a/Modules/Bindings/Tests/WASM_test/src/main.rs b/Modules/Bindings/Tests/WASM_test/src/main.rs index 8624252..36cdaa8 100644 --- a/Modules/Bindings/Tests/WASM_test/src/main.rs +++ b/Modules/Bindings/Tests/WASM_test/src/main.rs @@ -5,3 +5,5 @@ mod File_system; mod Task; + +mod Graphics; diff --git a/Modules/Bindings/src/Graphics/Object.rs b/Modules/Bindings/src/Graphics/Object.rs new file mode 100644 index 0000000..538a46c --- /dev/null +++ b/Modules/Bindings/src/Graphics/Object.rs @@ -0,0 +1,53 @@ +use std::{ + mem::size_of, + ptr::{copy_nonoverlapping, null_mut}, +}; + +use Binding_tool::Bind_function_native; +use Graphics::lvgl::sys::{ + lv_calendar_create, lv_disp_get_default, lv_disp_get_hor_res, lv_disp_get_scr_act, + lv_disp_get_ver_res, lv_mem_alloc, lv_mem_free, lv_mem_realloc, lv_memset_00, + lv_obj_allocate_spec_attr, lv_obj_class_t, lv_obj_create, lv_obj_del, + lv_obj_enable_style_refresh, lv_obj_get_index, lv_obj_mark_layout_as_dirty, lv_obj_set_parent, + lv_obj_t, +}; +use Virtual_machine::{Function_descriptor_type, Function_descriptors, Registrable_trait}; + +pub struct Graphics_bindings {} + +impl Registrable_trait for Graphics_bindings { + fn Get_functions(&self) -> &[Function_descriptor_type] { + &Graphics_bindings_functions + } +} + +impl Graphics_bindings { + pub fn New() -> Self { + println!("Size of lv_obj_t: {}", size_of::()); + Self {} + } +} + +const Graphics_bindings_functions: [Function_descriptor_type; 2] = + Function_descriptors!(Create_object_binding, Create_calendar_binding); + +#[Bind_function_native(Prefix = "Graphics")] +fn Create_object(Result: &mut lv_obj_t) { + unsafe { + let obj = lv_obj_create(null_mut()); + } +} + +#[Bind_function_native(Prefix = "Graphics")] +fn Create_calendar(Result: &mut lv_obj_t) { + unsafe { + let current_screen = lv_disp_get_scr_act(lv_disp_get_default()); + } +} + +#[Bind_function_native(Prefix = "Graphics")] +fn Delete_object(Object: &mut lv_obj_t) { + unsafe { + lv_obj_del(Object); + } +} diff --git a/Modules/Bindings/src/Graphics/mod.rs b/Modules/Bindings/src/Graphics/mod.rs new file mode 100644 index 0000000..d822cfd --- /dev/null +++ b/Modules/Bindings/src/Graphics/mod.rs @@ -0,0 +1,2 @@ +mod Object; +pub use Object::*; diff --git a/Modules/Bindings/src/lib.rs b/Modules/Bindings/src/lib.rs index 94bbb24..45f84f6 100644 --- a/Modules/Bindings/src/lib.rs +++ b/Modules/Bindings/src/lib.rs @@ -7,3 +7,6 @@ pub use File_system::*; mod Task; pub use Task::*; + +mod Graphics; +pub use Graphics::*;