diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index 47b3b2a..131afe0 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -48,3 +48,6 @@ anyhow = "1" name = "clear" path = "src/clear.rs" +[[bin]] +name = "btn" +path = "src/btn.rs" \ No newline at end of file diff --git a/sphinx-key/src/btn.rs b/sphinx-key/src/btn.rs new file mode 100644 index 0000000..5489a64 --- /dev/null +++ b/sphinx-key/src/btn.rs @@ -0,0 +1,26 @@ +mod periph; +mod status; + +use status::Status; + +use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported + +// use embedded_svc::storage::StorageBase; +use esp_idf_hal::peripherals::Peripherals; +use esp_idf_svc::nvs::EspNvs; +use esp_idf_svc::nvs::*; +use std::sync::mpsc; + +fn main() -> anyhow::Result<()> { + let peripherals = Peripherals::take().unwrap(); + let pins = peripherals.pins; + + let (led_tx, led_rx) = mpsc::channel::(); + // LED control thread + periph::led::led_control_loop(pins.gpio0, peripherals.rmt.channel0, led_rx); + + // BUTTON thread + periph::button::button_loop(pins.gpio8, led_tx.clone()); + + Ok(()) +} diff --git a/sphinx-key/src/clear.rs b/sphinx-key/src/clear.rs index 30a3cb3..48632b9 100644 --- a/sphinx-key/src/clear.rs +++ b/sphinx-key/src/clear.rs @@ -1,7 +1,5 @@ -mod conn; -mod core; -mod ota; mod periph; +mod status; #[allow(unused_imports)] use crate::periph::sd::mount_sd_card; diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 00cb246..e035df7 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -1,6 +1,7 @@ use crate::conn::mqtt::QOS; use crate::core::lss; use crate::ota::{update_sphinx_key, validate_ota_message}; +use crate::status::Status; use lss_connector::secp256k1::PublicKey; use sphinx_signer::lightning_signer::bitcoin::Network; @@ -32,23 +33,6 @@ pub enum Event { Control(Vec), } -#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)] -pub enum Status { - Starting, - MountingSDCard, - SyncingTime, - WifiAccessPoint, - Configuring, - ConnectingToWifi, - ConnectingToMqtt, - Connected, - Signing, - Ota, - Reset1, - Reset2, - Reset3, -} - pub const ROOT_STORE: &str = "/sdcard/store"; pub const SUB_TOPICS: &[&str] = &[topics::VLS, topics::LSS_MSG, topics::CONTROL]; diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index 835824f..760bc4d 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -3,9 +3,11 @@ mod conn; mod core; mod ota; mod periph; +mod status; use crate::core::control::{controller_from_seed, FlashPersister}; use crate::core::{config::*, events::*}; +use crate::status::Status; // use crate::periph::led::led_control_loop; use crate::periph::button::button_loop; #[allow(unused_imports)] diff --git a/sphinx-key/src/ota.rs b/sphinx-key/src/ota.rs index 9d17aed..a0daac4 100644 --- a/sphinx-key/src/ota.rs +++ b/sphinx-key/src/ota.rs @@ -1,4 +1,4 @@ -use crate::core::events::Status; +use crate::status::Status; use anyhow::{anyhow, Result}; use embedded_svc::http::client::Client; use embedded_svc::http::Status as HttpStatus; diff --git a/sphinx-key/src/periph/button.rs b/sphinx-key/src/periph/button.rs index 91793e7..b0d4eae 100644 --- a/sphinx-key/src/periph/button.rs +++ b/sphinx-key/src/periph/button.rs @@ -1,4 +1,4 @@ -use crate::core::events::Status; +use crate::status::Status; use esp_idf_hal::gpio; use esp_idf_hal::gpio::*; use std::sync::mpsc; diff --git a/sphinx-key/src/periph/led.rs b/sphinx-key/src/periph/led.rs index 37ecdeb..17c9984 100644 --- a/sphinx-key/src/periph/led.rs +++ b/sphinx-key/src/periph/led.rs @@ -1,4 +1,4 @@ -use crate::core::events::Status; +use crate::status::Status; use esp_idf_hal::rmt::config::TransmitConfig; use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, TxRmtDriver}; use esp_idf_hal::{gpio, rmt}; diff --git a/sphinx-key/src/status.rs b/sphinx-key/src/status.rs new file mode 100644 index 0000000..fa7c684 --- /dev/null +++ b/sphinx-key/src/status.rs @@ -0,0 +1,16 @@ +#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)] +pub enum Status { + Starting, + MountingSDCard, + SyncingTime, + WifiAccessPoint, + Configuring, + ConnectingToWifi, + ConnectingToMqtt, + Connected, + Signing, + Ota, + Reset1, + Reset2, + Reset3, +}