Resolved Review Comments
This commit is contained in:
@@ -921,13 +921,6 @@ if __name__ == "__main__":
|
|||||||
const="console_test",
|
const="console_test",
|
||||||
help=("Compiles and installs the console_test example that tests the "
|
help=("Compiles and installs the console_test example that tests the "
|
||||||
"console driver with messages of various lengths."))
|
"console driver with messages of various lengths."))
|
||||||
apps_group.add_argument(
|
|
||||||
"--nfct_test",
|
|
||||||
dest="application",
|
|
||||||
action="store_const",
|
|
||||||
const="nfct_test",
|
|
||||||
help=("Compiles and installs the nfct_test example that tests the "
|
|
||||||
"NFC driver."))
|
|
||||||
|
|
||||||
main_parser.set_defaults(features=["with_ctap1"])
|
main_parser.set_defaults(features=["with_ctap1"])
|
||||||
|
|
||||||
|
|||||||
72
third_party/libtock-drivers/src/nfc.rs
vendored
72
third_party/libtock-drivers/src/nfc.rs
vendored
@@ -1,5 +1,6 @@
|
|||||||
use crate::util;
|
use crate::util;
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
|
use libtock_core::result::{ENOMEM, SUCCESS};
|
||||||
use libtock_core::{callback, syscalls};
|
use libtock_core::{callback, syscalls};
|
||||||
|
|
||||||
const DRIVER_NUMBER: usize = 0x30003;
|
const DRIVER_NUMBER: usize = 0x30003;
|
||||||
@@ -23,25 +24,26 @@ mod allow_nr {
|
|||||||
pub const RECEIVE: usize = 2;
|
pub const RECEIVE: usize = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum TransOrRecvStatus {
|
||||||
|
Error,
|
||||||
|
InvalidBuffer,
|
||||||
|
OOM,
|
||||||
|
Success,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct NfcTag {}
|
pub struct NfcTag {}
|
||||||
|
|
||||||
impl NfcTag {
|
impl NfcTag {
|
||||||
pub fn enable_emulation() {
|
pub fn enable_emulation() -> bool {
|
||||||
NfcTag::emulate(true);
|
NfcTag::emulate(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable_emulation() {
|
pub fn disable_emulation() -> bool {
|
||||||
NfcTag::emulate(false);
|
NfcTag::emulate(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn emulate(enabled: bool) -> bool {
|
fn emulate(enabled: bool) -> bool {
|
||||||
let result_code =
|
syscalls::command(DRIVER_NUMBER, command_nr::EMULATE, enabled as usize, 0).is_ok()
|
||||||
syscalls::command(DRIVER_NUMBER, command_nr::EMULATE, enabled as usize, 0);
|
|
||||||
if result_code.is_err() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Subscribe to the tag being SELECTED callback.
|
/// Subscribe to the tag being SELECTED callback.
|
||||||
@@ -63,34 +65,21 @@ impl NfcTag {
|
|||||||
|
|
||||||
/// Configure the tag type command.
|
/// Configure the tag type command.
|
||||||
pub fn configure(tag_type: u8) -> bool {
|
pub fn configure(tag_type: u8) -> bool {
|
||||||
let result_code =
|
syscalls::command(DRIVER_NUMBER, command_nr::CONFIGURE, tag_type as usize, 0).is_ok()
|
||||||
syscalls::command(DRIVER_NUMBER, command_nr::CONFIGURE, tag_type as usize, 0);
|
|
||||||
if result_code.is_err() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum frame delay value to support
|
/// Set the maximum frame delay value to support transmission with the reader.
|
||||||
/// transmission with the reader.
|
|
||||||
pub fn set_framedelaymax(delay: u32) -> bool {
|
pub fn set_framedelaymax(delay: u32) -> bool {
|
||||||
let result_code =
|
syscalls::command(DRIVER_NUMBER, command_nr::FRAMEDELAYMAX, delay as usize, 0).is_ok()
|
||||||
syscalls::command(DRIVER_NUMBER, command_nr::FRAMEDELAYMAX, delay as usize, 0);
|
|
||||||
if result_code.is_err() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 1. Share with the driver a buffer.
|
/// 1. Share with the driver a buffer.
|
||||||
/// 2. Subscribe to having a successful receive callback.
|
/// 2. Subscribe to having a successful receive callback.
|
||||||
/// 3. Issue the request for reception.
|
/// 3. Issue the request for reception.
|
||||||
pub fn receive(buf: &mut [u8]) -> bool {
|
pub fn receive(buf: &mut [u8; 256]) -> TransOrRecvStatus {
|
||||||
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::RECEIVE, buf);
|
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::RECEIVE, buf);
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
return false;
|
return TransOrRecvStatus::InvalidBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
let done = Cell::new(false);
|
let done = Cell::new(false);
|
||||||
@@ -101,25 +90,28 @@ impl NfcTag {
|
|||||||
&mut alarm,
|
&mut alarm,
|
||||||
);
|
);
|
||||||
if subscription.is_err() {
|
if subscription.is_err() {
|
||||||
return false;
|
return TransOrRecvStatus::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::RECEIVE, 0, 0);
|
let result_code =
|
||||||
if result_code.is_err() {
|
unsafe { syscalls::raw::command(DRIVER_NUMBER, command_nr::RECEIVE, 0, 0) };
|
||||||
return false;
|
match result_code {
|
||||||
|
SUCCESS => (),
|
||||||
|
ENOMEM => return TransOrRecvStatus::OOM,
|
||||||
|
_ => return TransOrRecvStatus::Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
util::yieldk_for(|| done.get());
|
util::yieldk_for(|| done.get());
|
||||||
true
|
TransOrRecvStatus::Success
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 1. Share with the driver a buffer containing the app's reply.
|
/// 1. Share with the driver a buffer containing the app's reply.
|
||||||
/// 2. Subscribe to having a successful transmission callback.
|
/// 2. Subscribe to having a successful transmission callback.
|
||||||
/// 3. Issue the request for transmitting.
|
/// 3. Issue the request for transmitting.
|
||||||
pub fn transmit(buf: &mut [u8], amount: usize) -> bool {
|
pub fn transmit(buf: &mut [u8], amount: usize) -> TransOrRecvStatus {
|
||||||
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::TRANSMIT, buf);
|
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::TRANSMIT, buf);
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
return false;
|
return TransOrRecvStatus::InvalidBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
let done = Cell::new(false);
|
let done = Cell::new(false);
|
||||||
@@ -130,15 +122,15 @@ impl NfcTag {
|
|||||||
&mut alarm,
|
&mut alarm,
|
||||||
);
|
);
|
||||||
if subscription.is_err() {
|
if subscription.is_err() {
|
||||||
return false;
|
return TransOrRecvStatus::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT, amount, 0);
|
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT, amount, 0);
|
||||||
if result_code.is_err() {
|
if result_code.is_err() {
|
||||||
return false;
|
return TransOrRecvStatus::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
util::yieldk_for(|| done.get());
|
util::yieldk_for(|| done.get());
|
||||||
true
|
TransOrRecvStatus::Success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user