Skip to main content

mx_remote/wire/
enums.rs

1// Author: Lars Op den Kamp (lars@opdenkamp-it.nl)
2// Copyright (c) 2026 Op den Kamp IT Solutions
3
4//! Wire enumerations and bitmasks.
5//!
6//! Each type is a newtype over the integer that travels on the wire, with
7//! named constants rather than a closed set of variants. A value this library
8//! has no name for reaches the caller as it arrived: zero is a valid value for
9//! most of these, so a confidently wrong reading is worse than an unrecognised
10//! one.
11
12use core::fmt;
13use core::ops::{BitAnd, BitOr, BitOrAssign};
14
15/// Declares a bitmask newtype with the given named bit constants.
16///
17/// The representation defaults to `u32`; give it explicitly as `Name: u64` for
18/// a mask whose wire field is wider.
19macro_rules! bitmask {
20    (
21        $(#[$meta:meta])*
22        $name:ident { $( $(#[$cmeta:meta])* $cname:ident = $value:expr; )* }
23    ) => {
24        bitmask! {
25            $(#[$meta])*
26            $name: u32 { $( $(#[$cmeta])* $cname = $value; )* }
27        }
28    };
29    (
30        $(#[$meta:meta])*
31        $name:ident: $repr:ty { $( $(#[$cmeta:meta])* $cname:ident = $value:expr; )* }
32    ) => {
33        $(#[$meta])*
34        #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
35        pub struct $name($repr);
36
37        impl $name {
38            /// No bits set.
39            pub const NONE: Self = Self(0);
40
41            $( $(#[$cmeta])* pub const $cname: Self = Self($value); )*
42
43            /// Wraps a raw wire value, including bits this library has no name for.
44            pub const fn from_bits(bits: $repr) -> Self {
45                Self(bits)
46            }
47
48            /// Returns the raw wire value.
49            pub const fn bits(self) -> $repr {
50                self.0
51            }
52
53            /// Reports whether every bit in `other` is set.
54            pub const fn has(self, other: Self) -> bool {
55                self.0 & other.0 == other.0
56            }
57
58            /// Reports whether no bit is set.
59            pub const fn is_empty(self) -> bool {
60                self.0 == 0
61            }
62        }
63
64        impl BitOr for $name {
65            type Output = Self;
66            fn bitor(self, rhs: Self) -> Self {
67                Self(self.0 | rhs.0)
68            }
69        }
70
71        impl BitOrAssign for $name {
72            fn bitor_assign(&mut self, rhs: Self) {
73                self.0 |= rhs.0;
74            }
75        }
76
77        impl BitAnd for $name {
78            type Output = Self;
79            fn bitand(self, rhs: Self) -> Self {
80                Self(self.0 & rhs.0)
81            }
82        }
83
84        impl fmt::Display for $name {
85            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86                // Two hex digits per byte of the wire field, plus "0x".
87                write!(
88                    f,
89                    "{:#0width$x}",
90                    self.0,
91                    width = core::mem::size_of::<$repr>() * 2 + 2
92                )
93            }
94        }
95    };
96}
97
98/// Declares an enumeration newtype over `$repr` with the given named constants.
99macro_rules! wire_enum {
100    (
101        $(#[$meta:meta])*
102        $name:ident: $repr:ty { $( $(#[$cmeta:meta])* $cname:ident = $value:expr; )* }
103    ) => {
104        $(#[$meta])*
105        #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
106        pub struct $name($repr);
107
108        impl $name {
109            $( $(#[$cmeta])* pub const $cname: Self = Self($value); )*
110
111            /// Wraps a raw wire value, including one this library has no name for.
112            pub const fn from_wire(value: $repr) -> Self {
113                Self(value)
114            }
115
116            /// Returns the raw wire value.
117            pub const fn to_wire(self) -> $repr {
118                self.0
119            }
120        }
121    };
122}
123
124bitmask! {
125    /// Capabilities a device reports in its hello frame.
126    DeviceFeature {
127        /// Receives infrared.
128        IR_RX = 1 << 0;
129        /// Transmits infrared.
130        IR_TX = 1 << 1;
131        /// Speaks CEC.
132        CEC = 1 << 2;
133        /// Acts as a OneIP stream source.
134        V2IP_SOURCE = 1 << 3;
135        /// Acts as a OneIP stream sink.
136        V2IP_SINK = 1 << 4;
137        /// Routes video.
138        VIDEO_ROUTING = 1 << 5;
139        /// Routes audio.
140        AUDIO_ROUTING = 1 << 6;
141        /// Controls volume.
142        VOLUME_CONTROL = 1 << 7;
143        /// Supports audio return.
144        AUDIO_RETURN = 1 << 8;
145        /// Passes remote-control commands through.
146        REMOTE_CONTROL = 1 << 9;
147        /// Installer setup has been completed.
148        SETUP_COMPLETED = 1 << 10;
149        /// Is the master of its mesh.
150        MESH_MASTER = 1 << 11;
151        /// Has a notification pending.
152        STATUS_NOTIFY = 1 << 12;
153        /// Has a warning pending.
154        STATUS_WARNING = 1 << 13;
155        /// Has an error pending.
156        STATUS_ERROR = 1 << 14;
157        /// Is about to reboot.
158        STATUS_REBOOT = 1 << 15;
159        /// Is a member of a mesh.
160        MESH_MEMBER = 1 << 16;
161        /// Is an audio amplifier.
162        AUDIO_AMPLIFIER = 1 << 17;
163        /// Is still booting.
164        BOOTING = 1 << 18;
165        /// Is a management client rather than a device.
166        MANAGER = 1 << 19;
167        /// Is in power-save mode.
168        STATUS_POWER_SAVE = 1 << 20;
169        /// Supports meshing.
170        MESH = 1 << 21;
171        /// Is a multiviewer.
172        MULTIVIEWER = 1 << 22;
173        /// Has crashed since it last booted.
174        STATUS_CRASHED = 1 << 23;
175        /// Supports video walls.
176        VIDEO_WALL = 1 << 24;
177        /// Initialises the configuration it broadcasts.
178        ///
179        /// Firmware without this bit sends a device configuration built over
180        /// uninitialised memory, so fields it did not mean to write carry junk.
181        CONFIG_INITIALISED = 1 << 25;
182        /// Receives one or more peers only by broadcast, because its multicast
183        /// receive path is faulty.
184        STATUS_MCAST_FAULT = 1 << 26;
185        /// Powers its video processor down in power save. A device without it
186        /// refuses to enter power save.
187        POWER_SAVE = 1 << 27;
188        /// Tags its uplink by the VLAN configuration it reports, and takes one
189        /// written to it.
190        VLAN = 1 << 28;
191        /// Copies the overlay settings and logos of another unit when asked.
192        OSD_SYNC = 1 << 29;
193        /// Is downloading or installing a firmware or video processor
194        /// upgrade. [`STATUS_REBOOT`](Self::STATUS_REBOOT) follows when it
195        /// reboots to complete it.
196        STATUS_UPGRADING = 1 << 30;
197        /// Flips on every reboot, so a peer that sees it change knows the device restarted.
198        BOOT_BIT = 1 << 31;
199    }
200}
201
202bitmask! {
203    /// What a OneIP device's video processor supports, as the device reports it
204    /// in its configuration.
205    ///
206    /// Read-only, and a device's own: it fills the field in only on the frame
207    /// describing itself, and leaves it zero on one it sends to configure
208    /// another device. There is no write path.
209    ///
210    /// Bits are assigned by the video processor and only ever appended, so a
211    /// bit this library has no name for is a later capability rather than an
212    /// error. A device reports no features at all until its processor answers,
213    /// and an older processor answers with none of the optional commands, so an
214    /// empty mask is never reported as a capability set - see
215    /// [`crate::Remote::v2ip_features`], which reports it as unknown instead.
216    V2ipFpgaFeature: u64 {
217        /// Applies a DSCP marking to the streams it sources.
218        SOURCE_DSCP = 1 << 0;
219        /// Reports the audio format arriving at its sink.
220        SINK_AUDIO_FORMAT = 1 << 1;
221        /// Places a tiling window on its sink.
222        SINK_TILING_WINDOW = 1 << 2;
223        /// Reports the state of its sink's overlay.
224        SINK_OVERLAY_STATE = 1 << 3;
225        /// Reports its sink's state.
226        SINK_STATE = 1 << 4;
227        /// Reports information about the stream its sink receives.
228        SINK_STREAM_INFO = 1 << 5;
229        /// Draws a test pattern, tone and lip-sync flash on its sink's output.
230        SINK_TEST_PATTERN = 1 << 8;
231    }
232}
233
234bitmask! {
235    /// The device settings a OneIP configuration can carry, each on its own bit.
236    ///
237    /// The same bits serve as the settings a frame carries and as the values
238    /// of the on/off ones among them. `IR_PROFILE` to `POWER_SAVE_SCHEDULE`
239    /// carry a value elsewhere in the block and have no on/off value of their
240    /// own.
241    ///
242    /// A device reports every setting it has, so one it never reports is one
243    /// it does not have.
244    V2ipDeviceSetting {
245        /// Disables the decoder while the display is off.
246        SINK_CHECK_POWER = 1 << 0;
247        /// Disables the HDMI output while there is no signal.
248        SINK_OFF_NO_SIGNAL = 1 << 1;
249        /// Sends infrared modulated.
250        IR_TX_MODULATED = 1 << 2;
251        /// Lights the status LED.
252        STATUS_LED = 1 << 3;
253        /// Lights the network port LEDs.
254        NETWORK_LED = 1 << 4;
255        /// Runs the fan in quiet mode.
256        FAN_QUIET = 1 << 5;
257        /// Accepts CEC combo keys.
258        CEC_COMBO_KEYS = 1 << 6;
259        /// Accepts CEC combo keys for the device's own input.
260        CEC_COMBO_INPUT = 1 << 7;
261        /// The infrared profile of the device's global infrared port.
262        IR_PROFILE = 1 << 8;
263        /// The infrared profile of the output's infrared port.
264        IR_PROFILE_SINK = 1 << 9;
265        /// The infrared profiles stored on the device. Reported by the device
266        /// itself and never written.
267        IR_PROFILES = 1 << 10;
268        /// The minutes a device stays idle before it powers down by itself.
269        AUTO_POWER_SAVE = 1 << 11;
270        /// The daily windows in which the device powers down.
271        POWER_SAVE_SCHEDULE = 1 << 12;
272        /// The device's clock has been set, on/off. Reported by the device
273        /// itself and never written.
274        CLOCK_SET = 1 << 13;
275        /// The PTP mode the device runs.
276        PTP_MODE = 1 << 14;
277        /// The PTP domain the device runs in.
278        PTP_DOMAIN = 1 << 15;
279        /// The priority1 the device announces as a PTP grandmaster.
280        PTP_PRIORITY1 = 1 << 16;
281        /// Sends the source's audio as an AES67 flow, where the source allows.
282        AES67 = 1 << 17;
283        /// The power save level the device powers down to.
284        POWER_SAVE_LEVEL = 1 << 18;
285        /// The interval between the device's PTP announce messages.
286        PTP_ANNOUNCE = 1 << 19;
287        /// The interval between the device's PTP sync messages.
288        PTP_SYNC = 1 << 20;
289        /// The interval between the device's PTP delay requests.
290        PTP_DELAY_REQ = 1 << 21;
291        /// The announce intervals before the device drops a silent PTP master.
292        PTP_ANNOUNCE_TIMEOUT = 1 << 22;
293        /// The DSCP of the device's PTP messages.
294        PTP_DSCP = 1 << 23;
295        /// The minutes after which the device forgets a SAP announcement it
296        /// heard.
297        SAP_EXPIRE = 1 << 24;
298        /// Listens for SAP announcements.
299        SAP_LISTEN = 1 << 25;
300        /// Sends SAP announcements.
301        SAP_ANNOUNCE = 1 << 26;
302        /// The seconds between the device's SAP announcements.
303        SAP_INTERVAL = 1 << 27;
304        /// Never powers down by itself: automatic power save and the power
305        /// save schedule leave the device running, and switching this on
306        /// wakes a device either has powered down. A power save request
307        /// still powers it down. Writing
308        /// [`POWER_SAVE_LEVEL`](Self::POWER_SAVE_LEVEL) switches it off.
309        POWER_SAVE_DISABLED = 1 << 28;
310        /// The TTL of the device's streams, video, audio and ancillary
311        /// alike. Reported only by a device with an encoder.
312        STREAM_TTL = 1 << 29;
313        /// Connects to the cloud service. A device that does not report it
314        /// connects regardless.
315        CLOUD = 1 << 30;
316        /// The angle the device's HDMI output is turned by. Reported only by
317        /// a device with an HDMI output.
318        SINK_ROTATION = 1 << 31;
319    }
320}
321
322wire_enum! {
323    /// When a OneIP output mixes 5.1 and 7.1 PCM down to stereo.
324    V2ipDownmixMode: u8 {
325        /// Never.
326        OFF = 0;
327        /// When the display's EDID lists two PCM channels or fewer.
328        AUTO = 1;
329        /// Always.
330        ALWAYS = 2;
331    }
332}
333
334wire_enum! {
335    /// How loud a OneIP output's stereo downmix is.
336    V2ipDownmixLevel: u8 {
337        /// Scaled so the mix never clips.
338        NORMALISED = 0;
339        /// Unscaled, with dialogue at the level it has in stereo.
340        UNSCALED = 1;
341    }
342}
343
344wire_enum! {
345    /// How far a OneIP device powers down in power save, each level saving more
346    /// than the one before.
347    V2ipPowerSaveLevel: u8 {
348        /// No level.
349        NONE = 0;
350        /// Part of the video processing powers down.
351        REDUCED = 1;
352        /// All of the video processing powers down.
353        LOW = 2;
354        /// Everything but the network powers down.
355        OFF = 3;
356    }
357}
358
359bitmask! {
360    /// What a unit offers at one power save level.
361    UnitPowerSave: u8 {
362        /// The unit can power down to this level.
363        SUPPORTED = 1 << 0;
364        /// A signal on the HDMI input wakes the unit.
365        INPUT_WAKE = 1 << 1;
366        /// The display powering on wakes the unit, and the unit can power it
367        /// on.
368        OUTPUT_WAKE = 1 << 2;
369    }
370}
371
372wire_enum! {
373    /// How a OneIP device takes part in PTP.
374    V2ipPtpMode: u8 {
375        /// No PTP.
376        OFF = 0;
377        /// Follows a grandmaster, and never becomes one.
378        FOLLOWER = 1;
379        /// Follows a grandmaster, or becomes one when there is none.
380        AUTO = 2;
381    }
382}
383
384wire_enum! {
385    /// The test pattern a OneIP sink draws on its output.
386    V2ipTestPattern: u8 {
387        /// No pattern.
388        OFF = 0;
389        /// Colour bars.
390        BARS = 1;
391        /// One flat colour, the one the test card carries.
392        FLAT = 2;
393        /// A ramp.
394        RAMP = 3;
395        /// A grid.
396        GRID = 4;
397        /// A strip.
398        STRIP = 5;
399        /// A test card.
400        CARD = 6;
401    }
402}
403
404wire_enum! {
405    /// The test tone a OneIP sink plays on its output.
406    V2ipToneMode: u8 {
407        /// No tone.
408        OFF = 0;
409        /// A continuous tone.
410        CONTINUOUS = 1;
411        /// A channel ident.
412        IDENT = 2;
413        /// A line-up tone, which needs two channels or more.
414        LINEUP = 3;
415        /// A beep on each lip-sync mark.
416        BEEP = 4;
417    }
418}
419
420bitmask! {
421    /// What a OneIP sink reports about its test card.
422    V2ipTestcardFlag: u8 {
423        /// The sink can draw the test card.
424        SUPPORTED = 1 << 0;
425        /// The output shows the pattern.
426        SHOWING = 1 << 1;
427        /// The tone plays on the output.
428        PLAYING = 1 << 2;
429        /// A pattern change has yet to reach the video processor.
430        PATTERN_PENDING = 1 << 3;
431        /// A tone change has yet to reach the video processor.
432        TONE_PENDING = 1 << 4;
433        /// A lip-sync change has yet to reach the video processor.
434        SYNC_PENDING = 1 << 5;
435    }
436}
437
438bitmask! {
439    /// The flags of what a OneIP output plays from a session description.
440    V2ipSdpFlag: u8 {
441        /// The output plays a stream from a description.
442        ACTIVE = 1 << 0;
443        /// And nothing else, as no video is routed to it.
444        AUDIO_ONLY = 1 << 1;
445        /// The clock mode and state hold the video processor's answer.
446        CLOCK = 1 << 2;
447    }
448}
449
450wire_enum! {
451    /// The sample encoding of a stream a OneIP output plays from a description.
452    V2ipSdpEncoding: u8 {
453        /// None.
454        NONE = 0;
455        /// 16-bit linear PCM.
456        L16 = 1;
457        /// 24-bit linear PCM.
458        L24 = 2;
459        /// AM824.
460        AM824 = 3;
461    }
462}
463
464wire_enum! {
465    /// Where a described stream's media clock comes from.
466    V2ipSdpMediaClock: u8 {
467        /// None given.
468        NONE = 0;
469        /// Direct, at an offset from the reference clock.
470        DIRECT = 1;
471        /// The sender's.
472        SENDER = 2;
473    }
474}
475
476wire_enum! {
477    /// The reference clock a described stream names.
478    V2ipSdpRefClock: u8 {
479        /// None given.
480        NONE = 0;
481        /// PTP.
482        PTP = 1;
483        /// A traceable clock.
484        TRACEABLE = 2;
485        /// The sender's local MAC.
486        LOCAL_MAC = 3;
487    }
488}
489
490wire_enum! {
491    /// What a OneIP output's video processor times a described stream by.
492    V2ipSdpClockMode: u8 {
493        /// Arrival.
494        ARRIVAL = 0;
495        /// PTP.
496        PTP = 1;
497        /// The sender.
498        SENDER = 2;
499    }
500}
501
502wire_enum! {
503    /// How far a OneIP output's video processor has got with a described
504    /// stream's timing.
505    V2ipSdpClockState: u8 {
506        /// Idle.
507        IDLE = 0;
508        /// Running its servo.
509        SERVO = 1;
510        /// Aligning.
511        ALIGNING = 2;
512        /// Timed.
513        TIMED = 3;
514        /// Parked.
515        PARKED = 4;
516        /// Playing untimed.
517        UNTIMED = 5;
518        /// The timing is not supported.
519        UNSUPPORTED = 6;
520    }
521}
522
523bitmask! {
524    /// The flags of a unit's status report.
525    UnitFlag {
526        /// A changed setting takes effect after a reboot.
527        REBOOT_REQUIRED = 1 << 0;
528        /// A newer video processor image is available.
529        FPGA_UPGRADE = 1 << 1;
530        /// The IP configuration comes from DHCP.
531        DHCP = 1 << 2;
532        /// The IP configuration was changed through the mesh, and is reverted
533        /// unless the mesh controller confirms it in time.
534        NET_PENDING = 1 << 3;
535        /// The fan runs in quiet mode.
536        FAN_QUIET = 1 << 4;
537        /// Powered by an external supply rather than PoE.
538        EXTERNAL_PSU = 1 << 5;
539        /// The video processor runs with its IP configured. Without it the
540        /// encoder and decoder health carry nothing.
541        FPGA_CONFIGURED = 1 << 6;
542        /// The encoder is enabled.
543        ENCODER_ACTIVE = 1 << 7;
544        /// The decoder is enabled.
545        DECODER_ACTIVE = 1 << 8;
546        /// The decoder disables itself without a display.
547        AUTO_DISABLE = 1 << 9;
548        /// The decoder disabled itself without a display.
549        AUTO_DISABLE_ACTIVE = 1 << 10;
550        /// The HDMI output switches off without a signal.
551        OFF_NO_SIGNAL = 1 << 11;
552        /// The HDMI output switched off without a signal.
553        OFF_NO_SIGNAL_ACTIVE = 1 << 12;
554        /// Display power is checked before the decoder is enabled.
555        POWER_CHECK = 1 << 13;
556        /// The boot count is reported.
557        BOOT_COUNT = 1 << 14;
558        /// The fan speed is reported.
559        FAN_SPEED = 1 << 15;
560    }
561}
562
563wire_enum! {
564    /// What a unit command asks of its unit.
565    UnitCommandKind: u8 {
566        /// Clear the current system status.
567        CLEAR_STATUS = 0;
568        /// Upgrade the video processor to the latest image.
569        FPGA_UPGRADE = 1;
570        /// Change the IP configuration.
571        NET_CONFIG = 2;
572        /// Keep a pending IP configuration.
573        NET_CONFIRM = 3;
574    }
575}
576
577bitmask! {
578    /// The flags of a unit command.
579    UnitCommandFlag: u8 {
580        /// With [`UnitCommandKind::FPGA_UPGRADE`]: flash the image even if it
581        /// is running already.
582        FORCE = 1 << 0;
583        /// With [`UnitCommandKind::NET_CONFIG`]: use DHCP, ignoring the
584        /// addresses.
585        DHCP = 1 << 1;
586    }
587}
588
589bitmask! {
590    /// The flags of a OneIP device's PTP state.
591    V2ipPtpFlag: u8 {
592        /// The device runs PTP and the block holds its state. A block without
593        /// it holds nothing: the device has no PTP, or is in power save.
594        VALID = 1 << 0;
595        /// The device locked to a master since its PTP started, so its mesh
596        /// holds a time.
597        FOLLOWED = 1 << 1;
598    }
599}
600
601wire_enum! {
602    /// How far a OneIP device's PTP clock has locked to its master.
603    V2ipPtpLock: u8 {
604        /// Not locked.
605        UNLOCKED = 0;
606        /// Locking.
607        LOCKING = 1;
608        /// Locked.
609        LOCKED = 2;
610    }
611}
612
613bitmask! {
614    /// The flags of a OneIP device's VLAN configuration.
615    V2ipVlanFlag: u16 {
616        /// The block carries a configuration. A block without it carries
617        /// nothing, whatever its other bytes hold.
618        VALID = 1 << 0;
619        /// Untagged frames arriving on the uplink are dropped instead of
620        /// reaching the device.
621        TRUNK = 1 << 1;
622        /// Reported by the device: the configuration is applied, and reverted
623        /// unless the mesh controller confirms it. Never written.
624        PENDING = 1 << 2;
625        /// Sent by the mesh controller: a pending configuration it heard, which
626        /// the device then keeps.
627        CONFIRM = 1 << 3;
628        /// Reported by the device: it has an SFP port. Never written.
629        HAS_SFP = 1 << 4;
630    }
631}
632
633impl V2ipDeviceSetting {
634    /// The settings that are on or off, as opposed to carrying a value, and
635    /// that can be written.
636    pub const SWITCHES: Self = Self(
637        0xFF | Self::AES67.0
638            | Self::SAP_LISTEN.0
639            | Self::SAP_ANNOUNCE.0
640            | Self::POWER_SAVE_DISABLED.0
641            | Self::CLOUD.0,
642    );
643
644    /// The settings only a device reports about itself, which no write
645    /// carries.
646    pub const REPORTED_ONLY: Self = Self(Self::IR_PROFILES.0 | Self::CLOCK_SET.0);
647
648    /// The PTP settings.
649    pub const PTP_SETTINGS: Self =
650        Self(Self::PTP_MODE.0 | Self::PTP_DOMAIN.0 | Self::PTP_PRIORITY1.0);
651
652    /// The PTP message settings.
653    pub const PTP_MESSAGES: Self = Self(
654        Self::PTP_ANNOUNCE.0
655            | Self::PTP_SYNC.0
656            | Self::PTP_DELAY_REQ.0
657            | Self::PTP_ANNOUNCE_TIMEOUT.0
658            | Self::PTP_DSCP.0,
659    );
660
661    /// The settings whose values a frame carries in a block of their own
662    /// behind the rest, [`V2ipPtpMessages`](crate::V2ipPtpMessages): the PTP
663    /// message settings, the two SAP values, the stream TTL and the output's
664    /// rotation.
665    pub const SETTINGS_BLOCK: Self = Self(
666        Self::PTP_MESSAGES.0
667            | Self::SAP_EXPIRE.0
668            | Self::SAP_INTERVAL.0
669            | Self::STREAM_TTL.0
670            | Self::SINK_ROTATION.0,
671    );
672
673    /// These bits with every bit of `other` cleared.
674    pub(crate) const fn without(self, other: Self) -> Self {
675        Self(self.0 & !other.0)
676    }
677}
678
679bitmask! {
680    /// Capabilities of a single bay.
681    BayFeatures {
682        /// HDMI output.
683        HDMI_OUT = 1 << 0;
684        /// HDMI input.
685        HDMI_IN = 1 << 1;
686        /// Digital audio output.
687        AUDIO_DIG_OUT = 1 << 2;
688        /// Digital audio input.
689        AUDIO_DIG_IN = 1 << 3;
690        /// Analogue audio output.
691        AUDIO_ANA_OUT = 1 << 4;
692        /// Analogue audio input.
693        AUDIO_ANA_IN = 1 << 5;
694        /// Infrared input.
695        IR_IN = 1 << 6;
696        /// Infrared output.
697        IR_OUT = 1 << 7;
698        /// Amplified audio output.
699        AUDIO_AMP_OUT = 1 << 8;
700        /// Remote-control output.
701        RC_OUT = 1 << 9;
702        /// Remote-control input.
703        RC_IN = 1 << 10;
704        /// Dolby decoding.
705        DOLBY = 1 << 11;
706        /// Switches itself off when idle.
707        AUTO_OFF = 1 << 12;
708        /// Is a remote OneIP source.
709        V2IP_SOURCE_REMOTE = 1 << 13;
710        /// Is a remote OneIP sink.
711        V2IP_SINK_REMOTE = 1 << 14;
712        /// Is a local OneIP source.
713        V2IP_SOURCE_LOCAL = 1 << 15;
714        /// Is a local OneIP sink.
715        V2IP_SINK_LOCAL = 1 << 16;
716    }
717}
718
719bitmask! {
720    /// Live status flags of a single bay.
721    ///
722    /// Bits 16-19 and 22-23 are bit-fields rather than flags; read them with
723    /// [`BayStatus::rc_type`] and [`BayStatus::hdcp`].
724    BayStatus {
725        /// The bay reports a fault.
726        FAULT = 1 << 0;
727        /// The bay is hidden from the user interface.
728        HIDDEN = 1 << 1;
729        /// The amplifier zone the bay drives is powered on.
730        POWERED = 1 << 2;
731        /// A signal is present.
732        SIGNAL_DETECTED = 1 << 3;
733        /// Hot-plug detect is asserted.
734        HPD_DETECTED = 1 << 4;
735        /// The signal is scrambled.
736        SIGNAL_SCRAMBLE = 1 << 5;
737        /// An HDBaseT link is up.
738        HDBT_CONNECTED = 1 << 6;
739        /// A CEC device answered.
740        CEC_DETECTED = 1 << 7;
741        /// The attached device was powered on.
742        POWERED_ON = 1 << 8;
743        /// The attached device was powered off.
744        POWERED_OFF = 1 << 9;
745        /// Audio return over HDMI is active.
746        AUDIO_ARC_HDMI = 1 << 10;
747        /// Audio return over optical is active.
748        AUDIO_ARC_OPTIC = 1 << 11;
749        /// Audio return over analogue is active.
750        AUDIO_ARC_ANALOG = 1 << 12;
751        /// The bay is offline.
752        OFFLINE = 1 << 13;
753        /// The OneIP decoder is disabled.
754        DECODER_DISABLE = 1 << 14;
755        /// The OneIP encoder is disabled.
756        ENCODER_DISABLE = 1 << 15;
757        /// CEC is switched off for this bay.
758        CEC_DISABLED = 1 << 20;
759        /// The OneIP encoder reports an error.
760        ENCODER_ERROR = 1 << 21;
761        /// The bay's name was generated - a default, or taken from CEC or the
762        /// EDID - rather than set by a user. A device that predates this bit
763        /// never sets it, so a clear bit does not prove a user set the name.
764        AUTO_NAME = 1 << 24;
765    }
766}
767
768impl BayStatus {
769    const RC_TYPE_SHIFT: u32 = 16;
770    const RC_TYPE_MASK: u32 = 0xF << Self::RC_TYPE_SHIFT;
771    const HDCP_SHIFT: u32 = 22;
772    const HDCP_MASK: u32 = 0x3 << Self::HDCP_SHIFT;
773
774    /// Extracts the remote-control type carried in bits 16-19.
775    pub const fn rc_type(self) -> RcType {
776        RcType(((self.0 & Self::RC_TYPE_MASK) >> Self::RC_TYPE_SHIFT) as u8)
777    }
778
779    /// Extracts the HDCP version carried in bits 22-23.
780    pub const fn hdcp(self) -> u8 {
781        ((self.0 & Self::HDCP_MASK) >> Self::HDCP_SHIFT) as u8
782    }
783}
784
785bitmask! {
786    /// Media carried by a virtual link.
787    LinkFeature {
788        /// Video over HDMI.
789        VIDEO_HDMI = 1 << 0;
790        /// Audio over optical.
791        AUDIO_OPTICAL = 1 << 1;
792        /// Audio over analogue.
793        AUDIO_ANALOG = 1 << 2;
794        /// Infrared.
795        IR = 1 << 3;
796        /// Remote control.
797        RC = 1 << 4;
798    }
799}
800
801wire_enum! {
802    /// A remote-control action.
803    RcAction: u16 {
804        /// Toggle power.
805        POWER_TOGGLE = 0;
806        /// Power on.
807        POWER_ON = 1;
808        /// Power off.
809        POWER_OFF = 2;
810        /// Volume up.
811        VOLUME_UP = 3;
812        /// Volume down.
813        VOLUME_DOWN = 4;
814        /// Toggle mute.
815        VOLUME_MUTE = 5;
816    }
817}
818
819wire_enum! {
820    /// A remote-control key code (CEC or IR).
821    RcKey: u16 {
822        /// Digit 0.
823        NUM0 = 0;
824        /// Digit 1.
825        NUM1 = 1;
826        /// Digit 2.
827        NUM2 = 2;
828        /// Digit 3.
829        NUM3 = 3;
830        /// Digit 4.
831        NUM4 = 4;
832        /// Digit 5.
833        NUM5 = 5;
834        /// Digit 6.
835        NUM6 = 6;
836        /// Digit 7.
837        NUM7 = 7;
838        /// Digit 8.
839        NUM8 = 8;
840        /// Digit 9.
841        NUM9 = 9;
842        /// Confirm the highlighted item.
843        SELECT = 10;
844        /// Go back one step.
845        BACK = 11;
846        /// Navigate up.
847        UP = 12;
848        /// Navigate down.
849        DOWN = 13;
850        /// Navigate left.
851        LEFT = 14;
852        /// Navigate right.
853        RIGHT = 15;
854        /// Open the main menu.
855        MENU = 16;
856        /// Open the content menu.
857        CONTENT_MENU = 17;
858        /// Next channel.
859        CHANNEL_UP = 18;
860        /// Previous channel.
861        CHANNEL_DOWN = 19;
862        /// Start playback.
863        PLAY = 20;
864        /// Pause playback.
865        PAUSE = 21;
866        /// Stop playback.
867        STOP = 22;
868        /// Start recording.
869        RECORD = 23;
870        /// Fast forward.
871        FAST_FORWARD = 24;
872        /// Rewind.
873        REWIND = 25;
874        /// Red colour key.
875        RED = 26;
876        /// Green colour key.
877        GREEN = 27;
878        /// Yellow colour key.
879        YELLOW = 28;
880        /// Blue colour key.
881        BLUE = 29;
882        /// Open help.
883        HELP = 30;
884        /// Show information.
885        INFORMATION = 31;
886        /// Open teletext.
887        TEXT = 32;
888        /// Open the programme guide.
889        GUIDE = 33;
890        /// Open video on demand.
891        VIDEO_ON_DEMAND = 34;
892        /// Return to the previous channel.
893        PREVIOUS_CHANNEL = 80;
894        /// Toggle 3D mode.
895        MODE_3D = 81;
896        /// Toggle subtitles.
897        SUBTITLE = 82;
898        /// Select an audio track.
899        SOUND_SELECT = 83;
900        /// Select an input.
901        INPUT_SELECT = 84;
902        /// Eject the medium.
903        EJECT = 85;
904        /// Next chapter.
905        NEXT_CHAPTER = 86;
906        /// Previous chapter.
907        PREV_CHAPTER = 87;
908        /// Open interactive services.
909        INTERACTIVE = 128;
910        /// Open search.
911        SEARCH = 129;
912        /// Sky home key.
913        SKY = 130;
914        /// Base of the range carrying a raw CEC user-control code.
915        CUSTOM_CEC = 1280;
916        /// Base of the range carrying a raw Sky key code.
917        CUSTOM_SKY = 2048;
918    }
919}
920
921wire_enum! {
922    /// The remote-control protocol of a connected sink or source.
923    RcType: u8 {
924        /// Infrared.
925        IR = 0;
926        /// HDMI CEC.
927        CEC = 1;
928        /// Sky UK over IP.
929        SKY_UK = 2;
930        /// TiVo.
931        TIVO = 3;
932        /// Kodi.
933        KODI = 4;
934        /// Dish.
935        DISH = 5;
936        /// DirecTV.
937        DIRECTV = 6;
938        /// Another MX Remote device.
939        MX_REMOTE = 7;
940        /// Routed inside the device itself.
941        INTERNAL = 8;
942    }
943}
944
945impl fmt::Display for RcType {
946    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
947        let name = match *self {
948            Self::IR => "IR",
949            Self::CEC => "CEC",
950            Self::SKY_UK => "Sky",
951            Self::TIVO => "TiVo",
952            Self::KODI => "Kodi",
953            Self::DISH => "Dish",
954            Self::DIRECTV => "DirecTV",
955            Self::MX_REMOTE => "MX-Remote",
956            Self::INTERNAL => "Internal",
957            _ => "Unknown",
958        };
959        f.write_str(name)
960    }
961}
962
963wire_enum! {
964    /// An EDID preset selectable on an HDMI input.
965    EdidProfile: u16 {
966        /// 1080p with stereo audio.
967        STEREO_1080P = 0;
968        /// A fixed EDID stored on the device.
969        FIXED = 1;
970        /// 4K.
971        UHD_4K = 2;
972        /// 1080p with 5.1 audio.
973        SURROUND51_1080P = 3;
974        /// 720p.
975        HD_720P = 4;
976        /// 1080p with 7.1 audio.
977        SURROUND71_1080P = 5;
978        /// 4K with 7.1 audio.
979        SURROUND71_4K = 6;
980        /// 4K HDR with stereo audio.
981        HDR_STEREO_4K = 7;
982        /// 4K HDR with 7.1 audio.
983        HDR_SURROUND71_4K = 8;
984        /// 4K HDR, audio to the AVR only.
985        HDR_AVR_ONLY_4K = 9;
986        /// The lowest common denominator of the connected sinks.
987        LOWEST_COMMON = 10;
988        /// The lowest common denominator of every sink, connected or not.
989        LOWEST_COMMON_ALL = 11;
990        /// 4K HDR with Dolby Atmos.
991        HDR_ATMOS_4K = 12;
992        /// Copy the EDID of sink 1; the range runs to [`EdidProfile::SINK_32`].
993        SINK_1 = 101;
994        /// Copy the EDID of sink 32; the range starts at [`EdidProfile::SINK_1`].
995        SINK_32 = 132;
996        /// Base of the range carrying a user-supplied EDID.
997        CUSTOM_0 = 500;
998        /// The device reports no profile.
999        UNKNOWN = 0xFFF;
1000    }
1001}
1002
1003impl fmt::Display for EdidProfile {
1004    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1005        let name = match *self {
1006            Self::STEREO_1080P => "1080p stereo",
1007            Self::FIXED => "fixed",
1008            Self::UHD_4K => "4K",
1009            Self::SURROUND51_1080P => "1080p 5.1",
1010            Self::HD_720P => "720p",
1011            Self::SURROUND71_1080P => "1080p 7.1",
1012            Self::SURROUND71_4K => "4K 7.1",
1013            Self::HDR_STEREO_4K => "4K HDR Stereo",
1014            Self::HDR_SURROUND71_4K => "4K HDR 7.1",
1015            Self::HDR_AVR_ONLY_4K => "4K HDR AVR",
1016            Self::LOWEST_COMMON => "lowest common denominator",
1017            Self::LOWEST_COMMON_ALL => "lowest common denominator (all sinks)",
1018            Self::HDR_ATMOS_4K => "4K HDR Dolby Atmos",
1019            _ => {
1020                if self.0 >= Self::SINK_1.0 && self.0 <= Self::SINK_32.0 {
1021                    return write!(f, "copy from sink #{}", self.0 - Self::SINK_1.0 + 1);
1022                }
1023                return write!(f, "custom #{}", self.0);
1024            }
1025        };
1026        f.write_str(name)
1027    }
1028}
1029
1030wire_enum! {
1031    /// A firmware component.
1032    FirmwareType: u8 {
1033        /// The unit's own firmware.
1034        MCU = 0;
1035        /// The video processor's FPGA image.
1036        FPGA = 1;
1037        /// The video processor's RTOS image.
1038        RTOS = 2;
1039        /// The video processor's loader image.
1040        LOADER = 3;
1041        /// The unit's bootloader.
1042        BOOTLOADER = 4;
1043    }
1044}
1045
1046impl fmt::Display for FirmwareType {
1047    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1048        let name = match *self {
1049            Self::MCU => "MCU",
1050            Self::FPGA => "FPGA",
1051            Self::RTOS => "RTOS",
1052            Self::LOADER => "Loader",
1053            Self::BOOTLOADER => "Bootloader",
1054            _ => return write!(f, "firmware #{}", self.0),
1055        };
1056        f.write_str(name)
1057    }
1058}
1059
1060wire_enum! {
1061    /// The negotiated speed of a network port.
1062    UtpLinkSpeed: u8 {
1063        /// The device reports no speed.
1064        UNKNOWN = 0;
1065        /// 10Mbit/s.
1066        SPEED_10M = 1;
1067        /// 100Mbit/s.
1068        SPEED_100M = 2;
1069        /// 200Mbit/s.
1070        SPEED_200M = 3;
1071        /// 1Gbit/s.
1072        SPEED_1G = 4;
1073    }
1074}
1075
1076impl fmt::Display for UtpLinkSpeed {
1077    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1078        let name = match *self {
1079            Self::SPEED_10M => "10Mbit/s",
1080            Self::SPEED_100M => "100Mbit/s",
1081            Self::SPEED_200M => "200Mbit/s",
1082            Self::SPEED_1G => "1Gbit/s",
1083            _ => "Unknown",
1084        };
1085        f.write_str(name)
1086    }
1087}
1088
1089wire_enum! {
1090    /// The window layout of a multiviewer.
1091    MultiviewerViewMode: u8 {
1092        /// The device reports no layout.
1093        UNKNOWN = 0;
1094        /// One full-screen window.
1095        SINGLE = 1;
1096        /// Picture in picture.
1097        PIP = 2;
1098        /// Two windows, large.
1099        TWO_SCREEN_LARGE = 3;
1100        /// Two windows, small.
1101        TWO_SCREEN_SMALL = 4;
1102        /// Three windows, large.
1103        THREE_SCREEN_LARGE = 5;
1104        /// Three windows, small.
1105        THREE_SCREEN_SMALL = 6;
1106        /// Four windows, equal size.
1107        FOUR_SCREEN_EQUAL = 7;
1108        /// Four windows, small.
1109        FOUR_SCREEN_SMALL = 8;
1110    }
1111}
1112
1113wire_enum! {
1114    /// The corner a multiviewer places its picture-in-picture window in.
1115    MultiviewerPipPosition: u8 {
1116        /// The device reports no position.
1117        UNKNOWN = 0;
1118        /// Top left.
1119        LEFT_TOP = 1;
1120        /// Bottom left.
1121        LEFT_BOTTOM = 2;
1122        /// Top right.
1123        RIGHT_TOP = 3;
1124        /// Bottom right.
1125        RIGHT_BOTTOM = 4;
1126    }
1127}
1128
1129wire_enum! {
1130    /// The size of a multiviewer's picture-in-picture window.
1131    MultiviewerPipSize: u8 {
1132        /// The device reports no size.
1133        UNKNOWN = 0;
1134        /// Small.
1135        SMALL = 1;
1136        /// Medium.
1137        MEDIUM = 2;
1138        /// Large.
1139        LARGE = 3;
1140    }
1141}
1142
1143wire_enum! {
1144    /// The resolution and refresh rate a multiviewer drives its output at.
1145    MultiviewerOutputMode: u8 {
1146        /// The device reports no output mode.
1147        UNKNOWN = 0;
1148        /// 4096x2160p60.
1149        DCI4K_P60 = 1;
1150        /// 4096x2160p50.
1151        DCI4K_P50 = 2;
1152        /// 3840x2160p60.
1153        UHD_P60 = 3;
1154        /// 3840x2160p50.
1155        UHD_P50 = 4;
1156        /// 3840x2160p30.
1157        UHD_P30 = 5;
1158        /// 3840x2160p25.
1159        UHD_P25 = 6;
1160        /// 1920x1200p60, reduced blanking.
1161        WUXGA_P60_RB = 7;
1162        /// 1920x1080p60.
1163        HD1080_P60 = 8;
1164        /// 1920x1080p50.
1165        HD1080_P50 = 9;
1166        /// 1360x768p60.
1167        WXGA_P60 = 10;
1168        /// 1280x800p60.
1169        WXGA800_P60 = 11;
1170        /// 1280x720p60.
1171        HD720_P60 = 12;
1172        /// 1280x720p50.
1173        HD720_P50 = 13;
1174        /// 1024x768p60.
1175        XGA_P60 = 14;
1176    }
1177}
1178
1179wire_enum! {
1180    /// The HDCP version a multiviewer output negotiates.
1181    MultiviewerHdcpMode: u8 {
1182        /// The device reports no HDCP mode.
1183        UNKNOWN = 0;
1184        /// HDCP 1.4.
1185        V14 = 1;
1186        /// HDCP 2.2.
1187        V22 = 2;
1188        /// Content protection off.
1189        OFF = 3;
1190    }
1191}
1192
1193wire_enum! {
1194    /// The IT-content flag a multiviewer sets on its output.
1195    MultiviewerItcMode: u8 {
1196        /// The device reports no IT-content mode.
1197        UNKNOWN = 0;
1198        /// Video content.
1199        VIDEO = 1;
1200        /// PC content.
1201        PC = 2;
1202    }
1203}
1204
1205wire_enum! {
1206    /// The EDID template a multiviewer presents to its sources.
1207    ///
1208    /// A template's name is the largest resolution it advertises and the audio
1209    /// format it declares support for.
1210    MultiviewerEdidTemplate: u8 {
1211        /// The device reports no template.
1212        EDID_UNKNOWN = 0;
1213        /// 4K2K60 4:4:4, stereo 2.0.
1214        EDID_4K2K60_444_STEREO = 1;
1215        /// 4K2K60 4:4:4, Dolby/DTS 5.1.
1216        EDID_4K2K60_444_DOLBY_DTS_51 = 2;
1217        /// 4K2K60 4:4:4, HD audio 7.1.
1218        EDID_4K2K60_444_HD_AUDIO_71 = 3;
1219        /// 4K2K30 4:4:4, stereo 2.0.
1220        EDID_4K2K30_444_STEREO = 4;
1221        /// 4K2K30 4:4:4, Dolby/DTS 5.1.
1222        EDID_4K2K30_444_DOLBY_DTS_51 = 5;
1223        /// 4K2K30 4:4:4, HD audio 7.1.
1224        EDID_4K2K30_444_HD_AUDIO_71 = 6;
1225        /// 1080p, stereo 2.0.
1226        EDID_1080P_STEREO = 7;
1227        /// 1080p, Dolby/DTS 5.1.
1228        EDID_1080P_DOLBY_DTS_51 = 8;
1229        /// 1080p, HD audio 7.1.
1230        EDID_1080P_HD_AUDIO_71 = 9;
1231        /// 1920x1200, stereo 2.0.
1232        EDID_1920X1200_STEREO = 10;
1233        /// 1680x1050, stereo 2.0.
1234        EDID_1680X1050_STEREO = 11;
1235        /// 1600x1200, stereo 2.0.
1236        EDID_1600X1200_STEREO = 12;
1237        /// 1440x900, stereo 2.0.
1238        EDID_1440X900_STEREO = 13;
1239        /// 1360x768, stereo 2.0.
1240        EDID_1360X768_STEREO = 14;
1241        /// 1280x1024, stereo 2.0.
1242        EDID_1280X1024_STEREO = 15;
1243        /// 1024x768, stereo 2.0.
1244        EDID_1024X768_STEREO = 16;
1245        /// 720p, stereo 2.0.
1246        EDID_720P_STEREO = 17;
1247        /// Whatever the display connected to the HDMI output presents. The
1248        /// template a multiviewer leaves the factory with.
1249        EDID_COPY_OUTPUT = 18;
1250        /// The EDID loaded onto the device.
1251        EDID_CUSTOM = 19;
1252    }
1253}
1254
1255wire_enum! {
1256    /// The aspect ratio a multiviewer scales its windows to.
1257    MultiviewerAspectRatio: u8 {
1258        /// The device reports no aspect ratio.
1259        UNKNOWN = 0;
1260        /// Fill the window.
1261        FULL = 1;
1262        /// 16:9.
1263        RATIO_16_9 = 2;
1264    }
1265}
1266
1267wire_enum! {
1268    /// A multiviewer setting that is on, off, or not reported.
1269    MultiviewerBool: u8 {
1270        /// Off.
1271        OFF = 0;
1272        /// On.
1273        ON = 1;
1274        /// The device reports no value.
1275        UNKNOWN = 0xFF;
1276    }
1277}
1278
1279wire_enum! {
1280    /// One of a multiviewer's four inputs.
1281    ///
1282    /// The wire numbers the inputs from zero and this type from one, so that
1283    /// zero can mean "not reported" the way it does for every other
1284    /// multiviewer setting. So `to_wire` and `from_wire` carry this type's
1285    /// numbering rather than the wire's, and neither is the conversion to
1286    /// reach for when a raw multiviewer byte is what is in hand.
1287    MultiviewerSource: u8 {
1288        /// The device reports no source.
1289        UNKNOWN = 0;
1290        /// Input 1.
1291        INPUT_1 = 1;
1292        /// Input 2.
1293        INPUT_2 = 2;
1294        /// Input 3.
1295        INPUT_3 = 3;
1296        /// Input 4.
1297        INPUT_4 = 4;
1298    }
1299}
1300
1301impl MultiviewerSource {
1302    /// Reads a zero-based wire value, mapping anything past input 4 to
1303    /// [`MultiviewerSource::UNKNOWN`].
1304    ///
1305    /// The firmware spells "not known" as 0xFF, which lands past input 4 and
1306    /// so needs no case of its own.
1307    pub(crate) const fn from_zero_based(value: u8) -> Self {
1308        if value > 3 {
1309            Self::UNKNOWN
1310        } else {
1311            Self(value + 1)
1312        }
1313    }
1314
1315    /// The zero-based value the wire carries, or `None` for a source naming no
1316    /// input.
1317    ///
1318    /// A multiviewer reads zero as its first input, so there is no value that
1319    /// says "leave this alone": a request that cannot name an input has to be
1320    /// refused rather than sent.
1321    pub(crate) const fn to_zero_based(self) -> Option<u8> {
1322        match self.0 {
1323            1..=4 => Some(self.0 - 1),
1324            _ => None,
1325        }
1326    }
1327}
1328
1329impl MultiviewerBool {
1330    /// Reads a wire value, mapping anything but 0 and 1 to
1331    /// [`MultiviewerBool::UNKNOWN`].
1332    pub(crate) const fn from_wire_tristate(value: u8) -> Self {
1333        if value > 1 {
1334            Self::UNKNOWN
1335        } else {
1336            Self(value)
1337        }
1338    }
1339}
1340
1341wire_enum! {
1342    /// The colour space a OneIP output scales to.
1343    ///
1344    /// The field is four bits wide and only these four values are defined. A
1345    /// receiver passes the whole nibble to its validator, so a fifth value is
1346    /// dropped without a word rather than clamped to one of these.
1347    V2ipColourSpace: u8 {
1348        /// RGB.
1349        RGB = 0;
1350        /// YCbCr 4:4:4.
1351        YCBCR444 = 1;
1352        /// YCbCr 4:2:2.
1353        YCBCR422 = 2;
1354        /// YCbCr 4:2:0.
1355        YCBCR420 = 3;
1356    }
1357}
1358
1359wire_enum! {
1360    /// The 2-byte `mxr_signal_type` carried in scaling configs and bay signal
1361    /// reports.
1362    ///
1363    /// Byte 0 is the CTA-861 short video descriptor, 0 when the signal is not
1364    /// HDMI. Byte 1 packs `color:4` in the low nibble, then `non_int:1` and
1365    /// `bpp:3` above it.
1366    MxrSignalType: u16 {
1367        /// No signal format was reported.
1368        NONE = 0;
1369    }
1370}
1371
1372/// The bpp index a sender writes when it has no bit depth to report.
1373///
1374/// It sits outside the four indices that name a real depth, so an unset
1375/// format reads differently from every genuine one.
1376const SIG_BPP_UNSET: u16 = 5;
1377
1378impl MxrSignalType {
1379    /// The CTA-861 short video descriptor, 0 when the signal is not HDMI.
1380    pub const fn svd(self) -> u8 {
1381        (self.0 & 0xFF) as u8
1382    }
1383
1384    /// The colour space.
1385    pub const fn colour_space(self) -> u8 {
1386        ((self.0 >> 8) & 0xF) as u8
1387    }
1388
1389    /// Whether the frame rate carries a 1000/1001 clock.
1390    pub const fn is_non_integer(self) -> bool {
1391        self.0 & (1 << 12) != 0
1392    }
1393
1394    /// The raw bpp index as carried on the wire. The field is an index, not a
1395    /// bit depth; [`MxrSignalType::bpp`] converts it.
1396    pub const fn bpp_index(self) -> u8 {
1397        ((self.0 >> 13) & 0x7) as u8
1398    }
1399
1400    /// The bit depth the bpp index stands for, `None` when unknown or unset.
1401    pub const fn bpp(self) -> Option<u8> {
1402        match self.bpp_index() {
1403            1 => Some(8),
1404            2 => Some(10),
1405            3 => Some(12),
1406            4 => Some(16),
1407            _ => None,
1408        }
1409    }
1410
1411    /// Reports whether the word carries a signal format at all.
1412    ///
1413    /// A bay with nothing configured says so two ways. A sender that zeroes
1414    /// the word and stamps the unset bpp index leaves an index no real depth
1415    /// uses, and one that writes a plain zero leaves nothing at all. Neither
1416    /// is a format, and the svd and colour space beside them are not answers
1417    /// either: both read as zero, which is what this word says for "not HDMI"
1418    /// and "RGB" when it *is* set.
1419    pub const fn is_set(self) -> bool {
1420        self.0 != 0 && self.bpp_index() as u16 != SIG_BPP_UNSET
1421    }
1422
1423    /// Builds the word from the fields a scaling write consumes.
1424    ///
1425    /// `non_int` is left clear: the receiving struct carries the bit, and the
1426    /// apply path does not read it.
1427    ///
1428    /// Building rather than editing is the point. A sink with no mode
1429    /// configured reports the word with the unset bpp index in it, so a caller
1430    /// that read that word back and filled in an svd would send an index no
1431    /// depth uses - which the receiver decodes to zero and rejects without
1432    /// answering.
1433    pub(crate) const fn from_parts(svd: u8, colour: u8, bpp_index: u8) -> Self {
1434        Self((svd as u16) | (((colour & 0xF) as u16) << 8) | (((bpp_index & 0x7) as u16) << 13))
1435    }
1436
1437    /// The bpp index that stands for a bit depth, `None` for a depth no index
1438    /// names.
1439    ///
1440    /// Only the three depths a OneIP output stage accepts are here. Index 4
1441    /// names 16bpp, which [`MxrSignalType::bpp`] reads back from a device, but
1442    /// the output stage refuses it - so offering it as something to write would
1443    /// send a frame that is decoded cleanly and then dropped in silence.
1444    pub(crate) const fn bpp_index_for_depth(depth: u8) -> Option<u8> {
1445        match depth {
1446            8 => Some(1),
1447            10 => Some(2),
1448            12 => Some(3),
1449            _ => None,
1450        }
1451    }
1452}
1453
1454impl fmt::Display for MxrSignalType {
1455    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1456        if !self.is_set() {
1457            return f.write_str("unset");
1458        }
1459        match self.bpp() {
1460            Some(bpp) => write!(
1461                f,
1462                "svd {}, color {}, {}bpp",
1463                self.svd(),
1464                self.colour_space(),
1465                bpp
1466            ),
1467            None => write!(f, "svd {}, color {}", self.svd(), self.colour_space()),
1468        }
1469    }
1470}
1471
1472bitmask! {
1473    /// The kinds of overlay setting an overlay sync copies.
1474    OsdSyncWhat: u8 {
1475        /// Captions.
1476        CAPTIONS = 1 << 0;
1477        /// Which logo is shown, and where.
1478        LOGO = 1 << 1;
1479        /// Background colours.
1480        BACKGROUNDS = 1 << 2;
1481        /// The logo images in the four slots.
1482        LOGO_SLOTS = 1 << 3;
1483    }
1484}
1485
1486bitmask! {
1487    /// What a unit says of the message on its output.
1488    OsdMessageFlag: u8 {
1489        /// A message is set. In a write: show it, rather than take it down.
1490        SET = 1 << 0;
1491        /// The output shows it, rather than another message ahead of it.
1492        SHOWN = 1 << 1;
1493        /// The unit's video processor composes the message layer.
1494        SUPPORTED = 1 << 2;
1495        /// The unit did not take the write it answers, and reports the
1496        /// message it kept.
1497        REFUSED = 1 << 3;
1498    }
1499}
1500
1501wire_enum! {
1502    /// Where a message stands against the unit's own messages: its upgrade,
1503    /// Locate Device and encrypted source messages.
1504    OsdMessagePriority: u8 {
1505        /// After them.
1506        LOW = 0;
1507        /// Between them.
1508        NORMAL = 1;
1509        /// Before them.
1510        TOP = 2;
1511    }
1512}
1513
1514wire_enum! {
1515    /// How far a unit has got with taking an overlay sync.
1516    OsdSyncState: u8 {
1517        /// Taking it.
1518        TAKING = 0;
1519        /// Every setting written and committed.
1520        DONE = 1;
1521        /// Failed, for the reason the report gives.
1522        FAILED = 2;
1523        /// Kept for later, as the unit's video processor is off in power
1524        /// save.
1525        DEFERRED = 3;
1526    }
1527}
1528
1529wire_enum! {
1530    /// The output size an overlay setting applies at.
1531    OsdSyncSize: u8 {
1532        /// Large outputs, which every value but `SMALL` also means.
1533        LARGE = 1;
1534        /// Small outputs.
1535        SMALL = 2;
1536    }
1537}
1538
1539wire_enum! {
1540    /// How a caption's lines are aligned.
1541    OsdCaptionAlign: u8 {
1542        /// To the left.
1543        LEFT = 0;
1544        /// Centred.
1545        CENTRE = 1;
1546        /// To the right.
1547        RIGHT = 2;
1548        /// The layout's default.
1549        DEFAULT = 0xFF;
1550    }
1551}
1552
1553wire_enum! {
1554    /// How a caption's text is read.
1555    OsdCaptionFormat: u8 {
1556        /// As plain text.
1557        PLAIN = 0;
1558        /// As Markdown.
1559        MARKDOWN = 1;
1560        /// The layout's default.
1561        DEFAULT = 0xFF;
1562    }
1563}
1564
1565bitmask! {
1566    /// The caption fields an overlay setting gives. A field left out keeps
1567    /// what the unit has.
1568    OsdCaptionField: u16 {
1569        /// The font.
1570        FONT = 1 << 0;
1571        /// The size.
1572        SIZE = 1 << 1;
1573        /// The horizontal position.
1574        X = 1 << 2;
1575        /// The vertical position.
1576        Y = 1 << 3;
1577        /// The alignment.
1578        ALIGN = 1 << 4;
1579        /// The format.
1580        FORMAT = 1 << 5;
1581        /// The colour.
1582        COLOUR = 1 << 6;
1583        /// The wrap width.
1584        WRAP = 1 << 7;
1585        /// The text.
1586        TEXT = 1 << 8;
1587    }
1588}
1589
1590bitmask! {
1591    /// The logo fields an overlay setting gives. A field left out keeps what
1592    /// the unit has.
1593    OsdLogoField: u16 {
1594        /// Which logo.
1595        LOGO = 1 << 0;
1596        /// The horizontal position.
1597        X = 1 << 1;
1598        /// The vertical position.
1599        Y = 1 << 2;
1600    }
1601}