use own wifi implementation to connect to wifi. store credentials in flash. no wifi connection yet
This commit is contained in:
+19
-14
@@ -9,6 +9,7 @@
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::sync::Arc;
|
||||
use creaturedex::Mutex;
|
||||
use creaturedex::background_tasks;
|
||||
use creaturedex::drivers::i2c_bus::I2cBusPinConfiguration;
|
||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||
@@ -19,14 +20,15 @@ use creaturedex::drivers::tertiary_lcd::{
|
||||
BOX, EMPTY, EXAMPLE, HEART, TertiaryDisplay, TertiaryDisplayPinConfiguration,
|
||||
};
|
||||
use creaturedex::navigation::inputs::Inputs;
|
||||
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::network::wifi::Wifi;
|
||||
use creaturedex::network::wifi::wait_for_wifi_credentials;
|
||||
use creaturedex::peripherals::Peripherals;
|
||||
use creaturedex::peripherals::storage::cardstore::CardStore;
|
||||
use creaturedex::peripherals::storage::store::Store;
|
||||
use creaturedex::peripherals::storage::wifistore::WifiStore;
|
||||
use embassy_executor::Spawner;
|
||||
use embedded_graphics::pixelcolor::BinaryColor;
|
||||
use embedded_graphics::{
|
||||
@@ -38,22 +40,16 @@ use embedded_hal_bus::i2c::AtomicDevice;
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::gpio::{Input, InputConfig, Pull};
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use log::error;
|
||||
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::rtc_cntl::Rtc;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(panic_info: &core::panic::PanicInfo) -> ! {
|
||||
error!("{}", panic_info);
|
||||
loop {}
|
||||
}
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
const HEAP_SIZE: usize = 73744;
|
||||
|
||||
const NVS_PARTITION_OFFSET: usize = 0x10000;
|
||||
const NVS_PARTITION_SIZE: usize = 0xfa000;
|
||||
const NVS_PARTITION_OFFSET: usize = 0x9000;
|
||||
const NVS_PARTITION_SIZE: usize = 0xa0000;
|
||||
|
||||
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||
@@ -133,18 +129,23 @@ async fn main(spawner: Spawner) {
|
||||
.expect("failed to create nvs"),
|
||||
));
|
||||
|
||||
setup_wifi(esp_peripherals.WIFI, Arc::clone(&nvs), &spawner).await;
|
||||
let wifi_store = WifiStore::new(nvs.clone()).await.expect("Could not initialize WiFi store");
|
||||
|
||||
let card_store = CardStore::new(nvs)
|
||||
let init_credentials = Wifi::initialize_credentials(&wifi_store).await.expect("Could not get init WiFi credentials");
|
||||
|
||||
let wifi = Wifi::new(esp_peripherals.WIFI, init_credentials).expect("Could not initialize WiFi");
|
||||
|
||||
let card_store = CardStore::new(nvs.clone())
|
||||
.await
|
||||
.expect("Could not initialize Card Store");
|
||||
|
||||
let store = Store { card_store };
|
||||
let store = Store { card_store, wifi_store };
|
||||
let rtc = Rtc::new(esp_peripherals.LPWR);
|
||||
|
||||
let peripherals = Box::leak(Box::new(Peripherals {
|
||||
store: Mutex::new(store),
|
||||
rtc,
|
||||
wifi: Mutex::new(wifi),
|
||||
}));
|
||||
|
||||
let mut nfc_driver = NfcPn532Driver::new(AtomicDevice::new(shared_i2c));
|
||||
@@ -191,6 +192,10 @@ async fn main(spawner: Spawner) {
|
||||
background_tasks::nfc_scanner(nfc_driver, outputs, peripherals, navigation_state)
|
||||
.expect("nfc scanner task failed"),
|
||||
);
|
||||
spawner.spawn(
|
||||
wait_for_wifi_credentials(outputs, peripherals)
|
||||
.expect("wifi credential task failed"),
|
||||
);
|
||||
|
||||
core::future::pending::<()>().await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user