Nicer (and correct) duration formatting
This commit is contained in:
parent
3c695be996
commit
dbdfa8ae44
|
|
@ -18,6 +18,7 @@ use slint::platform::Key;
|
|||
use xkbcommon::xkb::{self, FeedResult, KeyDirection, Keysym, Status};
|
||||
|
||||
use crate::matrix::{MATRIX_COLS, MATRIX_ROWS};
|
||||
use crate::util::{DurationExt, FormattedDuration};
|
||||
use crate::vial::CustomKeycodes;
|
||||
use crate::{KEYBOARD_REPORT_PROXY, PSRAM_ALLOCATOR};
|
||||
|
||||
|
|
@ -91,9 +92,8 @@ pub fn create_hid_report_interceptor() -> impl Future<Output = ()> {
|
|||
.unwrap();
|
||||
let duration = Instant::now().duration_since(instant_start);
|
||||
info!(
|
||||
"XKB keymap loaded successfully! Took {seconds}.{millis:03} seconds.",
|
||||
seconds = duration.as_secs(),
|
||||
millis = duration.as_millis() % 1_000
|
||||
"XKB keymap loaded successfully! Took {} seconds.",
|
||||
duration.display_as_secs(),
|
||||
);
|
||||
info!("Loading XKB compose map...");
|
||||
let instant_start = Instant::now();
|
||||
|
|
@ -107,9 +107,8 @@ pub fn create_hid_report_interceptor() -> impl Future<Output = ()> {
|
|||
.unwrap();
|
||||
let duration = Instant::now().duration_since(instant_start);
|
||||
info!(
|
||||
"XKB compose map loaded successfully! Took {seconds}.{millis:03} seconds.",
|
||||
seconds = duration.as_secs(),
|
||||
millis = duration.as_millis() % 1_000
|
||||
"XKB compose map loaded successfully! Took {} seconds.",
|
||||
duration.display_as_secs()
|
||||
);
|
||||
let mut state = xkb::State::new(&keymap);
|
||||
let mut previous_state = KeyboardReport::default();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use core::sync::atomic::{AtomicBool, Ordering};
|
|||
use alloc::boxed::Box;
|
||||
use alloc::vec;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_sync::blocking_mutex;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::channel::Channel;
|
||||
use embassy_sync::signal::Signal;
|
||||
|
|
@ -38,6 +39,7 @@ use esp_hal::lcd_cam::LcdCam;
|
|||
use esp_hal::lcd_cam::lcd::dpi::Dpi;
|
||||
use esp_hal::mcpwm::{McPwm, PeripheralClockConfig};
|
||||
use esp_hal::psram::{FlashFreq, PsramConfig, PsramSize, SpiRamFreq, SpiTimingConfigCoreClock};
|
||||
use esp_hal::sha::Sha;
|
||||
use esp_hal::system::Stack;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use esp_println::println;
|
||||
|
|
@ -77,6 +79,7 @@ mod logging;
|
|||
mod matrix;
|
||||
mod peripherals;
|
||||
mod ui;
|
||||
mod util;
|
||||
mod vial;
|
||||
|
||||
#[cfg(feature = "alt-log")]
|
||||
|
|
@ -100,6 +103,9 @@ static SIGNAL_LCD_SUBMIT: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
|||
/// Used to signal that the MCU is ready to render the GUI.
|
||||
static SIGNAL_UI_RENDER: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
||||
|
||||
pub static SHA: blocking_mutex::Mutex<CriticalSectionRawMutex, RefCell<Option<Sha>>> =
|
||||
blocking_mutex::Mutex::new(RefCell::new(None));
|
||||
|
||||
#[esp_rtos::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
#[cfg(feature = "usb-log")]
|
||||
|
|
@ -182,6 +188,10 @@ async fn main(_spawner: Spawner) {
|
|||
let mut _pwm = McPwm::new(peripherals.MCPWM0, PeripheralClockConfig::with_prescaler(1));
|
||||
let mut _pwm_pin = Output::new(peripherals.GPIO21, Level::High, OutputConfig::default());
|
||||
|
||||
SHA.lock(|sha| {
|
||||
*sha.borrow_mut() = Some(Sha::new(peripherals.SHA));
|
||||
});
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
let software_interrupt = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
||||
esp_rtos::start(
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
// #![cfg_attr(not(feature = "simulator"), no_main)]
|
||||
|
||||
use alloc::{boxed::Box, ffi::CString};
|
||||
use embassy_time::{Duration, Instant};
|
||||
use log::{info, warn};
|
||||
use slint::SharedString;
|
||||
use spectre_api_sys::{SpectreAlgorithm, SpectreCounter, SpectreKeyPurpose, SpectreUserKey};
|
||||
|
||||
#[cfg(feature = "limit-fps")]
|
||||
use crate::FRAME_DURATION_MIN;
|
||||
use crate::{SIGNAL_LCD_SUBMIT, SIGNAL_UI_RENDER, ui::backend::SlintBackend};
|
||||
use crate::{SIGNAL_LCD_SUBMIT, SIGNAL_UI_RENDER, ui::backend::SlintBackend, util::DurationExt};
|
||||
|
||||
pub mod backend;
|
||||
pub mod window_adapter;
|
||||
|
|
@ -27,12 +28,18 @@ pub async fn run_renderer_task(backend: SlintBackend) {
|
|||
return;
|
||||
};
|
||||
unsafe {
|
||||
let user_key_start = Instant::now();
|
||||
let user_key = &*spectre_api_sys::spectre_user_key(
|
||||
c"test".as_ptr(),
|
||||
c_string.as_ptr(),
|
||||
SpectreAlgorithm::Current,
|
||||
);
|
||||
warn!("{user_key:?}");
|
||||
let user_key_duration = Instant::now().duration_since(user_key_start);
|
||||
warn!(
|
||||
"User key derived in {} seconds:\n{user_key:02x?}",
|
||||
user_key_duration.display_as_secs()
|
||||
);
|
||||
let site_key_start = Instant::now();
|
||||
let site_key = &*spectre_api_sys::spectre_site_key(
|
||||
user_key as *const SpectreUserKey,
|
||||
c"example.org".as_ptr(),
|
||||
|
|
@ -40,7 +47,11 @@ pub async fn run_renderer_task(backend: SlintBackend) {
|
|||
SpectreKeyPurpose::Authentication,
|
||||
c"".as_ptr(),
|
||||
);
|
||||
warn!("{site_key:?}");
|
||||
let site_key_duration = Instant::now().duration_since(site_key_start);
|
||||
warn!(
|
||||
"Site key derived in {} seconds:\n{site_key:02x?}",
|
||||
site_key_duration.display_as_secs()
|
||||
);
|
||||
|
||||
// TODO: Free memory
|
||||
}
|
||||
|
|
|
|||
26
firmware2/src/util.rs
Normal file
26
firmware2/src/util.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use core::fmt::Display;
|
||||
|
||||
use embassy_time::Duration;
|
||||
|
||||
pub struct FormattedDuration<'a>(&'a Duration);
|
||||
|
||||
impl Display for FormattedDuration<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let &FormattedDuration(duration) = self;
|
||||
f.write_fmt(format_args!(
|
||||
"{:01}.{:06}",
|
||||
duration.as_secs(),
|
||||
duration.as_micros() % 1_000_000
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DurationExt {
|
||||
fn display_as_secs(&self) -> FormattedDuration<'_>;
|
||||
}
|
||||
|
||||
impl DurationExt for Duration {
|
||||
fn display_as_secs(&self) -> FormattedDuration<'_> {
|
||||
FormattedDuration(self)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue