re-org the codec crate so that it can accommodate gnarly backends

This is in anticipation of:

1) supply chain issues causing CODEC chips to change out
2) host integration being a PITA
This commit is contained in:
bunnie 2021-05-03 00:31:05 +08:00
parent f558f75116
commit 50174f99e5
4 changed files with 67 additions and 72 deletions

View file

@ -0,0 +1,13 @@
pub struct Codec {
}
impl Codec {
pub fn new() -> Codec {
Codec {
}
}
pub fn suspend(&self) {
}
pub fn resume(&self) {
}
}

View file

@ -0,0 +1,9 @@
#[cfg(not(target_os = "none"))]
mod hostaudio;
#[cfg(not(target_os = "none"))]
pub use crate::backend::hostaudio::*;
#[cfg(target_os = "none")]
mod tlv320aic3100;
#[cfg(target_os = "none")]
pub use crate::backend::tlv320aic3100::*;

View file

@ -0,0 +1,43 @@
use utralib::generated::*;
use xous::MemoryRange;
use susres::{RegManager, RegOrField, SuspendResume, ManagedMem};
pub struct Codec {
csr: utralib::CSR<u32>,
fifo: MemoryRange,
susres_manager: RegManager::<{utra::audio::AUDIO_NUMREGS}>,
}
impl Codec {
pub fn new() -> Codec {
let csr = xous::syscall::map_memory(
xous::MemoryAddress::new(utra::audio::HW_AUDIO_BASE),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map Audio CSR range");
let fifo = xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::HW_AUDIO_MEM),
None,
utralib::HW_AUDIO_MEM_LEN,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map Audio CSR range");
let mut codec = Codec {
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
susres_manager: RegManager::new(csr.as_mut_ptr() as *mut u32),
fifo,
};
codec
}
pub fn suspend(&mut self) {
self.susres_manager.suspend();
}
pub fn resume(&mut self) {
self.susres_manager.resume();
}
}

View file

@ -2,85 +2,15 @@
#![cfg_attr(target_os = "none", no_main)]
mod api;
mod backend;
use backend::Codec;
use num_traits::FromPrimitive;
use log::info;
#[cfg(target_os = "none")]
mod implementation {
use utralib::generated::*;
// use crate::api::*;
use log::info;
use susres::{RegManager, RegOrField, SuspendResume};
pub struct Codec {
csr: utralib::CSR<u32>,
fifo: xous::MemoryRange,
susres_manager: RegManager::<{utra::audio::AUDIO_NUMREGS}>,
}
impl Codec {
pub fn new() -> Codec {
let csr = xous::syscall::map_memory(
xous::MemoryAddress::new(utra::audio::HW_AUDIO_BASE),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map Audio CSR range");
let fifo = xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::HW_AUDIO_MEM),
None,
utralib::HW_AUDIO_MEM_LEN,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map Audio CSR range");
let mut codec = Codec {
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
susres_manager: RegManager::new(csr.as_mut_ptr() as *mut u32),
fifo,
};
codec
}
pub fn suspend(&mut self) {
self.susres_manager.suspend();
}
pub fn resume(&mut self) {
self.susres_manager.resume();
}
}
}
// a stub to try to avoid breaking hosted mode for as long as possible.
#[cfg(not(target_os = "none"))]
mod implementation {
use log::info;
pub struct Codec {
}
impl Codec {
pub fn new() -> Codec {
Codec {
}
}
pub fn suspend(&self) {
}
pub fn resume(&self) {
}
}
}
#[xous::xous_main]
fn xmain() -> ! {
use crate::implementation::Codec;
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info);
info!("my PID is {}", xous::process::id());