minidsp_protocol/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3//! Main protocol implementation.
4//!
5//! This crate provides the basic components in order to be able to send and receive
6//! commands and events from a device.
7//!
8//! It is meant to be as lean as possible in order to run in restricted environments.
9//! For this reason, it doesn't include any transport implementations.
10
11extern crate alloc;
12
13mod util;
14
15pub mod commands;
16pub use commands::{Commands, FromMemory};
17
18pub mod packet;
19use device::{probe_kind, DeviceKind};
20pub use packet::ParseError;
21
22pub mod source;
23pub use source::Source;
24
25#[cfg(feature = "devices")]
26pub mod device;
27
28pub mod eeprom;
29
30pub mod fixed_point;
31pub use fixed_point::FixedPoint;
32
33pub mod dialect;
34pub use dialect::{AddrEncoding, Dialect, FloatEncoding};
35
36#[derive(Copy, Clone)]
37#[cfg_attr(feature = "debug", derive(Debug))]
38#[cfg_attr(
39    feature = "use_serde",
40    derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
41)]
42/// Hardware id and dsp version
43pub struct DeviceInfo {
44    pub hw_id: u8,
45    pub dsp_version: u8,
46    pub serial: u32,
47}
48
49impl DeviceInfo {
50    pub fn device_kind(&self) -> DeviceKind {
51        probe_kind(self)
52    }
53
54    pub fn supports_dirac(&self) -> bool {
55        matches!(self.dsp_version, 61 | 94 | 95 | 101 | 105)
56    }
57}
58
59#[derive(Default, Clone, PartialEq)]
60#[cfg_attr(feature = "debug", derive(Debug))]
61#[cfg_attr(
62    feature = "use_serde",
63    derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
64)]
65/// Settings applying to all outputs
66pub struct MasterStatus {
67    /// Active configuration preset
68    pub preset: Option<u8>,
69
70    /// Active source
71    pub source: Option<Source>,
72
73    /// Volume in dB [-127, 0]
74    pub volume: Option<commands::Gain>,
75
76    /// Mute status
77    pub mute: Option<bool>,
78
79    /// Dirac Live status
80    pub dirac: Option<bool>,
81}