Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f960b2d46 |
Generated
+8
-52
@@ -306,7 +306,6 @@ dependencies = [
|
||||
"critical-section",
|
||||
"display-interface-spi",
|
||||
"embassy-executor",
|
||||
"embassy-futures",
|
||||
"embassy-time",
|
||||
"embedded-graphics",
|
||||
"embedded-graphics-core",
|
||||
@@ -321,8 +320,6 @@ dependencies = [
|
||||
"esp-rtos",
|
||||
"ili9341",
|
||||
"log",
|
||||
"ndef",
|
||||
"pn532",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -571,26 +568,6 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05"
|
||||
dependencies = [
|
||||
"derive_more-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more-impl"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
@@ -1531,27 +1508,27 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.34"
|
||||
version = "0.3.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
||||
checksum = "2cd50c473c80f6d7c3670a752354b8e569b1a7cbfdc0419ec88e5edad85e0dc7"
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.34"
|
||||
version = "0.3.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"
|
||||
checksum = "e34418ac499d6305c2fb5ad0ed2f6ac998c5f8ca209b4510f7f94242c647e307"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.34"
|
||||
version = "0.3.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
|
||||
checksum = "b231ed28831efb4a61a08580c4bc233ec56bc009f4cd8f52da2c3cb97df0c109"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.34"
|
||||
version = "0.3.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
||||
checksum = "a77a90a256fce34da66415271e30f94ee91c57b04b8a2c042d9cf3220179deaa"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
@@ -2003,17 +1980,6 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||
|
||||
[[package]]
|
||||
name = "ndef"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39081400340c14a9fcbb0122c311aca4e34ec2d19e3136613638ae7e2a362dbc"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"heapless 0.8.0",
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nonmax"
|
||||
version = "0.5.5"
|
||||
@@ -2618,16 +2584,6 @@ version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||
|
||||
[[package]]
|
||||
name = "pn532"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce656b2f9335bedbd8806597f6f78e644a955366673cd9280a0fb67a0d7b35a1"
|
||||
dependencies = [
|
||||
"embedded-hal 1.0.0",
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.14.0"
|
||||
|
||||
@@ -27,7 +27,6 @@ embedded-io = "0.7.1"
|
||||
embassy-executor = { version = "0.10.0", features = [
|
||||
] }
|
||||
embassy-time = { version = "0.5.1", default-features = false }
|
||||
embassy-futures = "0.1.2"
|
||||
esp-alloc = "0.10.0"
|
||||
esp-hal-wifimanager = { git = "https://github.com/InvisibleUSA/esp-hal-wifimanager", default-features = false, features = [
|
||||
"ap",
|
||||
@@ -41,8 +40,6 @@ embedded-hal-bus = "0.3.0"
|
||||
embedded-graphics = "0.8.2"
|
||||
embedded-graphics-core = "0.4.1"
|
||||
base64 = { version = "0.22", default-features = false, features = ["alloc"] }
|
||||
pn532 = "0.5.0"
|
||||
ndef = "0.5.0"
|
||||
|
||||
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
|
||||
[profile.dev]
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
[ "lcd1:MOSI", "esp1:35", "violet", [ "v105.6", "h-124.8", "v-144" ] ],
|
||||
[ "lcd1:SCK", "esp1:36", "white", [ "v115.2", "h-144", "v-86.4" ] ],
|
||||
[ "esp1:37", "lcd1:MISO", "magenta", [ "h57.6", "v105.6", "h172.8" ] ],
|
||||
[ "esp1:22", "lcd1:SCL", "yellow", [ "h48", "v163.2", "h192" ] ],
|
||||
[ "esp1:21", "lcd1:SDA", "cyan", [ "h38.4", "v144", "h211.2" ] ],
|
||||
[ "btn1:1.l", "esp1:GND.2", "green", [ "h-9.6", "v-48" ] ],
|
||||
[ "btn1:2.l", "esp1:38", "green", [ "h-9.6", "v19.4" ] ]
|
||||
],
|
||||
|
||||
+32
-50
@@ -7,23 +7,15 @@
|
||||
)]
|
||||
#![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::inputs::Inputs;
|
||||
use creaturedex::navigation::navigation;
|
||||
use creaturedex::navigation::navigation::inputs::Inputs;
|
||||
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::clock::ClockControl;
|
||||
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::peripherals::Peripherals;
|
||||
use esp_hal::system::SystemControl;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use log::error;
|
||||
|
||||
@@ -45,22 +37,40 @@ esp_bootloader_esp_idf::esp_app_desc!();
|
||||
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();
|
||||
|
||||
fn init() -> Peripherals {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: HEAP_SIZE);
|
||||
|
||||
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);
|
||||
let system = SystemControl::new(peripherals.SYSTEM);
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks).timer0;
|
||||
embassy::init(&clocks, timg0);
|
||||
|
||||
log::info!("Setup complete, entering main loop");
|
||||
|
||||
peripherals
|
||||
}
|
||||
|
||||
#[embassy_executor::main(executor = "esp_rtos::embassy::Executor")]
|
||||
async fn main(spawner: embassy_executor::Spawner) {
|
||||
let peripherals = init();
|
||||
|
||||
// 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;
|
||||
|
||||
let mut nav_state = NavigationState::new();
|
||||
|
||||
let mut display = init_primary_lcd(
|
||||
peripherals.SPI2,
|
||||
peripherals.GPIO36,
|
||||
@@ -71,34 +81,6 @@ async fn main(spawner: Spawner) {
|
||||
peripherals.GPIO12,
|
||||
);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
log::info!("Setup complete, entering main loop");
|
||||
|
||||
let mut nav_state = NavigationState::new();
|
||||
|
||||
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"));
|
||||
let mut inputs = Inputs::new(peripherals);
|
||||
spawner.spawn(navigation::run(inputs).await.expect("run task failed"));
|
||||
}
|
||||
|
||||
+1
-146
@@ -1,146 +1 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::convert::Infallible;
|
||||
use esp_hal::gpio::interconnect::{PeripheralInput, PeripheralOutput};
|
||||
use esp_hal::i2c::master::{Config as I2cConfig, I2c};
|
||||
use esp_hal::peripherals::I2C0;
|
||||
use esp_hal::time::{Duration, Instant, Rate};
|
||||
use log::{error, info};
|
||||
use pn532::i2c::I2CInterface;
|
||||
use pn532::requests::SAMMode;
|
||||
use pn532::{nb, Pn532, Request};
|
||||
|
||||
/// Timer implementation required by `pn532::CountDown`.
|
||||
pub struct TimerWrapper {
|
||||
start: Instant,
|
||||
duration: Duration,
|
||||
counter: u32,
|
||||
}
|
||||
|
||||
impl TimerWrapper {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
start: Instant::now(),
|
||||
duration: Duration::ZERO,
|
||||
counter: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TimerWrapper {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl pn532::CountDown for TimerWrapper {
|
||||
type Time = Duration;
|
||||
|
||||
fn start<T>(&mut self, timeout: T)
|
||||
where
|
||||
T: Into<Self::Time>,
|
||||
{
|
||||
self.start = Instant::now();
|
||||
self.duration = timeout.into();
|
||||
self.counter = 0;
|
||||
}
|
||||
|
||||
fn wait(&mut self) -> nb::Result<(), Infallible> {
|
||||
let elapsed = self.start.elapsed();
|
||||
self.counter += 1;
|
||||
if elapsed >= self.duration {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(nb::Error::WouldBlock)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Pn532Device<'a> = Pn532<I2CInterface<I2c<'a, esp_hal::Blocking>>, TimerWrapper, 32>;
|
||||
|
||||
/// PN532 NFC reader driver.
|
||||
pub struct NfcPn532Driver<'a> {
|
||||
pn532: Pn532Device<'a>,
|
||||
}
|
||||
|
||||
impl<'a> NfcPn532Driver<'a> {
|
||||
pub fn new<SDA, SCL>(i2c0: I2C0<'static>, sda: SDA, scl: SCL) -> Self
|
||||
where
|
||||
SDA: PeripheralInput<'static> + PeripheralOutput<'static>,
|
||||
SCL: PeripheralInput<'static> + PeripheralOutput<'static>,
|
||||
{
|
||||
let config = I2cConfig::default().with_frequency(Rate::from_khz(20));
|
||||
let i2c = I2c::new(i2c0, config)
|
||||
.expect("Failed to init I2C")
|
||||
.with_sda(sda)
|
||||
.with_scl(scl);
|
||||
|
||||
let pn532 = Pn532::new(I2CInterface { i2c }, TimerWrapper::new());
|
||||
Self { pn532 }
|
||||
}
|
||||
|
||||
pub fn configure_sam(&mut self, timeout: Duration) -> Result<(), ()> {
|
||||
if let Err(e) = self.pn532.process(
|
||||
&Request::sam_configuration(SAMMode::Normal, false),
|
||||
0,
|
||||
timeout,
|
||||
) {
|
||||
error!("Could not initialize PN532: {e:?}");
|
||||
Err(())
|
||||
} else {
|
||||
info!("Successfully init'ed PN532");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_target(&mut self, timeout: Duration) -> Result<(), ()> {
|
||||
match self.pn532.process(&Request::INLIST_ONE_ISO_A_TARGET, 23, timeout) {
|
||||
Ok(uid) => {
|
||||
info!("uid = {uid:?}");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
info!("No NFC card found: {e:?}");
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_nfc_page(iteration: u8, bytes: &[u8]) -> Result<[u8; 4], ()> {
|
||||
let success = bytes.first().is_some_and(|x| *x == 0);
|
||||
if success {
|
||||
let mut arr = [0; 4];
|
||||
arr.copy_from_slice(&bytes[1..5]);
|
||||
Ok(arr)
|
||||
} else {
|
||||
info!("err {iteration}: {:02x?}", bytes);
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_card_data(&mut self) -> Result<Vec<u8>, ()> {
|
||||
let ms_1000 = Duration::from_millis(1000);
|
||||
self.poll_target(Duration::from_secs(10))?;
|
||||
|
||||
let mut data: Vec<u8> = Vec::with_capacity(858);
|
||||
|
||||
for i in 0x04..=230 {
|
||||
let mut parse_result = Err(());
|
||||
while parse_result.is_err() {
|
||||
let Ok(result) = self.pn532.process(&Request::ntag_read(i), 17, ms_1000) else {
|
||||
continue;
|
||||
};
|
||||
parse_result = Self::parse_nfc_page(i, result);
|
||||
}
|
||||
let bytes = parse_result.unwrap();
|
||||
data.extend(bytes);
|
||||
}
|
||||
|
||||
info!("Full data: {data:02x?}");
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
pub fn device_mut(&mut self) -> &mut Pn532Device<'a> {
|
||||
&mut self.pn532
|
||||
}
|
||||
}
|
||||
|
||||
// Drivers nfc_pn532 module
|
||||
|
||||
@@ -10,10 +10,24 @@ pub enum NavCommand {
|
||||
}
|
||||
|
||||
pub struct Inputs {
|
||||
pub up: Input<'static>,
|
||||
pub down: Input<'static>,
|
||||
pub left: Input<'static>,
|
||||
pub right: Input<'static>,
|
||||
pub back: Input<'static>,
|
||||
pub ok: Input<'static>,
|
||||
up: Input<'static>,
|
||||
down: Input<'static>,
|
||||
left: Input<'static>,
|
||||
right: Input<'static>,
|
||||
back: Input<'static>,
|
||||
ok: Input<'static>,
|
||||
}
|
||||
|
||||
impl Inputs {
|
||||
pub fn new(peripherals: Peripherals) -> Self {
|
||||
let button_config = InputConfig::default().with_pull(Pull::Up);
|
||||
Self {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
use crate::navigation::inputs::Inputs;
|
||||
|
||||
pub const MAX_SELECTED: i8 = 3;
|
||||
|
||||
pub struct MainMenu {
|
||||
pub selected: i8,
|
||||
}
|
||||
|
||||
impl MainMenu {
|
||||
pub async fn display(self: &Self) {}
|
||||
}
|
||||
pub async fn show(_inputs: &mut Inputs) {}
|
||||
|
||||
@@ -1,35 +1,9 @@
|
||||
use crate::navigation::inputs::Inputs;
|
||||
use crate::navigation::main_menu::{MAX_SELECTED, MainMenu};
|
||||
|
||||
use embassy_futures::select::Either6;
|
||||
use embassy_futures::select::select6;
|
||||
|
||||
#[embassy_executor::task]
|
||||
//pub async fn run() -> Result<Infallible> {
|
||||
pub async fn run(mut inputs: Inputs) {
|
||||
let mut state = MainMenu { selected: 0 };
|
||||
|
||||
loop {
|
||||
let selection = select6(
|
||||
inputs.up.wait_for_low(),
|
||||
inputs.down.wait_for_low(),
|
||||
inputs.left.wait_for_low(),
|
||||
inputs.right.wait_for_low(),
|
||||
inputs.ok.wait_for_low(),
|
||||
inputs.back.wait_for_low(),
|
||||
)
|
||||
.await;
|
||||
|
||||
let value = match selection {
|
||||
Either6::First(_) => (state.selected.wrapping_sub(1)) % MAX_SELECTED,
|
||||
Either6::Second(_) => (state.selected.wrapping_add(1)) % MAX_SELECTED,
|
||||
_ => continue, // Either6::Third(_) => ,
|
||||
// Either6::Fourth(_) => (),
|
||||
// Either6::Fifth(_) => (),
|
||||
// Either6::Sixth(_) => (),
|
||||
};
|
||||
|
||||
state.selected = value;
|
||||
|
||||
state.display().await
|
||||
crate::navigation::main_menu::show(&mut inputs).await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user