Struct pn532::Pn532

source ·
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 to receive_response, process or process_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>

source

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());
source

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>

source

pub fn new(interface: I, timer: T) -> Self

Create a Pn532 instance

source

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);
source

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();
}
source

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

pub fn abort(&mut self) -> Result<(), Error<I::Error>>

Send an ACK frame to force the PN532 to abort the current process. In that case, the PN532 discontinues the last processing and does not answer anything to the host controller. Then, the PN532 starts again waiting for a new command.

source§

impl<I: Interface, const N: usize> Pn532<I, (), N>

source

pub fn new_async(interface: I) -> Self

Create a Pn532 instance without a timer

source

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);
source

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);

Trait Implementations§

source§

impl<I: Clone, T: Clone, const N: usize> Clone for Pn532<I, T, N>

source§

fn clone(&self) -> Pn532<I, T, N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<I: Debug, T: Debug, const N: usize> Debug for Pn532<I, T, N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I, T, const N: usize> Freeze for Pn532<I, T, N>
where I: Freeze, T: Freeze,

§

impl<I, T, const N: usize> RefUnwindSafe for Pn532<I, T, N>

§

impl<I, T, const N: usize> Send for Pn532<I, T, N>
where I: Send, T: Send,

§

impl<I, T, const N: usize> Sync for Pn532<I, T, N>
where I: Sync, T: Sync,

§

impl<I, T, const N: usize> Unpin for Pn532<I, T, N>
where I: Unpin, T: Unpin,

§

impl<I, T, const N: usize> UnwindSafe for Pn532<I, T, N>
where I: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.