Update libtock-drivers/ NFC driver
This commit is contained in:
63
third_party/libtock-drivers/src/nfc.rs
vendored
63
third_party/libtock-drivers/src/nfc.rs
vendored
@@ -9,6 +9,7 @@ mod command_nr {
|
||||
pub const RECEIVE: usize = 2;
|
||||
pub const EMULATE: usize = 3;
|
||||
pub const CONFIGURE: usize = 4;
|
||||
pub const FRAMEDELAYMAX: usize = 5;
|
||||
}
|
||||
|
||||
mod subscribe_nr {
|
||||
@@ -22,24 +23,29 @@ mod allow_nr {
|
||||
pub const RECEIVE: usize = 2;
|
||||
}
|
||||
|
||||
pub fn enable_emulation() {
|
||||
emulate(true);
|
||||
}
|
||||
pub struct NfcTag {}
|
||||
|
||||
pub fn disable_emulation() {
|
||||
emulate(false);
|
||||
}
|
||||
impl NfcTag {
|
||||
pub fn enable_emulation() {
|
||||
NfcTag::emulate(true);
|
||||
}
|
||||
|
||||
pub fn emulate(enabled: bool) -> bool {
|
||||
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::EMULATE, enabled as usize, 0);
|
||||
pub fn disable_emulation() {
|
||||
NfcTag::emulate(false);
|
||||
}
|
||||
|
||||
pub fn emulate(enabled: bool) -> bool {
|
||||
let result_code =
|
||||
syscalls::command(DRIVER_NUMBER, command_nr::EMULATE, enabled as usize, 0);
|
||||
if result_code.is_err() {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selected() -> bool {
|
||||
/// Subscribe to the tag being SELECTED callback.
|
||||
pub fn selected() -> bool {
|
||||
let is_selected = Cell::new(false);
|
||||
let mut is_selected_alarm = || is_selected.set(true);
|
||||
let subscription = syscalls::subscribe::<callback::Identity0Consumer, _>(
|
||||
@@ -53,18 +59,35 @@ pub fn selected() -> bool {
|
||||
|
||||
util::yieldk_for(|| is_selected.get());
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn configure(tag_type: u8) -> bool {
|
||||
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::CONFIGURE, tag_type as usize, 0);
|
||||
/// Configure the tag type command.
|
||||
pub fn configure(tag_type: u8) -> bool {
|
||||
let result_code =
|
||||
syscalls::command(DRIVER_NUMBER, command_nr::CONFIGURE, tag_type as usize, 0);
|
||||
if result_code.is_err() {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive(buf: &mut [u8]) -> bool {
|
||||
/// Set the maximum frame delay value to support
|
||||
/// transmission with the reader.
|
||||
pub fn set_framedelaymax(delay: u32) -> bool {
|
||||
let result_code =
|
||||
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.
|
||||
/// 2. Subscribe to having a successful receive callback.
|
||||
/// 3. Issue the request for reception.
|
||||
pub fn receive(buf: &mut [u8]) -> bool {
|
||||
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::RECEIVE, buf);
|
||||
if result.is_err() {
|
||||
return false;
|
||||
@@ -88,9 +111,12 @@ pub fn receive(buf: &mut [u8]) -> bool {
|
||||
|
||||
util::yieldk_for(|| done.get());
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transmit(buf: &mut [u8]) -> bool {
|
||||
/// 1. Share with the driver a buffer containing the app's reply.
|
||||
/// 2. Subscribe to having a successful transmission callback.
|
||||
/// 3. Issue the request for transmitting.
|
||||
pub fn transmit(buf: &mut [u8], amount: usize) -> bool {
|
||||
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::TRANSMIT, buf);
|
||||
if result.is_err() {
|
||||
return false;
|
||||
@@ -107,11 +133,12 @@ pub fn transmit(buf: &mut [u8]) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT, 0, 0);
|
||||
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT, amount, 0);
|
||||
if result_code.is_err() {
|
||||
return false;
|
||||
}
|
||||
|
||||
util::yieldk_for(|| done.get());
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user