firewire_fireface_protocols/
lib.rs

1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (c) 2021 Takashi Sakamoto
3
4#![doc = include_str!("../README.md")]
5
6pub mod former;
7pub mod latter;
8
9use {
10    glib::Error,
11    hinawa::{prelude::FwReqExtManual, FwNode, FwReq, FwTcode},
12    ieee1212_config_rom::*,
13};
14
15const RME_OUI: u32 = 0x00000a35;
16
17/// Parser of configuration rom for RME Fireface series.
18pub trait FfConfigRom {
19    fn get_model_id(&self) -> Option<u32>;
20}
21
22impl<'a> FfConfigRom for ConfigRom<'a> {
23    fn get_model_id(&self) -> Option<u32> {
24        self.root
25            .iter()
26            .find_map(|entry| EntryDataAccess::<u32>::get(entry, KeyType::Vendor))
27            .filter(|vendor_id| vendor_id.eq(&RME_OUI))
28            .and_then(|_| {
29                self.root
30                    .iter()
31                    .find_map(|entry| EntryDataAccess::<&[Entry]>::get(entry, KeyType::Unit))
32                    .and_then(|entries| {
33                        entries
34                            .iter()
35                            .find_map(|entry| EntryDataAccess::<u32>::get(entry, KeyType::Version))
36                    })
37            })
38    }
39}
40
41/// Nominal frequency of sampling clock.
42#[derive(Debug, Copy, Clone, PartialEq, Eq)]
43pub enum ClkNominalRate {
44    R32000,
45    R44100,
46    R48000,
47    R64000,
48    R88200,
49    R96000,
50    R128000,
51    R176400,
52    R192000,
53}
54
55impl Default for ClkNominalRate {
56    fn default() -> Self {
57        Self::R44100
58    }
59}
60
61/// Format of S/PDIF signal.
62#[derive(Debug, Copy, Clone, PartialEq, Eq)]
63pub enum SpdifFormat {
64    Consumer,
65    Professional,
66}
67
68impl Default for SpdifFormat {
69    fn default() -> Self {
70        Self::Consumer
71    }
72}
73
74/// Digital interface of S/PDIF signal.
75#[derive(Debug, Copy, Clone, PartialEq, Eq)]
76pub enum SpdifIface {
77    Coaxial,
78    Optical,
79}
80
81impl Default for SpdifIface {
82    fn default() -> Self {
83        Self::Coaxial
84    }
85}
86
87/// Configuration of S/PDIF input.
88#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
89pub struct SpdifInput {
90    /// The interface of S/PDIF signal.
91    pub iface: SpdifIface,
92    /// Whether to deliver preamble information by corresponding audio data channel of tx stream.
93    pub use_preemble: bool,
94}
95
96/// Type of signal to optical output interface.
97#[derive(Debug, Copy, Clone, PartialEq, Eq)]
98pub enum OpticalOutputSignal {
99    Adat,
100    Spdif,
101}
102
103impl Default for OpticalOutputSignal {
104    fn default() -> Self {
105        Self::Adat
106    }
107}
108
109/// Nominal level of line outputs.
110#[derive(Debug, Copy, Clone, PartialEq, Eq)]
111pub enum LineOutNominalLevel {
112    High,
113    /// -10 dBV.
114    Consumer,
115    /// +4 dBu.
116    Professional,
117}
118
119impl Default for LineOutNominalLevel {
120    fn default() -> Self {
121        Self::High
122    }
123}
124
125/// Serialize offsets for parameters.
126pub trait RmeFfOffsetParamsSerialize<T> {
127    /// Serialize parameters from raw data.
128    fn serialize_offsets(params: &T) -> Vec<u8>;
129}
130
131/// Deserialize offsets for parameters.
132pub trait RmeFfOffsetParamsDeserialize<T> {
133    /// Deserialize parameters into raw data.
134    fn deserialize_offsets(params: &mut T, raw: &[u8]);
135}
136
137/// Operation for parameters which can be updated wholly at once.
138pub trait RmeFfWhollyUpdatableParamsOperation<T> {
139    /// Update registers for whole parameters.
140    fn update_wholly(
141        req: &mut FwReq,
142        node: &mut FwNode,
143        params: &T,
144        timeout_ms: u32,
145    ) -> Result<(), Error>;
146}
147
148/// Operation for parameters which can be updated partially.
149pub trait RmeFfPartiallyUpdatableParamsOperation<T> {
150    fn update_partially(
151        req: &mut FwReq,
152        node: &mut FwNode,
153        params: &mut T,
154        update: T,
155        timeout_ms: u32,
156    ) -> Result<(), Error>;
157}
158
159/// Operation for parameters which can be cached wholly at once.
160pub trait RmeFfCacheableParamsOperation<T> {
161    /// Cache whole parameters from registers.
162    fn cache_wholly(
163        req: &mut FwReq,
164        node: &mut FwNode,
165        params: &mut T,
166        timeout_ms: u32,
167    ) -> Result<(), Error>;
168}