mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 15:24:32 +01:00
sphinx-key: customize button loop stack size
go from 10K bytes to 2.5K
This commit is contained in:
@@ -5,11 +5,13 @@ mod periph;
|
|||||||
mod status;
|
mod status;
|
||||||
|
|
||||||
pub use crate::core::control::FlashPersister;
|
pub use crate::core::control::FlashPersister;
|
||||||
|
use esp_idf_hal::gpio::Gpio9;
|
||||||
use esp_idf_hal::peripherals::Peripherals;
|
use esp_idf_hal::peripherals::Peripherals;
|
||||||
use esp_idf_svc::nvs::EspDefaultNvsPartition;
|
use esp_idf_svc::nvs::EspDefaultNvsPartition;
|
||||||
use esp_idf_svc::nvs::EspNvs;
|
use esp_idf_svc::nvs::EspNvs;
|
||||||
use esp_idf_svc::nvs::*;
|
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 esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported
|
||||||
|
use log;
|
||||||
use status::Status;
|
use status::Status;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@@ -36,7 +38,12 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let default_nvs = EspDefaultNvsPartition::take()?;
|
let default_nvs = EspDefaultNvsPartition::take()?;
|
||||||
let flash_per = FlashPersister::new(default_nvs.clone());
|
let flash_per = FlashPersister::new(default_nvs.clone());
|
||||||
let flash_arc = Arc::new(Mutex::new(flash_per));
|
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 {
|
loop {
|
||||||
thread::sleep(Duration::from_millis(1000));
|
thread::sleep(Duration::from_millis(1000));
|
||||||
|
|||||||
@@ -14,18 +14,17 @@ use crate::periph::sd::{mount_sd_card, simple_fs_test};
|
|||||||
use crate::status::Status;
|
use crate::status::Status;
|
||||||
|
|
||||||
use anyhow::Result;
|
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 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::sync::{mpsc, Arc, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::time::SystemTime;
|
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;
|
const ID_LEN: usize = 12;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
@@ -58,7 +57,12 @@ fn main() -> Result<()> {
|
|||||||
let flash_per = FlashPersister::new(default_nvs.clone());
|
let flash_per = FlashPersister::new(default_nvs.clone());
|
||||||
let flash_arc = Arc::new(Mutex::new(flash_per));
|
let flash_arc = Arc::new(Mutex::new(flash_per));
|
||||||
// BUTTON thread
|
// 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();
|
let flash = flash_arc.lock().unwrap();
|
||||||
if let Ok(exist) = flash.read_config() {
|
if let Ok(exist) = flash.read_config() {
|
||||||
let seed = flash.read_seed().expect("no seed...");
|
let seed = flash.read_seed().expect("no seed...");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::status::Status;
|
use crate::status::Status;
|
||||||
use crate::FlashPersister;
|
use crate::FlashPersister;
|
||||||
|
use anyhow::Result;
|
||||||
use esp_idf_hal::gpio;
|
use esp_idf_hal::gpio;
|
||||||
use esp_idf_hal::gpio::*;
|
use esp_idf_hal::gpio::*;
|
||||||
use sphinx_signer::sphinx_glyph::control::ControlPersist;
|
use sphinx_signer::sphinx_glyph::control::ControlPersist;
|
||||||
@@ -17,8 +18,9 @@ pub fn button_loop(
|
|||||||
gpio9: gpio::Gpio9,
|
gpio9: gpio::Gpio9,
|
||||||
tx: mpsc::Sender<Status>,
|
tx: mpsc::Sender<Status>,
|
||||||
flash_arc: Arc<Mutex<FlashPersister>>,
|
flash_arc: Arc<Mutex<FlashPersister>>,
|
||||||
) {
|
) -> Result<()> {
|
||||||
thread::spawn(move || {
|
let builder = thread::Builder::new().stack_size(2500);
|
||||||
|
builder.spawn(move || {
|
||||||
let mut button = PinDriver::input(gpio9).unwrap();
|
let mut button = PinDriver::input(gpio9).unwrap();
|
||||||
button.set_pull(Pull::Up).unwrap();
|
button.set_pull(Pull::Up).unwrap();
|
||||||
let mut pressed = false;
|
let mut pressed = false;
|
||||||
@@ -116,7 +118,8 @@ pub fn button_loop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Machine {
|
struct Machine {
|
||||||
|
|||||||
Reference in New Issue
Block a user