Crates.io | pn532 |
lib.rs | pn532 |
version | 0.4.0 |
source | src |
created_at | 2019-09-02 17:59:38.848048 |
updated_at | 2024-03-12 09:27:44.392407 |
description | PN532 protocol implementation |
homepage | |
repository | https://github.com/WMT-GmbH/pn532 |
max_upload_size | |
id | 161629 |
size | 77,323 |
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 the four provided interface structs can be used:
spi::SPIInterface
spi::SPIInterfaceWithIrq
i2c::I2CInterface
i2c::I2CInterfaceWithIrq
use pn532::{requests::SAMMode, spi::SPIInterface, Pn532, Request};
use pn532::spi::SPIInterface;
// 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 Err(e) = pn532.process(&Request::sam_configuration(SAMMode::Normal, false), 0, 50.ms()){
println!("Could not initialize PN532: {e:?}")
}
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
featureIf 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.
std
featureEnable the std feature to use serialport::SerialPortInterface
.
Only works for targets supported by the serialport
crate.