Compare commits
6
Commits
10dc9b1b83
...
rust-nfc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78fc70bd31
|
||
|
|
76dc34b115
|
||
|
|
c8ea94a3ca
|
||
|
|
744a844f75
|
||
|
|
302abd0a2d
|
||
|
|
b40e6fb9cc
|
+3
-3
@@ -1,5 +1,5 @@
|
||||
[target.xtensa-esp32s3-none-elf]
|
||||
runner = "espflash flash --monitor --chip esp32s3"
|
||||
[target.xtensa-esp32-none-elf]
|
||||
runner = "espflash flash --monitor --chip esp32"
|
||||
|
||||
[env]
|
||||
ESP_LOG="info"
|
||||
@@ -9,7 +9,7 @@ rustflags = [
|
||||
"-C", "link-arg=-nostartfiles",
|
||||
]
|
||||
|
||||
target = "xtensa-esp32s3-none-elf"
|
||||
target = "xtensa-esp32-none-elf"
|
||||
|
||||
[unstable]
|
||||
build-std = ["alloc", "core"]
|
||||
|
||||
Generated
+78
-94
@@ -97,6 +97,15 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b396d1f76d455557e1218ec8066ae14bba60b4b36ecd55577ba979f5db7ecaa"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "creaturedex"
|
||||
version = "0.1.0"
|
||||
@@ -116,6 +125,8 @@ dependencies = [
|
||||
"esp-rtos",
|
||||
"ili9341",
|
||||
"log",
|
||||
"ndef",
|
||||
"pn532",
|
||||
"smoltcp",
|
||||
]
|
||||
|
||||
@@ -245,6 +256,26 @@ 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"
|
||||
@@ -382,54 +413,6 @@ dependencies = [
|
||||
"heapless 0.9.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-time"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "592b0c143ec626e821d4d90da51a2bd91d559d6c442b7c74a47d368c9e23d97a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"critical-section",
|
||||
"document-features",
|
||||
"embassy-time-driver",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-time-driver"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ee71af1b3a0deaa53eaf2d39252f83504c853646e472400b763060389b9fcc9"
|
||||
dependencies = [
|
||||
"document-features",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-usb-driver"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa675c5f4349b6aa0fcffc4bf9b241f18cd11b97c1f8323273fb9a5449937fbd"
|
||||
dependencies = [
|
||||
"embedded-io-async 0.6.1",
|
||||
"embedded-io-async 0.7.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-usb-synopsys-otg"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb205e26d59e483e8c48f91f637ec217ec7e2cfb0b61d50482301b991b4ff431"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embassy-sync 0.8.0",
|
||||
"embassy-time",
|
||||
"embassy-usb-driver",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-can"
|
||||
version = "0.4.1"
|
||||
@@ -633,8 +616,6 @@ dependencies = [
|
||||
"embassy-embedded-hal",
|
||||
"embassy-futures",
|
||||
"embassy-sync 0.8.0",
|
||||
"embassy-usb-driver",
|
||||
"embassy-usb-synopsys-otg",
|
||||
"embedded-can",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
@@ -649,7 +630,6 @@ dependencies = [
|
||||
"esp-riscv-rt",
|
||||
"esp-rom-sys",
|
||||
"esp-sync",
|
||||
"esp-synopsys-usb-otg",
|
||||
"esp32",
|
||||
"esp32c2",
|
||||
"esp32c3",
|
||||
@@ -667,6 +647,8 @@ dependencies = [
|
||||
"rand_core 0.6.4",
|
||||
"rand_core 0.9.5",
|
||||
"riscv",
|
||||
"sha1",
|
||||
"sha2",
|
||||
"strum",
|
||||
"ufmt-write",
|
||||
"xtensa-lx",
|
||||
@@ -680,7 +662,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6aebfabb2c21bec45e575e4f6cb6bb7aa8e1b33e7ac45b5dffa0f9d33ff59105"
|
||||
dependencies = [
|
||||
"document-features",
|
||||
"object",
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -707,8 +688,8 @@ dependencies = [
|
||||
"esp-hal",
|
||||
"esp-metadata-generated",
|
||||
"esp-sync",
|
||||
"esp-wifi-sys-esp32s3",
|
||||
"esp32s3",
|
||||
"esp-wifi-sys-esp32",
|
||||
"esp32",
|
||||
"log",
|
||||
]
|
||||
|
||||
@@ -757,7 +738,7 @@ dependencies = [
|
||||
"esp-wifi-sys-esp32h2",
|
||||
"esp-wifi-sys-esp32s2",
|
||||
"esp-wifi-sys-esp32s3",
|
||||
"esp32s3",
|
||||
"esp32",
|
||||
"heapless 0.9.3",
|
||||
"instability",
|
||||
"log",
|
||||
@@ -799,7 +780,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"document-features",
|
||||
"esp-metadata-generated",
|
||||
"esp32s3",
|
||||
"esp32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -842,19 +823,6 @@ dependencies = [
|
||||
"xtensa-lx",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "esp-synopsys-usb-otg"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8938451cb19032f13365328ea66ab38c8d16deecdf322067442297110eb74468"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal 0.2.7",
|
||||
"ral-registers",
|
||||
"usb-device",
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "esp-wifi-sys-esp32"
|
||||
version = "0.2.0"
|
||||
@@ -1239,6 +1207,15 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||
|
||||
[[package]]
|
||||
name = "ndef"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"heapless 0.8.0",
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.4.2"
|
||||
@@ -1259,15 +1236,6 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.37.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
@@ -1280,6 +1248,16 @@ 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"
|
||||
@@ -1343,12 +1321,6 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ral-registers"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46b71a9d9206e8b46714c74255adcaea8b11e0350c1d8456165073c3f75fc81a"
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
@@ -1494,6 +1466,28 @@ dependencies = [
|
||||
"unsafe-libyaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smoltcp"
|
||||
version = "0.13.1"
|
||||
@@ -1691,16 +1685,6 @@ version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
||||
|
||||
[[package]]
|
||||
name = "usb-device"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6"
|
||||
dependencies = [
|
||||
"heapless 0.8.0",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.3"
|
||||
|
||||
+7
-5
@@ -9,25 +9,25 @@ name = "creaturedex"
|
||||
path = "./src/bin/main.rs"
|
||||
|
||||
[dependencies]
|
||||
esp-hal = { version = "~1.1.0", features = ["esp32s3", "log-04", "unstable"] }
|
||||
esp-hal = { version = "~1.1.0", features = ["esp32", "log-04", "unstable"] }
|
||||
|
||||
esp-rtos = { version = "0.3.0", features = [
|
||||
"esp-alloc",
|
||||
"esp-radio",
|
||||
"esp32s3",
|
||||
"esp32",
|
||||
"log-04",
|
||||
] }
|
||||
|
||||
esp-bootloader-esp-idf = { version = "0.5.0", features = ["esp32s3", "log-04"] }
|
||||
esp-bootloader-esp-idf = { version = "0.5.0", features = ["esp32", "log-04"] }
|
||||
log = "0.4.27"
|
||||
|
||||
critical-section = "1.2.0"
|
||||
embedded-io = "0.7.1"
|
||||
esp-alloc = "0.10.0"
|
||||
esp-println = { version = "0.17.0", features = ["esp32s3", "log-04"] }
|
||||
esp-println = { version = "0.17.0", features = ["esp32", "log-04"] }
|
||||
esp-radio = { version = "0.18.0", features = [
|
||||
"esp-alloc",
|
||||
"esp32s3",
|
||||
"esp32",
|
||||
"log-04",
|
||||
"unstable",
|
||||
"wifi",
|
||||
@@ -51,6 +51,8 @@ embedded-hal = "1.0.0"
|
||||
embedded-hal-bus = "0.3.0"
|
||||
embedded-graphics = "0.8.2"
|
||||
embedded-graphics-core = "0.4.1"
|
||||
pn532 = "0.5.0"
|
||||
ndef = { version = "0.5.0", path = "./ndef-rs" }
|
||||
|
||||
|
||||
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}:
|
||||
let
|
||||
host-triple = "x86_64-unknown-linux-gnu";
|
||||
gcc-arch = "xtensa-esp-elf";
|
||||
gcc-release = "16.1.0_20260609";
|
||||
toolchain-pkg = pkgs.stdenv.mkDerivation rec {
|
||||
pname = "esp32-xtensa-rust-toolchain";
|
||||
version = "1.97.0.0";
|
||||
srcs = [
|
||||
(pkgs.fetchurl {
|
||||
url = "https://github.com/esp-rs/rust-build/releases/download/v${version}/rust-${version}-${host-triple}.tar.xz";
|
||||
hash = "sha256-qZv+5pIh6f9thjiPaBHuaIzUBeagQAo80XhOjUY+nZk=";
|
||||
})
|
||||
(pkgs.fetchurl {
|
||||
url =
|
||||
let
|
||||
gcc-file = "${gcc-arch}-${gcc-release}-x86_64-linux-gnu.tar.xz";
|
||||
in
|
||||
"https://github.com/espressif/crosstool-NG/releases/download/esp-${gcc-release}/${gcc-file}";
|
||||
hash = "sha256-9wh1Lrs1yrIfGEsldBFO0Rh2GdsO24pLqRPAbKL6Z14=";
|
||||
})
|
||||
(pkgs.fetchurl {
|
||||
url = "https://github.com/esp-rs/rust-build/releases/download/v${version}/rust-src-${version}.tar.xz";
|
||||
hash = "sha256-Vo1oi5+PMy7E0EZXVE+tI+mc4R6ebPWDWXnmiijGi3M=";
|
||||
})
|
||||
# TODO maybe I need clang but so far it works without https://github.com/esp-rs/espup/blob/main/src/toolchain/llvm.rs
|
||||
];
|
||||
sourceRoot = ".";
|
||||
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
|
||||
buildInputs = [
|
||||
pkgs.zlib
|
||||
pkgs.stdenv.cc.cc.lib
|
||||
];
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
patchShebangs --build rust-nightly-x86_64-unknown-linux-gnu/install.sh rust-src-nightly/install.sh
|
||||
|
||||
rust-nightly-x86_64-unknown-linux-gnu/install.sh --destdir="$out" --prefix="" --without=rust-docs-json-preview,rust-docs --disable-ldconfig
|
||||
rust-src-nightly/install.sh --destdir="$out" --prefix="" --disable-ldconfig
|
||||
|
||||
cp -pr --reflink=auto -- xtensa-esp-elf "$out";
|
||||
# ensure linker is in PATH
|
||||
ln -s $out/xtensa-esp-elf/bin/* "$out/bin/"
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
in
|
||||
(pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
espflash
|
||||
toolchain-pkg
|
||||
];
|
||||
})
|
||||
+176
-26
@@ -7,6 +7,9 @@
|
||||
)]
|
||||
#![deny(clippy::large_stack_frames)]
|
||||
|
||||
use core::convert::Infallible;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use display_interface_spi::SPIInterface;
|
||||
use embedded_graphics::Drawable;
|
||||
use embedded_graphics::mono_font::MonoTextStyle;
|
||||
@@ -27,12 +30,14 @@ use esp_hal::spi::{
|
||||
Mode,
|
||||
master::{Config, Spi},
|
||||
};
|
||||
use esp_hal::time::Rate;
|
||||
use esp_hal::time::{Duration, Instant};
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use esp_println::dbg;
|
||||
use ili9341::Ili9341;
|
||||
use ili9341::Orientation;
|
||||
use log::{error, info};
|
||||
use pn532::i2c::I2CInterface;
|
||||
use pn532::nb;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(panic_info: &core::panic::PanicInfo) -> ! {
|
||||
@@ -60,24 +65,15 @@ fn main() -> ! {
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
// The following pins are used to bootstrap the chip. They are available
|
||||
// for use, but check the datasheet of the module for more information on them.
|
||||
// - GPIO0
|
||||
// - GPIO3
|
||||
// - GPIO45
|
||||
// - GPIO46
|
||||
// These 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 _ = peripherals.GPIO35;
|
||||
let _ = peripherals.GPIO36;
|
||||
let _ = peripherals.GPIO37;
|
||||
let sck = peripherals.GPIO18;
|
||||
let mosi = peripherals.GPIO23;
|
||||
let miso = peripherals.GPIO19;
|
||||
let cs_main = peripherals.GPIO5;
|
||||
let dc = peripherals.GPIO17;
|
||||
let reset_main = peripherals.GPIO16;
|
||||
|
||||
let sda = peripherals.GPIO21;
|
||||
let scl = peripherals.GPIO22;
|
||||
|
||||
esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 73744);
|
||||
|
||||
@@ -96,16 +92,16 @@ fn main() -> ! {
|
||||
.with_mode(Mode::_0),
|
||||
)
|
||||
.unwrap()
|
||||
.with_sck(peripherals.GPIO36)
|
||||
.with_mosi(peripherals.GPIO35)
|
||||
.with_miso(peripherals.GPIO37);
|
||||
.with_sck(sck)
|
||||
.with_mosi(mosi)
|
||||
.with_miso(miso);
|
||||
|
||||
let cs_main = Output::new(peripherals.GPIO11, Level::High, OutputConfig::default());
|
||||
let cs_main = Output::new(cs_main, Level::High, OutputConfig::default());
|
||||
|
||||
let mut delay = Delay::new();
|
||||
let spi_dev = ExclusiveDevice::new(spi_bus, cs_main, delay).unwrap();
|
||||
let reset_main = Output::new(peripherals.GPIO10, Level::High, OutputConfig::default());
|
||||
let spi_dc = Output::new(peripherals.GPIO12, Level::High, OutputConfig::default());
|
||||
let reset_main = Output::new(reset_main, Level::High, OutputConfig::default());
|
||||
let spi_dc = Output::new(dc, Level::High, OutputConfig::default());
|
||||
let iface = SPIInterface::new(spi_dev, spi_dc);
|
||||
|
||||
let mut display = Ili9341::new(
|
||||
@@ -117,18 +113,172 @@ fn main() -> ! {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
display.clear(Rgb565::BLACK).unwrap();
|
||||
// display.clear(Rgb565::BLACK).unwrap();
|
||||
|
||||
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
||||
Text::new("Hello, ESP32!", Point::new(20, 100), style)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
use pn532::{Pn532, Request, requests::SAMMode};
|
||||
|
||||
// spi is a struct implementing embedded_hal::spi::SpiDevice
|
||||
// timer is a struct implementing pn532::CountDown
|
||||
|
||||
use esp_hal::{
|
||||
i2c::master::{Config as I2cConfig, I2c},
|
||||
time::Rate,
|
||||
};
|
||||
|
||||
let config = I2cConfig::default().with_frequency(Rate::from_khz(20));
|
||||
let i2c = I2c::new(peripherals.I2C0, config)
|
||||
.expect("Failed to init I2C")
|
||||
.with_sda(sda)
|
||||
.with_scl(scl);
|
||||
|
||||
let mut pn532: Pn532<_, _, 32> = Pn532::new(I2CInterface { i2c }, TimerWrapper::new());
|
||||
|
||||
let ms_50 = Duration::from_millis(50);
|
||||
let ms_1000 = Duration::from_millis(1000);
|
||||
|
||||
let delay_start = Instant::now();
|
||||
while delay_start.elapsed() < Duration::from_millis(500) {}
|
||||
|
||||
let mut data: Vec<u8> = Vec::with_capacity(858);
|
||||
|
||||
if let Err(e) = pn532.process(
|
||||
&Request::sam_configuration(SAMMode::Normal, false),
|
||||
0,
|
||||
Duration::from_millis(5000),
|
||||
) {
|
||||
error!("Could not initialize PN532: {e:?}")
|
||||
} else {
|
||||
info!("Successfully init'ed PN532");
|
||||
}
|
||||
|
||||
loop {
|
||||
info!("Hello world!");
|
||||
|
||||
match pn532.process(
|
||||
&Request::INLIST_ONE_ISO_A_TARGET,
|
||||
23,
|
||||
Duration::from_secs(10),
|
||||
) {
|
||||
Ok(uid) => {
|
||||
info!("uid = {uid:?}");
|
||||
for i in (0x04..=230) {
|
||||
let mut parse_result = Err(());
|
||||
while parse_result.is_err() {
|
||||
let Ok(result) = pn532.process(&Request::ntag_read(i), 17, ms_1000) else {
|
||||
continue;
|
||||
};
|
||||
parse_result = parse_nfc(i, result);
|
||||
}
|
||||
let bytes = parse_result.unwrap();
|
||||
data.extend(bytes);
|
||||
}
|
||||
info!("Full data: {data:02x?}");
|
||||
match ndef::Message::try_from(&data[4..4 + 883]) {
|
||||
Ok(m) => info!("Parsed: {m:02x?}"),
|
||||
Err(e) => info!("Failed to parse: {e:?}"),
|
||||
}
|
||||
data.clear();
|
||||
}
|
||||
Err(e) => {
|
||||
info!("No NFC card found: {e:?}");
|
||||
}
|
||||
}
|
||||
|
||||
let delay_start = Instant::now();
|
||||
while delay_start.elapsed() < Duration::from_millis(500) {}
|
||||
}
|
||||
|
||||
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples
|
||||
}
|
||||
|
||||
fn parse_nfc(iteration: u8, bytes: &[u8]) -> Result<[u8; 4], ()> {
|
||||
let success = bytes.first().is_some_and(|x| *x == 0);
|
||||
if success {
|
||||
// info!("page {i}: {:02x?}", result);
|
||||
let mut arr = [0; 4];
|
||||
arr.copy_from_slice(&bytes[1..5]);
|
||||
Ok(arr)
|
||||
} else {
|
||||
info!("err {iteration}: {:02x?}", bytes);
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
struct TimerWrapper {
|
||||
// TODO Is that timer accurate enough?
|
||||
start: Instant,
|
||||
duration: Duration,
|
||||
counter: u32,
|
||||
}
|
||||
|
||||
impl TimerWrapper {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
start: Instant::now(),
|
||||
duration: Duration::ZERO,
|
||||
counter: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl pn532::CountDown for TimerWrapper {
|
||||
type Time = Duration;
|
||||
|
||||
fn start<T>(&mut self, timeout: T)
|
||||
where
|
||||
T: Into<Self::Time>,
|
||||
{
|
||||
// without this debug log, it works worse: stuck in NFC card search without ever returning.
|
||||
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 self.counter.is_multiple_of(1) {
|
||||
// info!("Elapsed: {elapsed}");
|
||||
}
|
||||
if elapsed >= self.duration {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(nb::Error::WouldBlock)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
struct TimerWrapper<'a, T>
|
||||
where
|
||||
T: esp_hal::DriverMode,
|
||||
{
|
||||
timer: esp_hal::timer::PeriodicTimer<'a, T>,
|
||||
}
|
||||
|
||||
impl<'a, TIM> pn532::CountDown for TimerWrapper<'a, TIM>
|
||||
where
|
||||
TIM: esp_hal::DriverMode,
|
||||
{
|
||||
type Time = Duration;
|
||||
fn start<T>(&mut self, timeout: T)
|
||||
where
|
||||
T: Into<Self::Time>,
|
||||
{
|
||||
self.timer.start(timeout.into()).unwrap();
|
||||
}
|
||||
|
||||
fn wait(&mut self) -> nb::Result<(), Infallible> {
|
||||
// convert nb::Result<(), void::Void> to nb::Result<(), Infallible>
|
||||
match self.timer.wait() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(nb::Error::WouldBlock),
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
[wokwi]
|
||||
version = 1
|
||||
gdbServerPort = 3333
|
||||
elf = "target/xtensa-esp32s3-none-elf/debug/creaturedex"
|
||||
firmware = "target/xtensa-esp32s3-none-elf/debug/creaturedex"
|
||||
elf = "target/xtensa-esp32-none-elf/debug/creaturedex"
|
||||
firmware = "target/xtensa-esp32-none-elf/debug/creaturedex"
|
||||
|
||||
Reference in New Issue
Block a user