#![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::shared_bus::init_dual_displays; 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::{BinaryColor, Rgb565}; use embedded_graphics::prelude::RgbColor; use embedded_graphics::{ mono_font::{MonoTextStyle, ascii::FONT_6X10}, prelude::*, text::Text, }; use esp_hal::clock::CpuClock; use esp_hal::delay::Delay; use esp_hal::time::Duration; 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, mut oled) = init_dual_displays( peripherals.SPI2, peripherals.GPIO36, // sck peripherals.GPIO35, // mosi peripherals.GPIO37, // miso peripherals.GPIO11, // primary cs peripherals.GPIO13, // oled cs peripherals.GPIO10, // shared reset peripherals.GPIO12, // shared dc &mut delay, ); setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await; let mut nav_state = NavigationState::new(); oled.clear(BinaryColor::Off).unwrap(); let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); Text::new("Hello OLED", Point::new(10, 20), text_style) .draw(&mut oled) .unwrap(); oled.flush().unwrap(); let text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE); display.clear_screen(0).unwrap(); Text::new("Hello OLED", Point::new(10, 20), text_style).draw(&mut display).unwrap(); 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 { Timer::after_millis(10).await; } }