Implemented tertiary LCD display

This commit is contained in:
2026-08-22 18:25:48 +02:00
parent b44ae59c8b
commit 07c5210d7b
7 changed files with 251 additions and 119 deletions
+26 -6
View File
@@ -11,14 +11,19 @@ use alloc::boxed::Box;
use creaturedex::card::decoder::split_nfc_hex;
use creaturedex::card::model::Card;
use creaturedex::display::primary_lcd::{PrimaryLcdDisplay, init_primary_lcd};
use creaturedex::display::tertiary_lcd::{init_tertiary_lcd, write_wrapped};
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
use creaturedex::navigation::inputs::Inputs;
use creaturedex::navigation::navigation::{self, CARD_DATA};
use creaturedex::network::wifi::setup_wifi;
use embassy_executor::Spawner;
use embedded_hal_bus::i2c::AtomicDevice;
use embedded_hal_bus::util::AtomicCell;
use esp_hal::Blocking;
use esp_hal::clock::CpuClock;
use esp_hal::gpio::{Input, InputConfig, Pull};
use esp_hal::timer::timg::TimerGroup;
use esp_hal::i2c::master::{Config as I2cConfig, I2c};
use log::error;
#[panic_handler]
@@ -63,14 +68,29 @@ async fn main(spawner: Spawner) {
peripherals.GPIO12, // shared dc
)));
setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
let config = I2cConfig::default().with_frequency(esp_hal::time::Rate::from_khz(20));
let i2c = match I2c::new(peripherals.I2C0, config) {
Ok(bus) => bus.with_sda(peripherals.GPIO17).with_scl(peripherals.GPIO18),
Err(e) => {
log::error!("Shared I2C bus initialization failed for GPIO17/GPIO18: {e:?}");
panic!("Shared I2C bus initialization failed");
}
};
let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c)));
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
let mut nfc_driver =
NfcPn532Driver::new(peripherals.I2C0, peripherals.GPIO17, peripherals.GPIO18);
let mut lcd = init_tertiary_lcd(AtomicDevice::new(shared_i2c));
if let Err(_) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") {
log::error!("Tertiary LCD startup text write failed over shared I2C bus; check the shared bus, wiring, and device responses");
}
// setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
let mut nfc_driver = NfcPn532Driver::new(AtomicDevice::new(shared_i2c));
if nfc_driver.configure_sam().await.is_ok() {
log::info!("NFC SAM configuration successful");
log::info!("NFC SAM configuration successful on the shared I2C bus");
} else {
log::error!("NFC SAM configuration failed");
log::error!("NFC SAM configuration failed on the shared I2C bus");
}
let button_config = InputConfig::default().with_pull(Pull::Up);
@@ -90,7 +110,7 @@ async fn main(spawner: Spawner) {
#[embassy_executor::task]
async fn nfc_driver_task(mut nfc_driver: NfcPn532Driver<'static>) {
async fn nfc_driver_task(mut nfc_driver: NfcPn532Driver<AtomicDevice<'static, I2c<'static, Blocking>>>) {
loop {
while CARD_DATA.lock().await.is_none() {
match nfc_driver.read_card_data().await {