xpanse_api/interfaces/nfc.rs
1//! NFC device interfaces.
2//!
3//! Provides NFC device capabilities that drivers can publish through the
4//! [`crate::registry::Registry`] and that apps can use to read/write NFC tags.
5//! Transport-agnostic: supports I2C, SPI, or other backends.
6
7use alloc::boxed::Box;
8use core::future::Future;
9use core::pin::Pin;
10
11/// NFC operation error.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum NfcError {
14 /// Communication error (I2C/SPI/etc).
15 BusError,
16 /// Invalid address or length.
17 InvalidAddress,
18 /// Device not responding.
19 NoDevice,
20}
21
22/// Async interface for interacting with an NFC device.
23pub trait Nfc: Send {
24 /// Read data from the NFC device EEPROM at the specified address.
25 ///
26 /// # Arguments
27 /// * `address` - Starting byte address in the EEPROM.
28 /// * `data` - Buffer to read into.
29 ///
30 /// # Returns
31 /// `Ok(())` on success, `Err` on communication failure.
32 fn read<'a>(
33 &'a mut self,
34 address: u16,
35 data: &'a mut [u8],
36 ) -> Pin<Box<dyn Future<Output = Result<(), NfcError>> + 'a>>;
37
38 /// Write data to the NFC device EEPROM at the specified address.
39 ///
40 /// # Arguments
41 /// * `address` - Starting byte address in the EEPROM.
42 /// * `data` - Data to write.
43 ///
44 /// # Returns
45 /// `Ok(())` on success, `Err` on communication failure or write protection.
46 fn write<'a>(
47 &'a mut self,
48 address: u16,
49 data: &'a [u8],
50 ) -> Pin<Box<dyn Future<Output = Result<(), NfcError>> + 'a>>;
51
52 /// Detect if an NFC field is present.
53 ///
54 /// Returns `true` if a reader field is currently active.
55 fn detect_field<'a>(
56 &'a mut self,
57 ) -> Pin<Box<dyn Future<Output = Result<bool, NfcError>> + 'a>>;
58}
59