#![no_std] #![no_main] #![deny( clippy::mem_forget, reason = "mem::forget is generally not safe to do with esp_hal types, especially those \ holding buffers for the duration of a data transfer." )] #![deny(clippy::large_stack_frames)] use creaturedex::card::mock::{MOCK_PAYLOAD, MOCK_PAYLOAD2}; use creaturedex::display::primary_lcd::init_primary_lcd; use creaturedex::display::views::card_view::render_nfc_payload; use creaturedex::drivers::nfc_pn532::NfcPn532Driver; use creaturedex::navigation::input::init_navigation_button; use creaturedex::navigation::state::NavigationState; use creaturedex::network::wifi::setup_wifi; use embassy_executor::Spawner; use embassy_time::Timer; use embedded_graphics::draw_target::DrawTarget; use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics::prelude::RgbColor; use esp_hal::time::Duration; use esp_hal::clock::CpuClock; use esp_hal::delay::Delay; use esp_hal::timer::timg::TimerGroup; use log::error; #[panic_handler] fn panic(panic_info: &core::panic::PanicInfo) -> ! { error!("{}", panic_info); loop {} } extern crate alloc; // This creates a default app-descriptor required by the esp-idf bootloader. // For more information see: esp_bootloader_esp_idf::esp_app_desc!(); #[allow( clippy::large_stack_frames, reason = "it's not unusual to allocate larger buffers etc. in main" )] #[esp_rtos::main] async fn main(spawner: Spawner) { esp_println::logger::init_logger_from_env(); let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); let peripherals = esp_hal::init(config); // The following GPIO pins are in use by some feature of the module and should not be used. let _ = peripherals.GPIO27; let _ = peripherals.GPIO28; let _ = peripherals.GPIO29; let _ = peripherals.GPIO30; let _ = peripherals.GPIO31; let _ = peripherals.GPIO32; let _ = peripherals.GPIO33; let _ = peripherals.GPIO34; esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 73744); let mut delay = Delay::new(); let button1 = init_navigation_button(peripherals.GPIO38); let timg0 = TimerGroup::new(peripherals.TIMG0); let sw_interrupt = esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0); let mut display = init_primary_lcd( peripherals.SPI2, peripherals.GPIO36, // sck peripherals.GPIO35, // mosi peripherals.GPIO37, // miso peripherals.GPIO11, // primary cs peripherals.GPIO10, // shared reset peripherals.GPIO12, // shared dc &mut delay, ); setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await; log::info!("Setup complete, entering main loop"); let mut nav_state = NavigationState::new(); let mut nfc_driver = NfcPn532Driver::new(peripherals.I2C0, peripherals.GPIO17, peripherals.GPIO18); let timeout = Duration::from_millis(1000); if nfc_driver.configure_sam(timeout).is_ok() { log::info!("NFC SAM configuration successful"); } else { log::error!("NFC SAM configuration failed"); } loop { if let Ok(card_data) = nfc_driver.read_card_data() { log::info!("NFC Card Read: {:?}", card_data); render_nfc_payload(&mut display, &card_data); } if button1.is_low() { log::info!("Button pressed!"); display.clear(Rgb565::BLACK).unwrap(); let payload = if nav_state.toggle_payload() { &MOCK_PAYLOAD } else { &MOCK_PAYLOAD2 }; render_nfc_payload(&mut display, payload); } Timer::after_millis(10).await; } }