rewrite wifi crate
This commit is contained in:
+6
-3
@@ -8,6 +8,7 @@
|
||||
#![deny(clippy::large_stack_frames)]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::sync::Arc;
|
||||
use creaturedex::background_tasks;
|
||||
use creaturedex::drivers::i2c_bus::I2cBusPinConfiguration;
|
||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||
@@ -22,6 +23,7 @@ use creaturedex::navigation::navigation::Mutex;
|
||||
use creaturedex::navigation::navigation::{self};
|
||||
use creaturedex::navigation::outputs::Outputs;
|
||||
use creaturedex::navigation::state::NavigationState;
|
||||
use creaturedex::network::wifi::setup_wifi;
|
||||
use creaturedex::peripherals::Peripherals;
|
||||
use creaturedex::peripherals::storage::cardstore::CardStore;
|
||||
use creaturedex::peripherals::storage::store::Store;
|
||||
@@ -126,10 +128,12 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let storage = esp_storage::FlashStorage::new(esp_peripherals.FLASH);
|
||||
|
||||
let nvs = Mutex::new(
|
||||
let nvs = Arc::new(Mutex::new(
|
||||
esp_nvs::Nvs::new(NVS_PARTITION_OFFSET, NVS_PARTITION_SIZE, storage)
|
||||
.expect("failed to create nvs"),
|
||||
);
|
||||
));
|
||||
|
||||
setup_wifi(esp_peripherals.WIFI, Arc::clone(&nvs), &spawner).await;
|
||||
|
||||
let card_store = CardStore::new(nvs)
|
||||
.await
|
||||
@@ -137,7 +141,6 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let store = Store { card_store };
|
||||
let rtc = Rtc::new(esp_peripherals.LPWR);
|
||||
//setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
|
||||
|
||||
let peripherals = Box::leak(Box::new(Peripherals {
|
||||
store: Mutex::new(store),
|
||||
|
||||
+7
-3
@@ -1,12 +1,15 @@
|
||||
use crate::navigation::navigation::Mutex;
|
||||
use crate::peripherals::storage::Nvs;
|
||||
use alloc::sync::Arc;
|
||||
use embassy_executor::Spawner;
|
||||
|
||||
#[cfg(not(feature = "wokwi"))]
|
||||
pub async fn setup_wifi(
|
||||
wifi: esp_hal::peripherals::WIFI<'static>,
|
||||
flash: esp_hal::peripherals::FLASH<'static>,
|
||||
nvs: Arc<Mutex<Nvs>>,
|
||||
spawner: &Spawner,
|
||||
) {
|
||||
let nvs = esp_hal_wifimanager::Nvs::new(0x9000, 0x6000, flash).unwrap();
|
||||
let espnvs = esp_hal_wifimanager::Nvs::new_from_nvs(nvs, 0, 0);
|
||||
|
||||
let mut wm_settings = esp_hal_wifimanager::WmSettings::default();
|
||||
|
||||
@@ -19,7 +22,8 @@ pub async fn setup_wifi(
|
||||
wm_settings.wifi_conn_timeout = 30000;
|
||||
wm_settings.esp_reset_timeout = Some(300000); // 5min
|
||||
|
||||
let wifi_res = esp_hal_wifimanager::init_wm(wm_settings, spawner, Some(&nvs), wifi, None).await;
|
||||
let wifi_res =
|
||||
esp_hal_wifimanager::init_wm(wm_settings, spawner, Some(&espnvs), wifi, None).await;
|
||||
|
||||
log::info!("wifi_res: {wifi_res:?}");
|
||||
}
|
||||
|
||||
@@ -1,33 +1,5 @@
|
||||
use esp_storage::FlashStorage;
|
||||
|
||||
pub struct MemoryRegion {
|
||||
pub offset: u32,
|
||||
pub size: usize,
|
||||
}
|
||||
|
||||
impl MemoryRegion {
|
||||
pub const fn new(offset: u32, size: usize) -> Self {
|
||||
assert!(offset.is_multiple_of(4), "Flash requires 4 bytes alignment");
|
||||
assert!(size.is_multiple_of(4), "Flash requires 4 bytes alignment");
|
||||
Self { offset, size }
|
||||
}
|
||||
|
||||
pub const fn end(&self) -> usize {
|
||||
self.offset as usize + self.size
|
||||
}
|
||||
}
|
||||
|
||||
pub const MAX_FLASH: usize = 16 * 1024 * 1024;
|
||||
|
||||
pub const MAGIC_REGION: MemoryRegion = MemoryRegion::new(0, 4);
|
||||
|
||||
pub const SETTINGS_REGION: MemoryRegion = MemoryRegion::new(MAGIC_REGION.end() as u32, 1024);
|
||||
|
||||
pub const CARDSTORE_REGION: MemoryRegion = MemoryRegion::new(
|
||||
SETTINGS_REGION.end() as u32,
|
||||
MAX_FLASH - SETTINGS_REGION.end(),
|
||||
);
|
||||
|
||||
pub type Nvs = esp_nvs::Nvs<FlashStorage<'static>>;
|
||||
|
||||
pub mod cardstore;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::card::model::RawCard;
|
||||
use crate::peripherals::Mutex;
|
||||
use crate::peripherals::storage::Nvs;
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
use binary_serde::{BinarySerde, DeserializeError, Endianness};
|
||||
use core::error::Error;
|
||||
@@ -67,11 +68,11 @@ impl CardStoreMetaData {
|
||||
}
|
||||
|
||||
pub struct CardStore {
|
||||
nvs: Mutex<Nvs>,
|
||||
nvs: Arc<Mutex<Nvs>>,
|
||||
}
|
||||
|
||||
impl CardStore {
|
||||
pub async fn new(nvs: Mutex<Nvs>) -> Result<Self, CardStoreError> {
|
||||
pub async fn new(nvs: Arc<Mutex<Nvs>>) -> Result<Self, CardStoreError> {
|
||||
if !Self::is_initialized(&nvs).await? {
|
||||
log::info!("CardStore has not been initialized");
|
||||
Self::initialize(&nvs).await?;
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::navigation::navigation::Navigable;
|
||||
use crate::navigation::navigation::NewState;
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::peripherals::Peripherals;
|
||||
use crate::peripherals::storage::MAGIC_REGION;
|
||||
use crate::views::view::View;
|
||||
use alloc::boxed::Box;
|
||||
use core::error;
|
||||
|
||||
Reference in New Issue
Block a user