mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-23 08:34:29 +01:00
sphinx-key: customize led loop stack size
these two previous commits bring the post-startup DRAM usage from 90k to 92k. I thought we were reducing stack sizes from 10k to 1.5k as in this commit, which would yield a similar delta on DRAM usage, but I might be wrong here.
This commit is contained in:
@@ -5,7 +5,9 @@ mod periph;
|
||||
mod status;
|
||||
|
||||
pub use crate::core::control::FlashPersister;
|
||||
use esp_idf_hal::gpio::Gpio0;
|
||||
use esp_idf_hal::gpio::Gpio9;
|
||||
use esp_idf_hal::peripheral::Peripheral;
|
||||
use esp_idf_hal::peripherals::Peripherals;
|
||||
use esp_idf_svc::nvs::EspDefaultNvsPartition;
|
||||
use esp_idf_svc::nvs::EspNvs;
|
||||
@@ -22,17 +24,21 @@ const ID_LEN: usize = 12;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
esp_idf_sys::link_patches();
|
||||
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
let mut peripherals = Peripherals::take().unwrap();
|
||||
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let pins = peripherals.pins;
|
||||
|
||||
let (led_tx, led_rx) = mpsc::channel::<Status>();
|
||||
// LED control thread
|
||||
periph::led::led_control_loop(pins.gpio0, peripherals.rmt.channel0, led_rx);
|
||||
let (mut led_tx, mut led_rx) = mpsc::channel::<Status>();
|
||||
while let Err(e) = periph::led::led_control_loop(
|
||||
unsafe { Gpio0::new() },
|
||||
unsafe { peripherals.rmt.channel0.clone_unchecked() },
|
||||
led_rx,
|
||||
) {
|
||||
log::error!("unable to spawn led thread: {:?}", e);
|
||||
thread::sleep(Duration::from_millis(1000));
|
||||
(led_tx, led_rx) = mpsc::channel::<Status>();
|
||||
}
|
||||
|
||||
// BUTTON thread
|
||||
let default_nvs = EspDefaultNvsPartition::take()?;
|
||||
|
||||
@@ -14,7 +14,8 @@ 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::gpio::{Gpio0, Gpio9};
|
||||
use esp_idf_hal::peripheral::Peripheral;
|
||||
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
|
||||
@@ -31,17 +32,21 @@ fn main() -> Result<()> {
|
||||
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
|
||||
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
|
||||
esp_idf_sys::link_patches();
|
||||
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
let mut peripherals = Peripherals::take().unwrap();
|
||||
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let pins = peripherals.pins;
|
||||
|
||||
let (led_tx, led_rx) = mpsc::channel();
|
||||
// LED control thread
|
||||
led_control_loop(pins.gpio0, peripherals.rmt.channel0, led_rx);
|
||||
let (mut led_tx, mut led_rx) = mpsc::channel::<Status>();
|
||||
while let Err(e) = led_control_loop(
|
||||
unsafe { Gpio0::new() },
|
||||
unsafe { peripherals.rmt.channel0.clone_unchecked() },
|
||||
led_rx,
|
||||
) {
|
||||
log::error!("unable to spawn led thread: {:?}", e);
|
||||
thread::sleep(Duration::from_millis(1000));
|
||||
(led_tx, led_rx) = mpsc::channel::<Status>();
|
||||
}
|
||||
|
||||
led_tx.send(Status::MountingSDCard).unwrap();
|
||||
println!("About to mount the sdcard...");
|
||||
@@ -57,9 +62,7 @@ fn main() -> Result<()> {
|
||||
let flash_per = FlashPersister::new(default_nvs.clone());
|
||||
let flash_arc = Arc::new(Mutex::new(flash_per));
|
||||
// BUTTON thread
|
||||
while let Err(e) =
|
||||
button_loop(unsafe { Gpio9::new() }, 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));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::status::Status;
|
||||
use anyhow::Result;
|
||||
use esp_idf_hal::rmt::config::TransmitConfig;
|
||||
use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, TxRmtDriver};
|
||||
use esp_idf_hal::{gpio, rmt};
|
||||
@@ -37,12 +38,17 @@ fn states() -> BTreeMap<Status, (Color, Time)> {
|
||||
s
|
||||
}
|
||||
|
||||
pub fn led_control_loop(gpio0: gpio::Gpio0, channel0: rmt::CHANNEL0, rx: mpsc::Receiver<Status>) {
|
||||
pub fn led_control_loop(
|
||||
gpio0: gpio::Gpio0,
|
||||
channel0: rmt::CHANNEL0,
|
||||
rx: mpsc::Receiver<Status>,
|
||||
) -> Result<()> {
|
||||
let config = TransmitConfig::new().clock_divider(1);
|
||||
let transmit = Arc::new(Mutex::new(
|
||||
TxRmtDriver::new(channel0, gpio0, &config).unwrap(),
|
||||
));
|
||||
thread::spawn(move || {
|
||||
let builder = thread::Builder::new().stack_size(1500);
|
||||
builder.spawn(move || {
|
||||
let mut led = Led::new(0x000001, 100);
|
||||
let states = states();
|
||||
loop {
|
||||
@@ -55,7 +61,8 @@ pub fn led_control_loop(gpio0: gpio::Gpio0, channel0: rmt::CHANNEL0, rx: mpsc::R
|
||||
led.blink(transmit.clone());
|
||||
thread::sleep(Duration::from_millis(400));
|
||||
}
|
||||
});
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl Led {
|
||||
|
||||
Reference in New Issue
Block a user