Skip to content

support for other chips from st25r39xxx family #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ cargo build --release --manifest-path rnfc-fm175xx/Cargo.toml --features ''
cargo build --release --manifest-path rnfc-fm175xx/Cargo.toml --features 'defmt'
cargo build --release --manifest-path rnfc-fm175xx/Cargo.toml --features 'log'

cargo build --release --manifest-path rnfc-st25r39/Cargo.toml --features ''
cargo build --release --manifest-path rnfc-st25r39/Cargo.toml --features 'defmt'
cargo build --release --manifest-path rnfc-st25r39/Cargo.toml --features 'log'
cargo build --release --manifest-path rnfc-st25r39/Cargo.toml --features 'st25r3916, defmt'
cargo build --release --manifest-path rnfc-st25r39/Cargo.toml --features 'st25r3916, log'
cargo build --release --manifest-path rnfc-st25r39/Cargo.toml --features 'st25r3911b, defmt'
cargo build --release --manifest-path rnfc-st25r39/Cargo.toml --features 'st25r3911b, log'

cargo build --release --manifest-path rnfc-acr122u/Cargo.toml --features ''

Expand Down
2 changes: 1 addition & 1 deletion examples/st25r39-disco/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ default = [
]

[dependencies]
rnfc-st25r39 = { path = "../../rnfc-st25r39", features = [ "defmt" ] }
rnfc-st25r39 = { path = "../../rnfc-st25r39", features = [ "defmt", "st25r3916" ] }
rnfc = { path = "../../rnfc", features = [ "defmt" ] }

embassy-executor = { version = "0.7", features = ["defmt", "nightly", "arch-cortex-m", "executor-thread"] }
Expand Down
3 changes: 2 additions & 1 deletion examples/st25r39-disco/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use embassy_time::{Duration, Timer};
use rnfc::iso14443a::Poller;
use rnfc::iso_dep::IsoDepA;
use rnfc::traits::iso_dep::Reader;
use rnfc_st25r39::{SpiInterface, St25r39, WakeupConfig, WakeupMethodConfig, WakeupPeriod, WakeupReference};
use rnfc_st25r39::impls::{WakeupConfig, WakeupMethodConfig, WakeupPeriod, WakeupReference};
use rnfc_st25r39::{SpiInterface, St25r39};
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
Expand Down
7 changes: 5 additions & 2 deletions rnfc-st25r39/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ version = "0.1.0"
edition = "2021"

[features]
defmt = [ "dep:defmt", "rnfc-traits/defmt", "heapless/defmt-03" ]
defmt = ["dep:defmt", "rnfc-traits/defmt", "heapless/defmt-03"]
st25r3916 = []
st25r3911b = []
default = []

[dependencies]
defmt = { version = "0.3", optional = true }
Expand All @@ -13,6 +16,6 @@ log = { version = "0.4.14", optional = true }
embassy-time = { version = "0.4" }
embassy-futures = { version = "0.1.1" }
rnfc-traits = { version = "0.1.0", path = "../rnfc-traits" }
heapless = "0.8"
heapless = "0.8"
embedded-hal = { version = "1" }
embedded-hal-async = { version = "1" }
9 changes: 5 additions & 4 deletions rnfc-st25r39/src/aat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ impl<I: Interface, IrqPin: InputPin + Wait> St25r39<I, IrqPin> {
a = new_a;
b = new_b;
}
self.regs().ant_tune_a().write_value(a)?;
self.regs().ant_tune_a().write_value(b)?;

self.regs().ant_tune_a().write_value(a.into())?;
self.regs().ant_tune_a().write_value(b.into())?;

Ok(())
}

async fn aat_measure(&mut self, a: u8, b: u8, conf: &AatConfig) -> Result<u32, Error<I::Error>> {
self.regs().ant_tune_a().write_value(a)?;
self.regs().ant_tune_a().write_value(b)?;
self.regs().ant_tune_a().write_value(a.into())?;
self.regs().ant_tune_a().write_value(b.into())?;

// Wait for caps to settle.
Timer::after(Duration::from_millis(1)).await;
Expand Down
101 changes: 101 additions & 0 deletions rnfc-st25r39/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/// Direct commands
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[allow(unused)]
pub enum Command {
// #[cfg(feature = "st25r3916")]
// Puts the chip in default state, st25r39{16,20} (same as after power-up)
// SetDefault1 = 0xC0,
/// Puts the chip in default state (same as after power-up)
SetDefault = 0xC1,
/// Stops all activities and clears FIFO same as C3
Stop = 0xC2,
/// Stops all activities and clears FIFO same as C2
Clear = 0xC3,
/// Transmit with CRC
TransmitWithCrc = 0xC4,
/// Transmit without CRC
TransmitWithoutCrc = 0xC5,
/// Transmit REQA
TransmitReqa = 0xC6,
/// Transmit WUPA
TransmitWupa = 0xC7,
/// NFC transmit with Initial RF Collision Avoidance
InitialRfCollision = 0xC8,
/// NFC transmit with Response RF Collision Avoidance
ResponseRfCollisionN = 0xC9,
#[cfg(feature = "st25r3911b")]
/// NFC transmit with Response RF Collision Avoidance with n=0
ResponseRfCollisionNzero = 0xCA,
#[cfg(feature = "st25r3911b")]
/// Accepted in NFCIP-1 active communication bitrate detection mode
GotoNormalNFCMode = 0xCB,
#[cfg(feature = "st25r3911b")]
/// Presets Rx and Tx configuration based on state of Mode definition register and Bit rate definition register
PresetAnalog = 0xCC,
#[cfg(feature = "st25r3916")]
/// Passive target logic to Sense/Idle state
GotoSense = 0xCD,
#[cfg(feature = "st25r3916")]
/// Passive target logic to Sleep/Halt state
GotoSleep = 0xCE,
/// Mask receive data
MaskReceiveData = 0xD0,
/// Unmask receive data
UnmaskReceiveData = 0xD1,
#[cfg(feature = "st25r3916")]
/// AM Modulation state change
AmModStateChange = 0xD2,
/// Measure singal amplitude on RFI inputs
MeasureAmplitude = 0xD3,
#[cfg(feature = "st25r3911b")]
/// Performs gain reduction based on the current noise level
Squelch = 0xD4,
/// Reset RX Gain
ResetRxgain = 0xD5,
/// Adjust regulators
AdjustRegulators = 0xD6,
#[cfg(feature = "st25r3911b")]
/// Starts sequence that activates the Tx, measures the modulation depth, and adapts it to comply with the specified modulation depth
CalibrateModDepth = 0xD7,
#[cfg(feature = "st25r3911b")]
/// Calibrates antenna
CalibrateAntenna = 0xD8,
#[cfg(feature = "st25r3916")]
/// Starts the sequence to adjust the driver timing.
CalibrateDriverTiming = 0xD8,
/// Measure phase between RFO and RFI signal
MeasurePhase = 0xD9,
/// Clear RSSI bits and restart the measurement
ClearRssi = 0xDA,
#[cfg(feature = "st25r3916")]
/// Clears FIFO, Collision and IRQ status
ClearFifo = 0xDB,
/// Transparent mode - amplitude of signal present on RFI inputs is measured, result is stored in A/D converter output register
TransparentMode = 0xDC,
/// Calibrate the capacitive sensor
CalibrateCSensor = 0xDD,
/// Measure capacitance sensor
MeasureCapacitance = 0xDE,
/// Measure power supply voltage
MeasureVdd = 0xDF,
/// Start the general purpose timer
StartGpTimer = 0xE0,
/// Start the wake-up timer
StartWupTimer = 0xE1,
/// Start the mask-receive timer
StartMaskReceiveTimer = 0xE2,
/// Start the no-response timer
StartNoResponseTimer = 0xE3,
#[cfg(feature = "st25r3916")]
/// Start PPon2 timer
StartPpon2Timer = 0xE4,
#[cfg(feature = "st25r3916")]
/// Stop No Response Timer
StopNrt = 0xE8,
#[cfg(feature = "st25r3916")]
/// Enable R/W access to the test registers
SpaceBAccess = 0xFB,
/// Enable R/W access to the test registers
TestAccess = 0xFC,
}
85 changes: 85 additions & 0 deletions rnfc-st25r39/src/impls/interrupts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[allow(unused)]
pub enum Interrupt {
#[cfg(feature = "st25r3911b")]
/// IRQ due to error and wake-up timer
Err = 0,
#[cfg(feature = "st25r3916")]
/// RFU interrupt
Rfu = 0,
#[cfg(feature = "st25r3911b")]
/// IRQ due to timer or NFC event
Tim = 1,
#[cfg(feature = "st25r3916")]
/// automatic reception restart interrupt
RxRest = 1,
/// bit collision interrupt
Col = 2,
/// end of transmission interrupt
Txe = 3,
/// end of receive interrupt
Rxe = 4,
/// start of receive interrupt
Rxs = 5,
/// FIFO water level interrupt
Fwl = 6,
/// oscillator stable interrupt
Osc = 7,
/// initiator bit rate recognised interrupt
Nfct = 8,
/// minimum guard time expired interrupt
Cat = 9,
/// collision during RF collision avoidance interrupt
Cac = 10,
/// external field off interrupt
Eof = 11,
/// external field on interrupt
Eon = 12,
/// general purpose timer expired interrupt
Gpe = 13,
/// no-response timer expired interrupt
Nre = 14,
/// termination of direct command interrupt
Dct = 15,
/// wake-up due to capacitance measurement
Wcap = 16,
/// wake-up due to phase interrupt
Wph = 17,
/// wake-up due to amplitude interrupt
Wam = 18,
/// wake-up interrupt
Wt = 19,
/// hard framing error interrupt
Err1 = 20,
/// soft framing error interrupt
Err2 = 21,
/// parity error interrupt
Par = 22,
/// CRC error interrupt
Crc = 23,
#[cfg(feature = "st25r3916")]
/// 106kb/s Passive target state interrupt: Active
WuA = 24,
#[cfg(feature = "st25r3916")]
/// 106kb/s Passive target state interrupt: Active*
WuAX = 25,
#[cfg(feature = "st25r3916")]
/// RFU2 interrupt
Rfu2 = 26,
#[cfg(feature = "st25r3916")]
/// 212/424b/s Passive target interrupt: Active
WuF = 27,
#[cfg(feature = "st25r3916")]
/// RXE with an automatic response interrupt
RxePta = 28,
#[cfg(feature = "st25r3916")]
/// Anticollision done and Field On interrupt
Apon = 29,
#[cfg(feature = "st25r3916")]
/// Passive target slot number water level interrupt
SlWl = 30,
#[cfg(feature = "st25r3916")]
/// PPON2 Field on waiting Timer interrupt
Ppon2 = 31,
}
Loading