minidsp_protocol/device/
mod.rs

1//! Static device definitions
2//!
3//! This is where support for other devices should be added
4
5use crate::dialect::Dialect;
6
7#[allow(unused_imports)]
8use super::{
9    commands::{Addr, Value},
10    AddrEncoding, FixedPoint, FloatEncoding,
11    Source::{self as Source, *},
12};
13
14mod probe;
15pub use probe::{by_kind, probe, probe_kind, DeviceKind};
16
17#[cfg(feature = "device_2x4hd")]
18pub mod m2x4hd;
19
20#[cfg(feature = "device_4x10hd")]
21pub mod m4x10hd;
22
23#[cfg(feature = "device_10x10hd")]
24pub mod m10x10hd;
25
26#[cfg(feature = "device_msharc4x8")]
27pub mod msharc4x8;
28
29#[cfg(feature = "device_shd")]
30pub mod shd;
31
32#[cfg(feature = "device_ddrc24")]
33pub mod ddrc24;
34
35#[cfg(feature = "device_ddrc88bm")]
36pub mod ddrc88bm;
37
38#[cfg(feature = "device_nanodigi2x8")]
39pub mod nanodigi2x8;
40
41#[cfg(feature = "device_c8x12v2")]
42pub mod c8x12v2;
43
44#[cfg(feature = "device_m2x4")]
45pub mod m2x4;
46
47pub static GENERIC: Device = Device {
48    product_name: "Generic",
49    sources: &[],
50    inputs: &[],
51    outputs: &[],
52    fir_max_taps: 0,
53    internal_sampling_rate: 0,
54    #[cfg(feature = "symbols")]
55    symbols: &[],
56    dialect: Dialect::const_default(),
57};
58
59/// Defines how the high level api should interact with the device based on its memory layout
60#[cfg_attr(feature = "debug", derive(Debug))]
61pub struct Device {
62    /// The name identifying the product, e.g. "2x4HD"
63    pub product_name: &'static str,
64    /// The name of the input sources
65    pub sources: &'static [Source],
66    /// The definitions for all input channels
67    pub inputs: &'static [Input],
68    /// The definitions for all output channels
69    pub outputs: &'static [Output],
70    /// Maximum total number of FIR taps
71    pub fir_max_taps: u16,
72    /// Internal sampling rate in Hz
73    pub internal_sampling_rate: u32,
74    /// Dialect spoken by this device
75    pub dialect: Dialect,
76    // A mapping of all symbols by name, as defined in the xml config
77    #[cfg(feature = "symbols")]
78    pub symbols: &'static [(&'static str, u16)],
79}
80
81impl Default for Device {
82    fn default() -> Self {
83        Self {
84            product_name: Default::default(),
85            sources: Default::default(),
86            inputs: Default::default(),
87            outputs: Default::default(),
88            fir_max_taps: Default::default(),
89            internal_sampling_rate: Default::default(),
90            #[cfg(feature = "symbols")]
91            symbols: Default::default(),
92            dialect: Dialect::const_default(),
93        }
94    }
95}
96
97/// Defines an input channel and its features
98#[cfg_attr(feature = "debug", derive(Debug))]
99pub struct Input {
100    /// Mute and Gain
101    pub gate: Option<Gate>,
102    /// Volume Meter
103    pub meter: Option<u16>,
104    /// Parametric Equalizers
105    pub peq: &'static [u16],
106    /// Routing matrix, one entry per output channel connected to this input
107    pub routing: &'static [Gate],
108}
109
110/// Defines an output channel and its features
111#[cfg_attr(feature = "debug", derive(Debug))]
112pub struct Output {
113    /// Mute and Gain
114    pub gate: Gate,
115    /// Volume Meter
116    pub meter: Option<u16>,
117    /// Address of the delay value
118    pub delay_addr: Option<u16>,
119    /// Address of the invert toggle
120    pub invert_addr: u16,
121    /// Parametric equalizers
122    pub peq: &'static [u16],
123    /// Crossover biquads
124    pub xover: Option<Crossover>,
125    /// Compressor
126    pub compressor: Option<Compressor>,
127    /// Address of the FIR bypass toggle
128    pub fir: Option<Fir>,
129}
130
131/// Reference to a control having both a mute and gain setting
132#[cfg_attr(feature = "debug", derive(Debug))]
133pub struct Gate {
134    /// Address controlling whether audio is enabled, 1 = off 2 = on
135    pub enable: u16,
136
137    /// Address where the gain is controlled
138    pub gain: Option<u16>,
139}
140#[cfg_attr(feature = "debug", derive(Debug))]
141pub struct Compressor {
142    pub bypass: u16,
143    pub threshold: u16,
144    pub ratio: u16,
145    pub attack: u16,
146    pub release: u16,
147    pub meter: Option<u16>,
148}
149
150#[cfg_attr(feature = "debug", derive(Debug))]
151pub struct Crossover {
152    /// First address of each biquad groups, each containing 4 sequential biquads.
153    pub peqs: &'static [u16],
154}
155
156#[cfg_attr(feature = "debug", derive(Debug))]
157pub struct Fir {
158    /// Index to use in the FIRLoad commands
159    pub index: u8,
160
161    /// Address saving the number of active coefficients
162    pub num_coefficients: u16,
163
164    /// Bypass address
165    pub bypass: u16,
166
167    /// Maximum supported coefficients
168    pub max_coefficients: u16,
169}