diff --git a/core/embed/rust/src/ui/event.rs b/core/embed/rust/src/ui/event.rs deleted file mode 100644 index 7e629a4c26..0000000000 --- a/core/embed/rust/src/ui/event.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::{error, ui::geometry::Point}; -use core::convert::TryInto; - -#[cfg(feature = "touch")] -use crate::ui::geometry::Direction; - -#[derive(Copy, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] -pub enum PhysicalButton { - Left, - Right, -} - -#[derive(Copy, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] -pub enum ButtonEvent { - /// Button pressed down. - /// ▼ * | * ▼ - ButtonPressed(PhysicalButton), - /// Button released up. - /// ▲ * | * ▲ - ButtonReleased(PhysicalButton), - HoldStarted, - HoldEnded, -} - -impl ButtonEvent { - pub fn new(event: u32, button: u32) -> Result { - let button = match button { - 0 => PhysicalButton::Left, - 1 => PhysicalButton::Right, - _ => return Err(error::Error::OutOfRange), - }; - let result = match event { - 1 => Self::ButtonPressed(button), - 2 => Self::ButtonReleased(button), - _ => return Err(error::Error::OutOfRange), - }; - Ok(result) - } -} - -#[derive(Copy, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] -pub enum TouchEvent { - /// A person has started touching the screen at given absolute coordinates. - /// `TouchMove` will usually follow, and `TouchEnd` should finish the - /// interaction. - TouchStart(Point), - /// Touch has moved into a different point on the screen. - TouchMove(Point), - /// Touch has ended at a point on the screen. - TouchEnd(Point), - /// Touch event has been suppressed by more important event - i.e. Swipe. - TouchAbort, -} - -impl TouchEvent { - pub fn new(event: u32, x: u32, y: u32) -> Result { - let point = Point::new(x.try_into()?, y.try_into()?); - let result = match event { - 1 => Self::TouchStart(point), - 2 => Self::TouchMove(point), - 4 => Self::TouchEnd(point), - _ => return Err(error::Error::OutOfRange), - }; - Ok(result) - } -} - -#[derive(Copy, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] -pub enum USBEvent { - /// USB host has connected/disconnected. - Connected(bool), -} - -#[cfg(feature = "touch")] -#[derive(Copy, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] -pub enum SwipeEvent { - Move(Direction, i16), - End(Direction), -} diff --git a/core/embed/rust/src/ui/event/button.rs b/core/embed/rust/src/ui/event/button.rs new file mode 100644 index 0000000000..d7bae42a7a --- /dev/null +++ b/core/embed/rust/src/ui/event/button.rs @@ -0,0 +1,37 @@ +use crate::error::Error; + +#[derive(Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] +pub enum PhysicalButton { + Left, + Right, +} + +#[derive(Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] +pub enum ButtonEvent { + /// Button pressed down. + /// ▼ * | * ▼ + ButtonPressed(PhysicalButton), + /// Button released up. + /// ▲ * | * ▲ + ButtonReleased(PhysicalButton), + HoldStarted, + HoldEnded, +} + +impl ButtonEvent { + pub fn new(event: u32, button: u32) -> Result { + let button = match button { + 0 => PhysicalButton::Left, + 1 => PhysicalButton::Right, + _ => return Err(Error::OutOfRange), + }; + let result = match event { + 1 => Self::ButtonPressed(button), + 2 => Self::ButtonReleased(button), + _ => return Err(Error::OutOfRange), + }; + Ok(result) + } +} diff --git a/core/embed/rust/src/ui/event/mod.rs b/core/embed/rust/src/ui/event/mod.rs new file mode 100644 index 0000000000..62df32784e --- /dev/null +++ b/core/embed/rust/src/ui/event/mod.rs @@ -0,0 +1,16 @@ +#[cfg(feature = "button")] +pub mod button; +#[cfg(feature = "touch")] +pub mod touch; + +#[cfg(feature = "button")] +pub use button::{ButtonEvent, PhysicalButton}; +#[cfg(feature = "touch")] +pub use touch::{SwipeEvent, TouchEvent}; + +#[derive(Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] +pub enum USBEvent { + /// USB host has connected/disconnected. + Connected(bool), +} diff --git a/core/embed/rust/src/ui/event/touch.rs b/core/embed/rust/src/ui/event/touch.rs new file mode 100644 index 0000000000..093298119f --- /dev/null +++ b/core/embed/rust/src/ui/event/touch.rs @@ -0,0 +1,39 @@ +use crate::{ + error::Error, + ui::geometry::{Direction, Point}, +}; + +#[derive(Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] +pub enum TouchEvent { + /// A person has started touching the screen at given absolute coordinates. + /// `TouchMove` will usually follow, and `TouchEnd` should finish the + /// interaction. + TouchStart(Point), + /// Touch has moved into a different point on the screen. + TouchMove(Point), + /// Touch has ended at a point on the screen. + TouchEnd(Point), + /// Touch event has been suppressed by more important event - i.e. Swipe. + TouchAbort, +} + +impl TouchEvent { + pub fn new(event: u32, x: u32, y: u32) -> Result { + let point = Point::new(x.try_into()?, y.try_into()?); + let result = match event { + 1 => Self::TouchStart(point), + 2 => Self::TouchMove(point), + 4 => Self::TouchEnd(point), + _ => return Err(Error::OutOfRange), + }; + Ok(result) + } +} + +#[derive(Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))] +pub enum SwipeEvent { + Move(Direction, i16), + End(Direction), +}