#![allow(clippy::new_without_default)]
use crate::interface::Frame;
#[path = "side_att_db.rs"]
mod side_att_db;
pub use side_att_db::*;
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub struct AnalogueAudioPath {
data: u8,
}
impl Default for AnalogueAudioPath {
fn default() -> Self {
Self::new()
}
}
impl AnalogueAudioPath {
pub fn new() -> Self {
Self { data: 0b1010 }
}
pub fn to_frame(&self) -> Frame {
Frame {
data: 0b100 << 9 | self.data as u16,
}
}
}
impl AnalogueAudioPath {
pub fn micboost(&self) -> bool {
let pos = 0;
self.data & (1 << pos) == 1 << pos
}
pub fn mutemic(&self) -> bool {
let pos = 1;
self.data & (1 << pos) == 1 << pos
}
pub fn insel(&self) -> InselV {
let pos = 2;
match self.data & (1 << pos) == 1 << pos {
false => InselV::Line,
true => InselV::Mic,
}
}
pub fn bypass(&self) -> bool {
let pos = 3;
self.data & (1 << pos) == 1 << pos
}
pub fn dacsel(&self) -> bool {
let pos = 4;
self.data & (1 << pos) == 1 << pos
}
pub fn sidetone(&self) -> bool {
let pos = 5;
self.data & (1 << pos) == 1 << pos
}
pub fn sideatt(&self) -> SideAttdB {
let pos = 6;
unsafe { SideAttdB::from_raw_unchecked(((self.data & (0b11 << pos)) >> pos) as _) }
}
pub fn set_micboost(&mut self, value: bool) -> &mut Self {
let pos = 0;
self.data = self.data & !(1 << pos) | (value as u8) << pos;
self
}
pub fn set_mutemic(&mut self, value: bool) -> &mut Self {
let pos = 1;
self.data = self.data & !(1 << pos) | (value as u8) << pos;
self
}
pub fn set_insel(&mut self, value: InselV) -> &mut Self {
let pos = 2;
self.data = self.data & !(1 << pos) | (value as u8) << pos;
self
}
pub fn set_bypass(&mut self, value: bool) -> &mut Self {
let pos = 3;
self.data = self.data & !(1 << pos) | (value as u8) << pos;
self
}
pub fn set_dacsel(&mut self, value: bool) -> &mut Self {
let pos = 4;
self.data = self.data & !(1 << pos) | (value as u8) << pos;
self
}
pub fn set_sidetone(&mut self, value: bool) -> &mut Self {
let pos = 5;
self.data = self.data & !(1 << pos) | (value as u8) << pos;
self
}
pub fn set_sideatt(&mut self, value: SideAttdB) -> &mut Self {
let pos = 6;
self.data = self.data & !(0b11 << pos) | (value.into_raw() as u8);
self
}
}
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum InselV {
Line = 0,
Mic = 1,
}