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 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: Itimer: 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());

Create a Pn532 instance

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 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.

Create a Pn532 instance without a timer

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.