Skip to content

Commit

Permalink
Move screen drivers into Drivers crate and refactor graphics and screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD committed Jul 12, 2024
1 parent 515d0c6 commit 3561eb2
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 208 deletions.
19 changes: 17 additions & 2 deletions Modules/Drivers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
File_system = { path = "../File_system" }
Screen = { version = "0.1.0", path = "../Screen" }
Task = { version = "0.1.0", path = "../Task" }
Users = { version = "0.1.0", path = "../Users" }
paste = "1.0.15"
Expand Down Expand Up @@ -44,6 +45,20 @@ mipidsi = "0.5.0"
display-interface-spi = "0.4.1"
embedded-graphics = "0.7.1"

[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))'.dev-dependencies]
Graphics = { path = "../Graphics", features = ["RGB565"] }

[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))'.dependencies]
sdl2 = "0.37.0"

[[test]]
name = "Native_file_system"
path = "Tests/Native/File_system.rs"

[[test]]
name = "Native_touch_screen"
path = "Tests/Native/Touch_screen.rs"

[[test]]
name = "Native"
path = "Tests/Native/Main.rs"
name = "Native_graphics"
path = "Tests/Native/Graphics.rs"
82 changes: 82 additions & 0 deletions Modules/Drivers/Tests/Native/Graphics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

use std::{
thread::sleep,
time::{Duration, Instant},
};
use File_system::{File_type, Mode_type, Path_type};

const Pointer_device_path: &Path_type =
unsafe { Path_type::New_unchecked_constant("/Device/Pointer") };

#[cfg(target_os = "linux")]
#[test]
#[ignore]
fn main() {
use Drivers::Native::New_touchscreen;
use Screen::Point_type;

use Graphics::lvgl::{self, Widget};

const Horizontal_resolution: u32 = 800;
const Vertical_resolution: u32 = 480;
const Buffer_size: usize = (Horizontal_resolution * Vertical_resolution / 2) as usize;

let (S, Pointer) = New_touchscreen(Point_type::New(
Horizontal_resolution as i16,
Vertical_resolution as i16,
))
.expect("Error creating touchscreen");

let S = Box::new(S);

Users::Initialize().expect("Error initializing users manager");

Task::Initialize().expect("Error initializing task manager");

let Virtual_file_system = File_system::Initialize().expect("Error initializing file system");

Virtual_file_system
.Add_device(&Pointer_device_path, Box::new(Pointer))
.expect("Error adding pointer device");

let Pointer_file = File_type::Open(
Virtual_file_system,
Pointer_device_path,
Mode_type::Read_only().into(),
)
.expect("Error opening pointer file");

Graphics::Initialize().expect("Error initializing manager");

let Graphics_manager = Graphics::Get_instance().expect("Error getting manager");

let Resolution = S.Get_resolution().expect("Error getting resolution");

let Display = Graphics_manager
.Create_display::<Buffer_size>(S, Resolution, Pointer_file)
.expect("Error adding screen");

let mut S = Display.Get_object().expect("Error getting screen");

let _ = lvgl::widgets::Slider::create(&mut S);

let Calendar = lvgl::widgets::Calendar::create(&mut S);
assert!(Calendar.is_ok());
let mut Calendar = Calendar.unwrap();

let mut Style = lvgl::style::Style::default();
Style.set_bg_color(lvgl::Color::from_rgb((255, 0, 0)));

Calendar.add_style(lvgl::obj::Part::Any, &mut Style);
Calendar.set_align(lvgl::Align::Center, 0, 0);

loop {
let Start = Instant::now();
lvgl::task_handler();
sleep(Duration::from_millis(5));
lvgl::tick_inc(Instant::now().duration_since(Start));
}
}
1 change: 0 additions & 1 deletion Modules/Drivers/Tests/Native/Main.rs

This file was deleted.

49 changes: 49 additions & 0 deletions Modules/Drivers/Tests/Native/Touch_screen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

use Drivers::Native::New_touchscreen;
use File_system::Device_trait;
use Screen::{Area_type, Color_ARGB8888_type, Error_type, Point_type, Screen_traits};

#[test]
#[cfg(target_os = "linux")]
fn Test_touchscreen() {
const Horizontal_resolution: u32 = 800;
const Vertical_resolution: u32 = 480;

let Touchscreen = New_touchscreen(Point_type::New(
Horizontal_resolution as i16,
Vertical_resolution as i16,
));

assert!(Touchscreen.is_ok());

let (mut Screen, Pointer_device_type) =
Touchscreen.expect("Touchscreen initialization failed.");

let mut Buffer = [0; 5];

assert_eq!(Pointer_device_type.Read(&mut Buffer), Ok(5));

Screen
.Update(
Area_type::New(Point_type::New(0, 0), Point_type::New(9, 9)),
&[Color_ARGB8888_type::New(255, 255, 255, 255); 100],
)
.expect("Screen update failed.");

assert_eq!(
Screen.Update(
Area_type::New(Point_type::New(0, 0), Point_type::New(10, 9),),
&[Color_ARGB8888_type::New(255, 255, 255, 255); 100],
),
Err(Error_type::Invalid_dimension)
);

assert_eq!(Screen.Get_resolution().unwrap(), Point_type::New(800, 480));

unsafe {
sdl2::sys::SDL_Quit(); // Force SDL2 to quit to avoid conflicts with other tests.
}
}
Loading

0 comments on commit 3561eb2

Please sign in to comment.