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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (c) 2021 Takashi Sakamoto

#![doc = include_str!("../README.md")]

pub mod former;
pub mod latter;

use ieee1212_config_rom::*;

const RME_OUI: u32 = 0x00000a35;

/// Parser of configuration rom for RME Fireface series.
pub trait FfConfigRom {
    fn get_model_id(&self) -> Option<u32>;
}

impl<'a> FfConfigRom for ConfigRom<'a> {
    fn get_model_id(&self) -> Option<u32> {
        self.root
            .iter()
            .find_map(|entry| EntryDataAccess::<u32>::get(entry, KeyType::Vendor))
            .filter(|vendor_id| vendor_id.eq(&RME_OUI))
            .and_then(|_| {
                self.root
                    .iter()
                    .find_map(|entry| EntryDataAccess::<&[Entry]>::get(entry, KeyType::Unit))
                    .and_then(|entries| {
                        entries
                            .iter()
                            .find_map(|entry| EntryDataAccess::<u32>::get(entry, KeyType::Version))
                    })
            })
    }
}

/// Nominal frequency of sampling clock.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ClkNominalRate {
    R32000,
    R44100,
    R48000,
    R64000,
    R88200,
    R96000,
    R128000,
    R176400,
    R192000,
}

impl Default for ClkNominalRate {
    fn default() -> Self {
        Self::R44100
    }
}

/// Format of S/PDIF signal.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum SpdifFormat {
    Consumer,
    Professional,
}

impl Default for SpdifFormat {
    fn default() -> Self {
        Self::Consumer
    }
}

/// Digital interface of S/PDIF signal.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum SpdifIface {
    Coaxial,
    Optical,
}

impl Default for SpdifIface {
    fn default() -> Self {
        Self::Coaxial
    }
}

/// Configuration of S/PDIF input.
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct SpdifInput {
    /// The interface of S/PDIF signal.
    pub iface: SpdifIface,
    /// Whether to deliver preamble information by corresponding audio data channel of tx stream.
    pub use_preemble: bool,
}

/// Type of signal to optical output interface.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum OpticalOutputSignal {
    Adat,
    Spdif,
}

impl Default for OpticalOutputSignal {
    fn default() -> Self {
        Self::Adat
    }
}

/// Nominal level of line outputs.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum LineOutNominalLevel {
    High,
    /// -10 dBV.
    Consumer,
    /// +4 dBu.
    Professional,
}

impl Default for LineOutNominalLevel {
    fn default() -> Self {
        Self::High
    }
}