Struct pn532::Pn532 [−][src]
pub struct Pn532<I, T, const N: usize = 32_usize> {
pub interface: I,
pub timer: T,
// some fields omitted
}
Expand description
Main struct of this crate
Provides blocking methods process
and process_async
for sending requests and parsing responses.
Other methods can be used if fine-grain control is required.
Note:
The Pn532
uses an internal buffer for sending and receiving messages.
The size of the buffer is determined by the N
type parameter which has a default value of 32
.
Choosing N
too small will result in panics.
The following inequality should hold for all requests and responses:
N - 9 >= max(response_len, M)
where
N
is the const generic type parameter of this struct.response_len
is the largest number passed toreceive_response
,process
orprocess_async
M
is the largest const generic type parameter ofRequest
references passed to any sending methods of this struct
Fields
interface: I
timer: T
Implementations
Send a request, wait for an ACK and then wait for a response.
response_len
is the largest expected length of the returned data.
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());
Send a request and wait for an ACK.
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());
Send a request.
use pn532::Request;
let mut pn532 = get_pn532();
pn532.send(&Request::GET_FIRMWARE_VERSION);
Receive an ACK frame.
This should be done after send
was called and the interface was checked to be ready.
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();
}
Receive a response frame.
This should be done after send
and receive_ack
was called and
the interface was checked to be ready.
response_len
is the largest expected length of the returned data.
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);
}
Send a request, wait for an ACK and then wait for a response.
response_len
is the largest expected length of the returned data.
use pn532::Request;
let mut pn532 = get_async_pn532();
let future = pn532.process_async(&Request::GET_FIRMWARE_VERSION, 4);
Trait Implementations
Auto Trait Implementations
impl<I, T, const N: usize> RefUnwindSafe for Pn532<I, T, N> where
I: RefUnwindSafe,
T: RefUnwindSafe,
impl<I, T, const N: usize> UnwindSafe for Pn532<I, T, N> where
I: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more