Add card detection

This commit is contained in:
2026-08-26 00:08:47 +08:00
parent 5c95cc40f7
commit 261b04fec3
69 changed files with 2178 additions and 5928 deletions
+59
View File
@@ -0,0 +1,59 @@
#![no_std]
#![forbid(unsafe_code)]
//! A `no_std` [`embedded-hal`] driver for the NXP PN532 NFC controller over I2C.
//!
//! This crate is a Rust port of the well-known
//! [Adafruit/Seeed PN532 Arduino library](https://github.com/elechouse/PN532),
//! targeting the I2C interface (the most common breakout-board wiring).
//!
//! The driver is transport-agnostic via the [`Interface`] trait; [`I2cInterface`]
//! provides the I2C implementation on top of a blocking `embedded_hal::i2c::I2c`
//! bus plus a `embedded_hal::delay::DelayNs` delay source.
//!
//! # Example
//!
//! ```ignore
//! use embedded_hal::delay::DelayNs;
//! use pn532::{BaudRate, I2cInterface, Pn532};
//!
//! # struct Delay;
//! # impl DelayNs for Delay { fn delay_ns(&mut self, _: u32) {} }
//! #
//! # fn demo<I2C>(i2c: I2C, delay: Delay)
//! # where I2C: embedded_hal::i2c::I2c
//! # {
//! let mut nfc = Pn532::new(I2cInterface::new(i2c, delay));
//! nfc.begin().unwrap();
//! nfc.sam_config().unwrap();
//!
//! let uid = nfc
//! .read_passive_target_id(BaudRate::ISO14443A106kbps, 1000)
//! .unwrap();
//! if let Some(uid) = uid {
//! // uid.bytes[..uid.len as usize] contains the card UID
//! }
//! # }
//! ```
//!
//! # Limitations
//!
//! * Responses are limited to 64 bytes, matching the PN532's internal packet
//! buffer (this also constrains multi-block FeliCa reads).
//! * The I2C interface is blocking and uses busy-wait polling for the PN532's
//! "ready" flag, mirroring the original Arduino implementation.
pub mod commands;
pub mod error;
pub mod felica;
pub mod interface;
pub(crate) mod driver;
pub mod tg;
pub mod mifare;
pub mod iso14443a;
pub use commands::BaudRate;
pub use driver::{FelicaPollingResponse, Pn532, TargetInitStatus, Uid};
pub use error::Error;
pub use interface::{I2cInterface, Interface, NoIrq, NoReset};