Skip to content

Commit

Permalink
I2C transactions were fixed in esp-hal 0.21, remove workaround for PN…
Browse files Browse the repository at this point in the history
…532 reading
  • Loading branch information
zargony committed Oct 27, 2024
1 parent b37a98d commit 3fb6948
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions firmware/partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ nvs, data, nvs, 0x9000, 0x3000,
config, 0x54, 0x44, 0xc000, 0x1000,
otadata, data, ota, 0xd000, 0x2000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
ota_0, app, ota_0, 0x110000, 1M,
ota_1, app, ota_1, 0x210000, 1M,
factory, app, factory, 0x10000, 2M,
#ota_0, app, ota_0, 0x110000, 1M,
#ota_1, app, ota_1, 0x210000, 1M,
16 changes: 7 additions & 9 deletions firmware/src/pn532.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::convert::Infallible;
use core::fmt::Debug;
use embassy_time::{with_timeout, Duration};
use embedded_hal_async::digital::Wait;
use embedded_hal_async::i2c::I2c;
use embedded_hal_async::i2c::{I2c, Operation};
use log::warn;
use pn532::i2c::{I2C_ADDRESS, PN532_I2C_READY};
use pn532::requests::BorrowedRequest;
Expand Down Expand Up @@ -75,20 +75,18 @@ impl<I2C: I2c, IRQ: Wait<Error = Infallible>> Interface for I2CInterfaceWithIrq<
}

async fn read(&mut self, frame: &mut [u8]) -> Result<(), Self::Error> {
// FIXME: Find a way to drop the first byte (ready status) without copying
// It would be more efficient to use a transaction with separate read operations for status
// and frame, but somehow this results in AckCheckFailed errors with embedded-hal 1.0
// self.i2c.transaction(I2C_ADDRESS, &mut [Operation::Read(&mut buf), Operation::Read(frame)])?;
let mut buf = [0; BUFFER_SIZE + 1];
let mut status = [0];
self.i2c
.read(I2C_ADDRESS, &mut buf[..frame.len() + 1])
.transaction(
I2C_ADDRESS,
&mut [Operation::Read(&mut status), Operation::Read(frame)],
)
.await?;
// Status in a read frame should always indicate ready since `read` is always called after
// `wait_ready`. But sometimes it doesn't, which we ignore for now.
if buf[0] != PN532_I2C_READY {
if status[0] != PN532_I2C_READY {
warn!("PN532: read while not ready");
}
frame.copy_from_slice(&buf[1..frame.len() + 1]);
Ok(())
}
}
Expand Down

0 comments on commit 3fb6948

Please sign in to comment.