Update in libtock-drivers/ and nfct_test.rs application
This commit is contained in:
@@ -925,9 +925,9 @@ if __name__ == "__main__":
|
|||||||
"--nfct_test",
|
"--nfct_test",
|
||||||
dest="application",
|
dest="application",
|
||||||
action="store_const",
|
action="store_const",
|
||||||
const="console_test",
|
const="nfct_test",
|
||||||
help=("Compiles and installs the console_test example that tests the "
|
help=("Compiles and installs the nfct_test example that tests the "
|
||||||
"console driver with messages of various lengths."))
|
"NFC driver."))
|
||||||
|
|
||||||
main_parser.set_defaults(features=["with_ctap1"])
|
main_parser.set_defaults(features=["with_ctap1"])
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ use libtock_drivers::console::Console;
|
|||||||
use libtock_drivers::nfc;
|
use libtock_drivers::nfc;
|
||||||
|
|
||||||
fn main(){
|
fn main(){
|
||||||
|
let mut console = Console::new();
|
||||||
|
|
||||||
writeln!(console, "****************************************").unwrap();
|
writeln!(console, "****************************************").unwrap();
|
||||||
writeln!(console, "nfct_test application is installed").unwrap();
|
writeln!(console, "nfct_test application is installed").unwrap();
|
||||||
writeln!(console, "****************************************").unwrap();
|
writeln!(console, "****************************************").unwrap();
|
||||||
|
|||||||
109
third_party/libtock-drivers/src/nfc.rs
vendored
109
third_party/libtock-drivers/src/nfc.rs
vendored
@@ -22,29 +22,29 @@ mod allow_nr {
|
|||||||
pub const RECEIVE: usize = 2;
|
pub const RECEIVE: usize = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const TX_BUFFER_SIZE: usize = 256;
|
pub fn enable_emulation() {
|
||||||
pub const RX_BUFFER_SIZE: usize = 256;
|
emulate(true);
|
||||||
|
|
||||||
pub struct NfcTag {
|
|
||||||
tx_buffer: [u8; BUFFER_SIZE],
|
|
||||||
rx_buffer: [u8; BUFFER_SIZE],
|
|
||||||
tag_type: u8,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NfcTag {
|
pub fn disable_emulation() {
|
||||||
pub fn new() -> Console {
|
emulate(false);
|
||||||
Console {
|
}
|
||||||
tx_buffer: [0; TX_BUFFER_SIZE],
|
|
||||||
tx_buffer: [0; RX_BUFFER_SIZE],
|
pub fn emulate(enabled: bool) -> bool {
|
||||||
tag_type: 0,
|
let result_code = syscalls::command(
|
||||||
}
|
DRIVER_NUMBER,
|
||||||
|
command_nr::EMULATE,
|
||||||
|
enabled as usize,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
if result_code.is_err() {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_tag_type(&mut self, type: u8) {
|
true
|
||||||
self.tag_type = type;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn selected(&self) -> bool {
|
pub fn selected() -> bool {
|
||||||
let is_selected = Cell::new(false);
|
let is_selected = Cell::new(false);
|
||||||
let mut is_selected_alarm = || is_selected.set(true);
|
let mut is_selected_alarm = || is_selected.set(true);
|
||||||
let subscription = syscalls::subscribe::<callback::Identity0Consumer, _>(
|
let subscription = syscalls::subscribe::<callback::Identity0Consumer, _>(
|
||||||
@@ -53,14 +53,75 @@ impl NfcTag {
|
|||||||
&mut is_selected_alarm,
|
&mut is_selected_alarm,
|
||||||
);
|
);
|
||||||
if subscription.is_err() {
|
if subscription.is_err() {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
util::yieldk_for(|| is_selected.get());
|
util::yieldk_for(|| is_selected.get());
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn receive(&self) {
|
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 {
|
||||||
|
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::RECEIVE, buf);
|
||||||
|
if result.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let done = Cell::new(false);
|
||||||
|
let mut alarm = || done.set(true);
|
||||||
|
let subscription = syscalls::subscribe::<callback::Identity0Consumer, _>(
|
||||||
|
DRIVER_NUMBER,
|
||||||
|
subscribe_nr::RECEIVE,
|
||||||
|
&mut alarm,
|
||||||
|
);
|
||||||
|
if subscription.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::RECEIVE, 0, 0);
|
||||||
|
if result_code.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
util::yieldk_for(|| done.get());
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn transmit(buf: &mut [u8]) -> bool {
|
||||||
|
let result = syscalls::allow(DRIVER_NUMBER, allow_nr::TRANSMIT, buf);
|
||||||
|
if result.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let done = Cell::new(false);
|
||||||
|
let mut alarm = || done.set(true);
|
||||||
|
let subscription = syscalls::subscribe::<callback::Identity0Consumer, _>(
|
||||||
|
DRIVER_NUMBER,
|
||||||
|
subscribe_nr::TRANSMIT,
|
||||||
|
&mut alarm,
|
||||||
|
);
|
||||||
|
if subscription.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result_code = syscalls::command(DRIVER_NUMBER, command_nr::TRANSMIT, 0, 0);
|
||||||
|
if result_code.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
util::yieldk_for(|| done.get());
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user