### Example TimerWrapper Implementation for esp_hal Source: https://docs.rs/pn532/0.5.0/pn532/trait.CountDown.html An example implementation of the CountDown trait using esp_hal's PeriodicTimer. It converts the timer's native result types to match the trait's requirements. ```rust struct TimerWrapper<'a, T> { timer: esp_hal::timer::PeriodicTimer<'a, T>, } impl<'a, TIM> CountDown for TimerWrapper<'a, TIM> where TIM: esp_hal::timer::Timer, { type Time = MicrosDurationU64; fn start(&mut self, timeout: T) where T: Into, { 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), } } } ``` -------------------------------- ### CountDown::start() Method Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SysTimer.html Starts a new count-down timer for SysTimer. The count can be any type that can be converted into Duration. ```rust fn start(&mut self, count: T) where T: Into, ``` -------------------------------- ### SPI Example for PN532 Initialization and Data Reading Source: https://docs.rs/pn532/0.5.0/pn532/index.html Demonstrates how to initialize the PN532 using SPI and perform basic operations like SAM configuration, target listing, and reading data from an NTAG. ```rust use pn532::{requests::SAMMode, spi::SPIInterface, Pn532, Request}; use pn532::IntoDuration; // trait for `ms()`, your HAL might have its own // spi is a struct implementing embedded_hal::spi::SpiDevice // timer is a struct implementing pn532::CountDown let mut pn532: Pn532<_, _, 32> = Pn532::new(SPIInterface { spi }, timer); if let Err(e) = pn532.process(&Request::sam_configuration(SAMMode::Normal, false), 0, 50.ms()){ println!("Could not initialize PN532: {e:?}") } if let Ok(uid) = pn532.process(&Request::INLIST_ONE_ISO_A_TARGET, 7, 1000.ms()){ let result = pn532.process(&Request::ntag_read(10), 17, 50.ms()).unwrap(); if result[0] == 0x00 { println!("page 10: {:?}", &result[1..5]); } } ``` -------------------------------- ### Predefined Request: Get Firmware Version Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for querying the PN532's firmware version. This request has no associated data. ```rust pub const GET_FIRMWARE_VERSION: Request<0> ``` -------------------------------- ### SysTimer Implementations Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SysTimer.html Details on how SysTimer implements the CountDown and Default traits, providing functionality for starting and waiting on countdowns, and setting default values. ```APIDOC ## SysTimer Implementations ### impl CountDown for SysTimer #### type Time = Duration The unit of time used by this timer is `Duration`. #### fn start(&mut self, count: T) Starts a new count-down. The `count` can be any type that can be converted into `Duration`. - **count** (T): The duration to count down from. #### fn wait(&mut self) -> Result<(), Infallible> Non-blockingly waits until the count-down finishes. Returns `Ok(())` if the countdown completes successfully, or `Err(Infallible)` if an error occurs (though `Infallible` indicates no actual error can occur). ### impl Default for SysTimer #### fn default() -> SysTimer Returns the default value for `SysTimer`, which is a newly created `SysTimer` instance. ``` -------------------------------- ### CountDown Trait Definition Source: https://docs.rs/pn532/0.5.0/pn532/trait.CountDown.html Defines the interface for a count-down timer with associated time type, start, and wait methods. ```rust pub trait CountDown { type Time; // Required methods fn start(&mut self, count: T) where T: Into; fn wait(&mut self) -> Result<(), Infallible>; } ``` -------------------------------- ### Pn532::new Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Creates a new Pn532 instance with a specified interface and timer. ```APIDOC ## Pn532::new ### Description Creates a Pn532 instance with a specified interface and timer. ### Signature ```rust pub fn new(interface: I, timer: T) -> Self ``` ### Parameters * `interface`: An object implementing the `Interface` trait. * `timer`: An object implementing the `CountDown` trait. ``` -------------------------------- ### Get TypeId of a BorrowedRequest Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html Retrieves the `TypeId` of the `BorrowedRequest` instance. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### I2CInterface Methods Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html This section details the methods available for the I2CInterface, including writing frames, checking readiness, and reading data. ```APIDOC ## Interface for I2CInterface This documentation covers the methods provided by the `I2CInterface` struct when it implements the `Interface` trait. ### write Writes a `frame` to the Pn532. - **Parameters**: - `frame`: A mutable slice of bytes representing the data frame to be written. - **Returns**: - `Result<(), Self::Error>`: Ok(()) if the write is successful, or an error if it fails. ### wait_ready Checks if the Pn532 has data to be read. This method can use either the serial link or the IRQ pin. - **Returns**: - `Poll>`: Poll::Ready(Ok(())) if data is ready, Poll::Pending if not, or an error if checking readiness fails. ### read Reads data from the Pn532 into the provided buffer. This method is intended to be called only after `wait_ready` has indicated that data is available. - **Parameters**: - `buf`: A mutable slice of bytes to store the data read from the Pn532. - **Returns**: - `Result<(), Self::Error>`: Ok(()) if the read is successful, or an error if it fails. ``` -------------------------------- ### Interface Implementation for SPIInterface Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterface.html Details the methods available for interacting with the PN532 chip via SPI, including writing data, checking readiness, and reading data. ```APIDOC ## impl Interface for SPIInterface where SPI: SpiDevice, ### Associated Types * `Error`: Error specific to the serial link. ### Methods * `write(&mut self, frame: &mut [u8]) -> Result<(), Self::Error>`: Writes a `frame` to the Pn532. * `wait_ready(&mut self) -> Poll>`: Checks if the Pn532 has data to be read. Uses either the serial link or the IRQ pin. * `read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error>`: Reads data from the Pn532 into `buf`. This method will only be called if `wait_ready` returned `Poll::Ready(Ok(()))` before. ``` -------------------------------- ### Clone Implementation for SPIInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterfaceWithIrq.html Provides a Clone implementation for SPIInterfaceWithIrq, allowing the creation of duplicate instances. This requires both the SPI and IRQ types to also implement Clone. ```rust impl Clone for SPIInterfaceWithIrq where SPI: SpiDevice + Clone, IRQ: InputPin + Clone, { fn clone(&self) -> SPIInterfaceWithIrq { // ... implementation details ... } } ``` -------------------------------- ### Pn532::new_async Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Creates a Pn532 instance for asynchronous operations, without a timer. ```APIDOC ## Pn532::new_async ### Description Creates a Pn532 instance for asynchronous operations, without a timer. ### Signature ```rust pub fn new_async(interface: I) -> Self ``` ### Parameters * `interface`: An object implementing the `Interface` trait. ``` -------------------------------- ### Debug Implementation for SPIInterface Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterface.html Enables debugging output for the SPIInterface. ```APIDOC ## impl Debug for SPIInterface where SPI: SpiDevice + Debug, ### Methods * `fmt(&self, f: &mut Formatter<'_>) -> Result`: Formats the value using the given formatter. ``` -------------------------------- ### Predefined Request: Select Tag 1 Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for selecting the first tag. Requires 1 byte of data. ```rust pub const SELECT_TAG_1: Request<1> ``` -------------------------------- ### Predefined Request: Inlist One ISO A Target Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for initiating an ISO/IEC 14443-3 Type A target detection. Requires 2 bytes of data. ```rust pub const INLIST_ONE_ISO_A_TARGET: Request<2> ``` -------------------------------- ### Predefined Request: Select Tag 2 Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for selecting the second tag. Requires 1 byte of data. ```rust pub const SELECT_TAG_2: Request<1> ``` -------------------------------- ### Clone Implementation for SPIInterface Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterface.html Provides functionality to create a duplicate of the SPIInterface. ```APIDOC ## impl Clone for SPIInterface where SPI: SpiDevice + Clone, ### Methods * `clone(&self) -> SPIInterface`: Returns a duplicate of the value. * `clone_from(&mut self, source: &Self)`: Performs copy-assignment from `source`. ``` -------------------------------- ### Request Constructor Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant function to create a new Request instance with a given command and data. ```rust pub const fn new(command: Command, data: [u8; N]) -> Self ``` -------------------------------- ### Interface Implementation for SPIInterface Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterface.html Implements the Interface trait for SPIInterface, providing methods for SPI communication with the PN532. This includes writing frames, waiting for data readiness, and reading data. ```rust impl Interface for SPIInterface where SPI: SpiDevice, { type Error = ::Error; fn write(&mut self, frame: &mut [u8]) -> Result<(), Self::Error> { // ... implementation details ... } fn wait_ready(&mut self) -> Poll> { // ... implementation details ... } fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { // ... implementation details ... } } ``` -------------------------------- ### SysTimer::new Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SysTimer.html Constructs a new SysTimer instance. This timer is based on `std::time::Instant` and is available only when the `std` feature flag is enabled. ```APIDOC ## SysTimer::new ### Description Creates a new `SysTimer` instance. This timer uses `std::time::Instant` for its monotonic clock. ### Method `pub fn new() -> SysTimer` ### Parameters None ### Returns A new `SysTimer` instance. ``` -------------------------------- ### Predefined Request: Release Tag 1 Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for releasing the first tag. Requires 1 byte of data. ```rust pub const RELEASE_TAG_1: Request<1> ``` -------------------------------- ### SAM Configuration Request Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Function to create a SAM configuration request. It takes a SAM mode and a boolean indicating IRQ pin usage, returning a Request with 3 bytes of data. ```rust pub const fn sam_configuration(mode: SAMMode, use_irq_pin: bool) -> Request<3> ``` -------------------------------- ### CloneToUninit Trait Implementation (Nightly) Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the nightly-only experimental CloneToUninit trait for copying data to uninitialized memory. Requires the underlying type to implement Clone. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) 🔬This is a nightly-only experimental API. (`clone_to_uninit`) Performs copy-assignment from `self` to `dest`. Read more ``` -------------------------------- ### Interface Implementation for I2CInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterfaceWithIrq.html Implements the Interface trait for I2CInterfaceWithIrq, providing methods for writing, reading, and checking readiness for I2C communication with the PN532. This implementation utilizes both the I2C peripheral and the IRQ pin. ```rust impl Interface for I2CInterfaceWithIrq where I2C: I2c, IRQ: InputPin, { type Error = ::Error; #[inline] fn write(&mut self, frame: &mut [u8]) -> Result<(), Self::Error> { self.i2c.write(frame) } #[inline] fn wait_ready(&mut self) -> Poll> { match self.irq.is_high() { Ok(true) => Poll::Ready(Ok(())), Ok(false) => Poll::Pending, Err(e) => Poll::Ready(Err(e.into())), } } #[inline] fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { self.i2c.read(buf) } } ``` -------------------------------- ### Debug Implementation for SPIInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterfaceWithIrq.html Enables debugging output for the SPIInterfaceWithIrq struct. This implementation requires the SPI and IRQ types to also implement Debug. ```rust impl Debug for SPIInterfaceWithIrq where SPI: SpiDevice + Debug, IRQ: InputPin + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> Result { // ... implementation details ... } } ``` -------------------------------- ### Predefined Request: Release Tag 2 Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for releasing the second tag. Requires 1 byte of data. ```rust pub const RELEASE_TAG_2: Request<1> ``` -------------------------------- ### Convert to Another Type Using From Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html Converts the current type into another type `U` for which `U` implements `From`. ```rust fn into(self) -> U ``` -------------------------------- ### Interface Implementation for SPIInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterfaceWithIrq.html Implements the Interface trait for SPIInterfaceWithIrq, providing methods for writing frames, checking readiness via SPI or IRQ, and reading data from the PN532. ```rust impl Interface for SPIInterfaceWithIrq where SPI: SpiDevice, IRQ: InputPin, { type Error = ::Error; fn write(&mut self, frame: &mut [u8]) -> Result<(), Self::Error> { // ... implementation details ... } fn wait_ready(&mut self) -> Poll> { // ... implementation details ... } fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { // ... implementation details ... } } ``` -------------------------------- ### Process Request with Response Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends a request, waits for an ACK, and then waits for a response. Specify the largest expected response length and a timeout. Ensure the buffer size N satisfies N - 9 >= max(response_len, M). ```rust use pn532::Request; use pn532::IntoDuration; // trait for `ms()`, your HAL might have its own let mut pn532 = get_pn532(); let result = pn532.process(&Request::GET_FIRMWARE_VERSION, 4, 50.ms()); ``` -------------------------------- ### Create Pn532 Instance Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Instantiates a Pn532 struct with a provided interface and timer. This is the standard constructor for blocking operations. ```rust pub fn new(interface: I, timer: T) -> Self ``` -------------------------------- ### Create Pn532 Instance without Timer Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Instantiates a Pn532 struct with only an interface, suitable for asynchronous operations where a timer is not managed by this struct. Use `new_async` for this purpose. ```rust pub fn new_async(interface: I) -> Self ``` -------------------------------- ### Interface Implementation for I2CInterface Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the Interface trait for I2CInterface, providing methods for writing data, checking readiness, and reading data from the PN532 via I2C. ```rust type Error = ::Error Error specific to the serial link. ``` ```rust fn write(&mut self, frame: &mut [u8]) -> Result<(), Self::Error> Writes a `frame` to the Pn532 Read more ``` ```rust fn wait_ready(&mut self) -> Poll> Checks if the Pn532 has data to be read. Uses either the serial link or the IRQ pin. ``` ```rust fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> Reads data from the Pn532 into `buf`. This method will only be called if `wait_ready` returned `Poll::Ready(Ok(()))` before. ``` -------------------------------- ### SysTimer::new() Constructor Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SysTimer.html Creates a new instance of SysTimer. This function is part of the SysTimer implementation. ```rust pub fn new() -> SysTimer ``` -------------------------------- ### Request PartialEq Implementation Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Implements the PartialEq trait for the Request struct, allowing for equality comparisons between Request instances. ```rust fn eq(&self, other: &Request) -> bool Tests for `self` and `other` values to be equal, and is used by `==`. ``` ```rust fn ne(&self, other: &Rhs) -> bool Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. ``` -------------------------------- ### SPIInterfaceWithIrq Struct Definition Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterfaceWithIrq.html Defines the SPIInterfaceWithIrq struct, which holds the SPI device and an IRQ input pin. This struct is generic over the SPI device and IRQ pin types, requiring them to implement SpiDevice and InputPin respectively. ```rust pub struct SPIInterfaceWithIrq where SPI: SpiDevice, IRQ: InputPin, { pub spi: SPI, pub irq: IRQ, } ``` -------------------------------- ### Request StructuralPartialEq Implementation Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Implements the StructuralPartialEq trait for the Request struct. ```rust impl StructuralPartialEq for Request ``` -------------------------------- ### Create a new BorrowedRequest Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html Use the `new` associated function to construct a BorrowedRequest with a specified command and data slice. ```rust pub const fn new(command: Command, data: &'a [u8]) -> Self ``` -------------------------------- ### Debug Implementation for SPIInterface Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterface.html Implements the Debug trait for SPIInterface, enabling formatted output for debugging purposes. Requires the SPI type to also implement Debug. ```rust impl Debug for SPIInterface where SPI: SpiDevice + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> Result { // ... implementation details ... } } ``` -------------------------------- ### Debug Implementation for I2CInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterfaceWithIrq.html Implements the Debug trait for I2CInterfaceWithIrq, enabling instances to be formatted for debugging output. Both the I2C peripheral and IRQ pin must also implement Debug. ```rust impl Debug for I2CInterfaceWithIrq where I2C: I2c + Debug, IRQ: InputPin + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.debug_struct("I2CInterfaceWithIrq") .field("i2c", &self.i2c) .field("irq", &self.irq) .finish() } } ``` -------------------------------- ### Clone Implementation for I2CInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterfaceWithIrq.html Implements the Clone trait for I2CInterfaceWithIrq, allowing instances to be duplicated. Both the I2C peripheral and IRQ pin must also implement Clone. ```rust impl Clone for I2CInterfaceWithIrq where I2C: I2c + Clone, IRQ: InputPin + Clone, { #[inline] fn clone(&self) -> I2CInterfaceWithIrq { I2CInterfaceWithIrq { i2c: self.i2c.clone(), irq: self.irq.clone() } } } ``` -------------------------------- ### SerialPortInterface::wait_ready Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SerialPortInterface.html Checks if the PN532 device has data available to be read. It can utilize either the serial link or an IRQ pin for this check. ```APIDOC ## SerialPortInterface::wait_ready ### Description Checks if the Pn532 has data to be read. Uses either the serial link or the IRQ pin. ### Method `wait_ready` ### Parameters `&mut self` ### Returns `Poll>` - `Poll::Ready(Ok(()))` if data is ready, otherwise `Poll::Pending` or an error. ``` -------------------------------- ### SPIInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterfaceWithIrq.html The SPIInterfaceWithIrq struct encapsulates an SPI device and an IRQ input pin, enabling interrupt-driven SPI communication. ```APIDOC ## Struct SPIInterfaceWithIrq ### Description Represents an SPI interface that includes an IRQ (Interrupt Request) pin. This allows for interrupt-driven communication, where the device can signal the host when data is ready or an event has occurred. ### Fields * `spi`: The SPI device used for data transfer. * `irq`: The IRQ input pin used for interrupt signaling. ### Trait Implementations #### `Clone` Allows creating a copy of the `SPIInterfaceWithIrq` instance. #### `Debug` Enables debugging output for the `SPIInterfaceWithIrq` instance. #### `Interface` Provides methods for SPI communication with the PN532 chip: * **`write`**: Writes a frame of data to the PN532. * **`wait_ready`**: Checks if the PN532 is ready to be read from, using either the serial link or the IRQ pin. * **`read`**: Reads data from the PN532 into a buffer. This is typically called after `wait_ready` indicates data is available. ``` -------------------------------- ### Pn532::process_async Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Asynchronously sends a request, waits for an ACK, and then waits for a response. The `response_len` parameter specifies the maximum expected length of the response data. ```APIDOC ## Pn532::process_async ### Description Asynchronously sends a request, waits for an ACK, and then waits for a response. The `response_len` parameter specifies the maximum expected length of the response data. ### Signature ```rust pub async fn process_async<'a>( &mut self, request: impl Into>, response_len: usize, ) -> Result<&[u8], Error> ``` ### Parameters * `request`: The request to send, which can be converted into a `BorrowedRequest`. * `response_len`: The maximum expected length of the response data. ### Returns A `Result` containing a slice of bytes representing the response data on success, or an `Error` on failure. ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the Any trait, which provides access to the type's metadata. This is a blanket implementation for any type T that is 'static. ```rust fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Pn532::abort Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends an ACK frame to force the PN532 to abort the current process. The PN532 will then wait for a new command. ```APIDOC ## Pn532::abort ### Description Sends an ACK frame to force the PN532 to abort the current process. The PN532 will then wait for a new command. ### Signature ```rust pub fn abort(&mut self) -> Result<(), Error> ``` ### Returns A `Result` indicating success or failure. ``` -------------------------------- ### Clone Implementation for SPIInterface Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterface.html Implements the Clone trait for SPIInterface, allowing instances to be duplicated. Requires the SPI type to also implement Clone. ```rust impl Clone for SPIInterface where SPI: SpiDevice + Clone, { fn clone(&self) -> SPIInterface { // ... implementation details ... } fn clone_from(&mut self, source: &Self) { // ... implementation details ... } } ``` -------------------------------- ### Pn532::process Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends a request, waits for an ACK, and then waits for a response. The `response_len` parameter specifies the maximum expected length of the response data. ```APIDOC ## Pn532::process ### Description Sends a request, waits for an ACK, and then waits for a response. The `response_len` parameter specifies the maximum expected length of the response data. ### Signature ```rust pub fn process<'a>( &mut self, request: impl Into>, response_len: usize, timeout: T::Time, ) -> Result<&[u8], Error> ``` ### Parameters * `request`: The request to send, which can be converted into a `BorrowedRequest`. * `response_len`: The maximum expected length of the response data. * `timeout`: The timeout duration for the operation. ### Returns A `Result` containing a slice of bytes representing the response data on success, or an `Error` on failure. ``` -------------------------------- ### Check Serial Port Ready Status Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SerialPortInterface.html Checks if the PN532 device is ready to be read from, using either the serial link or an IRQ pin. This method is part of the Interface trait implementation. ```rust fn wait_ready(&mut self) -> Poll> ``` -------------------------------- ### Receive Response Frame Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Waits for a response frame from the PN532. This should be called after `send` and `receive_ack` have been successfully completed, and the interface is ready. Specify the command sent and the largest expected data length. ```rust use core::task::Poll; use pn532::{Interface, Request}; let mut pn532 = get_pn532(); pn532.send(&Request::GET_FIRMWARE_VERSION); // do something else if let Poll::Ready(Ok(_)) = pn532.interface.wait_ready() { pn532.receive_ack(); } // do something else if let Poll::Ready(Ok(_)) = pn532.interface.wait_ready() { let result = pn532.receive_response(Request::GET_FIRMWARE_VERSION.command, 4); } ``` -------------------------------- ### Request Struct Definition Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Defines the generic Request struct which holds a command and a data array of a specified size. ```rust pub struct Request { pub command: Command, pub data: [u8; N], } ``` -------------------------------- ### PN532_I2C_READY Constant Definition Source: https://docs.rs/pn532/0.5.0/pn532/i2c/constant.PN532_I2C_READY.html Defines the byte value for the PN532 I2C ready status. Use this constant in `Interface::wait_ready` implementations to check if the PN532 is ready for I2C communication. ```rust pub const PN532_I2C_READY: u8 = 0x01; ``` -------------------------------- ### Try Convert Into Another Type Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html Attempts to convert the current type into another type `U` for which `U` implements `TryFrom`. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Abort Current Process Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends an ACK frame to force the PN532 to abort its current operation. The chip will then reset to waiting for a new command. ```rust pub fn abort(&mut self) -> Result<(), Error> ``` -------------------------------- ### Process Request without Response Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends a request and waits only for an ACK. Useful for commands that do not return data. Ensure the buffer size N is sufficient for the request. ```rust use pn532::Request; use pn532::IntoDuration; // trait for `ms()`, your HAL might have its own let mut pn532 = get_pn532(); pn532.process_no_response(&Request::INLIST_ONE_ISO_A_TARGET, 5.ms()); ``` -------------------------------- ### Asynchronous Process Request with Response Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Asynchronously sends a request, waits for an ACK, and then waits for a response. Specify the largest expected response length. This method returns a future. ```rust use pn532::Request; let mut pn532 = get_async_pn532(); let future = pn532.process_async(&Request::GET_FIRMWARE_VERSION, 4); ``` -------------------------------- ### PN532_SPI_READY Constant Definition Source: https://docs.rs/pn532/0.5.0/pn532/spi/constant.PN532_SPI_READY.html Defines the PN532_SPI_READY constant, a byte value used to indicate the SPI interface is ready. This is typically used within `Interface::wait_ready` implementations. ```rust pub const PN532_SPI_READY: u8 = 128u8; ``` -------------------------------- ### Request Eq Implementation Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Implements the Eq trait for the Request struct, indicating that equality is reflexive, symmetric, and transitive. ```rust impl Eq for Request ``` -------------------------------- ### Read Data from Serial Port Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SerialPortInterface.html Reads data from the PN532 device into a provided buffer. This method should only be called after `wait_ready` has indicated readiness. ```rust fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> ``` -------------------------------- ### Try Convert From Another Type Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html Attempts to convert from type `U` into `T`. Returns a `Result` indicating success or failure. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Into Trait Implementation Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the Into trait, allowing conversion to a type U if U implements From. This is a standard blanket implementation. ```rust fn into(self) -> U Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ``` -------------------------------- ### From Trait Implementation Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the From trait, allowing conversion from a type T to itself. This is a standard blanket implementation. ```rust fn from(t: T) -> T Returns the argument unchanged. ``` -------------------------------- ### Pn532::process_no_response_async Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Asynchronously sends a request and waits only for an ACK, without expecting a subsequent response. ```APIDOC ## Pn532::process_no_response_async ### Description Asynchronously sends a request and waits only for an ACK, without expecting a subsequent response. ### Signature ```rust pub async fn process_no_response_async<'a>( &mut self, request: impl Into>, ) -> Result<(), Error> ``` ### Parameters * `request`: The request to send, which can be converted into a `BorrowedRequest`. ### Returns A `Result` indicating success or failure. ``` -------------------------------- ### Pn532 Struct Definition Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Defines the main Pn532 struct with generic parameters for interface, timer, and buffer size. ```rust pub struct Pn532 { pub interface: I, pub timer: T, /* private fields */ } ``` -------------------------------- ### Clone Implementation for I2CInterface Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the Clone trait for I2CInterface, allowing for the creation of duplicate instances. Requires the underlying I2C type to also implement Clone. ```rust fn clone(&self) -> I2CInterface Returns a duplicate of the value. Read more ``` ```rust fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. Read more ``` -------------------------------- ### Convert Request to BorrowedRequest Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html Converts a `Request` into a `BorrowedRequest<'a>` using the `From` trait. ```rust fn from(value: &'a Request) -> BorrowedRequest<'a> ``` -------------------------------- ### Predefined Request: Deselect Tag 2 Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for deselecting the second tag. Requires 1 byte of data. ```rust pub const DESELECT_TAG_2: Request<1> ``` -------------------------------- ### Predefined Request: Deselect Tag 1 Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html A constant Request instance for deselecting the first tag. Requires 1 byte of data. ```rust pub const DESELECT_TAG_1: Request<1> ``` -------------------------------- ### CountDown::wait() Method Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SysTimer.html Non-blockingly waits until the SysTimer's count-down finishes. Returns Ok(()) upon completion or if the timer has already finished. ```rust fn wait(&mut self) -> Result<(), Infallible> ``` -------------------------------- ### Debug Implementation for I2CInterface Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the Debug trait for I2CInterface, enabling formatted output for debugging purposes. Requires the underlying I2C type to also implement Debug. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. Read more ``` -------------------------------- ### NTAG Write Request Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Function to create a request for writing 4 bytes to an NTAG page. It takes the page number and the bytes to write, returning a Request with 7 bytes of data. ```rust pub const fn ntag_write(page: u8, bytes: &[u8; 4]) -> Request<7> ``` -------------------------------- ### PN532 Command Enum Definition Source: https://docs.rs/pn532/0.5.0/pn532/requests/enum.Command.html Defines the various commands supported by the PN532 chip. These commands are used to control the device, manage RF communication, and interact with NFC targets. ```rust #[repr(u8)] pub enum Command { Diagnose = 0, GetFirmwareVersion = 2, GetGeneralStatus = 4, ReadRegister = 6, WriteRegister = 8, ReadGPIO = 12, WriteGPIO = 14, SetSerialBaudRate = 16, SetParameters = 18, SAMConfiguration = 20, PowerDown = 22, RFConfiguration = 50, RFRegulationTest = 88, InJumpForDEP = 86, InJumpForPSL = 70, InListPassiveTarget = 74, InATR = 80, InPSL = 78, InDataExchange = 64, InCommunicateThru = 66, InDeselect = 68, InRelease = 82, InSelect = 84, InAutoPoll = 96, TgInitAsTarget = 140, TgSetGeneralBytes = 146, TgGetData = 134, TgSetData = 142, TgSetMetaData = 148, TgGetInitiatorCommand = 136, TgResponseToInitiator = 144, TgGetTargetStatus = 138, } ``` -------------------------------- ### NTAG Password Authentication Request Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Function to create a request for authenticating with an NTAG using a password. It takes the password bytes and returns a Request with 5 bytes of data. ```rust pub const fn ntag_pwd_auth(bytes: &[u8; 4]) -> Request<5> ``` -------------------------------- ### SerialPortInterface::read Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SerialPortInterface.html Reads data from the PN532 device into a provided buffer. This method should only be called after `wait_ready` has indicated that data is available. ```APIDOC ## SerialPortInterface::read ### Description Reads data from the Pn532 into `buf`. This method will only be called if `wait_ready` returned `Poll::Ready(Ok(()))` before. ### Method `read` ### Parameters - `&mut self` - `buf: &mut [u8]` - The buffer to read data into. ### Returns `Result<(), Self::Error>` - Ok(()) on successful read, or an error specific to the serial link. ``` -------------------------------- ### Return Argument Unchanged Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html The `from` function for `T` to `T` conversion simply returns the argument unchanged. ```rust fn from(t: T) -> T ``` -------------------------------- ### I2CInterfaceWithIrq Struct Definition Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterfaceWithIrq.html Defines the I2CInterfaceWithIrq struct, which holds an I2C peripheral and an IRQ input pin. This struct is generic over the I2C and IRQ types, requiring them to implement specific traits. ```rust pub struct I2CInterfaceWithIrq where I2C: I2c, IRQ: InputPin, { pub i2c: I2C, pub irq: IRQ, } ``` -------------------------------- ### I2CInterfaceWithIrq Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterfaceWithIrq.html Represents an I2C interface for the PN532 chip that also utilizes an Interrupt Request (IRQ) pin for efficient communication. ```APIDOC ## Struct I2CInterfaceWithIrq I2C Interface with IRQ pin ### Fields * `i2c`: The I2C peripheral used for communication. * `irq`: The InputPin used as an IRQ. ### Trait Implementations #### `impl Interface for I2CInterfaceWithIrq` This implementation provides the core interface methods for interacting with the PN532. ##### `fn write(&mut self, frame: &mut [u8]) -> Result<(), Self::Error>` Writes a `frame` to the PN532. ##### `fn wait_ready(&mut self) -> Poll>` Checks if the PN532 has data to be read. Uses either the serial link or the IRQ pin. ##### `fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error>` Reads data from the PN532 into `buf`. This method will only be called if `wait_ready` returned `Poll::Ready(Ok(()))` before. ``` -------------------------------- ### Request Clone Implementation Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Implements the Clone trait for the Request struct, allowing for duplication of Request instances. ```rust fn clone(&self) -> Request Returns a duplicate of the value. Read more ``` ```rust fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. Read more ``` -------------------------------- ### TryFrom Trait Implementation Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the TryFrom trait for fallible conversions from type U to T, where U implements Into. This is a standard blanket implementation. ```rust type Error = Infallible The type returned in the event of a conversion error. ``` ```rust fn try_from(value: U) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### Send Request Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends a request to the PN532 chip without waiting for a response. This is a low-level operation; typically used before calling `receive_ack` or `receive_response`. ```rust use pn532::Request; let mut pn532 = get_pn532(); pn532.send(&Request::GET_FIRMWARE_VERSION); ``` -------------------------------- ### SPIInterface Source: https://docs.rs/pn532/0.5.0/pn532/spi/struct.SPIInterface.html Represents an SPI interface for the PN532 chip, without using an IRQ pin. It holds an SPI device. ```APIDOC ## Struct SPIInterface `pub struct SPIInterface where SPI: SpiDevice, { pub spi: SPI, }` SPI Interface without IRQ pin. ### Fields * `spi: SPI` - The SPI device used for communication. ``` -------------------------------- ### NTAG Read Request Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Function to create a request for reading a page from an NTAG. It takes the page number and returns a Request with 3 bytes of data. ```rust pub const fn ntag_read(page: u8) -> Request<3> ``` -------------------------------- ### Asynchronous Process Request without Response Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Asynchronously sends a request and waits only for an ACK. This method returns a future and is suitable for commands that do not return data. ```rust use pn532::Request; let mut pn532 = get_async_pn532(); let future = pn532.process_no_response_async(&Request::INLIST_ONE_ISO_A_TARGET); ``` -------------------------------- ### Pn532::process_no_response Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends a request and waits only for an ACK, without expecting a subsequent response. ```APIDOC ## Pn532::process_no_response ### Description Sends a request and waits only for an ACK, without expecting a subsequent response. ### Signature ```rust pub fn process_no_response<'a>( &mut self, request: impl Into>, timeout: T::Time, ) -> Result<(), Error> ``` ### Parameters * `request`: The request to send, which can be converted into a `BorrowedRequest`. * `timeout`: The timeout duration for the operation. ### Returns A `Result` indicating success or failure. ``` -------------------------------- ### TryInto Trait Implementation Source: https://docs.rs/pn532/0.5.0/pn532/i2c/struct.I2CInterface.html Implements the TryInto trait for fallible conversions from type T to U, where U implements TryFrom. This is a standard blanket implementation. ```rust type Error = >::Error The type returned in the event of a conversion error. ``` ```rust fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### Pn532::receive_response Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Receives a response frame from the PN532. This should be called after `send` and `receive_ack`, and after ensuring the interface is ready. `response_len` is the largest expected length of the data. ```APIDOC ## Pn532::receive_response ### Description Receives a response frame from the PN532. This should be called after `send` and `receive_ack`, and after ensuring the interface is ready. `response_len` is the largest expected length of the data. ### Signature ```rust pub fn receive_response( &mut self, sent_command: Command, response_len: usize, ) -> Result<&[u8], Error> ``` ### Parameters * `sent_command`: The command that was sent, used to validate the response. * `response_len`: The maximum expected length of the response data. ### Returns A `Result` containing a slice of bytes representing the response data on success, or an `Error` on failure. ``` -------------------------------- ### RF Regulation Test Request Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.Request.html Function to create an RF regulation test request. It requires transmit speed and framing parameters, returning a Request with 1 byte of data. ```rust pub const fn rf_regulation_test( tx_speed: TxSpeed, tx_framing: TxFraming, ) -> Request<1> ``` -------------------------------- ### Receive ACK Frame Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Waits for and verifies an ACK frame from the PN532. This should be called after `send` and after confirming the interface is ready, typically after a `wait_ready` call. ```rust use core::task::Poll; use pn532::{Interface, Request}; let mut pn532 = get_pn532(); pn532.send(&Request::GET_FIRMWARE_VERSION); // do something else if let Poll::Ready(Ok(_)) = pn532.interface.wait_ready() { pn532.receive_ack(); } ``` -------------------------------- ### Pn532::receive_ack Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Receives an ACK frame from the PN532. This should be called after `send` and after ensuring the interface is ready. ```APIDOC ## Pn532::receive_ack ### Description Receives an ACK frame from the PN532. This should be called after `send` and after ensuring the interface is ready. ### Signature ```rust pub fn receive_ack(&mut self) -> Result<(), Error> ``` ### Returns A `Result` indicating success or failure. ``` -------------------------------- ### Pn532::send Source: https://docs.rs/pn532/0.5.0/pn532/struct.Pn532.html Sends a request to the PN532 chip. This method does not wait for a response or ACK. ```APIDOC ## Pn532::send ### Description Sends a request to the PN532 chip. This method does not wait for a response or ACK. ### Signature ```rust pub fn send<'a>( &mut self, request: impl Into>, ) -> Result<(), Error> ``` ### Parameters * `request`: The request to send, which can be converted into a `BorrowedRequest`. ### Returns A `Result` indicating success or failure. ``` -------------------------------- ### SAMMode Enum Definition Source: https://docs.rs/pn532/0.5.0/pn532/requests/enum.SAMMode.html Defines the possible modes for the Secure Access Module (SAM) configuration. Use this enum when calling the SAMConfiguration command. ```rust pub enum SAMMode { Normal, VirtualCard { timeout: u8, }, WiredCard, DualCard, } ``` -------------------------------- ### BorrowedRequest Struct Definition Source: https://docs.rs/pn532/0.5.0/pn532/requests/struct.BorrowedRequest.html Defines the structure of a BorrowedRequest, which includes a Command and a slice of byte data. ```rust pub struct BorrowedRequest<'a> { pub command: Command, pub data: &'a [u8], } ``` -------------------------------- ### SerialPortInterface::write Source: https://docs.rs/pn532/0.5.0/pn532/serialport/struct.SerialPortInterface.html Writes a data frame to the PN532 device via the serial link. This method is part of the `Interface` trait implementation. ```APIDOC ## SerialPortInterface::write ### Description Writes a `frame` to the Pn532. ### Method `write` ### Parameters - `&mut self` - `frame: &mut [u8]` - The byte slice representing the data frame to be written. ### Returns `Result<(), Self::Error>` - Ok(()) on successful write, or an error specific to the serial link. ``` -------------------------------- ### TxSpeed Enum Definition Source: https://docs.rs/pn532/0.5.0/pn532/requests/enum.TxSpeed.html Defines the possible transmission speeds for the RFRegulationTest command. Each variant corresponds to a specific bitrate. ```rust #[repr(u8)] pub enum TxSpeed { Tx106kbps = 0, Tx212kbps = 16, Tx424kbps = 32, Tx848kbps = 48, } ``` -------------------------------- ### PN532 Interface Trait Definition Source: https://docs.rs/pn532/0.5.0/pn532/trait.Interface.html Defines the essential methods for serial communication with the PN532 chip. This trait abstracts over different communication protocols. ```rust pub trait Interface { type Error: Debug; // Required methods fn write(&mut self, frame: &mut [u8]) -> Result<(), Self::Error>; fn wait_ready(&mut self) -> Poll>; fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error>; } ``` -------------------------------- ### NTAGCommand Enum Definition Source: https://docs.rs/pn532/0.5.0/pn532/requests/enum.NTAGCommand.html Defines the available commands for NTAG devices. Each command is mapped to a specific u8 value. ```rust #[repr(u8)] pub enum NTAGCommand { GetVersion = 96, Read = 48, FastRead = 58, Write = 162, CompWrite = 160, ReadCnt = 57, PwdAuth = 27, ReadSig = 60, } ``` -------------------------------- ### Printing Error Codes from Status Byte Source: https://docs.rs/pn532/0.5.0/pn532/enum.ErrorCode.html A Rust function that takes a status byte, attempts to convert it into an `ErrorCode` variant using `try_from`, and prints the corresponding error code or 'unknown error code' if the byte does not match any known error. ```rust fn print_error(status_byte: u8){ if let Ok(error_code) = ErrorCode::try_from(status_byte){ println!("{:?}", error_code); } else { println!("unknown error code"); } } ```