Add read/write for felica

felica types refactor
This commit is contained in:
2026-08-27 10:02:50 +08:00
parent 0810cdb892
commit 86373a2d33
19 changed files with 875 additions and 184 deletions
+5 -4
View File
@@ -1,8 +1,9 @@
use crate::commands::{PN532_COMMAND_TGGETDATA, PN532_COMMAND_TGINITASTARGET, PN532_COMMAND_TGSETDATA};
use crate::error::StatusCode;
use crate::{Error, Interface, Pn532, TargetInitStatus};
use core::time::Duration;
impl<B: Interface> Pn532<B> {
impl<B: Interface, const N: usize> Pn532<B, N> {
/// Initialize the PN532 as a target using a raw command frame.
pub fn tg_init_as_target(
&mut self,
@@ -36,7 +37,7 @@ impl<B: Interface> Pn532<B> {
self.buffer[0] = PN532_COMMAND_TGGETDATA;
self.send(1)?;
let len = self.read_timeout(3000)?;
let len = self.read_timeout(Duration::from_millis(3000))?;
if len == 0 {
return Ok(0);
}
@@ -55,7 +56,7 @@ impl<B: Interface> Pn532<B> {
header: &[u8],
body: &[u8],
) -> Result<(), Error<B::TransportError>> {
if header.len() > crate::driver::PACKET_BUFFER_SIZE - 1 {
if header.len() > N - 1 {
self.buffer[0] = PN532_COMMAND_TGSETDATA;
self.interface.write_command(&self.buffer[..1], header)?;
} else {
@@ -65,7 +66,7 @@ impl<B: Interface> Pn532<B> {
.write_command(&self.buffer[..1 + header.len()], body)?;
}
let len = self.read_timeout(3000)?;
let len = self.read_timeout(Duration::from_millis(3000))?;
if len == 0 || self.buffer[0] != 0 {
return Err(Error::Status(StatusCode::from_repr(self.buffer[0]).unwrap()));
}