add no-codec mode to status

this is for DVT builds where the codec isn't supported, needed
for efuse testing
This commit is contained in:
bunnie 2022-12-08 17:14:21 +08:00
parent a5d341c7a6
commit dd82b7f32a
3 changed files with 49 additions and 31 deletions

View file

@ -61,4 +61,5 @@ dbg-ecupdate = []
ditherpunk = [] ditherpunk = []
test-rekey = [] test-rekey = []
efuse = [] efuse = []
no-codec = []
default = [] default = []

View file

@ -220,6 +220,7 @@ fn wrapped_main() -> ! {
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
let susres = susres::Susres::new_without_hook(&xns).unwrap(); let susres = susres::Susres::new_without_hook(&xns).unwrap();
let mut netmgr = net::NetManager::new(); let mut netmgr = net::NetManager::new();
#[cfg(not(feature="no-codec"))]
let mut codec = codec::Codec::new(&xns).unwrap(); let mut codec = codec::Codec::new(&xns).unwrap();
// screensize is controlled by the GAM, it's set in main.rs near the top // screensize is controlled by the GAM, it's set in main.rs near the top
@ -413,30 +414,32 @@ fn wrapped_main() -> ! {
}); });
// keyboard mapping is restored directly by the keyboard hardware // keyboard mapping is restored directly by the keyboard hardware
#[cfg(not(feature="no-codec"))]
log::info!("audio enabled: {}", all_prefs.audio_enabled); {
match all_prefs.audio_enabled { log::info!("audio enabled: {}", all_prefs.audio_enabled);
true => { match all_prefs.audio_enabled {
match codec.setup_8k_stream() { true => {
Ok(()) => { match codec.setup_8k_stream() {
send_message(prefs_cid, Message::new_scalar(PrefsMenuUpdateOp::UpdateMenuAudioDisabled.to_usize().unwrap(), 0, 0, 0, 0)).unwrap(); Ok(()) => {
Ok(()) send_message(prefs_cid, Message::new_scalar(PrefsMenuUpdateOp::UpdateMenuAudioDisabled.to_usize().unwrap(), 0, 0, 0, 0)).unwrap();
}, Ok(())
Err(e) => Err(e), },
Err(e) => Err(e),
}
} }
} false => Ok(())
false => Ok(()) }.unwrap_or_else(|error| {
}.unwrap_or_else(|error| { log::error!("cannot set audio enabled: {:?}", error);
log::error!("cannot set audio enabled: {:?}", error); });
});
codec.set_headphone_volume(codec::VolumeOps::Set, Some(percentage_to_db(all_prefs.headset_volume) as f32)).unwrap_or_else(|error| { codec.set_headphone_volume(codec::VolumeOps::Set, Some(percentage_to_db(all_prefs.headset_volume) as f32)).unwrap_or_else(|error| {
log::error!("cannot set headphone volume: {:?}", error); log::error!("cannot set headphone volume: {:?}", error);
}); });
codec.set_speaker_volume(codec::VolumeOps::Set, Some(percentage_to_db(all_prefs.earpiece_volume) as f32)).unwrap_or_else(|error| { codec.set_speaker_volume(codec::VolumeOps::Set, Some(percentage_to_db(all_prefs.earpiece_volume) as f32)).unwrap_or_else(|error| {
log::error!("cannot set speaker volume: {:?}", error); log::error!("cannot set speaker volume: {:?}", error);
}); });
}
}); });
// ------------------------ check firmware status and apply updates // ------------------------ check firmware status and apply updates

View file

@ -94,6 +94,7 @@ struct DevicePrefs {
gam: gam::Gam, gam: gam::Gam,
kbd: keyboard::Keyboard, kbd: keyboard::Keyboard,
time_ux_cid: xous::CID, time_ux_cid: xous::CID,
#[cfg(not(feature="no-codec"))]
codec: codec::Codec, codec: codec::Codec,
menu: Option<gam::MenuMatic>, menu: Option<gam::MenuMatic>,
menu_manager_sid: xous::SID, menu_manager_sid: xous::SID,
@ -107,6 +108,7 @@ impl PrefHandler for DevicePrefs {
if match FromPrimitive::from_usize(op) { if match FromPrimitive::from_usize(op) {
Some(other) => { Some(other) => {
let other: PrefsMenuUpdateOp = other; let other: PrefsMenuUpdateOp = other;
#[cfg(not(feature="no-codec"))]
match other { match other {
PrefsMenuUpdateOp::UpdateMenuAudioEnabled => self.alter_menu_audio_off(), PrefsMenuUpdateOp::UpdateMenuAudioEnabled => self.alter_menu_audio_off(),
PrefsMenuUpdateOp::UpdateMenuAudioDisabled => self.alter_menu_audio_on(), PrefsMenuUpdateOp::UpdateMenuAudioDisabled => self.alter_menu_audio_on(),
@ -166,6 +168,7 @@ impl DevicePrefs {
time_ux_cid: xous::CID, time_ux_cid: xous::CID,
menu_manager_sid: xous::SID, menu_manager_sid: xous::SID,
menu_conn: xous::CID, menu_conn: xous::CID,
#[cfg(not(feature="no-codec"))]
codec: codec::Codec, codec: codec::Codec,
status_conn: xous::CID, status_conn: xous::CID,
) -> Self { ) -> Self {
@ -175,6 +178,7 @@ impl DevicePrefs {
gam: gam::Gam::new(&xns).unwrap(), gam: gam::Gam::new(&xns).unwrap(),
kbd: keyboard::Keyboard::new(&xns).unwrap(), kbd: keyboard::Keyboard::new(&xns).unwrap(),
time_ux_cid, time_ux_cid,
#[cfg(not(feature="no-codec"))]
codec, codec,
menu: None, menu: None,
menu_manager_sid, menu_manager_sid,
@ -205,7 +209,7 @@ impl DevicePrefs {
SetTime, SetTime,
SetTimezone, SetTimezone,
]; ];
#[cfg(not(feature="no-codec"))]
if self.codec.is_running().unwrap_or_default() { if self.codec.is_running().unwrap_or_default() {
ret.push(AudioOff); ret.push(AudioOff);
@ -233,9 +237,13 @@ impl DevicePrefs {
WLANMenu => self.wlan_menu(), WLANMenu => self.wlan_menu(),
SetTime => self.set_time_menu(), SetTime => self.set_time_menu(),
SetTimezone => self.set_timezone_menu(), SetTimezone => self.set_timezone_menu(),
#[cfg(not(feature="no-codec"))]
AudioOn => self.audio_on(), AudioOn => self.audio_on(),
#[cfg(not(feature="no-codec"))]
AudioOff => self.audio_off(), AudioOff => self.audio_off(),
#[cfg(not(feature="no-codec"))]
HeadsetVolume => self.headset_volume(), HeadsetVolume => self.headset_volume(),
#[cfg(not(feature="no-codec"))]
EarpieceVolume => self.earpiece_volume(), EarpieceVolume => self.earpiece_volume(),
_ => unimplemented!("should not end up here!"), _ => unimplemented!("should not end up here!"),
@ -438,7 +446,7 @@ impl DevicePrefs {
Ok(()) Ok(())
} }
#[cfg(not(feature="no-codec"))]
fn audio_on(&mut self) -> Result<(), DevicePrefsError> { fn audio_on(&mut self) -> Result<(), DevicePrefsError> {
self.codec.setup_8k_stream()?; self.codec.setup_8k_stream()?;
@ -447,7 +455,7 @@ impl DevicePrefs {
Ok(()) Ok(())
} }
#[cfg(not(feature="no-codec"))]
fn alter_menu_audio_on(&mut self) { fn alter_menu_audio_on(&mut self) {
let menu = self.menu.as_ref().unwrap(); let menu = self.menu.as_ref().unwrap();
@ -483,7 +491,7 @@ impl DevicePrefs {
close_on_select: true, close_on_select: true,
}); });
} }
#[cfg(not(feature="no-codec"))]
fn audio_off(&mut self) -> Result<(), DevicePrefsError> { fn audio_off(&mut self) -> Result<(), DevicePrefsError> {
self.codec.power_off()?; self.codec.power_off()?;
@ -492,7 +500,7 @@ impl DevicePrefs {
Ok(()) Ok(())
} }
#[cfg(not(feature="no-codec"))]
fn alter_menu_audio_off(&mut self) { fn alter_menu_audio_off(&mut self) {
let menu = self.menu.as_ref().unwrap(); let menu = self.menu.as_ref().unwrap();
// hide volume toggles // hide volume toggles
@ -515,7 +523,7 @@ impl DevicePrefs {
close_on_select: true, close_on_select: true,
}); });
} }
#[cfg(not(feature="no-codec"))]
fn headphone_connected(&mut self) -> Result<bool, DevicePrefsError> { fn headphone_connected(&mut self) -> Result<bool, DevicePrefsError> {
match self.codec.poll_headphone_state()? { match self.codec.poll_headphone_state()? {
codec::HeadphoneState::PresentWithMic => Ok(true), codec::HeadphoneState::PresentWithMic => Ok(true),
@ -523,7 +531,7 @@ impl DevicePrefs {
_ => Ok(false), _ => Ok(false),
} }
} }
#[cfg(not(feature="no-codec"))]
fn volume_slider(&mut self, title: &str, headset: bool) -> Result<(i32, u32), DevicePrefsError> { fn volume_slider(&mut self, title: &str, headset: bool) -> Result<(i32, u32), DevicePrefsError> {
// We're aiming at 20 step levels in the UI, which is the result of dividing // We're aiming at 20 step levels in the UI, which is the result of dividing
// 80dB levels available through codec by 4 (https://xkcd.com/221/). // 80dB levels available through codec by 4 (https://xkcd.com/221/).
@ -539,7 +547,7 @@ impl DevicePrefs {
Ok((db_val as i32, val as u32)) Ok((db_val as i32, val as u32))
} }
#[cfg(not(feature="no-codec"))]
fn headset_volume(&mut self) -> Result<(), DevicePrefsError> { // headset -> headphone fn headset_volume(&mut self) -> Result<(), DevicePrefsError> { // headset -> headphone
let (db_val, slider_val) = self.volume_slider(t!("prefs.headphone_volume", xous::LANG), true)?; let (db_val, slider_val) = self.volume_slider(t!("prefs.headphone_volume", xous::LANG), true)?;
self.codec.set_headphone_volume(codec::VolumeOps::Set, Some(db_val as f32))?; self.codec.set_headphone_volume(codec::VolumeOps::Set, Some(db_val as f32))?;
@ -547,7 +555,7 @@ impl DevicePrefs {
Ok(()) Ok(())
} }
#[cfg(not(feature="no-codec"))]
fn earpiece_volume(&mut self) -> Result<(), DevicePrefsError> { // earpiece -> speaker fn earpiece_volume(&mut self) -> Result<(), DevicePrefsError> { // earpiece -> speaker
let (db_val, slider_val) = self.volume_slider(t!("prefs.speaker_volume", xous::LANG), false)?; let (db_val, slider_val) = self.volume_slider(t!("prefs.speaker_volume", xous::LANG), false)?;
self.codec.set_speaker_volume(codec::VolumeOps::Set, Some(db_val as f32))?; self.codec.set_speaker_volume(codec::VolumeOps::Set, Some(db_val as f32))?;
@ -595,13 +603,19 @@ fn run_menu_thread(sid: xous::SID, status_cid: xous::CID) {
let time_sid = xous::create_server().unwrap(); let time_sid = xous::create_server().unwrap();
let time_cid = xous::connect(time_sid).unwrap(); let time_cid = xous::connect(time_sid).unwrap();
crate::time::start_time_ux(time_sid); crate::time::start_time_ux(time_sid);
#[cfg(not(feature="no-codec"))]
let codec = codec::Codec::new(&xns).unwrap(); let codec = codec::Codec::new(&xns).unwrap();
#[cfg(not(feature="no-codec"))]
let mut handlers: Vec<Box<dyn PrefHandler>> = vec![ let mut handlers: Vec<Box<dyn PrefHandler>> = vec![
Box::new(DevicePrefs::new(&xns, time_cid, menumatic_sid, menu_conn, codec, status_cid)), Box::new(DevicePrefs::new(&xns, time_cid, menumatic_sid, menu_conn, codec, status_cid)),
Box::new(wifi::WLANMan::new(&xns)), Box::new(wifi::WLANMan::new(&xns)),
]; ];
#[cfg(feature="no-codec")]
let mut handlers: Vec<Box<dyn PrefHandler>> = vec![
Box::new(DevicePrefs::new(&xns, time_cid, menumatic_sid, menu_conn, status_cid)),
Box::new(wifi::WLANMan::new(&xns)),
];
// claim menumatic's on all prefhandlers for this thread // claim menumatic's on all prefhandlers for this thread
for handler in handlers.iter_mut() { for handler in handlers.iter_mut() {