diff --git a/sphinx-key/src/btn.rs b/sphinx-key/src/btn.rs index 346ac50..317db2a 100644 --- a/sphinx-key/src/btn.rs +++ b/sphinx-key/src/btn.rs @@ -5,11 +5,13 @@ mod periph; mod status; pub use crate::core::control::FlashPersister; +use esp_idf_hal::gpio::Gpio9; use esp_idf_hal::peripherals::Peripherals; use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::nvs::EspNvs; use esp_idf_svc::nvs::*; use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use log; use status::Status; use std::sync::mpsc; use std::sync::{Arc, Mutex}; @@ -36,7 +38,12 @@ fn main() -> anyhow::Result<()> { let default_nvs = EspDefaultNvsPartition::take()?; let flash_per = FlashPersister::new(default_nvs.clone()); let flash_arc = Arc::new(Mutex::new(flash_per)); - periph::button::button_loop(pins.gpio9, led_tx.clone(), flash_arc); + while let Err(e) = + periph::button::button_loop(unsafe { Gpio9::new() }, led_tx.clone(), flash_arc.clone()) + { + log::error!("unable to spawn button thread: {:?}", e); + thread::sleep(Duration::from_millis(1000)); + } loop { thread::sleep(Duration::from_millis(1000)); diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index ed92749..bd7f3c0 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -14,18 +14,17 @@ use crate::periph::sd::{mount_sd_card, simple_fs_test}; use crate::status::Status; use anyhow::Result; +use esp_idf_hal::gpio::Gpio9; +use esp_idf_hal::peripherals::Peripherals; +use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use sphinx_signer::lightning_signer::bitcoin::Network; +use sphinx_signer::sphinx_glyph::control::{Config, ControlPersist, Policy, Velocity}; use std::sync::{mpsc, Arc, Mutex}; use std::thread; use std::time::Duration; use std::time::SystemTime; -use esp_idf_hal::peripherals::Peripherals; -use esp_idf_svc::nvs::EspDefaultNvsPartition; - -use sphinx_signer::lightning_signer::bitcoin::Network; -use sphinx_signer::sphinx_glyph::control::{Config, ControlPersist, Policy, Velocity}; - const ID_LEN: usize = 12; fn main() -> Result<()> { @@ -58,7 +57,12 @@ fn main() -> Result<()> { let flash_per = FlashPersister::new(default_nvs.clone()); let flash_arc = Arc::new(Mutex::new(flash_per)); // BUTTON thread - button_loop(pins.gpio9, led_tx.clone(), flash_arc.clone()); + while let Err(e) = + button_loop(unsafe { Gpio9::new() }, led_tx.clone(), flash_arc.clone()) + { + log::error!("unable to spawn button thread: {:?}", e); + thread::sleep(Duration::from_millis(1000)); + } let flash = flash_arc.lock().unwrap(); if let Ok(exist) = flash.read_config() { let seed = flash.read_seed().expect("no seed..."); diff --git a/sphinx-key/src/periph/button.rs b/sphinx-key/src/periph/button.rs index 1c75af8..fe2f7a8 100644 --- a/sphinx-key/src/periph/button.rs +++ b/sphinx-key/src/periph/button.rs @@ -1,5 +1,6 @@ use crate::status::Status; use crate::FlashPersister; +use anyhow::Result; use esp_idf_hal::gpio; use esp_idf_hal::gpio::*; use sphinx_signer::sphinx_glyph::control::ControlPersist; @@ -17,8 +18,9 @@ pub fn button_loop( gpio9: gpio::Gpio9, tx: mpsc::Sender, flash_arc: Arc>, -) { - thread::spawn(move || { +) -> Result<()> { + let builder = thread::Builder::new().stack_size(2500); + builder.spawn(move || { let mut button = PinDriver::input(gpio9).unwrap(); button.set_pull(Pull::Up).unwrap(); let mut pressed = false; @@ -116,7 +118,8 @@ pub fn button_loop( } } } - }); + })?; + Ok(()) } struct Machine {