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 xkbcommon::xkb::{self, FeedResult, KeyDirection, Keysym, Status};
|
||||||
|
|
||||||
use crate::matrix::{MATRIX_COLS, MATRIX_ROWS};
|
use crate::matrix::{MATRIX_COLS, MATRIX_ROWS};
|
||||||
|
use crate::util::{DurationExt, FormattedDuration};
|
||||||
use crate::vial::CustomKeycodes;
|
use crate::vial::CustomKeycodes;
|
||||||
use crate::{KEYBOARD_REPORT_PROXY, PSRAM_ALLOCATOR};
|
use crate::{KEYBOARD_REPORT_PROXY, PSRAM_ALLOCATOR};
|
||||||
|
|
||||||
|
|
@ -91,9 +92,8 @@ pub fn create_hid_report_interceptor() -> impl Future<Output = ()> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let duration = Instant::now().duration_since(instant_start);
|
let duration = Instant::now().duration_since(instant_start);
|
||||||
info!(
|
info!(
|
||||||
"XKB keymap loaded successfully! Took {seconds}.{millis:03} seconds.",
|
"XKB keymap loaded successfully! Took {} seconds.",
|
||||||
seconds = duration.as_secs(),
|
duration.display_as_secs(),
|
||||||
millis = duration.as_millis() % 1_000
|
|
||||||
);
|
);
|
||||||
info!("Loading XKB compose map...");
|
info!("Loading XKB compose map...");
|
||||||
let instant_start = Instant::now();
|
let instant_start = Instant::now();
|
||||||
|
|
@ -107,9 +107,8 @@ pub fn create_hid_report_interceptor() -> impl Future<Output = ()> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let duration = Instant::now().duration_since(instant_start);
|
let duration = Instant::now().duration_since(instant_start);
|
||||||
info!(
|
info!(
|
||||||
"XKB compose map loaded successfully! Took {seconds}.{millis:03} seconds.",
|
"XKB compose map loaded successfully! Took {} seconds.",
|
||||||
seconds = duration.as_secs(),
|
duration.display_as_secs()
|
||||||
millis = duration.as_millis() % 1_000
|
|
||||||
);
|
);
|
||||||
let mut state = xkb::State::new(&keymap);
|
let mut state = xkb::State::new(&keymap);
|
||||||
let mut previous_state = KeyboardReport::default();
|
let mut previous_state = KeyboardReport::default();
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ use core::sync::atomic::{AtomicBool, Ordering};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_sync::blocking_mutex;
|
||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
use embassy_sync::channel::Channel;
|
use embassy_sync::channel::Channel;
|
||||||
use embassy_sync::signal::Signal;
|
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::lcd_cam::lcd::dpi::Dpi;
|
||||||
use esp_hal::mcpwm::{McPwm, PeripheralClockConfig};
|
use esp_hal::mcpwm::{McPwm, PeripheralClockConfig};
|
||||||
use esp_hal::psram::{FlashFreq, PsramConfig, PsramSize, SpiRamFreq, SpiTimingConfigCoreClock};
|
use esp_hal::psram::{FlashFreq, PsramConfig, PsramSize, SpiRamFreq, SpiTimingConfigCoreClock};
|
||||||
|
use esp_hal::sha::Sha;
|
||||||
use esp_hal::system::Stack;
|
use esp_hal::system::Stack;
|
||||||
use esp_hal::timer::timg::TimerGroup;
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
use esp_println::println;
|
use esp_println::println;
|
||||||
|
|
@ -77,6 +79,7 @@ mod logging;
|
||||||
mod matrix;
|
mod matrix;
|
||||||
mod peripherals;
|
mod peripherals;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
mod util;
|
||||||
mod vial;
|
mod vial;
|
||||||
|
|
||||||
#[cfg(feature = "alt-log")]
|
#[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.
|
/// Used to signal that the MCU is ready to render the GUI.
|
||||||
static SIGNAL_UI_RENDER: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
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]
|
#[esp_rtos::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
#[cfg(feature = "usb-log")]
|
#[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 = McPwm::new(peripherals.MCPWM0, PeripheralClockConfig::with_prescaler(1));
|
||||||
let mut _pwm_pin = Output::new(peripherals.GPIO21, Level::High, OutputConfig::default());
|
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 timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
let software_interrupt = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
let software_interrupt = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
||||||
esp_rtos::start(
|
esp_rtos::start(
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
// #![cfg_attr(not(feature = "simulator"), no_main)]
|
// #![cfg_attr(not(feature = "simulator"), no_main)]
|
||||||
|
|
||||||
use alloc::{boxed::Box, ffi::CString};
|
use alloc::{boxed::Box, ffi::CString};
|
||||||
|
use embassy_time::{Duration, Instant};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use slint::SharedString;
|
use slint::SharedString;
|
||||||
use spectre_api_sys::{SpectreAlgorithm, SpectreCounter, SpectreKeyPurpose, SpectreUserKey};
|
use spectre_api_sys::{SpectreAlgorithm, SpectreCounter, SpectreKeyPurpose, SpectreUserKey};
|
||||||
|
|
||||||
#[cfg(feature = "limit-fps")]
|
#[cfg(feature = "limit-fps")]
|
||||||
use crate::FRAME_DURATION_MIN;
|
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 backend;
|
||||||
pub mod window_adapter;
|
pub mod window_adapter;
|
||||||
|
|
@ -27,12 +28,18 @@ pub async fn run_renderer_task(backend: SlintBackend) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let user_key_start = Instant::now();
|
||||||
let user_key = &*spectre_api_sys::spectre_user_key(
|
let user_key = &*spectre_api_sys::spectre_user_key(
|
||||||
c"test".as_ptr(),
|
c"test".as_ptr(),
|
||||||
c_string.as_ptr(),
|
c_string.as_ptr(),
|
||||||
SpectreAlgorithm::Current,
|
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(
|
let site_key = &*spectre_api_sys::spectre_site_key(
|
||||||
user_key as *const SpectreUserKey,
|
user_key as *const SpectreUserKey,
|
||||||
c"example.org".as_ptr(),
|
c"example.org".as_ptr(),
|
||||||
|
|
@ -40,7 +47,11 @@ pub async fn run_renderer_task(backend: SlintBackend) {
|
||||||
SpectreKeyPurpose::Authentication,
|
SpectreKeyPurpose::Authentication,
|
||||||
c"".as_ptr(),
|
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
|
// 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