mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 01:18:28 +00:00
refactor(core/rust): use separate files for button and touch events
this makes it easier to feature-gate them
This commit is contained in:
parent
e049efd171
commit
943d6d9b30
@ -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<Self, error::Error> {
|
||||
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<Self, error::Error> {
|
||||
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),
|
||||
}
|
37
core/embed/rust/src/ui/event/button.rs
Normal file
37
core/embed/rust/src/ui/event/button.rs
Normal file
@ -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<Self, Error> {
|
||||
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)
|
||||
}
|
||||
}
|
16
core/embed/rust/src/ui/event/mod.rs
Normal file
16
core/embed/rust/src/ui/event/mod.rs
Normal file
@ -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),
|
||||
}
|
39
core/embed/rust/src/ui/event/touch.rs
Normal file
39
core/embed/rust/src/ui/event/touch.rs
Normal file
@ -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<Self, Error> {
|
||||
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),
|
||||
}
|
Loading…
Reference in New Issue
Block a user