add peripherals module which has shared state of all peripherals #47
@@ -1,6 +1,5 @@
|
||||
use crate::storage::cardstore::CardStore;
|
||||
use crate::peripherals::Peripherals;
|
||||
use embedded_hal_bus::i2c::AtomicDevice;
|
||||
use esp_hal::rtc_cntl::Rtc;
|
||||
use esp_hal::{Blocking, i2c::master::I2c, time::Instant};
|
||||
|
||||
use crate::{
|
||||
@@ -16,8 +15,7 @@ use crate::{
|
||||
)]
|
||||
pub async fn nfc_scanner(
|
||||
mut nfc_driver: NfcPn532Driver<AtomicDevice<'static, I2c<'static, Blocking>>>,
|
||||
mut card_store: CardStore,
|
||||
rtc: Rtc<'static>,
|
||||
peripherals: &'static Peripherals,
|
||||
) {
|
||||
loop {
|
||||
while CARD_DATA.lock().await.is_none() {
|
||||
@@ -37,7 +35,14 @@ pub async fn nfc_scanner(
|
||||
};
|
||||
CARD_DATA.lock().await.replace(card);
|
||||
|
||||
match card_store.save_raw_card(split_data, rtc.current_time_us()) {
|
||||
match peripherals
|
||||
.store
|
||||
.lock()
|
||||
.await
|
||||
.card_store
|
||||
.save_raw_card(split_data, peripherals.rtc.current_time_us())
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(error) => {
|
||||
log::error!("Error storing card in flash: {:?}", error)
|
||||
|
||||
+54
-33
@@ -7,6 +7,7 @@
|
||||
)]
|
||||
#![deny(clippy::large_stack_frames)]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use creaturedex::background_tasks;
|
||||
use creaturedex::drivers::i2c_bus::I2cBusPinConfiguration;
|
||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||
@@ -15,11 +16,14 @@ use creaturedex::drivers::spi_bus;
|
||||
use creaturedex::drivers::tertiary_lcd::{
|
||||
BOX, EMPTY, EXAMPLE, HEART, TertiaryDisplay, TertiaryDisplayPinConfiguration,
|
||||
};
|
||||
use creaturedex::navigation::navigation::Mutex;
|
||||
use creaturedex::navigation::inputs::Inputs;
|
||||
use creaturedex::navigation::navigation::{self};
|
||||
use creaturedex::navigation::outputs::Outputs;
|
||||
use creaturedex::storage::cardstore::CardStore;
|
||||
use creaturedex::storage::store::Store;
|
||||
use creaturedex::peripherals::Peripherals;
|
||||
use creaturedex::peripherals::storage::cardstore::CardStore;
|
||||
use creaturedex::peripherals::storage::flash_store::FlashStore;
|
||||
use creaturedex::peripherals::storage::store::Store;
|
||||
use embassy_executor::Spawner;
|
||||
use embedded_graphics::pixelcolor::BinaryColor;
|
||||
use embedded_graphics::{
|
||||
@@ -58,41 +62,44 @@ async fn main(spawner: Spawner) {
|
||||
creaturedex::logging::init();
|
||||
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
let esp_peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: HEAP_SIZE);
|
||||
|
||||
let sw_interrupt =
|
||||
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal::interrupt::software::SoftwareInterruptControl::new(esp_peripherals.SW_INTERRUPT);
|
||||
let timg0 = TimerGroup::new(esp_peripherals.TIMG0);
|
||||
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
||||
|
||||
let (primary, mut secondaries) = retry(
|
||||
5,
|
||||
spi_bus::DisplayPinConfiguration {
|
||||
spi_peripheral: peripherals.SPI2,
|
||||
sck: peripherals.GPIO36,
|
||||
mosi: peripherals.GPIO35,
|
||||
miso: peripherals.GPIO37,
|
||||
cs_primary: peripherals.GPIO11,
|
||||
cs_secondary_1: peripherals.GPIO13,
|
||||
cs_secondary_2: peripherals.GPIO14,
|
||||
cs_secondary_3: peripherals.GPIO21,
|
||||
reset_primary: peripherals.GPIO10,
|
||||
reset_secondary: peripherals.GPIO47,
|
||||
dc_pin: peripherals.GPIO12,
|
||||
spi_peripheral: esp_peripherals.SPI2,
|
||||
sck: esp_peripherals.GPIO36,
|
||||
mosi: esp_peripherals.GPIO35,
|
||||
miso: esp_peripherals.GPIO37,
|
||||
cs_primary: esp_peripherals.GPIO11,
|
||||
cs_secondary_1: esp_peripherals.GPIO13,
|
||||
cs_secondary_2: esp_peripherals.GPIO14,
|
||||
cs_secondary_3: esp_peripherals.GPIO21,
|
||||
reset_primary: esp_peripherals.GPIO10,
|
||||
reset_secondary: esp_peripherals.GPIO47,
|
||||
dc_pin: esp_peripherals.GPIO12,
|
||||
},
|
||||
spi_bus::DisplayPinConfiguration::build,
|
||||
);
|
||||
|
||||
// Initialize the shared I2C bus using the refactored i2c_bus module.
|
||||
let shared_i2c = {
|
||||
use alloc::boxed::Box;
|
||||
let bus = retry(5, I2cBusPinConfiguration {
|
||||
i2c_peripheral: peripherals.I2C0,
|
||||
scl: peripherals.GPIO18,
|
||||
sda: peripherals.GPIO17,
|
||||
}, I2cBusPinConfiguration::build);
|
||||
let bus = retry(
|
||||
5,
|
||||
I2cBusPinConfiguration {
|
||||
i2c_peripheral: esp_peripherals.I2C0,
|
||||
scl: esp_peripherals.GPIO18,
|
||||
sda: esp_peripherals.GPIO17,
|
||||
},
|
||||
I2cBusPinConfiguration::build,
|
||||
);
|
||||
Box::leak(Box::new(bus))
|
||||
};
|
||||
|
||||
@@ -113,12 +120,26 @@ async fn main(spawner: Spawner) {
|
||||
);
|
||||
}
|
||||
|
||||
let store = Store::new(peripherals.FLASH).expect("Could not initialize Flash Store");
|
||||
let cardstore = CardStore::new(store).expect("Could not initialize Card Store");
|
||||
let flash_store = Box::leak(Box::new(
|
||||
FlashStore::new(esp_peripherals.FLASH).expect("Could not initialize Flash Store"),
|
||||
));
|
||||
|
||||
let rtc = Rtc::new(peripherals.LPWR);
|
||||
let card_store = CardStore::new(flash_store)
|
||||
.await
|
||||
.expect("Could not initialize Card Store");
|
||||
|
||||
let store = Store {
|
||||
flash_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),
|
||||
rtc,
|
||||
}));
|
||||
|
||||
let mut nfc_driver = NfcPn532Driver::new(AtomicDevice::new(shared_i2c));
|
||||
if nfc_driver.configure_sam().await.is_ok() {
|
||||
log::info!("NFC SAM configuration successful on the shared I2C bus");
|
||||
@@ -128,12 +149,12 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let button_config = InputConfig::default().with_pull(Pull::Up);
|
||||
let inputs = Inputs {
|
||||
up: Input::new(peripherals.GPIO38, button_config),
|
||||
down: Input::new(peripherals.GPIO39, button_config),
|
||||
left: Input::new(peripherals.GPIO40, button_config),
|
||||
right: Input::new(peripherals.GPIO41, button_config),
|
||||
back: Input::new(peripherals.GPIO8, button_config),
|
||||
ok: Input::new(peripherals.GPIO0, button_config),
|
||||
up: Input::new(esp_peripherals.GPIO38, button_config),
|
||||
down: Input::new(esp_peripherals.GPIO39, button_config),
|
||||
left: Input::new(esp_peripherals.GPIO40, button_config),
|
||||
right: Input::new(esp_peripherals.GPIO41, button_config),
|
||||
back: Input::new(esp_peripherals.GPIO8, button_config),
|
||||
ok: Input::new(esp_peripherals.GPIO0, button_config),
|
||||
};
|
||||
|
||||
display_shit(&mut secondaries[0], "foo 1");
|
||||
@@ -153,9 +174,9 @@ async fn main(spawner: Spawner) {
|
||||
};
|
||||
|
||||
log::info!("Setup complete, entering main loop");
|
||||
spawner.spawn(navigation::run(inputs, outputs).expect("run task failed"));
|
||||
spawner.spawn(navigation::run(inputs, outputs, peripherals).expect("run task failed"));
|
||||
spawner.spawn(
|
||||
background_tasks::nfc_scanner(nfc_driver, cardstore, rtc).expect("nfc scanner task failed"),
|
||||
background_tasks::nfc_scanner(nfc_driver, peripherals).expect("nfc scanner task failed"),
|
||||
);
|
||||
core::future::pending::<()>().await
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@ pub mod drivers;
|
||||
pub mod logging;
|
||||
pub mod navigation;
|
||||
pub mod network;
|
||||
pub mod storage;
|
||||
pub mod peripherals;
|
||||
pub mod views;
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::navigation::inputs::ButtonAction;
|
||||
use crate::navigation::inputs::Inputs;
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::navigation::state::NavigationState;
|
||||
use crate::peripherals::Peripherals;
|
||||
use crate::views::view::View;
|
||||
|
||||
use embassy_futures::select::{Either, select};
|
||||
@@ -27,16 +28,25 @@ pub struct NewState {
|
||||
}
|
||||
|
||||
pub trait Navigable {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send;
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
peripherals: &Peripherals,
|
||||
) -> impl core::future::Future<Output = ()> + Send;
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send;
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn run(mut inputs: Inputs, mut outputs: Outputs) {
|
||||
pub async fn run(mut inputs: Inputs, mut outputs: Outputs, peripherals: &'static Peripherals) {
|
||||
log::info!("starting navigation");
|
||||
|
||||
let mut state = NavigationState::new();
|
||||
state.screens.last().unwrap().display(&mut outputs).await;
|
||||
state
|
||||
.screens
|
||||
.last()
|
||||
.unwrap()
|
||||
.display(&mut outputs, peripherals)
|
||||
.await;
|
||||
|
||||
loop {
|
||||
let selection = select(
|
||||
@@ -82,7 +92,12 @@ pub async fn run(mut inputs: Inputs, mut outputs: Outputs) {
|
||||
state.screens.push(new_state.view);
|
||||
|
||||
if action != Action::Timer || new_state.redraw {
|
||||
state.screens.last().unwrap().display(&mut outputs).await;
|
||||
state
|
||||
.screens
|
||||
.last()
|
||||
.unwrap()
|
||||
.display(&mut outputs, peripherals)
|
||||
.await;
|
||||
}
|
||||
|
||||
Timer::after(Duration::from_millis(DEBOUNCE_DURATION_MILLIS)).await;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
pub mod storage;
|
||||
|
||||
use crate::navigation::navigation::Mutex;
|
||||
use crate::peripherals::storage::store::Store;
|
||||
|
||||
use esp_hal::rtc_cntl::Rtc;
|
||||
|
||||
pub struct Peripherals {
|
||||
pub store: Mutex<Store>,
|
||||
pub rtc: Rtc<'static>,
|
||||
}
|
||||
@@ -27,5 +27,6 @@ const CARDSTORE_REGION: MemoryRegion = MemoryRegion::new(
|
||||
);
|
||||
|
||||
pub mod cardstore;
|
||||
pub mod flash_store;
|
||||
pub mod settings;
|
||||
pub mod store;
|
||||
@@ -6,9 +6,9 @@ use binary_serde::{BinarySerde, DeserializeError, Endianness};
|
||||
//use crate::card::model::Nfcraw_card;
|
||||
|
||||
use crate::card::model::RawCard;
|
||||
use crate::storage::store::{Store, StoreError};
|
||||
use crate::peripherals::storage::flash_store::{FlashStore, FlashStoreError};
|
||||
|
||||
use crate::storage::{CARDSTORE_REGION, MemoryRegion};
|
||||
use crate::peripherals::storage::{CARDSTORE_REGION, MemoryRegion};
|
||||
|
||||
const MAX_CARDS: usize = 20000;
|
||||
|
||||
@@ -65,13 +65,13 @@ impl AllocationTableEntry {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CardStoreError {
|
||||
Store(StoreError),
|
||||
Store(FlashStoreError),
|
||||
CorruptedEntry(DeserializeError),
|
||||
NoEntry,
|
||||
}
|
||||
|
||||
impl From<StoreError> for CardStoreError {
|
||||
fn from(error: StoreError) -> CardStoreError {
|
||||
impl From<FlashStoreError> for CardStoreError {
|
||||
fn from(error: FlashStoreError) -> CardStoreError {
|
||||
CardStoreError::Store(error)
|
||||
}
|
||||
}
|
||||
@@ -83,16 +83,16 @@ impl From<DeserializeError> for CardStoreError {
|
||||
}
|
||||
|
||||
pub struct CardStore {
|
||||
store: Store,
|
||||
store: &'static FlashStore,
|
||||
count: u32,
|
||||
pub allocation_table: BTreeMap<u32, AllocationTableEntry>,
|
||||
}
|
||||
|
||||
impl CardStore {
|
||||
pub fn new(mut store: Store) -> Result<Self, CardStoreError> {
|
||||
pub async fn new(store: &'static FlashStore) -> Result<Self, CardStoreError> {
|
||||
let mut count_bytes: [u8; COUNT_REGION.size] = [0; COUNT_REGION.size];
|
||||
|
||||
store.read(COUNT_REGION.offset, &mut count_bytes)?;
|
||||
store.read(COUNT_REGION.offset, &mut count_bytes).await?;
|
||||
|
||||
let count: u32 = u32::from_ne_bytes(count_bytes);
|
||||
|
||||
@@ -101,10 +101,12 @@ impl CardStore {
|
||||
let mut allocation_table_entries: Vec<u8> =
|
||||
Vec::with_capacity(AllocationTableEntry::SERIALIZED_SIZE * count as usize);
|
||||
|
||||
store.read(
|
||||
store
|
||||
.read(
|
||||
ALLOCATION_TABLE_REGION.offset,
|
||||
&mut allocation_table_entries,
|
||||
)?;
|
||||
)
|
||||
.await?;
|
||||
|
||||
let chunks =
|
||||
allocation_table_entries.into_chunks::<{ AllocationTableEntry::SERIALIZED_SIZE }>();
|
||||
@@ -123,14 +125,14 @@ impl CardStore {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_card_by_uuid(&mut self, uuid: u32) -> Result<RawCard, CardStoreError> {
|
||||
pub async fn get_card_by_uuid(&self, uuid: u32) -> Result<RawCard, CardStoreError> {
|
||||
let entry = self
|
||||
.allocation_table
|
||||
.get(&uuid)
|
||||
.ok_or(CardStoreError::NoEntry)?;
|
||||
|
||||
let mut raw_card: [u8; size_of::<RawCard>()] = [0; size_of::<RawCard>()];
|
||||
self.store.read(entry.offset, &mut raw_card)?;
|
||||
self.store.read(entry.offset, &mut raw_card).await?;
|
||||
|
||||
Ok(RawCard::binary_deserialize(
|
||||
raw_card.as_ref(),
|
||||
@@ -138,7 +140,7 @@ impl CardStore {
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn save_raw_card(
|
||||
pub async fn save_raw_card(
|
||||
&mut self,
|
||||
raw_card: RawCard,
|
||||
timestamp: u64,
|
||||
@@ -183,10 +185,12 @@ impl CardStore {
|
||||
log::debug!("writing RawCard to flash");
|
||||
let mut serialized_card: [u8; RawCard::SERIALIZED_SIZE] = [0; RawCard::SERIALIZED_SIZE];
|
||||
raw_card.binary_serialize(&mut serialized_card, Endianness::Little);
|
||||
self.store.write_erase(
|
||||
self.store
|
||||
.write_erase(
|
||||
CARDS_REGION.offset + entry.offset * RawCard::SERIALIZED_SIZE as u32,
|
||||
&mut serialized_card,
|
||||
)?;
|
||||
)
|
||||
.await?;
|
||||
} else {
|
||||
entry.last_read_date = timestamp;
|
||||
entry.read_count += 1;
|
||||
@@ -198,17 +202,20 @@ impl CardStore {
|
||||
let mut serialized_entry: [u8; AllocationTableEntry::SERIALIZED_SIZE] =
|
||||
[0; AllocationTableEntry::SERIALIZED_SIZE];
|
||||
entry.binary_serialize(&mut serialized_entry, Endianness::Little);
|
||||
self.store.write_erase(
|
||||
self.store
|
||||
.write_erase(
|
||||
ALLOCATION_TABLE_REGION.offset
|
||||
+ entry.offset * AllocationTableEntry::SERIALIZED_SIZE as u32,
|
||||
&mut serialized_entry,
|
||||
)?;
|
||||
)
|
||||
.await?;
|
||||
|
||||
self.count += 1;
|
||||
log::debug!("writing card count to flash");
|
||||
let mut serialized_count: [u8; 4] = self.count.to_le_bytes();
|
||||
self.store
|
||||
.write(COUNT_REGION.offset, serialized_count.as_mut_slice())?;
|
||||
.write(COUNT_REGION.offset, serialized_count.as_mut_slice())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
use crate::navigation::navigation::Mutex;
|
||||
use embedded_storage::nor_flash::NorFlash;
|
||||
use embedded_storage::nor_flash::ReadNorFlash;
|
||||
use esp_storage::{FlashStorage, FlashStorageError};
|
||||
|
||||
use crate::storage::MAGIC_REGION;
|
||||
use crate::peripherals::storage::MAGIC_REGION;
|
||||
|
||||
pub type StoreError = FlashStorageError;
|
||||
pub type FlashStoreError = FlashStorageError;
|
||||
|
||||
const FLASH_ADDR: u32 = 0x9000;
|
||||
|
||||
const INITIALIZATION_SIZE: usize = 0x1000;
|
||||
const FLASH_INITIALIZE_MAGIC: u32 = 0xde6de6de;
|
||||
|
||||
pub struct Store {
|
||||
pub storage: FlashStorage<'static>,
|
||||
pub struct FlashStore {
|
||||
pub storage: Mutex<FlashStorage<'static>>,
|
||||
}
|
||||
|
||||
impl Store {
|
||||
pub fn new(flash: esp_hal::peripherals::FLASH<'static>) -> Result<Self, StoreError> {
|
||||
impl FlashStore {
|
||||
pub fn new(flash: esp_hal::peripherals::FLASH<'static>) -> Result<Self, FlashStoreError> {
|
||||
let mut storage = FlashStorage::new(flash);
|
||||
|
||||
let mut magic: [u8; 4] = [0, 0, 0, 0];
|
||||
@@ -30,29 +31,31 @@ impl Store {
|
||||
Self::initialize_flash(&mut storage)?;
|
||||
}
|
||||
|
||||
Ok(Self { storage })
|
||||
Ok(Self {
|
||||
storage: Mutex::new(storage),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), StoreError> {
|
||||
self.storage.read(FLASH_ADDR + offset, bytes)
|
||||
pub async fn read(&self, offset: u32, bytes: &mut [u8]) -> Result<(), FlashStoreError> {
|
||||
self.storage.lock().await.read(FLASH_ADDR + offset, bytes)
|
||||
}
|
||||
|
||||
pub fn write(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), StoreError> {
|
||||
pub async fn write(&self, offset: u32, bytes: &mut [u8]) -> Result<(), FlashStoreError> {
|
||||
log::debug!("Writing {} bytes at offset 0x{offset:08x}", bytes.len());
|
||||
self.storage.write(FLASH_ADDR + offset, bytes)
|
||||
self.storage.lock().await.write(FLASH_ADDR + offset, bytes)
|
||||
}
|
||||
|
||||
pub fn write_erase(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), StoreError> {
|
||||
pub async fn write_erase(&self, offset: u32, bytes: &mut [u8]) -> Result<(), FlashStoreError> {
|
||||
log::debug!(
|
||||
"Erasing and Writing {} bytes at offset 0x{offset:08x}",
|
||||
bytes.len()
|
||||
);
|
||||
self.storage
|
||||
.erase(FLASH_ADDR + offset, FLASH_ADDR + bytes.len() as u32)?;
|
||||
self.storage.write(FLASH_ADDR + offset, bytes)
|
||||
let mut lock = self.storage.lock().await;
|
||||
lock.erase(FLASH_ADDR + offset, FLASH_ADDR + bytes.len() as u32)?;
|
||||
lock.write(FLASH_ADDR + offset, bytes)
|
||||
}
|
||||
|
||||
pub fn has_magic_bytes(storage: &mut FlashStorage) -> Result<bool, StoreError> {
|
||||
pub fn has_magic_bytes(storage: &mut FlashStorage) -> Result<bool, FlashStoreError> {
|
||||
let mut magic: [u8; 4] = [0, 0, 0, 0];
|
||||
storage.read(FLASH_ADDR + MAGIC_REGION.offset, &mut magic)?;
|
||||
log::debug!("Magic bytes are {magic:?}");
|
||||
@@ -60,7 +63,7 @@ impl Store {
|
||||
Ok(u32::from_ne_bytes(magic) == FLASH_INITIALIZE_MAGIC)
|
||||
}
|
||||
|
||||
pub fn initialize_flash(storage: &mut FlashStorage) -> Result<(), StoreError> {
|
||||
pub fn initialize_flash(storage: &mut FlashStorage) -> Result<(), FlashStoreError> {
|
||||
storage.erase(FLASH_ADDR, FLASH_ADDR + INITIALIZATION_SIZE as u32)?;
|
||||
let zeros: [u8; INITIALIZATION_SIZE] = [0; INITIALIZATION_SIZE];
|
||||
storage.write(FLASH_ADDR + MAGIC_REGION.end() as u32, &zeros)?;
|
||||
@@ -72,7 +75,7 @@ impl Store {
|
||||
if Self::has_magic_bytes(storage)? {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(StoreError::Other(FLASH_INITIALIZE_MAGIC as i32))
|
||||
Err(FlashStoreError::Other(FLASH_INITIALIZE_MAGIC as i32))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
use crate::peripherals::storage::cardstore::CardStore;
|
||||
use crate::peripherals::storage::flash_store::FlashStore;
|
||||
|
||||
pub struct Store {
|
||||
pub flash_store: &'static FlashStore,
|
||||
pub card_store: CardStore,
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::display::sprite::render_sprite_onto_ili9341;
|
||||
use crate::navigation::navigation::NewState;
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::peripherals::Peripherals;
|
||||
use alloc::format;
|
||||
use embedded_graphics::mono_font::MonoTextStyle;
|
||||
use embedded_graphics::mono_font::ascii::FONT_6X10;
|
||||
@@ -25,7 +26,11 @@ pub struct CardView {
|
||||
}
|
||||
|
||||
impl Navigable for CardView {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
_: &Peripherals,
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
async move {
|
||||
let display = &mut outputs.primary_display;
|
||||
display.clear(Rgb565::BLACK).unwrap();
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::navigation::navigation::Action;
|
||||
use crate::navigation::navigation::Navigable;
|
||||
use crate::navigation::navigation::NewState;
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::peripherals::Peripherals;
|
||||
use crate::views::view::View;
|
||||
use embedded_graphics::mono_font::MonoTextStyle;
|
||||
use embedded_graphics::mono_font::ascii::FONT_10X20;
|
||||
@@ -17,7 +18,11 @@ use embedded_graphics::prelude::Point;
|
||||
pub struct FlashInfoView {}
|
||||
|
||||
impl Navigable for FlashInfoView {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
peripherals: &Peripherals,
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
||||
Text::new("Flash Initialized: {:?}", Point::new(40, 40), style);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::peripherals::Peripherals;
|
||||
use core::future;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
@@ -22,7 +23,11 @@ pub struct JournalView {
|
||||
}
|
||||
|
||||
impl Navigable for JournalView {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
_: &Peripherals,
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
async move {
|
||||
outputs.primary_display.clear(Rgb565::BLACK).unwrap();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::peripherals::Peripherals;
|
||||
use alloc::vec;
|
||||
|
||||
use crate::card::model::Card;
|
||||
@@ -22,7 +23,11 @@ pub struct MainMenu {
|
||||
}
|
||||
|
||||
impl Navigable for MainMenu {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
_: &Peripherals
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
let display = &mut outputs.primary_display;
|
||||
display.clear(Rgb565::BLACK).unwrap();
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::peripherals::Peripherals;
|
||||
use embedded_graphics::Drawable;
|
||||
use embedded_graphics::draw_target::DrawTarget;
|
||||
use embedded_graphics::mono_font::MonoTextStyle;
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::navigation::inputs::ButtonAction;
|
||||
use crate::navigation::navigation::CARD_DATA;
|
||||
use crate::navigation::navigation::NewState;
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::peripherals::Peripherals;
|
||||
|
||||
use alloc::format;
|
||||
use embedded_graphics::Drawable;
|
||||
@@ -33,7 +34,11 @@ pub struct ScanMenu {
|
||||
}
|
||||
|
||||
impl Navigable for ScanMenu {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
_: &Peripherals
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
let display = &mut outputs.primary_display;
|
||||
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
||||
display.clear(Rgb565::BLACK).unwrap();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::navigation::navigation::{Action, Navigable, NewState};
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::peripherals::Peripherals;
|
||||
use crate::views::{flash_info_view::FlashInfoView, menu_item, view::View};
|
||||
|
||||
use crate::navigation::inputs::ButtonAction;
|
||||
@@ -16,7 +17,11 @@ pub struct SettingsMenu {
|
||||
}
|
||||
|
||||
impl Navigable for SettingsMenu {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
_: &Peripherals
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
let display = &mut outputs.primary_display;
|
||||
display.clear(Rgb565::BLACK).unwrap();
|
||||
menu_item::show(display, "System Inforation", 0, self.selected);
|
||||
|
||||
+14
-7
@@ -1,4 +1,5 @@
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::peripherals::Peripherals;
|
||||
use crate::views::card_view::CardView;
|
||||
use crate::views::{
|
||||
flash_info_view::FlashInfoView, journal_view::JournalView, main_menu::MainMenu,
|
||||
@@ -18,15 +19,21 @@ pub enum View {
|
||||
}
|
||||
|
||||
impl Navigable for View {
|
||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
||||
fn display(
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
peripherals: &Peripherals
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
async move {
|
||||
match self {
|
||||
View::Main(main_menu) => main_menu.display(outputs).await,
|
||||
View::Scan(scan_menu) => scan_menu.display(outputs).await,
|
||||
View::Settings(settings_menu) => settings_menu.display(outputs).await,
|
||||
View::Journal(journal_view) => journal_view.display(outputs).await,
|
||||
View::Card(card_view) => card_view.display(outputs).await,
|
||||
View::FlashInfo(flash_info_view) => flash_info_view.display(outputs).await,
|
||||
View::Main(main_menu) => main_menu.display(outputs, peripherals).await,
|
||||
View::Scan(scan_menu) => scan_menu.display(outputs, peripherals).await,
|
||||
View::Settings(settings_menu) => settings_menu.display(outputs, peripherals).await,
|
||||
View::Journal(journal_view) => journal_view.display(outputs, peripherals).await,
|
||||
View::Card(card_view) => card_view.display(outputs, peripherals).await,
|
||||
View::FlashInfo(flash_info_view) => {
|
||||
flash_info_view.display(outputs, peripherals).await
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user