mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-19 00:04:25 +01:00
Merge pull request #51 from stakwork/hold-until-sdcard
Hold execution until the sd card is mounted
This commit is contained in:
@@ -23,6 +23,7 @@ pub enum Event {
|
|||||||
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)]
|
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
Starting,
|
Starting,
|
||||||
|
MountingSDCard,
|
||||||
WifiAccessPoint,
|
WifiAccessPoint,
|
||||||
Configuring,
|
Configuring,
|
||||||
ConnectingToWifi,
|
ConnectingToWifi,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ mod periph;
|
|||||||
|
|
||||||
use crate::core::{config::*, events::*};
|
use crate::core::{config::*, events::*};
|
||||||
use crate::periph::led::led_control_loop;
|
use crate::periph::led::led_control_loop;
|
||||||
use crate::periph::sd::{sd_card, simple_fs_test};
|
use crate::periph::sd::{mount_sd_card, simple_fs_test};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
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
|
||||||
@@ -42,9 +42,13 @@ fn main() -> Result<()> {
|
|||||||
// LED control thread
|
// LED control thread
|
||||||
led_control_loop(pins.gpio8, peripherals.rmt.channel0, led_rx);
|
led_control_loop(pins.gpio8, peripherals.rmt.channel0, led_rx);
|
||||||
|
|
||||||
// sd card
|
led_tx.send(Status::MountingSDCard).unwrap();
|
||||||
sd_card();
|
println!("About to mount the sdcard...");
|
||||||
// simple_fs_test();
|
while let Err(_e) = mount_sd_card() {
|
||||||
|
println!("Failed to mount sd card. Make sure it is connected, trying again...");
|
||||||
|
thread::sleep(Duration::from_secs(5));
|
||||||
|
}
|
||||||
|
println!("SD card mounted!");
|
||||||
|
|
||||||
let default_nvs = Arc::new(EspDefaultNvs::new()?);
|
let default_nvs = Arc::new(EspDefaultNvs::new()?);
|
||||||
let mut store =
|
let mut store =
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ pub struct Led {
|
|||||||
fn states() -> BTreeMap<Status, (Color, Time)> {
|
fn states() -> BTreeMap<Status, (Color, Time)> {
|
||||||
let mut s = BTreeMap::new();
|
let mut s = BTreeMap::new();
|
||||||
s.insert(Status::Starting, (0x000001, 100));
|
s.insert(Status::Starting, (0x000001, 100));
|
||||||
|
s.insert(Status::MountingSDCard, (0x000102, 100));
|
||||||
s.insert(Status::WifiAccessPoint, (0x000100, 100));
|
s.insert(Status::WifiAccessPoint, (0x000100, 100));
|
||||||
s.insert(Status::Configuring, (0x010000, 20));
|
s.insert(Status::Configuring, (0x010000, 20));
|
||||||
s.insert(Status::ConnectingToWifi, (0x010100, 350));
|
s.insert(Status::ConnectingToWifi, (0x010100, 350));
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ enum SDMMCFreq {
|
|||||||
_26M = 26000,
|
_26M = 26000,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sd_card() {
|
pub fn mount_sd_card() -> anyhow::Result<()> {
|
||||||
let mount_config = esp_vfs_fat_sdmmc_mount_config_t {
|
let mount_config = esp_vfs_fat_sdmmc_mount_config_t {
|
||||||
format_if_mount_failed: false,
|
format_if_mount_failed: false,
|
||||||
max_files: 5,
|
max_files: 5,
|
||||||
@@ -80,18 +80,15 @@ pub fn sd_card() {
|
|||||||
intr_flags: 0,
|
intr_flags: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = esp!(unsafe {
|
if let Err(error) = esp!(unsafe {
|
||||||
spi_bus_initialize(
|
spi_bus_initialize(
|
||||||
SPI_HOST_SLOT as u32,
|
SPI_HOST_SLOT as u32,
|
||||||
&bus_cfg,
|
&bus_cfg,
|
||||||
esp_idf_sys::spi_common_dma_t_SPI_DMA_CH_AUTO,
|
esp_idf_sys::spi_common_dma_t_SPI_DMA_CH_AUTO,
|
||||||
)
|
)
|
||||||
});
|
}) {
|
||||||
|
if error.code() != 259 {
|
||||||
match res {
|
return Err(anyhow::Error::new(error));
|
||||||
Ok(_) => (),
|
|
||||||
Err(e) => {
|
|
||||||
println!("Failed to initialize SPI Bus: {}", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +121,7 @@ pub fn sd_card() {
|
|||||||
command_timeout_ms: 0,
|
command_timeout_ms: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = esp!(unsafe {
|
esp!(unsafe {
|
||||||
esp_vfs_fat_sdspi_mount(
|
esp_vfs_fat_sdspi_mount(
|
||||||
C_MOUNT_POINT.as_ptr() as *const c_char,
|
C_MOUNT_POINT.as_ptr() as *const c_char,
|
||||||
&host,
|
&host,
|
||||||
@@ -132,14 +129,8 @@ pub fn sd_card() {
|
|||||||
&mount_config,
|
&mount_config,
|
||||||
&mut card as *mut *mut sdmmc_card_t,
|
&mut card as *mut *mut sdmmc_card_t,
|
||||||
)
|
)
|
||||||
});
|
})?;
|
||||||
|
Ok(())
|
||||||
match res {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(e) => {
|
|
||||||
println!("Failed to mount filesystem: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simple_fs_test() {
|
pub fn simple_fs_test() {
|
||||||
|
|||||||
Reference in New Issue
Block a user