mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
basically working OQC test
This commit is contained in:
parent
c2c919ba81
commit
87228ad747
5 changed files with 241 additions and 179 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1303,6 +1303,7 @@ dependencies = [
|
||||||
"com",
|
"com",
|
||||||
"gam",
|
"gam",
|
||||||
"keyboard",
|
"keyboard",
|
||||||
|
"llio",
|
||||||
"log",
|
"log",
|
||||||
"log-server",
|
"log-server",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
|
|
|
||||||
|
|
@ -694,12 +694,14 @@ fn xmain() -> ! {
|
||||||
// - shellchat/environment
|
// - shellchat/environment
|
||||||
// - spinor (for turning off wfi during writes)
|
// - spinor (for turning off wfi during writes)
|
||||||
// - rootkeys (for reboots)
|
// - rootkeys (for reboots)
|
||||||
let llio_sid = xns.register_name(api::SERVER_NAME_LLIO, Some(7)).expect("can't register server");
|
// - oqc-test (for testing the vibe motor)
|
||||||
|
let num_conns = 8;
|
||||||
|
let llio_sid = xns.register_name(api::SERVER_NAME_LLIO, Some(num_conns)).expect("can't register server");
|
||||||
log::trace!("registered with NS -- {:?}", llio_sid);
|
log::trace!("registered with NS -- {:?}", llio_sid);
|
||||||
|
|
||||||
// create the I2C handler thread
|
// create the I2C handler thread
|
||||||
// each connection to llio also creates an i2c connection, so it has the same expectation list
|
// each connection to llio also creates an i2c connection, so it has the same expectation list
|
||||||
let i2c_sid = xns.register_name(api::SERVER_NAME_I2C, Some(7)).expect("can't register I2C thread");
|
let i2c_sid = xns.register_name(api::SERVER_NAME_I2C, Some(num_conns)).expect("can't register I2C thread");
|
||||||
log::trace!("registered I2C thread with NS -- {:?}", i2c_sid);
|
log::trace!("registered I2C thread with NS -- {:?}", i2c_sid);
|
||||||
let (sid0, sid1, sid2, sid3) = i2c_sid.to_u32();
|
let (sid0, sid1, sid2, sid3) = i2c_sid.to_u32();
|
||||||
xous::create_thread_4(i2c_thread, sid0 as usize, sid1 as usize, sid2 as usize, sid3 as usize).expect("couldn't start I2C handler thread");
|
xous::create_thread_4(i2c_thread, sid0 as usize, sid1 as usize, sid2 as usize, sid3 as usize).expect("couldn't start I2C handler thread");
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ num-traits = {version = "0.2", default-features = false}
|
||||||
gam = {path = "../gam"}
|
gam = {path = "../gam"}
|
||||||
keyboard = {path = "../keyboard"}
|
keyboard = {path = "../keyboard"}
|
||||||
com = {path = "../com"}
|
com = {path = "../com"}
|
||||||
|
llio = {path = "../llio"}
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
utralib = { path = "../../utralib"}
|
utralib = { path = "../../utralib"}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ mod api;
|
||||||
use api::*;
|
use api::*;
|
||||||
use num_traits::*;
|
use num_traits::*;
|
||||||
use gam::modal::*;
|
use gam::modal::*;
|
||||||
use std::collections::HashMap;
|
|
||||||
use keyboard::{RowCol, KeyRawStates};
|
use keyboard::{RowCol, KeyRawStates};
|
||||||
|
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
|
|
@ -17,11 +16,17 @@ fn xmain() -> ! {
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
// one connection expected:
|
// one connection expected:
|
||||||
// - shellchat program initiator
|
// - shellchat program initiator
|
||||||
let oqc_sid = xns.register_name(api::SERVER_NAME_OQC, Some(1)).expect("can't register server");
|
// - keyboard callback
|
||||||
|
let oqc_sid = xns.register_name(api::SERVER_NAME_OQC, Some(2)).expect("can't register server");
|
||||||
|
|
||||||
let ticktimer = ticktimer_server::Ticktimer::new().unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().unwrap();
|
||||||
let kbd = keyboard::Keyboard::new(&xns).unwrap();
|
let kbd = keyboard::Keyboard::new(&xns).unwrap();
|
||||||
|
kbd.register_raw_listener(
|
||||||
|
SERVER_NAME_OQC,
|
||||||
|
Opcode::KeyCode.to_usize().unwrap()
|
||||||
|
);
|
||||||
let com = com::Com::new(&xns).unwrap();
|
let com = com::Com::new(&xns).unwrap();
|
||||||
|
let llio = llio::Llio::new(&xns).unwrap();
|
||||||
|
|
||||||
let test_cid = xous::connect(oqc_sid).unwrap();
|
let test_cid = xous::connect(oqc_sid).unwrap();
|
||||||
let mut test_action = Notification::new(
|
let mut test_action = Notification::new(
|
||||||
|
|
@ -56,14 +61,10 @@ fn xmain() -> ! {
|
||||||
Opcode::ModalKeys.to_u32().unwrap(),
|
Opcode::ModalKeys.to_u32().unwrap(),
|
||||||
Opcode::ModalDrop.to_u32().unwrap(),
|
Opcode::ModalDrop.to_u32().unwrap(),
|
||||||
);
|
);
|
||||||
kbd.register_raw_listener(
|
|
||||||
SERVER_NAME_OQC,
|
|
||||||
Opcode::KeyCode.to_usize().unwrap()
|
|
||||||
);
|
|
||||||
|
|
||||||
// test the screen
|
// test the screen
|
||||||
com.set_backlight(255, 255).unwrap();
|
com.set_backlight(255, 255).unwrap();
|
||||||
test_modal.gam.selftest(3_000); // 12_000 by default
|
test_modal.gam.selftest(8_000); // 12_000 by default
|
||||||
|
|
||||||
// now start the keyboard test
|
// now start the keyboard test
|
||||||
timeout = if timeout_set > 120_000 {
|
timeout = if timeout_set > 120_000 {
|
||||||
|
|
@ -79,6 +80,7 @@ fn xmain() -> ! {
|
||||||
Some(bot_str.as_str()), false, None);
|
Some(bot_str.as_str()), false, None);
|
||||||
test_modal.activate();
|
test_modal.activate();
|
||||||
test_modal.redraw();
|
test_modal.redraw();
|
||||||
|
test_modal.gam.set_vibe(true).unwrap();
|
||||||
|
|
||||||
// start a thread that advances the timer when not hitting keys
|
// start a thread that advances the timer when not hitting keys
|
||||||
xous::create_thread_2(ping_thread, xous::connect(oqc_sid).unwrap() as usize, timeout as usize).unwrap();
|
xous::create_thread_2(ping_thread, xous::connect(oqc_sid).unwrap() as usize, timeout as usize).unwrap();
|
||||||
|
|
@ -89,76 +91,88 @@ fn xmain() -> ! {
|
||||||
test_run = true;
|
test_run = true;
|
||||||
}),
|
}),
|
||||||
Some(Opcode::KeyCode) => {
|
Some(Opcode::KeyCode) => {
|
||||||
if test_finished {
|
if test_run {
|
||||||
// we'll continue to get keycodes, but ignore them once the test is finished
|
if test_finished {
|
||||||
continue;
|
// we'll continue to get keycodes, but ignore them once the test is finished
|
||||||
}
|
continue;
|
||||||
let elapsed = ticktimer.elapsed_ms();
|
|
||||||
if elapsed - start_time < timeout {
|
|
||||||
let buffer = unsafe {
|
|
||||||
xous_ipc::Buffer::from_memory_message(msg.body.memory_message().unwrap())
|
|
||||||
};
|
|
||||||
let krs = buffer.to_original::<[(u8, u8); 32],_>().unwrap();
|
|
||||||
let mut rawstates = KeyRawStates::new();
|
|
||||||
for &(r, c) in krs[..16].iter() {
|
|
||||||
if r != 255 || c != 255 {
|
|
||||||
rawstates.keydowns.push(RowCol{r, c});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for &(r, c) in krs[16..].iter() {
|
let elapsed = ticktimer.elapsed_ms();
|
||||||
if r!= 255 || c != 255 {
|
if elapsed - start_time < timeout {
|
||||||
rawstates.keyups.push(RowCol{r, c});
|
let buffer = unsafe {
|
||||||
|
xous_ipc::Buffer::from_memory_message(msg.body.memory_message().unwrap())
|
||||||
|
};
|
||||||
|
let krs = buffer.to_original::<[(u8, u8); 32],_>().unwrap();
|
||||||
|
let mut rawstates = KeyRawStates::new();
|
||||||
|
for &(r, c) in krs[..16].iter() {
|
||||||
|
if r != 255 || c != 255 {
|
||||||
|
rawstates.keydowns.push(RowCol{r, c});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for &(r, c) in krs[16..].iter() {
|
||||||
|
if r!= 255 || c != 255 {
|
||||||
|
rawstates.keyups.push(RowCol{r, c});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if rawstates.keydowns.len() > 0 { // only worry about keydowns
|
if rawstates.keydowns.len() > 0 { // only worry about keydowns
|
||||||
for &key in rawstates.keydowns.iter() {
|
for &key in rawstates.keydowns.iter() {
|
||||||
match remaining.get(&key) {
|
for (rc, hit) in remaining.iter_mut() {
|
||||||
Some(_hit) => {
|
if *rc == key {
|
||||||
log::info!("got {}", map_codes(key));
|
*hit = true;
|
||||||
remaining.insert(key, true);
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
if key.r != 254 { // 254 is (ab)used by the tester thread to create a ping event
|
|
||||||
log::warn!("got unexpected r/c: {:?}", key)
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
/*
|
||||||
|
match remaining.get(&key) {
|
||||||
|
Some(_hit) => {
|
||||||
|
log::info!("got {}", map_codes(key));
|
||||||
|
remaining.insert(key, true);
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
if key.r != 254 { // 254 is (ab)used by the tester thread to create a ping event
|
||||||
|
log::warn!("got unexpected r/c: {:?}", key)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
if elapsed - last_redraw_time > 100 { // rate limit redraws to 10Hz
|
||||||
|
render_string(&mut bot_str, &remaining, timeout - (elapsed - start_time));
|
||||||
|
test_modal.modify(None, None, false,
|
||||||
|
Some(bot_str.as_str()), false, None);
|
||||||
|
test_modal.redraw();
|
||||||
|
last_redraw_time = elapsed;
|
||||||
|
llio.vibe(llio::VibePattern::Short).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if elapsed - last_redraw_time > 100 { // rate limit redraws to 10Hz
|
|
||||||
render_string(&mut bot_str, &remaining, timeout - (elapsed - start_time));
|
|
||||||
test_modal.modify(None, None, false,
|
|
||||||
Some(bot_str.as_str()), false, None);
|
|
||||||
test_modal.redraw();
|
|
||||||
last_redraw_time = elapsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// iterate and see if all keys have been hit
|
// iterate and see if all keys have been hit
|
||||||
let mut finished = true;
|
let mut finished = true;
|
||||||
for &vals in remaining.values() {
|
for &(_rc, vals) in remaining.iter() {
|
||||||
if vals == false {
|
if vals == false {
|
||||||
finished = false;
|
finished = false;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if finished {
|
||||||
if finished {
|
passing = Some(true);
|
||||||
passing = Some(true);
|
com.set_backlight(0, 0).unwrap();
|
||||||
|
test_modal.gam.relinquish_focus().unwrap();
|
||||||
|
log::info!("all keys hit, exiting");
|
||||||
|
test_finished = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// timeout
|
||||||
|
passing = Some(false);
|
||||||
com.set_backlight(0, 0).unwrap();
|
com.set_backlight(0, 0).unwrap();
|
||||||
test_modal.gam.relinquish_focus().unwrap();
|
test_modal.gam.relinquish_focus().unwrap();
|
||||||
log::info!("all keys hit, exiting");
|
log::info!("test done, relinquishing focus");
|
||||||
test_finished = true;
|
test_finished = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// timeout
|
// simply ignore the reports in
|
||||||
passing = Some(false);
|
// we have to register our key listener early on, otherwise the rootkeys won't work for normal use
|
||||||
com.set_backlight(0, 0).unwrap();
|
// we do want the keyboard listener slots to be fully occupied, otherwise something nefarious could
|
||||||
test_modal.gam.relinquish_focus().unwrap();
|
// squat the unused port...
|
||||||
log::info!("test done, relinquishing focus");
|
|
||||||
test_finished = true;
|
|
||||||
}
|
|
||||||
if !test_run {
|
|
||||||
log::warn!("OQC got keycodes when unexpected");
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(Opcode::Status) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::Status) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
|
|
@ -200,62 +214,62 @@ fn xmain() -> ! {
|
||||||
xous::terminate_process(0)
|
xous::terminate_process(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn populate_vectors() -> HashMap::<RowCol, bool> {
|
fn populate_vectors() -> Vec::<(RowCol, bool)> {
|
||||||
let mut vectors = HashMap::<RowCol, bool>::new();
|
let mut vectors = Vec::<(RowCol, bool)>::new();
|
||||||
vectors.insert(RowCol::new(0, 0), false);
|
vectors.push((RowCol::new(0, 0), false));
|
||||||
vectors.insert(RowCol::new(0, 1), false);
|
vectors.push((RowCol::new(0, 1), false));
|
||||||
vectors.insert(RowCol::new(0, 2), false);
|
vectors.push((RowCol::new(0, 2), false));
|
||||||
vectors.insert(RowCol::new(0, 3), false);
|
vectors.push((RowCol::new(0, 3), false));
|
||||||
vectors.insert(RowCol::new(0, 4), false);
|
vectors.push((RowCol::new(0, 4), false));
|
||||||
vectors.insert(RowCol::new(4, 5), false);
|
vectors.push((RowCol::new(4, 5), false));
|
||||||
vectors.insert(RowCol::new(4, 6), false);
|
vectors.push((RowCol::new(4, 6), false));
|
||||||
vectors.insert(RowCol::new(4, 7), false);
|
vectors.push((RowCol::new(4, 7), false));
|
||||||
vectors.insert(RowCol::new(4, 8), false);
|
vectors.push((RowCol::new(4, 8), false));
|
||||||
vectors.insert(RowCol::new(4, 9), false);
|
vectors.push((RowCol::new(4, 9), false));
|
||||||
vectors.insert(RowCol::new(1, 0), false);
|
vectors.push((RowCol::new(1, 0), false));
|
||||||
vectors.insert(RowCol::new(1, 1), false);
|
vectors.push((RowCol::new(1, 1), false));
|
||||||
vectors.insert(RowCol::new(1, 2), false);
|
vectors.push((RowCol::new(1, 2), false));
|
||||||
vectors.insert(RowCol::new(1, 3), false);
|
vectors.push((RowCol::new(1, 3), false));
|
||||||
vectors.insert(RowCol::new(1, 4), false);
|
vectors.push((RowCol::new(1, 4), false));
|
||||||
vectors.insert(RowCol::new(5, 5), false);
|
vectors.push((RowCol::new(5, 5), false));
|
||||||
vectors.insert(RowCol::new(5, 6), false);
|
vectors.push((RowCol::new(5, 6), false));
|
||||||
vectors.insert(RowCol::new(5, 7), false);
|
vectors.push((RowCol::new(5, 7), false));
|
||||||
vectors.insert(RowCol::new(5, 8), false);
|
vectors.push((RowCol::new(5, 8), false));
|
||||||
vectors.insert(RowCol::new(5, 9), false);
|
vectors.push((RowCol::new(5, 9), false));
|
||||||
vectors.insert(RowCol::new(2, 0), false);
|
vectors.push((RowCol::new(2, 0), false));
|
||||||
vectors.insert(RowCol::new(2, 1), false);
|
vectors.push((RowCol::new(2, 1), false));
|
||||||
vectors.insert(RowCol::new(2, 2), false);
|
vectors.push((RowCol::new(2, 2), false));
|
||||||
vectors.insert(RowCol::new(2, 3), false);
|
vectors.push((RowCol::new(2, 3), false));
|
||||||
vectors.insert(RowCol::new(2, 4), false);
|
vectors.push((RowCol::new(2, 4), false));
|
||||||
vectors.insert(RowCol::new(6, 5), false);
|
vectors.push((RowCol::new(6, 5), false));
|
||||||
vectors.insert(RowCol::new(6, 6), false);
|
vectors.push((RowCol::new(6, 6), false));
|
||||||
vectors.insert(RowCol::new(6, 7), false);
|
vectors.push((RowCol::new(6, 7), false));
|
||||||
vectors.insert(RowCol::new(6, 8), false);
|
vectors.push((RowCol::new(6, 8), false));
|
||||||
vectors.insert(RowCol::new(6, 9), false);
|
vectors.push((RowCol::new(6, 9), false));
|
||||||
vectors.insert(RowCol::new(3, 0), false);
|
vectors.push((RowCol::new(3, 0), false));
|
||||||
vectors.insert(RowCol::new(3, 1), false);
|
vectors.push((RowCol::new(3, 1), false));
|
||||||
vectors.insert(RowCol::new(3, 2), false);
|
vectors.push((RowCol::new(3, 2), false));
|
||||||
vectors.insert(RowCol::new(3, 3), false);
|
vectors.push((RowCol::new(3, 3), false));
|
||||||
vectors.insert(RowCol::new(3, 4), false);
|
vectors.push((RowCol::new(3, 4), false));
|
||||||
vectors.insert(RowCol::new(7, 5), false);
|
vectors.push((RowCol::new(7, 5), false));
|
||||||
vectors.insert(RowCol::new(7, 6), false);
|
vectors.push((RowCol::new(7, 6), false));
|
||||||
vectors.insert(RowCol::new(7, 7), false);
|
vectors.push((RowCol::new(7, 7), false));
|
||||||
vectors.insert(RowCol::new(7, 8), false);
|
vectors.push((RowCol::new(7, 8), false));
|
||||||
vectors.insert(RowCol::new(7, 9), false);
|
vectors.push((RowCol::new(7, 9), false));
|
||||||
vectors.insert(RowCol::new(8, 5), false);
|
vectors.push((RowCol::new(8, 5), false));
|
||||||
vectors.insert(RowCol::new(8, 6), false);
|
vectors.push((RowCol::new(8, 6), false));
|
||||||
vectors.insert(RowCol::new(8, 7), false);
|
vectors.push((RowCol::new(8, 7), false));
|
||||||
vectors.insert(RowCol::new(8, 8), false);
|
vectors.push((RowCol::new(8, 8), false));
|
||||||
vectors.insert(RowCol::new(8, 9), false);
|
vectors.push((RowCol::new(8, 9), false));
|
||||||
vectors.insert(RowCol::new(8, 0), false);
|
vectors.push((RowCol::new(8, 0), false));
|
||||||
vectors.insert(RowCol::new(8, 1), false);
|
vectors.push((RowCol::new(8, 1), false));
|
||||||
vectors.insert(RowCol::new(3, 8), false);
|
vectors.push((RowCol::new(3, 8), false));
|
||||||
vectors.insert(RowCol::new(3, 9), false);
|
vectors.push((RowCol::new(3, 9), false));
|
||||||
vectors.insert(RowCol::new(8, 3), false);
|
vectors.push((RowCol::new(8, 3), false));
|
||||||
vectors.insert(RowCol::new(3, 6), false);
|
vectors.push((RowCol::new(3, 6), false));
|
||||||
vectors.insert(RowCol::new(6, 4), false);
|
vectors.push((RowCol::new(6, 4), false));
|
||||||
vectors.insert(RowCol::new(8, 2), false);
|
vectors.push((RowCol::new(8, 2), false));
|
||||||
vectors.insert(RowCol::new(5, 2), false);
|
vectors.push((RowCol::new(5, 2), false));
|
||||||
|
|
||||||
vectors
|
vectors
|
||||||
}
|
}
|
||||||
|
|
@ -305,6 +319,7 @@ fn map_codes(code: RowCol) -> &'static str {
|
||||||
(7, 8) => "?",
|
(7, 8) => "?",
|
||||||
//(7, 9) => "↩️",
|
//(7, 9) => "↩️",
|
||||||
(7, 9) => "RET",
|
(7, 9) => "RET",
|
||||||
|
|
||||||
(8, 5) => "LS",
|
(8, 5) => "LS",
|
||||||
(8, 6) => ",",
|
(8, 6) => ",",
|
||||||
(8, 7) => "SP",
|
(8, 7) => "SP",
|
||||||
|
|
@ -327,25 +342,30 @@ fn map_codes(code: RowCol) -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_string(txt: &mut String, remaining: &HashMap<RowCol, bool>, time_remaining: u64) {
|
fn render_string(txt: &mut String, remaining: &Vec::<(RowCol, bool)>, time_remaining: u64) {
|
||||||
txt.clear();
|
txt.clear();
|
||||||
let mut keyrowstrs: [String; 5] = [
|
let mut keyrowstrs: [String; 7] = [
|
||||||
|
String::new(),
|
||||||
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
];
|
];
|
||||||
for (&code, &was_hit) in remaining.iter() {
|
for &(code, was_hit) in remaining.iter() {
|
||||||
if !was_hit {
|
if !was_hit {
|
||||||
// lookup table to help organize the key hits remaining
|
// lookup table to help organize the key hits remaining
|
||||||
let draw_row = match code.r {
|
let draw_row = match code.r {
|
||||||
0 | 4 => 0,
|
0 | 4 => 2,
|
||||||
1 | 5 => 1,
|
1 => 3,
|
||||||
2 | 6 => 2,
|
5 => if code.c != 2 {3} else {0},
|
||||||
3 => if code.c > 5 {3} else {4}
|
2 => 4,
|
||||||
7 => 3,
|
6 => if code.c != 4 {4} else {0},
|
||||||
_ => 4,
|
3 => if code.c <= 4 {5} else { if code.c == 6 {0} else {1} }
|
||||||
|
7 => 5,
|
||||||
|
8 => if code.c >= 5 {6} else { if code.c <= 1 {1} else {0} },
|
||||||
|
_ => 6,
|
||||||
};
|
};
|
||||||
keyrowstrs[draw_row].push_str(map_codes(code));
|
keyrowstrs[draw_row].push_str(map_codes(code));
|
||||||
keyrowstrs[draw_row].push_str(" ");
|
keyrowstrs[draw_row].push_str(" ");
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ use spectrum_analyzer::{FrequencyLimit, FrequencySpectrum, samples_fft_to_spectr
|
||||||
use spectrum_analyzer::windows::hann_window;
|
use spectrum_analyzer::windows::hann_window;
|
||||||
use rtc::{DateTime, Weekday};
|
use rtc::{DateTime, Weekday};
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
use core::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
|
static AUDIO_OQC: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Test {
|
pub struct Test {
|
||||||
|
|
@ -31,6 +34,7 @@ pub struct Test {
|
||||||
end_elapsed: Option<u64>,
|
end_elapsed: Option<u64>,
|
||||||
//kbd: Arc<Mutex<keyboard::Keyboard>>,
|
//kbd: Arc<Mutex<keyboard::Keyboard>>,
|
||||||
oqc: oqc_test::Oqc,
|
oqc: oqc_test::Oqc,
|
||||||
|
oqc_start: u64,
|
||||||
jtag: jtag::Jtag,
|
jtag: jtag::Jtag,
|
||||||
}
|
}
|
||||||
impl Test {
|
impl Test {
|
||||||
|
|
@ -66,6 +70,7 @@ impl Test {
|
||||||
end_elapsed: None,
|
end_elapsed: None,
|
||||||
//kbd: Arc::new(Mutex::new(keyboard::Keyboard::new(&xns).unwrap())),
|
//kbd: Arc::new(Mutex::new(keyboard::Keyboard::new(&xns).unwrap())),
|
||||||
oqc: oqc_test::Oqc::new(&xns).unwrap(),
|
oqc: oqc_test::Oqc::new(&xns).unwrap(),
|
||||||
|
oqc_start: 0,
|
||||||
jtag: jtag::Jtag::new(&xns).unwrap(),
|
jtag: jtag::Jtag::new(&xns).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -408,7 +413,27 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
susres.initiate_suspend().unwrap();
|
susres.initiate_suspend().unwrap();
|
||||||
env.ticktimer.sleep_ms(1000).unwrap(); // pause for the suspend/resume cycle
|
env.ticktimer.sleep_ms(1000).unwrap(); // pause for the suspend/resume cycle
|
||||||
|
|
||||||
/*
|
self.oqc.trigger(60_000);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match self.oqc.status() {
|
||||||
|
Some(true) => {
|
||||||
|
write!(ret, "{}\nCHECK: was backlight on?\ndid keyboard vibrate?\nwas there sound?\nIf so, then PASS\nNow engage PROG switch.",
|
||||||
|
env.com.ssid_fetch_as_string().unwrap()
|
||||||
|
).unwrap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Some(false) => {
|
||||||
|
write!(ret, "Keyboard test failed.").unwrap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
env.ticktimer.sleep_ms(500).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AUDIO_OQC.store(true, Ordering::Relaxed);
|
||||||
self.freq = 659.25;
|
self.freq = 659.25;
|
||||||
self.left_play = true;
|
self.left_play = true;
|
||||||
self.right_play = true;
|
self.right_play = true;
|
||||||
|
|
@ -425,36 +450,8 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
}
|
}
|
||||||
self.play_sample = 0.0;
|
self.play_sample = 0.0;
|
||||||
self.rec_sample = 0;
|
self.rec_sample = 0;
|
||||||
|
self.oqc_start = env.ticktimer.elapsed_ms();
|
||||||
self.codec.resume().unwrap();
|
self.codec.resume().unwrap();
|
||||||
*/
|
|
||||||
|
|
||||||
self.oqc.trigger(60_000);
|
|
||||||
|
|
||||||
loop {
|
|
||||||
match self.oqc.status() {
|
|
||||||
Some(true) => {
|
|
||||||
write!(ret, "{}\nCHECK: was backlight on?\nIf so, then PASS\nNow engage PROG switch.",
|
|
||||||
env.com.ssid_fetch_as_string().unwrap()
|
|
||||||
).unwrap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Some(false) => {
|
|
||||||
write!(ret, "Keyboard test failed.").unwrap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
env.ticktimer.sleep_ms(500).unwrap();
|
|
||||||
if self.freq >= 659.0 && self.freq <= 660.0 {
|
|
||||||
self.freq = 783.99;
|
|
||||||
} else if self.freq >= 783.0 && self.freq <= 784.0 {
|
|
||||||
self.freq = 987.77;
|
|
||||||
} else {
|
|
||||||
self.freq = 659.25
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.codec.pause().unwrap();
|
|
||||||
|
|
||||||
env.llio.wfi_override(false).unwrap();
|
env.llio.wfi_override(false).unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -467,6 +464,32 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
env.gam.set_devboot(false).unwrap();
|
env.gam.set_devboot(false).unwrap();
|
||||||
write!(ret, "devboot off").unwrap();
|
write!(ret, "devboot off").unwrap();
|
||||||
}
|
}
|
||||||
|
"ship" => {
|
||||||
|
if ((env.llio.adc_vbus().unwrap() as f64) * 0.005033) > 1.5 {
|
||||||
|
// if power is plugged in, deny powerdown request
|
||||||
|
write!(ret, "System can't go into ship mode while charging. Unplug charging cable and try again.").unwrap();
|
||||||
|
} else {
|
||||||
|
if Ok(true) == env.gam.shipmode_blank_request() {
|
||||||
|
env.ticktimer.sleep_ms(500).unwrap(); // let the screen redraw
|
||||||
|
|
||||||
|
// allow EC to snoop, so that it can wake up the system
|
||||||
|
env.llio.allow_ec_snoop(true).unwrap();
|
||||||
|
// allow the EC to power me down
|
||||||
|
env.llio.allow_power_off(true).unwrap();
|
||||||
|
// now send the power off command
|
||||||
|
env.com.ship_mode().unwrap();
|
||||||
|
|
||||||
|
// now send the power off command
|
||||||
|
env.com.power_off_soc().unwrap();
|
||||||
|
|
||||||
|
log::info!("CMD: ship mode now!");
|
||||||
|
// pause execution, nothing after this should be reachable
|
||||||
|
env.ticktimer.sleep_ms(10000).unwrap(); // ship mode happens in 10 seconds
|
||||||
|
log::info!("CMD: if you can read this, ship mode failed!");
|
||||||
|
}
|
||||||
|
write!(ret, "Ship mode request denied").unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
() // do nothing
|
() // do nothing
|
||||||
}
|
}
|
||||||
|
|
@ -476,7 +499,7 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn callback(&mut self, msg: &MessageEnvelope, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
fn callback(&mut self, msg: &MessageEnvelope, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||||
const AMPLITUDE: f32 = 0.8;
|
const AMPLITUDE: f32 = 0.8;
|
||||||
|
|
||||||
match &msg.body {
|
match &msg.body {
|
||||||
|
|
@ -489,6 +512,7 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
*free_play
|
*free_play
|
||||||
};
|
};
|
||||||
self.framecount += frames_to_push as u32;
|
self.framecount += frames_to_push as u32;
|
||||||
|
|
||||||
log::debug!("f{} p{}", self.framecount, frames_to_push);
|
log::debug!("f{} p{}", self.framecount, frames_to_push);
|
||||||
for _ in 0..frames_to_push {
|
for _ in 0..frames_to_push {
|
||||||
let mut frame: [u32; codec::FIFO_DEPTH] = [ZERO_PCM as u32 | (ZERO_PCM as u32) << 16; codec::FIFO_DEPTH];
|
let mut frame: [u32; codec::FIFO_DEPTH] = [ZERO_PCM as u32 | (ZERO_PCM as u32) << 16; codec::FIFO_DEPTH];
|
||||||
|
|
@ -507,23 +531,37 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
}
|
}
|
||||||
self.codec.swap_frames(&mut frames).unwrap();
|
self.codec.swap_frames(&mut frames).unwrap();
|
||||||
|
|
||||||
let rec_samples = self.recbuf.as_slice_mut::<u32>();
|
if !AUDIO_OQC.load(Ordering::Relaxed) {
|
||||||
let rec_len = rec_samples.len();
|
let rec_samples = self.recbuf.as_slice_mut::<u32>();
|
||||||
loop {
|
let rec_len = rec_samples.len();
|
||||||
if let Some(frame) = frames.dq_frame() {
|
loop {
|
||||||
for &sample in frame.iter() {
|
if let Some(frame) = frames.dq_frame() {
|
||||||
rec_samples[self.rec_sample] = sample;
|
for &sample in frame.iter() {
|
||||||
// increment and wrap around on overflow
|
rec_samples[self.rec_sample] = sample;
|
||||||
// we should be sampling a continuous tone, so we'll get a small phase discontinutity once in the buffer.
|
// increment and wrap around on overflow
|
||||||
// should be no problem for the analysis phase.
|
// we should be sampling a continuous tone, so we'll get a small phase discontinutity once in the buffer.
|
||||||
self.rec_sample += 1;
|
// should be no problem for the analysis phase.
|
||||||
if self.rec_sample >= rec_len {
|
self.rec_sample += 1;
|
||||||
self.rec_sample = 0;
|
if self.rec_sample >= rec_len {
|
||||||
|
self.rec_sample = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
break;
|
||||||
break;
|
};
|
||||||
};
|
}
|
||||||
|
} else {
|
||||||
|
let elapsed = env.ticktimer.elapsed_ms();
|
||||||
|
let increment = (elapsed - self.oqc_start) / 500;
|
||||||
|
match increment % 3 {
|
||||||
|
0 => self.freq = 659.25,
|
||||||
|
1 => self.freq = 783.99,
|
||||||
|
2 => self.freq = 987.77,
|
||||||
|
_ => self.freq = 659.25,
|
||||||
|
}
|
||||||
|
if elapsed - self.oqc_start > 6000 {
|
||||||
|
self.codec.pause().unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Message::Move(_mm) => {
|
Message::Move(_mm) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue