OLED driver with shared SPI bus integrated
This commit was merged in pull request #35.
This commit is contained in:
+18
-16
@@ -1,11 +1,9 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::convert::Infallible;
|
||||
use embedded_hal::i2c::I2c;
|
||||
use esp_hal::time::{Duration, Instant};
|
||||
use log::{error, info};
|
||||
use pn532::i2c::I2CInterface;
|
||||
use pn532::requests::SAMMode;
|
||||
use pn532::{nb, Pn532, Request};
|
||||
use pn532::{Pn532, Request};
|
||||
|
||||
pub type Pn532Device<I2C> = Pn532<I2CInterface<I2C>, (), 34>;
|
||||
|
||||
@@ -29,10 +27,11 @@ where
|
||||
}
|
||||
|
||||
pub async fn configure_sam(&mut self) -> Result<(), ()> {
|
||||
if let Err(e) = self.pn532.process_async(
|
||||
&Request::sam_configuration(SAMMode::Normal, false),
|
||||
0,
|
||||
).await {
|
||||
if let Err(e) = self
|
||||
.pn532
|
||||
.process_async(&Request::sam_configuration(SAMMode::Normal, false), 0)
|
||||
.await
|
||||
{
|
||||
error!("PN532 SAM configuration failed over I2C: {e:?}");
|
||||
Err(())
|
||||
} else {
|
||||
@@ -42,7 +41,11 @@ where
|
||||
}
|
||||
|
||||
pub async fn poll_target(&mut self) -> Result<(), ()> {
|
||||
match self.pn532.process_async(&Request::INLIST_ONE_ISO_A_TARGET, 23).await {
|
||||
match self
|
||||
.pn532
|
||||
.process_async(&Request::INLIST_ONE_ISO_A_TARGET, 23)
|
||||
.await
|
||||
{
|
||||
Ok(uid) => {
|
||||
info!("PN532 detected NFC target UID: {uid:?}");
|
||||
Ok(())
|
||||
@@ -78,24 +81,23 @@ where
|
||||
for i in (0x0B..=230).step_by(PAGES_PER_READ) {
|
||||
let mut parse_result = Err(());
|
||||
while parse_result.is_err() {
|
||||
let Ok(result) = self.pn532.process_async(&Request::ntag_read(i), PAGES_PER_READ * 4 + 1).await else {
|
||||
let Ok(result) = self
|
||||
.pn532
|
||||
.process_async(&Request::ntag_read(i), PAGES_PER_READ * 4 + 1)
|
||||
.await
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
parse_result = Self::parse_nfc_page(i, result);
|
||||
}
|
||||
let bytes = parse_result.unwrap();
|
||||
let bytes = if i == 0x0B {
|
||||
&bytes[1..]
|
||||
} else {
|
||||
&bytes
|
||||
};
|
||||
let bytes = if i == 0x0B { &bytes[1..] } else { &bytes };
|
||||
data.extend(bytes);
|
||||
}
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
|
||||
pub fn device_mut(&mut self) -> &mut Pn532Device<I2C> {
|
||||
&mut self.pn532
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user