1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-04 09:25:56 +00:00

fixup! fix(core): don't use 'static lifetime for BLEEvent

This commit is contained in:
Roman Zeyde 2025-03-20 20:58:46 +02:00
parent a0d635f543
commit ab02b04406
2 changed files with 15 additions and 11 deletions

View File

@ -316,13 +316,13 @@ pub enum AttachType {
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))]
pub enum Event<'a> {
pub enum Event {
#[cfg(feature = "button")]
Button(ButtonEvent),
#[cfg(feature = "touch")]
Touch(TouchEvent),
#[cfg(feature = "ble")]
BLE(BLEEvent<'a>),
BLE(BLEEvent),
USB(USBEvent),
/// Previously requested timer was triggered. This invalidates the timer
/// token (another timer has to be requested).
@ -339,9 +339,6 @@ pub enum Event<'a> {
/// Swipe and transition events
#[cfg(feature = "touch")]
Swipe(SwipeEvent),
/// Prevent build error when BLE is disabled
#[cfg(not(feature = "ble"))]
_NotUsed(&'a ()),
}
/// Result of an event processor.

View File

@ -1,20 +1,27 @@
use crate::error::Error;
use core::str;
use crate::error::{value_error, Error};
#[derive(Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "debug", derive(ufmt::derive::uDebug))]
pub enum BLEEvent<'a> {
pub enum BLEEvent {
Connected,
Disconnected,
PairingRequest(&'a [u8]),
PairingRequest(u32),
PairingCanceled,
}
impl<'a> BLEEvent<'a> {
pub fn new(event: u32, data: &'a [u8]) -> Result<Self, Error> {
impl BLEEvent {
pub fn new(event: u32, data: &[u8]) -> Result<Self, Error> {
let result = match event {
1 => Self::Connected,
2 => Self::Disconnected,
3 => Self::PairingRequest(data),
3 => {
let code_str = str::from_utf8(data).map_err(|_| value_error!(c"Non-UTF code"))?;
let code = u32::from_str_radix(code_str, 10)
.map_err(|_| value_error!(c"Non-decimal code"))?;
Self::PairingRequest(code)
}
4 => Self::PairingCanceled,
_ => return Err(Error::OutOfRange),
};