1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Configuration for digital audio path

use crate::bitmask::BitMask;
use crate::EnableDisable;

pub struct Deemphasis<'a> {
    index: u16,
    bitmask: BitMask<'a>,
}

impl<'a> Deemphasis<'a> {
    pub fn new(index: u16, data: &'a mut u16) -> Self {
        let bitmask = BitMask::new(data);

        Deemphasis { index, bitmask }
    }

    pub fn frequency_48(&mut self) {
        self.bitmask.apply(self.index, 2, 0b11)
    }

    pub fn frequency_441(&mut self) {
        self.bitmask.apply(self.index, 2, 0b10)
    }

    pub fn frequency_32(&mut self) {
        self.bitmask.apply(self.index, 2, 0b01)
    }

    pub fn disable(&mut self) {
        self.bitmask.apply(self.index, 2, 0b00)
    }
}

pub struct HpfDc<'a> {
    index: u16,
    bitmask: BitMask<'a>,
}

impl<'a> HpfDc<'a> {
    pub fn new(index: u16, data: &'a mut u16) -> Self {
        let bitmask = BitMask::new(data);

        HpfDc { index, bitmask }
    }

    pub fn store(&mut self) {
        self.bitmask.set(self.index);
    }

    pub fn clear(&mut self) {
        self.bitmask.unset(self.index);
    }
}

#[derive(Debug, Copy, Clone)]
pub struct DigitalAudioPath {
    pub(crate) data: u16,
}

impl DigitalAudioPath {
    pub fn new() -> Self {
        DigitalAudioPath {
            data: 0b0_0000_0000,
        }
    }

    /// ADC high pass filter
    pub fn adc_hpf(&mut self) -> EnableDisable {
        EnableDisable::new(0, &mut self.data)
    }

    /// De-emphasis control
    pub fn deemphasis(&mut self) -> Deemphasis {
        Deemphasis::new(1, &mut self.data)
    }

    /// DAC soft mute control
    pub fn dac_mut(&mut self) -> EnableDisable {
        EnableDisable::new(3, &mut self.data)
    }

    /// Store DC offset when high pass filter disabled
    pub fn hpor(&mut self) -> HpfDc {
        HpfDc::new(4, &mut self.data)
    }
}