From 6d98c5db3dfb5b2d643e0f1e27e5399006e49c1c Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 17 Mar 2022 15:20:20 +0800 Subject: [PATCH 1/5] fix braille keyboard mappings --- services/keyboard/src/main.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index 91f08a7d0..85e79ae24 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -325,10 +325,11 @@ mod implementation { */ let was_idle = self.chord_active == 0; for rc in krs.keydowns.iter() { + log::info!("keydown r: {} c: {}", rc.r, rc.c); self.chord[rc.r as usize][rc.c as usize] = true; self.chord_active += 1; } - log::trace!("self.chord: {:?}", self.chord); + log::info!("self.chord: {:?}", self.chord); let mut keystates: Vec = Vec::new(); let now = self.ticktimer.elapsed_ms(); @@ -339,7 +340,7 @@ mod implementation { if self.chord_active != 0 && ((now - self.chord_timestamp) >= self.chord_interval as u64) && !self.chord_captured { self.chord_captured = true; - log::trace!("interpreting chords"); + log::info!("interpreting chords"); // extract chord state /* keyboard: @@ -349,13 +350,20 @@ mod implementation { 1 4 2 5 */ + /* + 7/5 0/1 1/2 5/7 4/8 8/6 + 2/3 2/3 + 8/0 6/4 3/9 + 8/3 5/2 3/6 + 8/2 + */ let keys: [bool; 6] = [ - self.chord[5][7], - self.chord[4][8], - self.chord[3][9], self.chord[1][2], self.chord[0][1], - self.chord[8][0], + self.chord[7][5], + self.chord[5][7], + self.chord[4][8], + self.chord[8][6], ]; let mut keycode: usize = 0; for i in 0..keys.len() { @@ -363,7 +371,7 @@ mod implementation { keycode |= 1 << i; } } - log::trace!("keycode: 0x{:x}", keycode); + log::info!("keycode: 0x{:x}", keycode); let keychar = match keycode { 0b000_001 => Some('a'), 0b000_011 => Some('b'), @@ -418,15 +426,15 @@ mod implementation { let space = self.chord[2][3]; if space { keystates.push(' '); } - let esc = self.chord[8][6]; + let esc = self.chord[8][0]; let bs: char = 0x8_u8.into(); // back space if esc { keystates.push(bs); } - let func = self.chord[7][5]; + let func = self.chord[3][9]; let cr: char = 0xd_u8.into(); // carriage return if func { keystates.push(cr); } - log::trace!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}", + log::info!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}", up, left, right, down, center, space, esc, func); } for rc in krs.keyups.iter() { From 04f2e0fd2a4b301f4de4a7f463743b863cc228d6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 17 Mar 2022 17:56:27 +0800 Subject: [PATCH 2/5] restore headphone/speaker volume on resume --- services/codec/src/backend/tlv320aic3100.rs | 26 +++++++++++++++++---- services/codec/src/main.rs | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/services/codec/src/backend/tlv320aic3100.rs b/services/codec/src/backend/tlv320aic3100.rs index 5f98a6c85..48ded9bfb 100644 --- a/services/codec/src/backend/tlv320aic3100.rs +++ b/services/codec/src/backend/tlv320aic3100.rs @@ -28,6 +28,10 @@ pub struct Codec { live: bool, conn: xous::CID, drain: bool, + // to recall values through suspend/resume + speaker_gain: f32, + headphone_left_gain: f32, + headphone_right_gain: f32, } static SILENCE: [u32; FIFO_DEPTH] = [ZERO_PCM as u32 | (ZERO_PCM as u32) << 16; FIFO_DEPTH]; @@ -138,6 +142,9 @@ impl Codec { tx_stat_errors: 0, rx_stat_errors: 0, drain: false, + speaker_gain: -6.0, + headphone_left_gain: -15.0, + headphone_right_gain: -15.0, }; xous::claim_interrupt( @@ -182,6 +189,8 @@ impl Codec { } } self.susres_manager.resume(); + self.set_speaker_gain_db(self.speaker_gain); + self.set_headphone_gain_db(self.headphone_left_gain, self.headphone_right_gain); } pub fn init(&mut self) { @@ -191,6 +200,9 @@ impl Codec { self.audio_ports(); log::trace!("audio_mixer"); self.audio_mixer(); + // this restores the user state of gain, which is overriden during the audio_mixer() reset sequence + self.set_speaker_gain_db(self.speaker_gain); + self.set_headphone_gain_db(self.headphone_left_gain, self.headphone_right_gain); log::trace!("audio initialized!"); self.initialized = true; } @@ -233,6 +245,7 @@ impl Codec { } pub fn set_speaker_gain_db(&mut self, gain_db: f32) { + self.speaker_gain = gain_db; if gain_db <= -79.0 { // mute self.w(0, &[1]); // select page 1 @@ -247,18 +260,21 @@ impl Codec { } } - pub fn set_headphone_gain_db(&mut self, gain_db: f32) { - if gain_db <= -79.0 { + pub fn set_headphone_gain_db(&mut self, gain_db_left: f32, gain_db_right: f32) { + self.headphone_left_gain = gain_db_left; + self.headphone_right_gain = gain_db_right; + if gain_db_left <= -79.0 && gain_db_right <= -79.0 { // mute self.w(0, &[1]); // select page 1 self.w(31, &[0b0_0_0_10_1_0_0]); // headphones powered down } else { - let code = analog_volume_db_to_code(gain_db); + let code_left = analog_volume_db_to_code(gain_db_left); + let code_right = analog_volume_db_to_code(gain_db_right); self.w(0, &[1]); // select page 1 self.w(31, &[0b1_1_00011_0]); // headphones powered up self.w(36, &[ - 0b1_000_0000 | code, // HPL - 0b1_000_0000 | code, // HPR + 0b1_000_0000 | code_left, // HPL + 0b1_000_0000 | code_right, // HPR ]); } } diff --git a/services/codec/src/main.rs b/services/codec/src/main.rs index 1eefd3504..62f480f58 100644 --- a/services/codec/src/main.rs +++ b/services/codec/src/main.rs @@ -217,7 +217,7 @@ fn xmain() -> ! { }, _ => log::error!("got speaker volume primitive that we don't recognize, ignoring!"), }; - codec.set_headphone_gain_db(headphone_analog_gain_db); + codec.set_headphone_gain_db(headphone_analog_gain_db, headphone_analog_gain_db); }), None => { log::error!("couldn't convert opcode"); From 0f9ea0473a6544c65a170160ea29acb323aaeb37 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 17 Mar 2022 17:56:42 +0800 Subject: [PATCH 3/5] add sleep/resume indicator for the blind --- services/llio/Cargo.toml | 1 + services/llio/src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/services/llio/Cargo.toml b/services/llio/Cargo.toml index e25dbe4a2..8b4acac67 100644 --- a/services/llio/Cargo.toml +++ b/services/llio/Cargo.toml @@ -32,5 +32,6 @@ chrono = "0.4" [features] debugprint = [] wfi_off = [] # useful for serial port debugging, forces power on so the UART characters can finish printing +tts = [] default = [] # "debugprint" #default = ["debugprint"] # , "fccagent" diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 6a5e72c4d..d6e8cc65c 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -443,6 +443,10 @@ mod implementation { }, } } + /// this vibrates until the device sleeps + pub fn tts_sleep_indicate(&mut self) { + self.power_csr.wfo(utra::power::VIBE_VIBE, 1); + } pub fn xadc_vbus(&self) -> u16 { self.xadc_csr.rf(utra::trng::XADC_VBUS_XADC_VBUS) as u16 } @@ -597,7 +601,8 @@ mod implementation { pub fn set_usb_disable(&mut self, state: bool) { self.usb_disable = state; } - + pub fn tts_sleep_indicate(&mut self) { + } } } @@ -761,8 +766,12 @@ fn xmain() -> ! { match FromPrimitive::from_usize(msg.body.id()) { Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, { llio.suspend(); + #[cfg(feature="tts")] + llio.tts_sleep_indicate(); // this happens after the suspend call because we don't want the sleep indicator to be restored on resume susres.suspend_until_resume(token).expect("couldn't execute suspend/resume"); llio.resume(); + #[cfg(feature="tts")] + llio.vibe(VibePattern::Double); lockstatus_force_update = true; // notify the status bar that yes, it does need to redraw the lock status, even if the value hasn't changed since the last read }), Some(Opcode::CrgMode) => msg_scalar_unpack!(msg, _mode, _, _, _, { From 5d754efc0712d08649a320ebc432176c79a54dce Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 17 Mar 2022 17:56:52 +0800 Subject: [PATCH 4/5] reduce debug verbosity on braille --- services/keyboard/src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index 85e79ae24..b69a6cf1e 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -329,7 +329,7 @@ mod implementation { self.chord[rc.r as usize][rc.c as usize] = true; self.chord_active += 1; } - log::info!("self.chord: {:?}", self.chord); + log::trace!("self.chord: {:?}", self.chord); let mut keystates: Vec = Vec::new(); let now = self.ticktimer.elapsed_ms(); @@ -340,7 +340,7 @@ mod implementation { if self.chord_active != 0 && ((now - self.chord_timestamp) >= self.chord_interval as u64) && !self.chord_captured { self.chord_captured = true; - log::info!("interpreting chords"); + log::trace!("interpreting chords"); // extract chord state /* keyboard: @@ -371,7 +371,7 @@ mod implementation { keycode |= 1 << i; } } - log::info!("keycode: 0x{:x}", keycode); + log::trace!("keycode: 0x{:x}", keycode); let keychar = match keycode { 0b000_001 => Some('a'), 0b000_011 => Some('b'), @@ -434,7 +434,7 @@ mod implementation { let cr: char = 0xd_u8.into(); // carriage return if func { keystates.push(cr); } - log::info!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}", + log::debug!("up {}, left {}, right {}, down, {}, center, {}, space {}, esc {}, func {}", up, left, right, down, center, space, esc, func); } for rc in krs.keyups.iter() { From b1f8c1ea1bfec56bc75925b35c0f4280ef143744 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 17 Mar 2022 18:41:12 +0800 Subject: [PATCH 5/5] add power-on indicator for tts mode --- services/status/src/main.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/status/src/main.rs b/services/status/src/main.rs index 2a65a8837..bc4ac6b40 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -363,6 +363,18 @@ fn xmain() -> ! { log::debug!("subscribe to wifi updates"); netmgr.wifi_state_subscribe(cb_cid, StatusOpcode::WifiStats.to_u32().unwrap()).unwrap(); let mut wifi_status: WlanStatus = WlanStatus::from_ipc(WlanStatusIpc::default()); + + #[cfg(feature="tts")] + thread::spawn({ + move || { + // indicator of boot-up for blind users + let tt = ticktimer_server::Ticktimer::new().unwrap(); + tt.sleep_ms(1500).unwrap(); + let xns = xous_names::XousNames::new().unwrap(); + let llio = llio::Llio::new(&xns); + llio.vibe(llio::VibePattern::Double).unwrap(); + } + }); log::info!("|status: starting main loop"); // don't change this -- factory test looks for this exact string loop { let msg = xous::receive_message(status_sid).unwrap();