Crate pn532[][src]

Expand description

no_std implementation of the Pn532 protocol using embedded_hal traits.

Since communication with the Pn532 can be rather slow at times, communication can be split into multiple parts, a timeout can be provided or an async runtime can be used.

The Pn532 supports different serial links. The Interface trait abstracts over these different links.

Interface can be manually implemented or one these provided interface structs can be used:

SPI example

use pn532::{Pn532, Request};
use pn532::spi::SPIInterface;
use pn532::IntoDuration; // trait for `ms()`, your HAL might have its own

// spi, cs and timer are structs implementing their respective embedded_hal traits.

let interface = SPIInterface {
    spi,
    cs,
};
let mut pn532: Pn532<_, _, 32> = Pn532::new(interface, timer);
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]);
    }
}

msb-spi feature

If you want to use either spi::SPIInterface or spi::SPIInterfaceWithIrq and your peripheral cannot be set to lsb mode you need to enable the msb-spi feature of this crate.

Re-exports

pub use crate::requests::Request;

Modules

I2C interfaces

Pn532 Requests

SerialPort interface

SPI interfaces

Structs

Main struct of this crate

Enums

Pn532 Error

Some commands return a status byte. If this byte is not zero it will contain an ErrorCode.

Traits

Abstraction over the different serial links. Either SPI, I2C or HSU (High Speed UART).

Extension trait with convenience methods for turning u64 into Duration