Expand description
§ST25R95 NFC Transceiver Driver
This crate provides a high-level, type-safe driver for the ST25R95 NFC transceiver chip from STMicroelectronics. The ST25R95 is a multi-protocol NFC transceiver supporting reader and card emulation modes for various NFC protocols.
§Features
- Multi-protocol support: ISO/IEC 14443A/B, ISO/IEC 15693, and FeliCa protocols
- Reader and Card Emulation modes: Operate as either an NFC reader or emulate a card
- Type-state pattern: Compile-time guarantees for correct usage sequences
- Hardware abstraction: Trait-based SPI and GPIO interfaces for flexibility
- Embedded-friendly:
no_stdcompatible with minimal dependencies - Register-level control: Fine-tuned configuration of all ST25R95 parameters
§Type State Pattern
This driver uses a sophisticated type-state pattern to prevent incorrect usage at compile time.
The main St25r95 struct is parameterized by five type state markers:
- Field State (
F):FieldOnorFieldOff- controls whether the RF field is active - Role State (
R):Reader,CardEmulation, orNoRole- defines the operating mode - Protocol State (
P):Iso15693,Iso14443A,Iso14443B,FeliCa, orNoProtocol - SPI Interface (
S): User-provided implementation ofSt25r95Spi - GPIO Interface (
G): User-provided implementation ofSt25r95Gpio
This ensures that operations are only available when the chip is in the correct state. For example, you can only send/receive data when the field is on and a protocol is selected.
§Basic Usage
ⓘ
use st25r95::{St25r95, St25r95Spi, St25r95Gpio};
// Initialize the driver
let mut nfc = St25r95::new(spi_interface, gpio_interface)?;
// Select ISO14443A reader mode
let mut nfc = nfc.protocol_select_iso14443a(Default::default())?;
// Send a command to a tag and receive the response
let response = nfc.send_receive(&[0x26])?; // REQA command
// Turn off the RF field
let nfc = nfc.field_off()?;§Hardware Requirements
- ST25R95 NFC transceiver chip
- SPI interface for communication (MOSI, MISO, SCLK, CS)
- GPIO pin for interrupt handling (IRQ_OUT)
- Optional: GPIO pin for wake-up control (IRQ_IN)
§Protocol Support
§Reader Mode
- ISO/IEC 14443A: MIFARE Classic, MIFARE Ultralight, NTAG, etc.
- ISO/IEC 14443B: Calypso, etc.
- ISO/IEC 15693: Vicinity cards, ICODE SLI, Tag-it HF-I, etc.
- FeliCa: FeliCa cards and tags
§Card Emulation Mode
- ISO/IEC 14443A: Emulate Type A cards with anti-collision support
§Error Handling
The driver provides comprehensive error handling with specific error types for:
- Hardware communication failures
- Invalid parameter ranges
- Protocol-specific errors
- Timeout conditions
See the Error enum for detailed information about possible error conditions.
Modules§
- acc_a
- Protocol-Specific Optimization
- arc_b
- ST25R95 ARC_B Register (Analog RF Control B)
- auto_
detect_ filter - felica
- FeliCa Protocol Support
- iso15693
- ISO/IEC 15693 Vicinity Coupling Protocol Support
- iso14443a
- ISO/IEC 14443 Type A Protocol Support
- iso14443b
- ISO/IEC 14443 Type B Protocol Support
- timer_
window - wakeup
Structs§
- Card
Emulation - Marker type indicating card emulation mode operation
- Ctrl
ResConf - FeliCa
- Marker type for FeliCa protocol
- Field
Off - Marker type indicating the RF field is turned off
- FieldOn
- Marker type indicating the RF field is turned on
- Idle
Params - Configuration parameters for the Idle command
- Iso15693
- Marker type for ISO/IEC 15693 protocol (Vicinity cards)
- Iso14443A
- Marker type for ISO/IEC 14443 Type A protocol
- Iso14443B
- Marker type for ISO/IEC 14443 Type B protocol
- NoProtocol
- Marker type indicating no protocol has been selected
- NoRole
- Marker type indicating no role has been selected
- Poll
Flags - Read
Response - Response from ST25R95 command operations
- Reader
- Marker type indicating reader mode operation
- St25r95
- Main driver struct for the ST25R95 NFC transceiver chip
Enums§
- Command
- ST25R95 Command Enumeration
- Control
- Error
- Comprehensive error type for ST25R95 operations
- Protocol
- Enumeration of supported NFC protocols for the ST25R95
- St25r95
Error - ST25R95 hardware-reported errors
Constants§
- MAX_
BUFFER_ SIZE - Maximum buffer size for SPI communication with the ST25R95 chip
Traits§
- St25r95
Gpio - Trait for GPIO interface with the ST25R95 NFC transceiver
- St25r95
Spi - Trait for SPI communication with the ST25R95 NFC transceiver