add peripherals module which has shared state of all peripherals

This commit was merged in pull request #47.
This commit is contained in:
2026-08-29 17:57:08 +00:00
parent 282bcd163c
commit a31c818b37
18 changed files with 207 additions and 99 deletions
+10 -5
View File
@@ -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)