implement basic embassy framework
This commit is contained in:
+25
-35
@@ -11,7 +11,8 @@ 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::inputs::Inputs;
|
||||
use creaturedex::navigation::navigation;
|
||||
use creaturedex::navigation::state::NavigationState;
|
||||
use creaturedex::network::wifi::setup_wifi;
|
||||
use embassy_executor::Spawner;
|
||||
@@ -19,9 +20,10 @@ 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::gpio::{Input, InputConfig, Pull};
|
||||
use esp_hal::time::Duration;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use log::error;
|
||||
|
||||
@@ -33,6 +35,8 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! {
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
const HEAP_SIZE: usize = 73744;
|
||||
|
||||
// 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>
|
||||
esp_bootloader_esp_idf::esp_app_desc!();
|
||||
@@ -48,26 +52,15 @@ async fn main(spawner: Spawner) {
|
||||
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: HEAP_SIZE);
|
||||
|
||||
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);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
||||
|
||||
log::info!("Setup complete, entering main loop");
|
||||
|
||||
let mut display = init_primary_lcd(
|
||||
peripherals.SPI2,
|
||||
peripherals.GPIO36,
|
||||
@@ -76,7 +69,6 @@ async fn main(spawner: Spawner) {
|
||||
peripherals.GPIO11,
|
||||
peripherals.GPIO10,
|
||||
peripherals.GPIO12,
|
||||
&mut delay,
|
||||
);
|
||||
|
||||
setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
|
||||
@@ -85,7 +77,8 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
let mut nav_state = NavigationState::new();
|
||||
|
||||
let mut nfc_driver = NfcPn532Driver::new(peripherals.I2C0, peripherals.GPIO17, peripherals.GPIO18);
|
||||
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");
|
||||
@@ -93,22 +86,19 @@ async fn main(spawner: Spawner) {
|
||||
log::error!("NFC SAM configuration failed");
|
||||
}
|
||||
|
||||
loop {
|
||||
if let Ok(card_data) = nfc_driver.read_card_data() {
|
||||
log::info!("NFC Card Read: {:?}", card_data);
|
||||
}
|
||||
log::info!("Setup complete, entering main loop");
|
||||
|
||||
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
|
||||
};
|
||||
let mut nav_state = NavigationState::new();
|
||||
|
||||
render_nfc_payload(&mut display, payload);
|
||||
}
|
||||
Timer::after_millis(10).await;
|
||||
}
|
||||
let button_config = InputConfig::default().with_pull(Pull::Up);
|
||||
let mut inputs = Inputs {
|
||||
up: Input::new(peripherals.GPIO38, button_config.clone()),
|
||||
down: Input::new(peripherals.GPIO0, button_config.clone()),
|
||||
left: Input::new(peripherals.GPIO1, button_config.clone()),
|
||||
right: Input::new(peripherals.GPIO2, button_config.clone()),
|
||||
back: Input::new(peripherals.GPIO3, button_config.clone()),
|
||||
ok: Input::new(peripherals.GPIO4, button_config.clone()),
|
||||
};
|
||||
|
||||
spawner.spawn(navigation::run(inputs).expect("run task failed"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user