fix(core): fix tt ui loader haptic feedback

[no changelog]
pull/3812/head
tychovrahe 2 months ago committed by TychoVrahe
parent c680187b0e
commit d04ecba815

@ -359,7 +359,7 @@ fn generate_trezorhal_bindings() {
// haptic // haptic
.allowlist_type("haptic_effect_t") .allowlist_type("haptic_effect_t")
.allowlist_function("haptic_play") .allowlist_function("haptic_play")
.allowlist_function("haptic_play_rtp"); .allowlist_function("haptic_play_custom");
// Write the bindings to a file in the OUR_DIR. // Write the bindings to a file in the OUR_DIR.
bindings bindings

@ -12,8 +12,8 @@ pub fn play(effect: HapticEffect) {
} }
} }
pub fn play_rtp(amplitude: i8, duration: u16) { pub fn play_custom(amplitude_pct: i8, duration_ms: u16) {
unsafe { unsafe {
ffi::haptic_play_rtp(amplitude, duration); ffi::haptic_play_custom(amplitude_pct, duration_ms);
} }
} }

@ -1,5 +1,5 @@
#[cfg(feature = "haptic")] #[cfg(feature = "haptic")]
use crate::trezorhal::haptic::{self, play, HapticEffect}; use crate::trezorhal::haptic::{self, HapticEffect};
use crate::{ use crate::{
time::{Duration, Instant}, time::{Duration, Instant},
ui::{ ui::{
@ -18,6 +18,9 @@ use super::theme;
const GROWING_DURATION_MS: u32 = 1000; const GROWING_DURATION_MS: u32 = 1000;
const SHRINKING_DURATION_MS: u32 = 500; const SHRINKING_DURATION_MS: u32 = 500;
const HAPTIC_AMPLITUDE_MAX_PCT: i16 = 16;
const HAPTIC_AMPLITUDE_DURATION_MS: u16 = 100;
pub enum LoaderMsg { pub enum LoaderMsg {
GrownCompletely, GrownCompletely,
ShrunkCompletely, ShrunkCompletely,
@ -169,14 +172,20 @@ impl Component for Loader {
if self.is_completely_grown(now) { if self.is_completely_grown(now) {
#[cfg(feature = "haptic")] #[cfg(feature = "haptic")]
play(HapticEffect::HoldToConfirm); haptic::play(HapticEffect::HoldToConfirm);
return Some(LoaderMsg::GrownCompletely); return Some(LoaderMsg::GrownCompletely);
} else if self.is_completely_shrunk(now) { } else if self.is_completely_shrunk(now) {
return Some(LoaderMsg::ShrunkCompletely); return Some(LoaderMsg::ShrunkCompletely);
} else { } else {
let progress = self.progress(now).unwrap() as f32 / 1000.0; #[cfg(feature = "haptic")]
let ampl = i16::lerp(0, 76, progress); {
haptic::play_rtp(ampl as i8, 100); if matches!(self.state, State::Growing(_)) {
let progress =
self.progress(now).unwrap() as f32 / display::LOADER_MAX as f32;
let ampl = i16::lerp(0, HAPTIC_AMPLITUDE_MAX_PCT, progress);
haptic::play_custom(ampl as i8, HAPTIC_AMPLITUDE_DURATION_MS);
}
}
// There is further progress in the animation, request an animation frame event. // There is further progress in the animation, request an animation frame event.
ctx.request_anim_frame(); ctx.request_anim_frame();

@ -49,8 +49,9 @@ where
T: Component, T: Component,
{ {
pub fn with_hold(mut self) -> Result<Self, Error> { pub fn with_hold(mut self) -> Result<Self, Error> {
self.button_confirm = self.button_confirm = Button::with_text(TR::buttons__hold_to_confirm.into())
Button::with_text(TR::buttons__hold_to_confirm.into()).styled(theme::button_confirm()); .styled(theme::button_confirm())
.without_haptics();
self.loader = Some(Loader::new()); self.loader = Some(Loader::new());
Ok(self) Ok(self)
} }

@ -28,6 +28,6 @@ void haptic_play(haptic_effect_t effect);
// The function can be invoked repeatedly during the specified duration // The function can be invoked repeatedly during the specified duration
// (`duration_ms`) to modify the amplitude dynamically, allowing // (`duration_ms`) to modify the amplitude dynamically, allowing
// the creation of customized haptic effects. // the creation of customized haptic effects.
bool haptic_play_rtp(int8_t amplitude, uint16_t duration_ms); bool haptic_play_custom(int8_t amplitude_pct, uint16_t duration_ms);
#endif #endif

@ -78,6 +78,7 @@
#define PRESS_EFFECT_AMPLITUDE 25 #define PRESS_EFFECT_AMPLITUDE 25
#define PRESS_EFFECT_DURATION 10 #define PRESS_EFFECT_DURATION 10
#define MAX_AMPLITUDE 127
#define PRODTEST_EFFECT_AMPLITUDE 127 #define PRODTEST_EFFECT_AMPLITUDE 127
static bool set_reg(uint8_t addr, uint8_t value) { static bool set_reg(uint8_t addr, uint8_t value) {
@ -144,7 +145,7 @@ void haptic_init(void) {
TIM16->BDTR |= TIM_BDTR_MOE; TIM16->BDTR |= TIM_BDTR_MOE;
} }
bool haptic_play_rtp(int8_t amplitude, uint16_t duration_ms) { static bool haptic_play_rtp(int8_t amplitude, uint16_t duration_ms) {
if (!playing_rtp) { if (!playing_rtp) {
if (!set_reg(DRV2625_REG_MODE, if (!set_reg(DRV2625_REG_MODE,
DRV2625_REG_MODE_RTP | DRV2625_REG_MODE_TRGFUNC_ENABLE)) { DRV2625_REG_MODE_RTP | DRV2625_REG_MODE_TRGFUNC_ENABLE)) {
@ -198,6 +199,17 @@ void haptic_play(haptic_effect_t effect) {
} }
} }
bool haptic_play_custom(int8_t amplitude_pct, uint16_t duration_ms) {
if (amplitude_pct < 0) {
amplitude_pct = 0;
} else if (amplitude_pct > 100) {
amplitude_pct = 100;
}
return haptic_play_rtp((int8_t)((amplitude_pct * MAX_AMPLITUDE) / 100),
duration_ms);
}
bool haptic_test(uint16_t duration_ms) { bool haptic_test(uint16_t duration_ms) {
return haptic_play_rtp(PRODTEST_EFFECT_AMPLITUDE, duration_ms); return haptic_play_rtp(PRODTEST_EFFECT_AMPLITUDE, duration_ms);
} }

Loading…
Cancel
Save