pub struct Pn532<I, T, const N: usize = 32> {
pub interface: I,
pub timer: T,
/* private fields */
}
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 of [Request
] references passed to any sending methods of this struct
Fields§
§interface: I
§timer: T
Implementations§
source§impl<I: Interface, T: CountDown, const N: usize> Pn532<I, T, N>
impl<I: Interface, T: CountDown, const N: usize> Pn532<I, T, N>
sourcepub fn process<'a>(
&mut self,
request: impl Into<BorrowedRequest<'a>>,
response_len: usize,
timeout: T::Time
) -> Result<&[u8], Error<I::Error>>
pub fn process<'a>( &mut self, request: impl Into<BorrowedRequest<'a>>, response_len: usize, timeout: T::Time ) -> Result<&[u8], Error<I::Error>>
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());
sourcepub fn process_no_response<'a>(
&mut self,
request: impl Into<BorrowedRequest<'a>>,
timeout: T::Time
) -> Result<(), Error<I::Error>>
pub fn process_no_response<'a>( &mut self, request: impl Into<BorrowedRequest<'a>>, timeout: T::Time ) -> Result<(), Error<I::Error>>
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());
source§impl<I: Interface, T, const N: usize> Pn532<I, T, N>
impl<I: Interface, T, const N: usize> Pn532<I, T, N>
sourcepub fn send<'a>(
&mut self,
request: impl Into<BorrowedRequest<'a>>
) -> Result<(), Error<I::Error>>
pub fn send<'a>( &mut self, request: impl Into<BorrowedRequest<'a>> ) -> Result<(), Error<I::Error>>
Send a request.
use pn532::Request;
let mut pn532 = get_pn532();
pn532.send(&Request::GET_FIRMWARE_VERSION);
sourcepub fn receive_ack(&mut self) -> Result<(), Error<I::Error>>
pub fn receive_ack(&mut self) -> Result<(), Error<I::Error>>
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();
}
sourcepub fn receive_response(
&mut self,
sent_command: Command,
response_len: usize
) -> Result<&[u8], Error<I::Error>>
pub fn receive_response( &mut self, sent_command: Command, response_len: usize ) -> Result<&[u8], Error<I::Error>>
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);
}
source§impl<I: Interface, const N: usize> Pn532<I, (), N>
impl<I: Interface, const N: usize> Pn532<I, (), N>
sourcepub async fn process_async<'a>(
&mut self,
request: impl Into<BorrowedRequest<'a>>,
response_len: usize
) -> Result<&[u8], Error<I::Error>>
pub async fn process_async<'a>( &mut self, request: impl Into<BorrowedRequest<'a>>, response_len: usize ) -> Result<&[u8], Error<I::Error>>
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);
sourcepub async fn process_no_response_async<'a>(
&mut self,
request: impl Into<BorrowedRequest<'a>>
) -> Result<(), Error<I::Error>>
pub async fn process_no_response_async<'a>( &mut self, request: impl Into<BorrowedRequest<'a>> ) -> Result<(), Error<I::Error>>
Send a request and wait for an ACK.
use pn532::Request;
let mut pn532 = get_async_pn532();
let future = pn532.process_no_response_async(&Request::INLIST_ONE_ISO_A_TARGET);