From 3561eb21b1617fc554014fa3dbeaa988c17aed34 Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Fri, 12 Jul 2024 16:51:22 -0400 Subject: [PATCH] Move screen drivers into Drivers crate and refactor graphics and screen --- Modules/Drivers/Cargo.toml | 19 ++- Modules/Drivers/Tests/Native/Graphics.rs | 82 +++++++++ Modules/Drivers/Tests/Native/Main.rs | 1 - Modules/Drivers/Tests/Native/Touch_screen.rs | 49 ++++++ .../mod.rs => Drivers/src/Native/SDL2.rs} | 159 +++++++----------- Modules/Drivers/src/Native/mod.rs | 2 + Modules/Graphics/Cargo.toml | 4 +- Modules/Graphics/Tests/Graphics.rs | 80 --------- Modules/Graphics/src/Display.rs | 8 +- Modules/Graphics/src/Input.rs | 2 +- Modules/Graphics/src/Manager.rs | 8 +- Modules/Graphics/src/lib.rs | 6 + Modules/Screen/Cargo.toml | 6 - Modules/Screen/src/{Generics => }/Area.rs | 0 Modules/Screen/src/{Generics => }/Color.rs | 5 - Modules/Screen/src/Drivers/mod.rs | 2 - Modules/Screen/src/{Generics => }/Error.rs | 0 Modules/Screen/src/{Generics => }/Point.rs | 0 Modules/Screen/src/lib.rs | 41 ++++- Modules/Screen/src/{Generics => }/mod.rs | 0 20 files changed, 266 insertions(+), 208 deletions(-) create mode 100644 Modules/Drivers/Tests/Native/Graphics.rs delete mode 100644 Modules/Drivers/Tests/Native/Main.rs create mode 100644 Modules/Drivers/Tests/Native/Touch_screen.rs rename Modules/{Screen/src/Drivers/SDL2/mod.rs => Drivers/src/Native/SDL2.rs} (58%) rename Modules/Screen/src/{Generics => }/Area.rs (100%) rename Modules/Screen/src/{Generics => }/Color.rs (97%) delete mode 100644 Modules/Screen/src/Drivers/mod.rs rename Modules/Screen/src/{Generics => }/Error.rs (100%) rename Modules/Screen/src/{Generics => }/Point.rs (100%) rename Modules/Screen/src/{Generics => }/mod.rs (100%) diff --git a/Modules/Drivers/Cargo.toml b/Modules/Drivers/Cargo.toml index 8fb076e..095306c 100644 --- a/Modules/Drivers/Cargo.toml +++ b/Modules/Drivers/Cargo.toml @@ -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" @@ -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" diff --git a/Modules/Drivers/Tests/Native/Graphics.rs b/Modules/Drivers/Tests/Native/Graphics.rs new file mode 100644 index 0000000..2b4b0f8 --- /dev/null +++ b/Modules/Drivers/Tests/Native/Graphics.rs @@ -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::(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)); + } +} diff --git a/Modules/Drivers/Tests/Native/Main.rs b/Modules/Drivers/Tests/Native/Main.rs deleted file mode 100644 index 43eb009..0000000 --- a/Modules/Drivers/Tests/Native/Main.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod File_system; diff --git a/Modules/Drivers/Tests/Native/Touch_screen.rs b/Modules/Drivers/Tests/Native/Touch_screen.rs new file mode 100644 index 0000000..1d14a5b --- /dev/null +++ b/Modules/Drivers/Tests/Native/Touch_screen.rs @@ -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. + } +} diff --git a/Modules/Screen/src/Drivers/SDL2/mod.rs b/Modules/Drivers/src/Native/SDL2.rs similarity index 58% rename from Modules/Screen/src/Drivers/SDL2/mod.rs rename to Modules/Drivers/src/Native/SDL2.rs index c339acf..e0563e7 100644 --- a/Modules/Screen/src/Drivers/SDL2/mod.rs +++ b/Modules/Drivers/src/Native/SDL2.rs @@ -1,6 +1,6 @@ -use crate::{ - Generics, - Prelude::{Area_type, Color_ARGB8888_type, Error_type, Result_type}, +use Screen::{ + Area_type, Color_ARGB8888_type, Color_RGB565_type, Error_type, Point_type, Result_type, + Screen_traits, Touch_type, }; use sdl2::{ @@ -13,35 +13,32 @@ use File_system::Device_trait; use std::{mem::size_of, process::exit, sync::RwLock}; -impl From for Error_type { - fn from(Value: String) -> Self { - Self::Unknown(Value) - } +fn From_string_error(Value: String) -> Error_type { + Error_type::Unknown(Value) } -impl From for Error_type { - fn from(Error: WindowBuildError) -> Self { - match Error { - WindowBuildError::SdlError(Error) => Error.into(), - WindowBuildError::HeightOverflows(_) | WindowBuildError::WidthOverflows(_) => { - Error_type::Invalid_dimension - } - WindowBuildError::InvalidTitle(_) => Error_type::Unknown("Invalid title.".to_string()), +fn From_window_build_error(Error: WindowBuildError) -> Error_type { + match Error { + WindowBuildError::SdlError(Error) => From_string_error(Error), + WindowBuildError::HeightOverflows(_) | WindowBuildError::WidthOverflows(_) => { + Error_type::Invalid_dimension } + WindowBuildError::InvalidTitle(_) => Error_type::Unknown("Invalid title.".to_string()), } } -impl From for Error_type { - fn from(Error: IntegerOrSdlError) -> Self { - Error_type::Unknown(Error.to_string()) - } +fn From_integer_or_sdl_error(Error: IntegerOrSdlError) -> Error_type { + Error_type::Unknown(Error.to_string()) } pub struct Screen_type(Canvas); impl Screen_type { pub fn New(Window: video::Window) -> Result_type { - let mut Canvas = Window.into_canvas().build()?; + let mut Canvas = Window + .into_canvas() + .build() + .map_err(From_integer_or_sdl_error)?; Canvas.clear(); Canvas.present(); @@ -49,16 +46,16 @@ impl Screen_type { Ok(Self(Canvas)) } - pub fn Get_resolution(&self) -> Result_type { - Ok(self - .0 + pub fn Get_resolution(&self) -> Result_type { + self.0 .output_size() - .map(|(Width, Height)| Generics::Point_type::New(Width as i16, Height as i16))?) + .map(|(Width, Height)| Point_type::New(Width as i16, Height as i16)) + .map_err(From_string_error) } } -impl Generics::Screen_traits for Screen_type { - fn Update(&mut self, Area: Area_type, Buffer: &[Generics::Color_type]) -> Result_type<()> { +impl Screen_traits for Screen_type { + fn Update(&mut self, Area: Area_type, Buffer: &[Color_RGB565_type]) -> Result_type<()> { let mut Buffer_iterator = Buffer.iter(); let Point_1 = Area.Get_point_1(); @@ -70,7 +67,6 @@ impl Generics::Screen_traits for Screen_type { .next() .ok_or(Error_type::Invalid_dimension)?; - #[cfg(not(feature = "ARGB8888"))] let Color: Color_ARGB8888_type = (*Color).into(); self.0.set_draw_color(pixels::Color::RGB( @@ -88,10 +84,38 @@ impl Generics::Screen_traits for Screen_type { } } +impl Screen_traits for Screen_type { + fn Update(&mut self, Area: Area_type, Buffer: &[Color_ARGB8888_type]) -> Result_type<()> { + let mut Buffer_iterator = Buffer.iter(); + + let Point_1 = Area.Get_point_1(); + let Point_2 = Area.Get_point_2(); + + for Y in Point_1.Get_y() as i32..=Point_2.Get_y() as i32 { + for X in Point_1.Get_x() as i32..=Point_2.Get_x() as i32 { + let Color = Buffer_iterator + .next() + .ok_or(Error_type::Invalid_dimension)?; + + self.0.set_draw_color(pixels::Color::RGB( + Color.Get_red(), + Color.Get_green(), + Color.Get_blue(), + )); + + let _ = self.0.draw_point(sdl2::rect::Point::new(X, Y)); + } + } + self.0.present(); + + Ok(()) + } +} + pub struct Pointer_device_type { Window_identifier: u32, Event_pump: RwLock, - Last_input: RwLock<(Generics::Point_type, Generics::Touch_type)>, + Last_input: RwLock<(Point_type, Touch_type)>, } unsafe impl Send for Pointer_device_type {} @@ -103,10 +127,7 @@ impl Pointer_device_type { Self { Window_identifier, Event_pump: RwLock::new(Event_pump), - Last_input: RwLock::new(( - Generics::Point_type::New(0, 0), - Generics::Touch_type::Released, - )), + Last_input: RwLock::new((Point_type::New(0, 0), Touch_type::Released)), } } @@ -131,7 +152,7 @@ impl Pointer_device_type { Last_input.0 = Last_input.0.Set(x as i16, y as i16); Last_input.0 = Last_input.0.Set(x as i16, y as i16); - Last_input.1 = Generics::Touch_type::Pressed; + Last_input.1 = Touch_type::Pressed; } } event::Event::MouseButtonUp { @@ -145,7 +166,7 @@ impl Pointer_device_type { if (window_id == self.Window_identifier) && (mouse_btn == mouse::MouseButton::Left) { - Last_input.1 = Generics::Touch_type::Released; + Last_input.1 = Touch_type::Released; } } event::Event::MouseMotion { @@ -201,19 +222,18 @@ impl Device_trait for Pointer_device_type { } } -pub fn New_touchscreen( - Size: Generics::Point_type, -) -> Result_type<(Screen_type, Pointer_device_type)> { - let Context = sdl2::init()?; +pub fn New_touchscreen(Size: Point_type) -> Result_type<(Screen_type, Pointer_device_type)> { + let Context = sdl2::init().map_err(From_string_error)?; - let Video_subsystem = Context.video()?; + let Video_subsystem = Context.video().map_err(From_string_error)?; let Window = Video_subsystem .window("Xila", Size.Get_x() as u32, Size.Get_y() as u32) .position_centered() - .build()?; + .build() + .map_err(From_window_build_error)?; - let Event_pump = Context.event_pump()?; + let Event_pump = Context.event_pump().map_err(From_string_error)?; let Pointer = Pointer_device_type::New(Window.id(), Event_pump); @@ -221,60 +241,3 @@ pub fn New_touchscreen( Ok((Screen, Pointer)) } - -#[cfg(test)] -mod tests { - use Generics::Screen_traits; - - use super::*; - - #[test] - fn Test_touchscreen() { - const Horizontal_resolution: u32 = 800; - const Vertical_resolution: u32 = 480; - - let Touchscreen = New_touchscreen(Generics::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( - Generics::Point_type::New(0, 0), - Generics::Point_type::New(9, 9), - ), - &[Generics::Color_type::New(255, 255, 255); 100], - ) - .expect("Screen update failed."); - - assert_eq!( - Screen.Update( - Area_type::New( - Generics::Point_type::New(0, 0), - Generics::Point_type::New(10, 9), - ), - &[Generics::Color_type::New(255, 255, 255); 100], - ), - Err(Error_type::Invalid_dimension) - ); - - assert_eq!( - Screen.Get_resolution().unwrap(), - Generics::Point_type::New(800, 480) - ); - - unsafe { - sdl2::sys::SDL_Quit(); // Force SDL2 to quit to avoid conflicts with other tests. - } - } -} diff --git a/Modules/Drivers/src/Native/mod.rs b/Modules/Drivers/src/Native/mod.rs index 0050722..8bb008e 100644 --- a/Modules/Drivers/src/Native/mod.rs +++ b/Modules/Drivers/src/Native/mod.rs @@ -1,3 +1,5 @@ mod File_system; +mod SDL2; pub use File_system::*; +pub use SDL2::*; diff --git a/Modules/Graphics/Cargo.toml b/Modules/Graphics/Cargo.toml index 6134bd2..60ab6a4 100644 --- a/Modules/Graphics/Cargo.toml +++ b/Modules/Graphics/Cargo.toml @@ -31,8 +31,8 @@ Task = { path = "../Task" } [features] default = ["RGB565"] -RGB565 = ["Screen/RGB565"] -ARGB8888 = ["Screen/ARGB8888"] +RGB565 = [] +ARGB8888 = [] [[test]] name = "Graphics" diff --git a/Modules/Graphics/Tests/Graphics.rs b/Modules/Graphics/Tests/Graphics.rs index a888cf9..8b13789 100644 --- a/Modules/Graphics/Tests/Graphics.rs +++ b/Modules/Graphics/Tests/Graphics.rs @@ -1,81 +1 @@ -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] -#![allow(non_upper_case_globals)] -use lvgl::Widget; -use std::{ - thread::sleep, - time::{Duration, Instant}, -}; -use File_system::{File_type, Mode_type, Path_type}; -use Screen::{Drivers::SDL2::New_touchscreen, Prelude::Point_type}; - -const Pointer_device_path: &Path_type = - unsafe { Path_type::New_unchecked_constant("/Device/Pointer") }; - -#[cfg(target_os = "linux")] -#[test] -#[ignore] -fn main() { - lvgl::init(); - - 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::(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)); - } -} diff --git a/Modules/Graphics/src/Display.rs b/Modules/Graphics/src/Display.rs index f2ab7d5..8c47630 100644 --- a/Modules/Graphics/src/Display.rs +++ b/Modules/Graphics/src/Display.rs @@ -1,13 +1,13 @@ use std::mem::transmute; -use Screen::Prelude::{Area_type, Color_type, Point_type, Screen_traits}; +use Screen::{Area_type, Point_type, Screen_traits}; -use crate::{Draw_buffer::Draw_buffer_type, Result_type}; +use crate::{Color_type, Draw_buffer::Draw_buffer_type, Result_type}; pub struct Display_type { Display: lvgl::Display, #[allow(dead_code)] - Screen: Box, + Screen: Box>, } unsafe impl Send for Display_type {} @@ -16,7 +16,7 @@ unsafe impl Sync for Display_type {} impl Display_type { pub fn New( - mut Screen: Box, + mut Screen: Box>, Resolution: Point_type, ) -> Result_type { let Binding_function = |Refresh: &lvgl::DisplayRefresh| { diff --git a/Modules/Graphics/src/Input.rs b/Modules/Graphics/src/Input.rs index 03f068e..b9e942e 100644 --- a/Modules/Graphics/src/Input.rs +++ b/Modules/Graphics/src/Input.rs @@ -1,6 +1,6 @@ use lvgl::input_device::{pointer, InputDriver}; use File_system::File_type; -use Screen::Prelude::Touch_type; +use Screen::Touch_type; use crate::{Display::Display_type, Result_type}; diff --git a/Modules/Graphics/src/Manager.rs b/Modules/Graphics/src/Manager.rs index d73f9e5..5334464 100644 --- a/Modules/Graphics/src/Manager.rs +++ b/Modules/Graphics/src/Manager.rs @@ -1,9 +1,9 @@ use std::sync::Mutex; use File_system::File_type; -use Screen::Prelude::{Point_type, Screen_traits}; +use Screen::{Point_type, Screen_traits}; -use crate::{Display_type, Error_type, Input_type, Result_type}; +use crate::{Color_type, Display_type, Error_type, Input_type, Result_type}; /// Avoid using Arc, because the manager is a singleton. static mut Manager_instance: Option = None; @@ -14,6 +14,8 @@ pub fn Initialize() -> Result_type<&'static Manager_type> { return Err(Error_type::Already_initialized); } + lvgl::init(); + Manager_instance.replace(Manager_type::New()); } Get_instance() @@ -38,7 +40,7 @@ impl Manager_type { pub fn Create_display( &self, - Screen: Box, + Screen: Box>, Resolution: Point_type, Input_path: File_type, ) -> Result_type { diff --git a/Modules/Graphics/src/lib.rs b/Modules/Graphics/src/lib.rs index 04c5114..2a45159 100644 --- a/Modules/Graphics/src/lib.rs +++ b/Modules/Graphics/src/lib.rs @@ -18,3 +18,9 @@ pub use Manager::*; pub use lvgl; pub use lvgl::sys; + +#[cfg(feature = "ARGB8888")] +type Color_type = Screen::Color_ARGB8888_type; + +#[cfg(feature = "RGB565")] +type Color_type = Screen::Color_RGB565_type; diff --git a/Modules/Screen/Cargo.toml b/Modules/Screen/Cargo.toml index 9d40d3d..208abba 100644 --- a/Modules/Screen/Cargo.toml +++ b/Modules/Screen/Cargo.toml @@ -10,10 +10,4 @@ File_system = { path = "../File_system" } embedded-graphics = "0.8" [target.'cfg( target_arch = "x86_64" )'.dependencies] -sdl2 = { version = "0.37.0", features = [] } embedded-graphics = "0.8" - -[features] -default = ["RGB565"] -RGB565 = [] -ARGB8888 = [] diff --git a/Modules/Screen/src/Generics/Area.rs b/Modules/Screen/src/Area.rs similarity index 100% rename from Modules/Screen/src/Generics/Area.rs rename to Modules/Screen/src/Area.rs diff --git a/Modules/Screen/src/Generics/Color.rs b/Modules/Screen/src/Color.rs similarity index 97% rename from Modules/Screen/src/Generics/Color.rs rename to Modules/Screen/src/Color.rs index 51f68fa..0a6c383 100644 --- a/Modules/Screen/src/Generics/Color.rs +++ b/Modules/Screen/src/Color.rs @@ -1,8 +1,3 @@ -#[cfg(feature = "RGB565")] -pub type Color_type = Color_RGB565_type; -#[cfg(feature = "ARGB8888")] -pub type Color_type = Color_ARGB8888_type; - #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[repr(transparent)] pub struct Color_RGB565_type(u16); diff --git a/Modules/Screen/src/Drivers/mod.rs b/Modules/Screen/src/Drivers/mod.rs deleted file mode 100644 index f5a830d..0000000 --- a/Modules/Screen/src/Drivers/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[cfg(target_os = "linux")] -pub mod SDL2; diff --git a/Modules/Screen/src/Generics/Error.rs b/Modules/Screen/src/Error.rs similarity index 100% rename from Modules/Screen/src/Generics/Error.rs rename to Modules/Screen/src/Error.rs diff --git a/Modules/Screen/src/Generics/Point.rs b/Modules/Screen/src/Point.rs similarity index 100% rename from Modules/Screen/src/Generics/Point.rs rename to Modules/Screen/src/Point.rs diff --git a/Modules/Screen/src/lib.rs b/Modules/Screen/src/lib.rs index 85bb26d..4e66242 100644 --- a/Modules/Screen/src/lib.rs +++ b/Modules/Screen/src/lib.rs @@ -1,9 +1,42 @@ -#![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] + +mod Area; +mod Color; +mod Error; +mod Point; + +pub use Area::*; +pub use Color::*; +pub use Error::*; +pub use Point::*; + +pub trait Screen_traits { + fn Update(&mut self, Area: Area_type, Buffer: &[T]) -> Result_type<()>; +} + +#[derive(Clone, Copy)] +#[repr(C)] +pub enum Touch_type { + Pressed, + Released, +} -pub mod Generics; +impl From for u8 { + fn from(Value: Touch_type) -> u8 { + Value as u8 + } +} -pub mod Drivers; +impl TryFrom for Touch_type { + type Error = (); -pub mod Prelude; + fn try_from(Value: u8) -> Result { + match Value { + 0 => Ok(Self::Pressed), + 1 => Ok(Self::Released), + _ => Err(()), + } + } +} diff --git a/Modules/Screen/src/Generics/mod.rs b/Modules/Screen/src/mod.rs similarity index 100% rename from Modules/Screen/src/Generics/mod.rs rename to Modules/Screen/src/mod.rs